diff options
author | Karol Kosek <krkk@serenityos.org> | 2023-05-21 16:47:34 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-22 06:12:17 +0200 |
commit | 412630637a445a02b257442ef1ad5d735f9f1e53 (patch) | |
tree | a8df40a142804f833202f75ac34ed5eca9604146 /Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp | |
parent | a5936864d963e29d27d4a5fe4f04dab456ad378c (diff) | |
download | serenity-412630637a445a02b257442ef1ad5d735f9f1e53.zip |
SystemMonitor: Convert most widgets to a failable factory
I didn't convert widgets that don't do any failable tasks currently
or are lazy-initialized.
Diffstat (limited to 'Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp')
-rw-r--r-- | Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp b/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp index 83941126a2..6bd0e8d0f3 100644 --- a/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp @@ -15,34 +15,37 @@ REGISTER_WIDGET(SystemMonitor, ProcessFileDescriptorMapWidget) namespace SystemMonitor { -ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget() +ErrorOr<NonnullRefPtr<ProcessFileDescriptorMapWidget>> ProcessFileDescriptorMapWidget::try_create() { - set_layout<GUI::VerticalBoxLayout>(4); - m_table_view = add<GUI::TableView>(); + auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessFileDescriptorMapWidget())); + TRY(widget->try_set_layout<GUI::VerticalBoxLayout>(4)); + widget->m_table_view = TRY(widget->try_add<GUI::TableView>()); Vector<GUI::JsonArrayModel::FieldSpec> pid_fds_fields; - pid_fds_fields.empend("fd", "FD"_short_string, Gfx::TextAlignment::CenterRight); - pid_fds_fields.empend("class", "Class"_short_string, Gfx::TextAlignment::CenterLeft); - pid_fds_fields.empend("offset", "Offset"_short_string, Gfx::TextAlignment::CenterRight); - pid_fds_fields.empend("absolute_path", "Path"_short_string, Gfx::TextAlignment::CenterLeft); - pid_fds_fields.empend("Access"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { + TRY(pid_fds_fields.try_empend("fd", "FD"_short_string, Gfx::TextAlignment::CenterRight)); + TRY(pid_fds_fields.try_empend("class", "Class"_short_string, Gfx::TextAlignment::CenterLeft)); + TRY(pid_fds_fields.try_empend("offset", "Offset"_short_string, Gfx::TextAlignment::CenterRight)); + TRY(pid_fds_fields.try_empend("absolute_path", "Path"_short_string, Gfx::TextAlignment::CenterLeft)); + TRY(pid_fds_fields.try_empend("Access"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("seekable"sv).value_or(false) ? "Seekable" : "Sequential"; - }); - pid_fds_fields.empend("Blocking"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { + })); + TRY(pid_fds_fields.try_empend(TRY("Blocking"_string), Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("blocking"sv).value_or(false) ? "Blocking" : "Nonblocking"; - }); - pid_fds_fields.empend("On exec"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { + })); + TRY(pid_fds_fields.try_empend("On exec"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("cloexec"sv).value_or(false) ? "Close" : "Keep"; - }); - pid_fds_fields.empend("Can read"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { + })); + TRY(pid_fds_fields.try_empend(TRY("Can read"_string), Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("can_read"sv).value_or(false) ? "Yes" : "No"; - }); - pid_fds_fields.empend("Can write"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { + })); + TRY(pid_fds_fields.try_empend(TRY("Can write"_string), Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("can_write"sv).value_or(false) ? "Yes" : "No"; - }); + })); - m_model = GUI::JsonArrayModel::create({}, move(pid_fds_fields)); - m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_model))); + widget->m_model = GUI::JsonArrayModel::create({}, move(pid_fds_fields)); + widget->m_table_view->set_model(TRY(GUI::SortingProxyModel::create(*widget->m_model))); + + return widget; } void ProcessFileDescriptorMapWidget::set_pid(pid_t pid) |