diff --git a/Applications/SystemMonitor/CMakeLists.txt b/Applications/SystemMonitor/CMakeLists.txt index 03fcfd61ad..2f1b6c4b15 100644 --- a/Applications/SystemMonitor/CMakeLists.txt +++ b/Applications/SystemMonitor/CMakeLists.txt @@ -8,7 +8,6 @@ set(SOURCES ProcessMemoryMapWidget.cpp ProcessModel.cpp ProcessStacksWidget.cpp - ProcessTableView.cpp ProcessUnveiledPathsWidget.cpp ) diff --git a/Applications/SystemMonitor/ProcessTableView.cpp b/Applications/SystemMonitor/ProcessTableView.cpp deleted file mode 100644 index 74fc1485d0..0000000000 --- a/Applications/SystemMonitor/ProcessTableView.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "ProcessTableView.h" -#include "ProcessModel.h" -#include -#include - -ProcessTableView::ProcessTableView() -{ - set_model(GUI::SortingProxyModel::create(ProcessModel::create())); - model()->set_key_column_and_sort_order(ProcessModel::Column::CPU, GUI::SortOrder::Descending); - refresh(); - - on_selection = [this](auto&) { - if (on_process_selected) - on_process_selected(selected_pid()); - }; -} - -ProcessTableView::~ProcessTableView() -{ -} - -void ProcessTableView::refresh() -{ - model()->update(); -} - -pid_t ProcessTableView::selected_pid() const -{ - if (selection().is_empty()) - return -1; - return model()->data(model()->index(selection().first().row(), ProcessModel::Column::PID), GUI::Model::Role::Sort).as_i32(); -} diff --git a/Applications/SystemMonitor/ProcessTableView.h b/Applications/SystemMonitor/ProcessTableView.h deleted file mode 100644 index 0fe294c98e..0000000000 --- a/Applications/SystemMonitor/ProcessTableView.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include - -class GraphWidget; -class ProcessModel; - -class ProcessTableView final : public GUI::TableView { - C_OBJECT(ProcessTableView) -public: - virtual ~ProcessTableView() override; - - pid_t selected_pid() const; - - void refresh(); - - Function on_process_selected; - -private: - ProcessTableView(); -}; diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index f644477927..bed0c29625 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -32,7 +32,6 @@ #include "ProcessMemoryMapWidget.h" #include "ProcessModel.h" #include "ProcessStacksWidget.h" -#include "ProcessTableView.h" #include "ProcessUnveiledPathsWidget.h" #include #include @@ -50,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -104,8 +104,7 @@ private: String m_text; }; -static bool -can_access_pid(pid_t pid) +static bool can_access_pid(pid_t pid) { auto path = String::format("/proc/%d", pid); return access(path.characters(), X_OK) == 0; @@ -187,36 +186,47 @@ int main(int argc, char** argv) process_table_container.set_layout(); process_table_container.layout()->set_spacing(0); - auto& process_table_view = process_table_container.add(); + auto& process_table_view = process_table_container.add(); + process_table_view.set_headers_visible(true); + process_table_view.set_model(GUI::SortingProxyModel::create(ProcessModel::create())); + process_table_view.model()->set_key_column_and_sort_order(ProcessModel::Column::CPU, GUI::SortOrder::Descending); + process_table_view.model()->update(); auto& refresh_timer = window->add( 3000, [&] { - process_table_view.refresh(); + process_table_view.model()->update(); 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 selected_pid = [&]() -> pid_t { + if (process_table_view.selection().is_empty()) + return -1; + auto pid_index = process_table_view.model()->index(process_table_view.selection().first().row(), ProcessModel::Column::PID); + return process_table_view.model()->data(pid_index, GUI::Model::Role::Display).to_i32(); + }; + + auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&](const GUI::Action&) { + pid_t pid = 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"), [&](const GUI::Action&) { + pid_t pid = 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"), [&](const GUI::Action&) { + pid_t pid = selected_pid(); if (pid != -1) kill(pid, SIGCONT); }); auto profile_action = GUI::Action::create("Profile process", { Mod_Ctrl, Key_P }, - Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png"), [&process_table_view](auto&) { - pid_t pid = process_table_view.selected_pid(); + Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png"), [&](auto&) { + pid_t pid = selected_pid(); if (pid != -1) { auto pid_string = String::format("%d", pid); pid_t child; @@ -231,8 +241,8 @@ int main(int argc, char** argv) }); auto inspect_action = GUI::Action::create("Inspect process", { Mod_Ctrl, Key_I }, - Gfx::Bitmap::load_from_file("/res/icons/16x16/app-inspector.png"), [&process_table_view](auto&) { - pid_t pid = process_table_view.selected_pid(); + Gfx::Bitmap::load_from_file("/res/icons/16x16/app-inspector.png"), [&](auto&) { + pid_t pid = selected_pid(); if (pid != -1) { auto pid_string = String::format("%d", pid); pid_t child; @@ -308,7 +318,8 @@ int main(int argc, char** argv) auto& unveiled_paths_widget = process_tab_widget.add_tab("Unveiled paths"); auto& stacks_widget = process_tab_widget.add_tab("Stacks"); - process_table_view.on_process_selected = [&](pid_t pid) { + process_table_view.on_selection = [&](auto&) { + auto pid = selected_pid(); if (!can_access_pid(pid)) { process_tab_widget.set_visible(false); process_tab_unused_widget.set_text("Process cannot be accessed");