diff options
author | Maciej <sppmacd@pm.me> | 2022-10-29 21:52:20 +0200 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-11-02 12:00:26 +0000 |
commit | c90024fbabf0ef568ab7b5c8867f764b02b3d145 (patch) | |
tree | 5b3194e4381f1456d71f910d03bbe91b3b4b301a /Userland/Applications | |
parent | 38fb3257c8ffdf11ca2ce7a8f949af7a3f79df9c (diff) | |
download | serenity-c90024fbabf0ef568ab7b5c8867f764b02b3d145.zip |
SystemMonitor: Add context menu for opening adapter in NetworkSettings
Diffstat (limited to 'Userland/Applications')
3 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp index 65b9448ab5..e77f6ee1c8 100644 --- a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp +++ b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp @@ -9,6 +9,8 @@ #include <LibGUI/BoxLayout.h> #include <LibGUI/GroupBox.h> #include <LibGUI/JsonArrayModel.h> +#include <LibGUI/Menu.h> +#include <LibGUI/Process.h> #include <LibGUI/SortingProxyModel.h> #include <LibGUI/TableView.h> #include <LibGfx/Painter.h> @@ -71,6 +73,25 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); m_adapter_model = GUI::JsonArrayModel::create("/sys/kernel/net/adapters", move(net_adapters_fields)); m_adapter_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_adapter_model))); + m_adapter_context_menu = MUST(GUI::Menu::try_create()); + m_adapter_context_menu->add_action(GUI::Action::create( + "Open in Network Settings...", MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network.png"sv)), [this](GUI::Action&) { + m_adapter_table_view->selection().for_each_index([this](GUI::ModelIndex const& index) { + auto adapter_name = index.sibling_at_column(1).data().as_string(); + GUI::Process::spawn_or_show_error(window(), "/bin/Escalator"sv, Array { "/bin/NetworkSettings", adapter_name.characters() }); + }); + }, + this)); + m_adapter_table_view->on_context_menu_request = [this](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) { + if (!index.is_valid()) { + return; + } + auto adapter_name = index.sibling_at_column(1).data().as_string(); + if (adapter_name == "loop") { + return; + } + m_adapter_context_menu->popup(event.screen_position()); + }; auto& tcp_sockets_group_box = add<GUI::GroupBox>("TCP Sockets"sv); tcp_sockets_group_box.set_layout<GUI::VerticalBoxLayout>(); diff --git a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.h b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.h index 6b9cda5bd1..f8e21e1485 100644 --- a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.h +++ b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.h @@ -22,6 +22,7 @@ private: void update_models(); RefPtr<GUI::TableView> m_adapter_table_view; + RefPtr<GUI::Menu> m_adapter_context_menu; RefPtr<GUI::TableView> m_tcp_socket_table_view; RefPtr<GUI::TableView> m_udp_socket_table_view; RefPtr<GUI::JsonArrayModel> m_adapter_model; diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index 49c5c3af6d..5a9cde793e 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -246,6 +246,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/sys/kernel", "r")); TRY(Core::System::unveil("/dev", "r")); TRY(Core::System::unveil("/bin", "r")); + TRY(Core::System::unveil("/bin/Escalator", "x")); TRY(Core::System::unveil("/usr/lib", "r")); // This directory only exists if ports are installed |