diff options
author | Uma Sankar <umasankar.yedida@apxor.com> | 2020-08-14 22:48:33 +0530 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-15 00:20:34 +0200 |
commit | d5a77de906766c2034993261c7c5bca82275134b (patch) | |
tree | 0b9ab3f98329bd482bbb6bc5d439b17032811051 | |
parent | cdae3f53f1b3cc2175d3712717e368d1fe3bce1d (diff) | |
download | serenity-d5a77de906766c2034993261c7c5bca82275134b.zip |
LibGUI: Add a timer in ProcessChooser to get processes for every 1000ms
-rw-r--r-- | Libraries/LibGUI/ProcessChooser.cpp | 28 | ||||
-rw-r--r-- | Libraries/LibGUI/ProcessChooser.h | 5 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Libraries/LibGUI/ProcessChooser.cpp b/Libraries/LibGUI/ProcessChooser.cpp index 0d2cdb2a55..413b3b9888 100644 --- a/Libraries/LibGUI/ProcessChooser.cpp +++ b/Libraries/LibGUI/ProcessChooser.cpp @@ -91,6 +91,34 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& }; table_view.model()->update(); + + m_refresh_timer = add<Core::Timer>(); + + m_refresh_timer->start(m_refresh_interval); // Start the timer to update the processes + m_refresh_timer->on_timeout = [&table_view] { + auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update. + if (!table_view.selection().is_empty()) { + auto pid_as_variant = table_view.model()->data(table_view.selection().first(), GUI::Model::Role::Custom); + previous_selected_pid = pid_as_variant.as_i32(); + } + + table_view.model()->update(); + + if (previous_selected_pid == -1) { + return; + } + + auto model = table_view.model(); + auto row_count = model->row_count(); + auto column_index = 1; // Corresponds to PID column in the table_view. + for (int row_index = 0; row_index < row_count; ++row_index) { + auto cell_index = model->index(row_index, column_index); + auto pid_as_variant = model->data(cell_index, GUI::Model::Role::Custom); + if (previous_selected_pid == pid_as_variant.as_i32()) { + table_view.selection().set(cell_index); // Set only if PIDs are matched. + } + } + }; } ProcessChooser::~ProcessChooser() diff --git a/Libraries/LibGUI/ProcessChooser.h b/Libraries/LibGUI/ProcessChooser.h index 6b16f4b2ba..39e50ee463 100644 --- a/Libraries/LibGUI/ProcessChooser.h +++ b/Libraries/LibGUI/ProcessChooser.h @@ -27,6 +27,7 @@ #pragma once #include <LibGUI/Dialog.h> +#include <LibCore/Timer.h> namespace GUI { @@ -46,6 +47,10 @@ private: String m_window_title; String m_button_label; RefPtr<Gfx::Bitmap> m_window_icon; + + bool m_refresh_enabled { true }; + unsigned m_refresh_interval { 1000 }; + RefPtr<Core::Timer> m_refresh_timer; }; } |