diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-12-24 12:12:04 +0000 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-24 05:11:52 -0800 |
commit | f6633a1026a2e6080ea0c66d79e8bd69e9dd418b (patch) | |
tree | 99d035e16245e334af2acf966f07c7c01c777c9e | |
parent | c72a996542001ef8424661c676e693a161186ddf (diff) | |
download | serenity-f6633a1026a2e6080ea0c66d79e8bd69e9dd418b.zip |
LibGUI+Userland: Make SortingProxyModel::create() return ErrorOr
Unfortunately, most of the users are inside constructors, (and two
others are inside callback lambdas) so the error can't propagate, but
that can be improved later.
11 files changed, 20 insertions, 16 deletions
diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index a55230930b..e31b748eb3 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -132,7 +132,7 @@ void DirectoryView::handle_activation(GUI::ModelIndex const& index) DirectoryView::DirectoryView(Mode mode) : m_mode(mode) , m_model(GUI::FileSystemModel::create({})) - , m_sorting_model(GUI::SortingProxyModel::create(m_model)) + , m_sorting_model(MUST(GUI::SortingProxyModel::create(m_model))) { set_active_widget(nullptr); set_grabbable_margins(2); diff --git a/Userland/Applications/MouseSettings/ThemeWidget.cpp b/Userland/Applications/MouseSettings/ThemeWidget.cpp index 1589e9baad..32d2e0ce64 100644 --- a/Userland/Applications/MouseSettings/ThemeWidget.cpp +++ b/Userland/Applications/MouseSettings/ThemeWidget.cpp @@ -107,7 +107,7 @@ ThemeWidget::ThemeWidget() m_cursors_tableview->set_highlight_key_column(false); auto mouse_cursor_model = MouseCursorModel::create(); - auto sorting_proxy_model = GUI::SortingProxyModel::create(mouse_cursor_model); + auto sorting_proxy_model = MUST(GUI::SortingProxyModel::create(mouse_cursor_model)); sorting_proxy_model->set_sort_role(GUI::ModelRole::Display); m_cursors_tableview->set_model(sorting_proxy_model); diff --git a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp index e48f82b72b..f1fdcc9c98 100644 --- a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp +++ b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp @@ -65,7 +65,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() net_adapters_fields.empend("bytes_in", "Bytes In", Gfx::TextAlignment::CenterRight); net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); m_adapter_model = GUI::JsonArrayModel::create("/proc/net/adapters", move(net_adapters_fields)); - m_adapter_table_view->set_model(GUI::SortingProxyModel::create(*m_adapter_model)); + m_adapter_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_adapter_model))); auto& tcp_sockets_group_box = add<GUI::GroupBox>("TCP Sockets"); tcp_sockets_group_box.set_layout<GUI::VerticalBoxLayout>(); @@ -86,7 +86,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() net_tcp_fields.empend("bytes_in", "Bytes In", Gfx::TextAlignment::CenterRight); net_tcp_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); m_tcp_socket_model = GUI::JsonArrayModel::create("/proc/net/tcp", move(net_tcp_fields)); - m_tcp_socket_table_view->set_model(GUI::SortingProxyModel::create(*m_tcp_socket_model)); + m_tcp_socket_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_tcp_socket_model))); auto& udp_sockets_group_box = add<GUI::GroupBox>("UDP Sockets"); udp_sockets_group_box.set_layout<GUI::VerticalBoxLayout>(); @@ -100,7 +100,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() net_udp_fields.empend("local_address", "Local", Gfx::TextAlignment::CenterLeft); net_udp_fields.empend("local_port", "Port", Gfx::TextAlignment::CenterRight); m_udp_socket_model = GUI::JsonArrayModel::create("/proc/net/udp", move(net_udp_fields)); - m_udp_socket_table_view->set_model(GUI::SortingProxyModel::create(*m_udp_socket_model)); + m_udp_socket_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_udp_socket_model))); m_update_timer = add<Core::Timer>( 1000, [this] { diff --git a/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp b/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp index 879983aedf..90cdf3a674 100644 --- a/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp @@ -38,7 +38,7 @@ ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget() }); m_model = GUI::JsonArrayModel::create({}, move(pid_fds_fields)); - m_table_view->set_model(GUI::SortingProxyModel::create(*m_model)); + m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_model))); } ProcessFileDescriptorMapWidget::~ProcessFileDescriptorMapWidget() diff --git a/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp b/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp index 6cf99fed78..c10a656b51 100644 --- a/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp @@ -99,7 +99,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget() pid_vm_fields.empend("cow_pages", "# CoW", Gfx::TextAlignment::CenterRight); pid_vm_fields.empend("name", "Name", Gfx::TextAlignment::CenterLeft); m_json_model = GUI::JsonArrayModel::create({}, move(pid_vm_fields)); - m_table_view->set_model(GUI::SortingProxyModel::create(*m_json_model)); + m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_json_model))); m_table_view->set_column_painting_delegate(7, make<PagemapPaintingDelegate>()); diff --git a/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp b/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp index 2ad0045bac..9d4dff2316 100644 --- a/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp @@ -21,7 +21,7 @@ ProcessUnveiledPathsWidget::ProcessUnveiledPathsWidget() pid_unveil_fields.empend("permissions", "Permissions", Gfx::TextAlignment::CenterLeft); m_model = GUI::JsonArrayModel::create({}, move(pid_unveil_fields)); - m_table_view->set_model(GUI::SortingProxyModel::create(*m_model)); + m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_model))); } ProcessUnveiledPathsWidget::~ProcessUnveiledPathsWidget() diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index 1c4bb5ed01..cf1b61b604 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -180,7 +180,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto& process_table_view = process_table_container.add<GUI::TableView>(); process_table_view.set_column_headers_visible(true); - process_table_view.set_model(GUI::SortingProxyModel::create(process_model)); + process_table_view.set_model(TRY(GUI::SortingProxyModel::create(process_model))); for (auto column = 0; column < ProcessModel::Column::__Count; ++column) process_table_view.set_column_visible(column, false); process_table_view.set_column_visible(ProcessModel::Column::Icon, true); @@ -549,7 +549,7 @@ NonnullRefPtr<GUI::Widget> build_storage_widget() 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(MUST(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/df", move(df_fields))))); fs_table_view.set_column_painting_delegate(3, make<ProgressbarPaintingDelegate>()); @@ -647,7 +647,7 @@ NonnullRefPtr<GUI::Widget> build_hardware_tab() return String::formatted("{:02x}", revision_id); }); - pci_table_view.set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields)))); + pci_table_view.set_model(MUST(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields))))); pci_table_view.model()->invalidate(); } }; diff --git a/Userland/Demos/WidgetGallery/GalleryWidget.cpp b/Userland/Demos/WidgetGallery/GalleryWidget.cpp index 5f631e4164..29bafb120b 100644 --- a/Userland/Demos/WidgetGallery/GalleryWidget.cpp +++ b/Userland/Demos/WidgetGallery/GalleryWidget.cpp @@ -296,7 +296,7 @@ GalleryWidget::GalleryWidget() m_cursors_tableview->set_column_headers_visible(false); m_cursors_tableview->set_highlight_key_column(false); - auto sorting_proxy_model = GUI::SortingProxyModel::create(MouseCursorModel::create()); + auto sorting_proxy_model = MUST(GUI::SortingProxyModel::create(MouseCursorModel::create())); sorting_proxy_model->set_sort_role(GUI::ModelRole::Display); m_cursors_tableview->set_model(sorting_proxy_model); @@ -319,7 +319,7 @@ GalleryWidget::GalleryWidget() m_icons_tableview->set_column_headers_visible(false); m_icons_tableview->set_highlight_key_column(false); - auto sorting_proxy_icons_model = GUI::SortingProxyModel::create(FileIconsModel::create()); + auto sorting_proxy_icons_model = MUST(GUI::SortingProxyModel::create(FileIconsModel::create())); sorting_proxy_icons_model->set_sort_role(GUI::ModelRole::Display); m_icons_tableview->set_model(sorting_proxy_icons_model); diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index a92a3006f9..59cb9453ff 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -96,7 +96,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St m_view = *widget.find_descendant_of_type_named<GUI::MultiView>("view"); m_view->set_selection_mode(m_mode == Mode::OpenMultiple ? GUI::AbstractView::SelectionMode::MultiSelection : GUI::AbstractView::SelectionMode::SingleSelection); - m_view->set_model(SortingProxyModel::create(*m_model)); + m_view->set_model(MUST(SortingProxyModel::create(*m_model))); m_view->set_model_column(FileSystemModel::Column::Name); m_view->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending); m_view->set_column_visible(FileSystemModel::Column::User, true); diff --git a/Userland/Libraries/LibGUI/ProcessChooser.cpp b/Userland/Libraries/LibGUI/ProcessChooser.cpp index 91c9b9dab1..35ef3a4e2a 100644 --- a/Userland/Libraries/LibGUI/ProcessChooser.cpp +++ b/Userland/Libraries/LibGUI/ProcessChooser.cpp @@ -36,7 +36,7 @@ ProcessChooser::ProcessChooser(StringView window_title, StringView button_label, m_table_view = widget.add<GUI::TableView>(); auto process_model = RunningProcessesModel::create(); - auto sorting_model = GUI::SortingProxyModel::create(process_model); + auto sorting_model = MUST(GUI::SortingProxyModel::create(process_model)); sorting_model->set_sort_role(GUI::ModelRole::Display); m_table_view->set_model(sorting_model); m_table_view->set_key_column_and_sort_order(RunningProcessesModel::Column::PID, GUI::SortOrder::Descending); diff --git a/Userland/Libraries/LibGUI/SortingProxyModel.h b/Userland/Libraries/LibGUI/SortingProxyModel.h index 85ca910cb0..0c2a55d1d9 100644 --- a/Userland/Libraries/LibGUI/SortingProxyModel.h +++ b/Userland/Libraries/LibGUI/SortingProxyModel.h @@ -14,7 +14,11 @@ class SortingProxyModel : public Model , private ModelClient { public: - static NonnullRefPtr<SortingProxyModel> create(NonnullRefPtr<Model> source) { return adopt_ref(*new SortingProxyModel(move(source))); } + static ErrorOr<NonnullRefPtr<SortingProxyModel>> create(NonnullRefPtr<Model> source) + { + return adopt_nonnull_ref_or_enomem(new (nothrow) SortingProxyModel(move(source))); + } + virtual ~SortingProxyModel() override; virtual int row_count(ModelIndex const& = ModelIndex()) const override; |