summaryrefslogtreecommitdiff
path: root/Applications/SystemMonitor
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-04 19:07:55 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-04 21:04:06 +0100
commit028c011760b5b665fc2a72bb3c11fd3a6ca60d2c (patch)
treea961293992de78ebac5c3ffec864179d661dcc09 /Applications/SystemMonitor
parentfb09b6a8cec02cc473b3fed326d99055d80a60ba (diff)
downloadserenity-028c011760b5b665fc2a72bb3c11fd3a6ca60d2c.zip
LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can simply vend a ChildType&. This allows us to use "." instead of "->" at the call site, which is quite nice. :^)
Diffstat (limited to 'Applications/SystemMonitor')
-rw-r--r--Applications/SystemMonitor/MemoryStatsWidget.cpp18
-rw-r--r--Applications/SystemMonitor/NetworkStatisticsWidget.cpp24
-rw-r--r--Applications/SystemMonitor/main.cpp134
3 files changed, 88 insertions, 88 deletions
diff --git a/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Applications/SystemMonitor/MemoryStatsWidget.cpp
index 1aee3ab448..c9ebacc268 100644
--- a/Applications/SystemMonitor/MemoryStatsWidget.cpp
+++ b/Applications/SystemMonitor/MemoryStatsWidget.cpp
@@ -57,15 +57,15 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph)
layout()->set_spacing(3);
auto build_widgets_for_label = [this](const String& description) -> RefPtr<GUI::Label> {
- auto container = add<GUI::Widget>();
- container->set_layout<GUI::HorizontalBoxLayout>();
- container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
- container->set_preferred_size(275, 12);
- auto description_label = container->add<GUI::Label>(description);
- description_label->set_font(Gfx::Font::default_bold_font());
- description_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
- auto label = container->add<GUI::Label>();
- label->set_text_alignment(Gfx::TextAlignment::CenterRight);
+ auto& container = add<GUI::Widget>();
+ container.set_layout<GUI::HorizontalBoxLayout>();
+ container.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
+ container.set_preferred_size(275, 12);
+ auto& description_label = container.add<GUI::Label>(description);
+ description_label.set_font(Gfx::Font::default_bold_font());
+ description_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
+ auto& label = container.add<GUI::Label>();
+ label.set_text_alignment(Gfx::TextAlignment::CenterRight);
return label;
};
diff --git a/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Applications/SystemMonitor/NetworkStatisticsWidget.cpp
index c6c7f8fd39..b5abb54702 100644
--- a/Applications/SystemMonitor/NetworkStatisticsWidget.cpp
+++ b/Applications/SystemMonitor/NetworkStatisticsWidget.cpp
@@ -37,13 +37,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
layout()->set_margins({ 4, 4, 4, 4 });
set_fill_with_background_color(true);
- auto adapters_group_box = add<GUI::GroupBox>("Adapters");
- adapters_group_box->set_layout<GUI::VerticalBoxLayout>();
- adapters_group_box->layout()->set_margins({ 6, 16, 6, 6 });
- adapters_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
- adapters_group_box->set_preferred_size(0, 120);
+ auto& adapters_group_box = add<GUI::GroupBox>("Adapters");
+ adapters_group_box.set_layout<GUI::VerticalBoxLayout>();
+ adapters_group_box.layout()->set_margins({ 6, 16, 6, 6 });
+ adapters_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
+ adapters_group_box.set_preferred_size(0, 120);
- m_adapter_table_view = adapters_group_box->add<GUI::TableView>();
+ m_adapter_table_view = adapters_group_box.add<GUI::TableView>();
m_adapter_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> net_adapters_fields;
@@ -57,13 +57,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight);
m_adapter_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/adapters", move(net_adapters_fields)));
- auto sockets_group_box = add<GUI::GroupBox>("Sockets");
- sockets_group_box->set_layout<GUI::VerticalBoxLayout>();
- sockets_group_box->layout()->set_margins({ 6, 16, 6, 6 });
- sockets_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
- sockets_group_box->set_preferred_size(0, 0);
+ auto& sockets_group_box = add<GUI::GroupBox>("Sockets");
+ sockets_group_box.set_layout<GUI::VerticalBoxLayout>();
+ sockets_group_box.layout()->set_margins({ 6, 16, 6, 6 });
+ sockets_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
+ sockets_group_box.set_preferred_size(0, 0);
- m_socket_table_view = sockets_group_box->add<GUI::TableView>();
+ m_socket_table_view = sockets_group_box.add<GUI::TableView>();
m_socket_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> net_tcp_fields;
diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp
index 6965f5c49e..da4869d70e 100644
--- a/Applications/SystemMonitor/main.cpp
+++ b/Applications/SystemMonitor/main.cpp
@@ -120,59 +120,59 @@ int main(int argc, char** argv)
keeper.set_fill_with_background_color(true);
keeper.layout()->set_margins({ 4, 4, 4, 4 });
- auto tabwidget = keeper.add<GUI::TabWidget>();
+ auto& tabwidget = keeper.add<GUI::TabWidget>();
- auto process_container_splitter = tabwidget->add_tab<GUI::VerticalSplitter>("Processes");
+ auto process_container_splitter = tabwidget.add_tab<GUI::VerticalSplitter>("Processes");
- auto process_table_container = process_container_splitter->add<GUI::Widget>();
+ auto& process_table_container = process_container_splitter->add<GUI::Widget>();
- tabwidget->add_widget("Graphs", build_graphs_tab());
+ tabwidget.add_widget("Graphs", build_graphs_tab());
- tabwidget->add_widget("File systems", build_file_systems_tab());
+ tabwidget.add_widget("File systems", build_file_systems_tab());
- tabwidget->add_widget("PCI devices", build_pci_devices_tab());
+ tabwidget.add_widget("PCI devices", build_pci_devices_tab());
- tabwidget->add_widget("Devices", build_devices_tab());
+ tabwidget.add_widget("Devices", build_devices_tab());
auto network_stats_widget = NetworkStatisticsWidget::construct();
- tabwidget->add_widget("Network", network_stats_widget);
+ tabwidget.add_widget("Network", network_stats_widget);
- process_table_container->set_layout<GUI::VerticalBoxLayout>();
- process_table_container->layout()->set_margins({ 4, 0, 4, 0 });
- process_table_container->layout()->set_spacing(0);
+ process_table_container.set_layout<GUI::VerticalBoxLayout>();
+ process_table_container.layout()->set_margins({ 4, 0, 4, 0 });
+ process_table_container.layout()->set_spacing(0);
- auto toolbar = process_table_container->add<GUI::ToolBar>();
- toolbar->set_has_frame(false);
- auto process_table_view = process_table_container->add<ProcessTableView>();
+ auto& toolbar = process_table_container.add<GUI::ToolBar>();
+ toolbar.set_has_frame(false);
+ auto& process_table_view = process_table_container.add<ProcessTableView>();
- auto refresh_timer = window->add<Core::Timer>(
+ auto& refresh_timer = window->add<Core::Timer>(
1000, [&] {
- process_table_view->refresh();
+ process_table_view.refresh();
if (auto* memory_stats_widget = MemoryStatsWidget::the())
memory_stats_widget->refresh();
});
- auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GUI::Action&) {
- pid_t pid = process_table_view->selected_pid();
+ auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&process_table_view](const GUI::Action&) {
+ pid_t pid = process_table_view.selected_pid();
if (pid != -1)
kill(pid, SIGKILL);
});
- auto stop_action = GUI::Action::create("Stop process", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/stop16.png"), [process_table_view](const GUI::Action&) {
- pid_t pid = process_table_view->selected_pid();
+ auto stop_action = GUI::Action::create("Stop process", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/stop16.png"), [&process_table_view](const GUI::Action&) {
+ pid_t pid = process_table_view.selected_pid();
if (pid != -1)
kill(pid, SIGSTOP);
});
- auto continue_action = GUI::Action::create("Continue process", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/continue16.png"), [process_table_view](const GUI::Action&) {
- pid_t pid = process_table_view->selected_pid();
+ auto continue_action = GUI::Action::create("Continue process", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/continue16.png"), [&process_table_view](const GUI::Action&) {
+ pid_t pid = process_table_view.selected_pid();
if (pid != -1)
kill(pid, SIGCONT);
});
- toolbar->add_action(kill_action);
- toolbar->add_action(stop_action);
- toolbar->add_action(continue_action);
+ toolbar.add_action(kill_action);
+ toolbar.add_action(stop_action);
+ toolbar.add_action(continue_action);
auto menubar = make<GUI::MenuBar>();
auto app_menu = GUI::Menu::construct("System Monitor");
@@ -192,7 +192,7 @@ int main(int argc, char** argv)
process_context_menu->add_action(kill_action);
process_context_menu->add_action(stop_action);
process_context_menu->add_action(continue_action);
- process_table_view->on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
+ process_table_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
(void)index;
process_context_menu->popup(event.screen_position());
};
@@ -203,7 +203,7 @@ int main(int argc, char** argv)
auto make_frequency_action = [&](auto& title, int interval, bool checked = false) {
auto action = GUI::Action::create(title, [&refresh_timer, interval](auto& action) {
- refresh_timer->restart(interval);
+ refresh_timer.restart(interval);
action.set_checked(true);
});
action->set_checkable(true);
@@ -228,14 +228,14 @@ int main(int argc, char** argv)
app.set_menubar(move(menubar));
- auto process_tab_widget = process_container_splitter->add<GUI::TabWidget>();
+ auto& process_tab_widget = process_container_splitter->add<GUI::TabWidget>();
- auto memory_map_widget = process_tab_widget->add_tab<ProcessMemoryMapWidget>("Memory map");
- auto open_files_widget = process_tab_widget->add_tab<ProcessFileDescriptorMapWidget>("Open files");
- auto unveiled_paths_widget = process_tab_widget->add_tab<ProcessUnveiledPathsWidget>("Unveiled paths");
- auto stacks_widget = process_tab_widget->add_tab<ProcessStacksWidget>("Stacks");
+ auto memory_map_widget = process_tab_widget.add_tab<ProcessMemoryMapWidget>("Memory map");
+ auto open_files_widget = process_tab_widget.add_tab<ProcessFileDescriptorMapWidget>("Open files");
+ auto unveiled_paths_widget = process_tab_widget.add_tab<ProcessUnveiledPathsWidget>("Unveiled paths");
+ auto stacks_widget = process_tab_widget.add_tab<ProcessStacksWidget>("Stacks");
- process_table_view->on_process_selected = [&](pid_t pid) {
+ process_table_view.on_process_selected = [&](pid_t pid) {
open_files_widget->set_pid(pid);
stacks_widget->set_pid(pid);
memory_map_widget->set_pid(pid);
@@ -274,8 +274,8 @@ NonnullRefPtr<GUI::Widget> build_file_systems_tab()
fs_widget->on_first_show = [](GUI::LazyWidget& self) {
self.set_layout<GUI::VerticalBoxLayout>();
self.layout()->set_margins({ 4, 4, 4, 4 });
- auto fs_table_view = self.add<GUI::TableView>();
- fs_table_view->set_size_columns_to_fit_content(true);
+ auto& fs_table_view = self.add<GUI::TableView>();
+ fs_table_view.set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> df_fields;
df_fields.empend("mount_point", "Mount point", Gfx::TextAlignment::CenterLeft);
@@ -351,11 +351,11 @@ NonnullRefPtr<GUI::Widget> build_file_systems_tab()
df_fields.empend("free_inode_count", "Free inodes", Gfx::TextAlignment::CenterRight);
df_fields.empend("total_inode_count", "Total inodes", Gfx::TextAlignment::CenterRight);
df_fields.empend("block_size", "Block size", Gfx::TextAlignment::CenterRight);
- fs_table_view->set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/df", move(df_fields))));
+ fs_table_view.set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/df", move(df_fields))));
- fs_table_view->set_cell_painting_delegate(3, make<ProgressBarPaintingDelegate>());
+ fs_table_view.set_cell_painting_delegate(3, make<ProgressBarPaintingDelegate>());
- fs_table_view->model()->update();
+ fs_table_view.model()->update();
};
return fs_widget;
}
@@ -367,8 +367,8 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab()
pci_widget->on_first_show = [](GUI::LazyWidget& self) {
self.set_layout<GUI::VerticalBoxLayout>();
self.layout()->set_margins({ 4, 4, 4, 4 });
- auto pci_table_view = self.add<GUI::TableView>();
- pci_table_view->set_size_columns_to_fit_content(true);
+ auto& pci_table_view = self.add<GUI::TableView>();
+ pci_table_view.set_size_columns_to_fit_content(true);
auto db = PCIDB::Database::open();
@@ -411,8 +411,8 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab()
return String::format("%02x", revision_id);
});
- pci_table_view->set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields))));
- pci_table_view->model()->update();
+ pci_table_view.set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields))));
+ pci_table_view.model()->update();
};
return pci_widget;
@@ -426,10 +426,10 @@ NonnullRefPtr<GUI::Widget> build_devices_tab()
self.set_layout<GUI::VerticalBoxLayout>();
self.layout()->set_margins({ 4, 4, 4, 4 });
- auto devices_table_view = self.add<GUI::TableView>();
- devices_table_view->set_size_columns_to_fit_content(true);
- devices_table_view->set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
- devices_table_view->model()->update();
+ auto& devices_table_view = self.add<GUI::TableView>();
+ devices_table_view.set_size_columns_to_fit_content(true);
+ devices_table_view.set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
+ devices_table_view.model()->update();
};
return devices_widget;
@@ -445,36 +445,36 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
self.set_layout<GUI::VerticalBoxLayout>();
self.layout()->set_margins({ 4, 4, 4, 4 });
- auto cpu_graph_group_box = self.add<GUI::GroupBox>("CPU usage");
- cpu_graph_group_box->set_layout<GUI::VerticalBoxLayout>();
- cpu_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
- cpu_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
- cpu_graph_group_box->set_preferred_size(0, 120);
- auto cpu_graph = cpu_graph_group_box->add<GraphWidget>();
- cpu_graph->set_max(100);
- cpu_graph->set_text_color(Color::Green);
- cpu_graph->set_graph_color(Color::from_rgb(0x00bb00));
- cpu_graph->text_formatter = [](int value, int) {
+ auto& cpu_graph_group_box = self.add<GUI::GroupBox>("CPU usage");
+ cpu_graph_group_box.set_layout<GUI::VerticalBoxLayout>();
+ cpu_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 });
+ cpu_graph_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
+ cpu_graph_group_box.set_preferred_size(0, 120);
+ auto& cpu_graph = cpu_graph_group_box.add<GraphWidget>();
+ cpu_graph.set_max(100);
+ cpu_graph.set_text_color(Color::Green);
+ cpu_graph.set_graph_color(Color::from_rgb(0x00bb00));
+ cpu_graph.text_formatter = [](int value, int) {
return String::format("%d%%", value);
};
- ProcessModel::the().on_new_cpu_data_point = [graph = cpu_graph.ptr()](float cpu_percent) {
+ ProcessModel::the().on_new_cpu_data_point = [graph = &cpu_graph](float cpu_percent) {
graph->add_value(cpu_percent);
};
- auto memory_graph_group_box = self.add<GUI::GroupBox>("Memory usage");
- memory_graph_group_box->set_layout<GUI::VerticalBoxLayout>();
- memory_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
- memory_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
- memory_graph_group_box->set_preferred_size(0, 120);
- auto memory_graph = memory_graph_group_box->add<GraphWidget>();
- memory_graph->set_text_color(Color::Cyan);
- memory_graph->set_graph_color(Color::from_rgb(0x00bbbb));
- memory_graph->text_formatter = [](int value, int max) {
+ auto& memory_graph_group_box = self.add<GUI::GroupBox>("Memory usage");
+ memory_graph_group_box.set_layout<GUI::VerticalBoxLayout>();
+ memory_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 });
+ memory_graph_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
+ memory_graph_group_box.set_preferred_size(0, 120);
+ auto& memory_graph = memory_graph_group_box.add<GraphWidget>();
+ memory_graph.set_text_color(Color::Cyan);
+ memory_graph.set_graph_color(Color::from_rgb(0x00bbbb));
+ memory_graph.text_formatter = [](int value, int max) {
return String::format("%d / %d KB", value, max);
};
- auto memory_stats_widget = self.add<MemoryStatsWidget>(*memory_graph);
+ self.add<MemoryStatsWidget>(memory_graph);
};
return graphs_container;
}