diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-23 10:57:42 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-23 11:10:52 +0100 |
commit | 3d20da9ee451460b6e233f5efdf5a13e11525f97 (patch) | |
tree | 524b72d0874304c68036dbbc0514b632a4a08c59 /Applications/SystemMonitor | |
parent | 7ec758773cdd85755d91f52614f361e7e750c7e9 (diff) | |
download | serenity-3d20da9ee451460b6e233f5efdf5a13e11525f97.zip |
Userspace: Use Core::Object::add() when building interfaces
Diffstat (limited to 'Applications/SystemMonitor')
-rw-r--r-- | Applications/SystemMonitor/GraphWidget.cpp | 3 | ||||
-rw-r--r-- | Applications/SystemMonitor/GraphWidget.h | 2 | ||||
-rw-r--r-- | Applications/SystemMonitor/MemoryStatsWidget.cpp | 11 | ||||
-rw-r--r-- | Applications/SystemMonitor/MemoryStatsWidget.h | 2 | ||||
-rw-r--r-- | Applications/SystemMonitor/NetworkStatisticsWidget.cpp | 13 | ||||
-rw-r--r-- | Applications/SystemMonitor/ProcessMemoryMapWidget.cpp | 4 | ||||
-rw-r--r-- | Applications/SystemMonitor/ProcessStacksWidget.cpp | 4 | ||||
-rw-r--r-- | Applications/SystemMonitor/main.cpp | 39 |
8 files changed, 37 insertions, 41 deletions
diff --git a/Applications/SystemMonitor/GraphWidget.cpp b/Applications/SystemMonitor/GraphWidget.cpp index 70d6175b7e..0a82a17b66 100644 --- a/Applications/SystemMonitor/GraphWidget.cpp +++ b/Applications/SystemMonitor/GraphWidget.cpp @@ -28,8 +28,7 @@ #include <LibGUI/Painter.h> #include <LibGfx/Font.h> -GraphWidget::GraphWidget(GUI::Widget* parent) - : GUI::Frame(parent) +GraphWidget::GraphWidget() { set_frame_thickness(2); set_frame_shape(Gfx::FrameShape::Container); diff --git a/Applications/SystemMonitor/GraphWidget.h b/Applications/SystemMonitor/GraphWidget.h index 731d1b0c88..ab98ecf52e 100644 --- a/Applications/SystemMonitor/GraphWidget.h +++ b/Applications/SystemMonitor/GraphWidget.h @@ -41,7 +41,7 @@ public: Function<String(int value, int max)> text_formatter; private: - explicit GraphWidget(GUI::Widget* parent); + explicit GraphWidget(); virtual void paint_event(GUI::PaintEvent&) override; diff --git a/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Applications/SystemMonitor/MemoryStatsWidget.cpp index fae50431bb..83d3b56814 100644 --- a/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -43,9 +43,8 @@ MemoryStatsWidget* MemoryStatsWidget::the() return s_the; } -MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GUI::Widget* parent) - : GUI::Widget(parent) - , m_graph(graph) +MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph) + : m_graph(graph) { ASSERT(!s_the); s_the = this; @@ -58,14 +57,14 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GUI::Widget* parent) layout()->set_spacing(3); auto build_widgets_for_label = [this](const String& description) -> RefPtr<GUI::Label> { - auto container = GUI::Widget::construct(this); + auto container = add<GUI::Widget>(); container->set_layout(make<GUI::HorizontalBoxLayout>()); container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); container->set_preferred_size(275, 12); - auto description_label = GUI::Label::construct(description, container); + 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 = GUI::Label::construct(container); + auto label = container->add<GUI::Label>(); label->set_text_alignment(Gfx::TextAlignment::CenterRight); return label; }; diff --git a/Applications/SystemMonitor/MemoryStatsWidget.h b/Applications/SystemMonitor/MemoryStatsWidget.h index 5ad2c984c1..f2d8c2c36a 100644 --- a/Applications/SystemMonitor/MemoryStatsWidget.h +++ b/Applications/SystemMonitor/MemoryStatsWidget.h @@ -40,7 +40,7 @@ public: void refresh(); private: - MemoryStatsWidget(GraphWidget& graph, GUI::Widget* parent); + MemoryStatsWidget(GraphWidget& graph); GraphWidget& m_graph; RefPtr<GUI::Label> m_user_physical_pages_label; diff --git a/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Applications/SystemMonitor/NetworkStatisticsWidget.cpp index 6f51834554..591d10a5b5 100644 --- a/Applications/SystemMonitor/NetworkStatisticsWidget.cpp +++ b/Applications/SystemMonitor/NetworkStatisticsWidget.cpp @@ -38,13 +38,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GUI::Widget* parent) layout()->set_margins({ 4, 4, 4, 4 }); set_fill_with_background_color(true); - auto adapters_group_box = GUI::GroupBox::construct("Adapters", this); + auto adapters_group_box = add<GUI::GroupBox>("Adapters"); adapters_group_box->set_layout(make<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 = GUI::TableView::construct(adapters_group_box); + 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; @@ -58,13 +58,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GUI::Widget* parent) 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 = GUI::GroupBox::construct("Sockets", this); + auto sockets_group_box = add<GUI::GroupBox>("Sockets"); sockets_group_box->set_layout(make<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 = GUI::TableView::construct(sockets_group_box); + 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; @@ -81,11 +81,10 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GUI::Widget* parent) net_tcp_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); m_socket_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/tcp", move(net_tcp_fields))); - m_update_timer = Core::Timer::construct( + m_update_timer = add<Core::Timer>( 1000, [this] { update_models(); - }, - this); + }); update_models(); }; diff --git a/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp b/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp index b8f507e079..9f5e5c3346 100644 --- a/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp +++ b/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp @@ -36,7 +36,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget(GUI::Widget* parent) { set_layout(make<GUI::VerticalBoxLayout>()); layout()->set_margins({ 4, 4, 4, 4 }); - m_table_view = GUI::TableView::construct(this); + m_table_view = add<GUI::TableView>(); m_table_view->set_size_columns_to_fit_content(true); Vector<GUI::JsonArrayModel::FieldSpec> pid_vm_fields; pid_vm_fields.empend("Address", Gfx::TextAlignment::CenterLeft, [](auto& object) { @@ -73,7 +73,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget(GUI::Widget* parent) m_json_model = GUI::JsonArrayModel::create({}, move(pid_vm_fields)); m_table_view->set_model(GUI::SortingProxyModel::create(*m_json_model)); m_table_view->model()->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending); - m_timer = Core::Timer::construct(1000, [this] { refresh(); }, this); + m_timer = add<Core::Timer>(1000, [this] { refresh(); }); } ProcessMemoryMapWidget::~ProcessMemoryMapWidget() diff --git a/Applications/SystemMonitor/ProcessStacksWidget.cpp b/Applications/SystemMonitor/ProcessStacksWidget.cpp index cfa3fe5aa9..fdbcae184c 100644 --- a/Applications/SystemMonitor/ProcessStacksWidget.cpp +++ b/Applications/SystemMonitor/ProcessStacksWidget.cpp @@ -35,10 +35,10 @@ ProcessStacksWidget::ProcessStacksWidget(GUI::Widget* parent) { set_layout(make<GUI::VerticalBoxLayout>()); layout()->set_margins({ 4, 4, 4, 4 }); - m_stacks_editor = GUI::TextEditor::construct(GUI::TextEditor::Type::MultiLine, this); + m_stacks_editor = add<GUI::TextEditor>(); m_stacks_editor->set_readonly(true); - m_timer = Core::Timer::construct(1000, [this] { refresh(); }, this); + m_timer = add<Core::Timer>(1000, [this] { refresh(); }); } ProcessStacksWidget::~ProcessStacksWidget() diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 7101cb4418..3b85ef0e10 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -121,12 +121,12 @@ int main(int argc, char** argv) keeper->set_fill_with_background_color(true); keeper->layout()->set_margins({ 4, 4, 4, 4 }); - auto tabwidget = GUI::TabWidget::construct(keeper); + auto tabwidget = keeper->add<GUI::TabWidget>(); auto process_container_splitter = GUI::VerticalSplitter::construct(nullptr); tabwidget->add_widget("Processes", process_container_splitter); - auto process_table_container = GUI::Widget::construct(process_container_splitter.ptr()); + auto process_table_container = process_container_splitter->add<GUI::Widget>(); tabwidget->add_widget("Graphs", build_graphs_tab()); @@ -143,17 +143,16 @@ int main(int argc, char** argv) process_table_container->layout()->set_margins({ 4, 0, 4, 0 }); process_table_container->layout()->set_spacing(0); - auto toolbar = GUI::ToolBar::construct(process_table_container); + auto toolbar = process_table_container->add<GUI::ToolBar>(); toolbar->set_has_frame(false); - auto process_table_view = ProcessTableView::construct(process_table_container); + auto process_table_view = process_table_container->add<ProcessTableView>(); - auto refresh_timer = Core::Timer::construct( + auto refresh_timer = window->add<Core::Timer>( 1000, [&] { process_table_view->refresh(); if (auto* memory_stats_widget = MemoryStatsWidget::the()) memory_stats_widget->refresh(); - }, - window); + }); 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(); @@ -231,7 +230,7 @@ int main(int argc, char** argv) app.set_menubar(move(menubar)); - auto process_tab_widget = GUI::TabWidget::construct(process_container_splitter); + auto process_tab_widget = process_container_splitter->add<GUI::TabWidget>(); auto memory_map_widget = ProcessMemoryMapWidget::construct(nullptr); process_tab_widget->add_widget("Memory map", memory_map_widget); @@ -281,10 +280,10 @@ RefPtr<GUI::Widget> build_file_systems_tab() { auto fs_widget = GUI::LazyWidget::construct(); - fs_widget->on_first_show = [](auto& self) { + fs_widget->on_first_show = [](GUI::LazyWidget& self) { self.set_layout(make<GUI::VerticalBoxLayout>()); self.layout()->set_margins({ 4, 4, 4, 4 }); - auto fs_table_view = GUI::TableView::construct(&self); + auto fs_table_view = self.add<GUI::TableView>(); fs_table_view->set_size_columns_to_fit_content(true); Vector<GUI::JsonArrayModel::FieldSpec> df_fields; @@ -374,10 +373,10 @@ RefPtr<GUI::Widget> build_pci_devices_tab() { auto pci_widget = GUI::LazyWidget::construct(); - pci_widget->on_first_show = [](auto& self) { + pci_widget->on_first_show = [](GUI::LazyWidget& self) { self.set_layout(make<GUI::VerticalBoxLayout>()); self.layout()->set_margins({ 4, 4, 4, 4 }); - auto pci_table_view = GUI::TableView::construct(&self); + auto pci_table_view = self.add<GUI::TableView>(); pci_table_view->set_size_columns_to_fit_content(true); auto db = PCIDB::Database::open(); @@ -432,11 +431,11 @@ RefPtr<GUI::Widget> build_devices_tab() { auto devices_widget = GUI::LazyWidget::construct(); - devices_widget->on_first_show = [](auto& self) { + devices_widget->on_first_show = [](GUI::LazyWidget& self) { self.set_layout(make<GUI::VerticalBoxLayout>()); self.layout()->set_margins({ 4, 4, 4, 4 }); - auto devices_table_view = GUI::TableView::construct(&self); + 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(); @@ -449,18 +448,18 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab() { auto graphs_container = GUI::LazyWidget::construct(); - graphs_container->on_first_show = [](auto& self) { + graphs_container->on_first_show = [](GUI::LazyWidget& self) { self.set_fill_with_background_color(true); self.set_background_role(ColorRole::Button); self.set_layout(make<GUI::VerticalBoxLayout>()); self.layout()->set_margins({ 4, 4, 4, 4 }); - auto cpu_graph_group_box = GUI::GroupBox::construct("CPU usage", &self); + auto cpu_graph_group_box = self.add<GUI::GroupBox>("CPU usage"); cpu_graph_group_box->set_layout(make<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 = GraphWidget::construct(cpu_graph_group_box); + 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)); @@ -472,19 +471,19 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab() graph->add_value(cpu_percent); }; - auto memory_graph_group_box = GUI::GroupBox::construct("Memory usage", &self); + auto memory_graph_group_box = self.add<GUI::GroupBox>("Memory usage"); memory_graph_group_box->set_layout(make<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 = GraphWidget::construct(memory_graph_group_box); + 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 = MemoryStatsWidget::construct(*memory_graph, &self); + auto memory_stats_widget = self.add<MemoryStatsWidget>(*memory_graph); }; return graphs_container; } |