[gnome-usage: 1/2] Implemented searching in processes
- From: Petr Štětka <pstetka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage: 1/2] Implemented searching in processes
- Date: Wed, 8 Mar 2017 17:13:24 +0000 (UTC)
commit a0afa5909811a488b31131caf8680cc53d5a4edf
Author: Petr Štětka <pstetka redhat com>
Date: Wed Mar 8 18:12:38 2017 +0100
Implemented searching in processes
README.md | 7 +-----
src/application.vala | 7 ++++++
src/cpu-sub-view.vala | 11 ++++++++-
src/disk-sub-view.vala | 7 +++++-
src/header-bar.vala | 36 ++++++++++++++++++++++++++++++++--
src/memory-sub-view.vala | 11 ++++++++-
src/network-sub-view.vala | 11 ++++++++-
src/performance-view.vala | 33 +++++++++++++++++++++++++++----
src/process-list-box.vala | 46 ++++++++++++++++++++++++++++++++------------
src/view.vala | 4 +++
10 files changed, 139 insertions(+), 34 deletions(-)
---
diff --git a/README.md b/README.md
index bb15993..26290a0 100644
--- a/README.md
+++ b/README.md
@@ -6,13 +6,8 @@ New GNOME Usage!
- [x] Processor Usage
- [x] Memory usage
- [x] Network usage
-- [x] Add loading ProcessListBox when open app
-- [x] Show fancy clear Process Box
-- [x] Tweak network usage
-- [x] Add Running/Sleeping/Dead label
-- [x] Support other architectures than x86_64 (netinfo precompiled library)
+- [x] Search in processes
- [ ] Fix bug with refreshing ProcessListBox 50% (focus, and click when refresh)
-- [ ] Search in processes
- [ ] Storage view - 75%
- [ ] Power view (Design?)
- [ ] Disk usage (What library we can use?)
diff --git a/src/application.vala b/src/application.vala
index fdc120f..97d8583 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -12,6 +12,7 @@ namespace Usage
private const GLib.ActionEntry app_entries[] =
{
{ "about", on_about },
+ { "search", on_search },
{ "quit", on_quit }
};
@@ -64,6 +65,7 @@ namespace Usage
{
base.startup();
add_action_entries(app_entries, this);
+ set_accels_for_action ("app.search", {"<Primary>f"});
}
private void on_about(GLib.SimpleAction action, GLib.Variant? parameter)
@@ -84,5 +86,10 @@ namespace Usage
{
window.destroy();
}
+
+ private void on_search(GLib.SimpleAction action, GLib.Variant? parameter)
+ {
+ window.get_header_bar().action_on_search();
+ }
}
}
diff --git a/src/cpu-sub-view.vala b/src/cpu-sub-view.vala
index 8437554..ddc4455 100644
--- a/src/cpu-sub-view.vala
+++ b/src/cpu-sub-view.vala
@@ -1,7 +1,9 @@
namespace Usage
{
- public class ProcessorSubView : View
+ public class ProcessorSubView : View, SubView
{
+ private ProcessListBox process_list_box;
+
public ProcessorSubView()
{
name = "PROCESSOR";
@@ -18,7 +20,7 @@ namespace Usage
cpu_graph_box.width_request = 600;
cpu_graph_box.valign = Gtk.Align.START;
- var process_list_box = new ProcessListBox(ProcessListBoxType.PROCESSOR);
+ process_list_box = new ProcessListBox(ProcessListBoxType.PROCESSOR);
process_list_box.margin_bottom = 20;
process_list_box.margin_top = 30;
@@ -66,5 +68,10 @@ namespace Usage
add(scrolled_window);
}
+
+ public void search_in_processes(string text)
+ {
+ process_list_box.search(text);
+ }
}
}
diff --git a/src/disk-sub-view.vala b/src/disk-sub-view.vala
index 604014f..c00e989 100644
--- a/src/disk-sub-view.vala
+++ b/src/disk-sub-view.vala
@@ -1,6 +1,6 @@
namespace Usage
{
- public class DiskSubView : View
+ public class DiskSubView : View, SubView
{
public DiskSubView()
{
@@ -10,5 +10,10 @@ namespace Usage
label.get_style_context().add_class("dim-label");
this.add(label);
}
+
+ public void search_in_processes(string text)
+ {
+
+ }
}
}
diff --git a/src/header-bar.vala b/src/header-bar.vala
index 570e3e7..9563d82 100644
--- a/src/header-bar.vala
+++ b/src/header-bar.vala
@@ -11,11 +11,12 @@ namespace Usage
public class HeaderBar : Gtk.HeaderBar
{
private Gtk.StackSwitcher stack_switcher;
+ private Gtk.ToggleButton? performance_search_button;
private Gtk.Button? storage_back_button;
+ private Gtk.Button? storage_rescan_button;
private bool show_storage_back_btn = false;
private bool show_storage_rescan_btn = false;
private string title_text = "";
- private Gtk.Button? storage_rescan_button;
private HeaderBarMode mode;
public HeaderBar(Gtk.Stack stack)
@@ -35,12 +36,14 @@ namespace Usage
switch(this.mode)
{
case HeaderBarMode.PERFORMANCE:
+ remove_widget(performance_search_button);
+ performance_search_button = null;
break;
case HeaderBarMode.DATA:
break;
case HeaderBarMode.STORAGE:
- remove(storage_back_button);
- remove(storage_rescan_button);
+ remove_widget(storage_back_button);
+ remove_widget(storage_rescan_button);
storage_rescan_button = null;
storage_back_button = null;
break;
@@ -52,6 +55,13 @@ namespace Usage
{
case HeaderBarMode.PERFORMANCE:
show_stack_switcher();
+ performance_search_button = new Gtk.ToggleButton();
+ performance_search_button.set_image(new
Gtk.Image.from_icon_name("system-search-symbolic", Gtk.IconSize.BUTTON));
+ performance_search_button.toggled.connect(() => {
+ ((PerformanceView) (GLib.Application.get_default() as
Application).get_window().get_views()[0]).set_search_mode(performance_search_button.active);
+ });
+ performance_search_button.show();
+ pack_end(performance_search_button);
break;
case HeaderBarMode.DATA:
show_stack_switcher();
@@ -87,6 +97,12 @@ namespace Usage
this.mode = mode;
}
+ private void remove_widget(Gtk.Widget? widget)
+ {
+ if(widget != null)
+ remove(widget);
+ }
+
public HeaderBarMode get_mode()
{
return mode;
@@ -139,5 +155,19 @@ namespace Usage
show_storage_rescan_btn = false;
}
}
+
+ public void action_on_search()
+ {
+ switch(mode)
+ {
+ case HeaderBarMode.PERFORMANCE:
+ performance_search_button.set_active(!performance_search_button.get_active());
+ break;
+ case HeaderBarMode.DATA:
+ case HeaderBarMode.STORAGE:
+ case HeaderBarMode.POWER:
+ break;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/memory-sub-view.vala b/src/memory-sub-view.vala
index 35838e9..d531c79 100644
--- a/src/memory-sub-view.vala
+++ b/src/memory-sub-view.vala
@@ -1,7 +1,9 @@
namespace Usage
{
- public class MemorySubView : View
+ public class MemorySubView : View, SubView
{
+ private ProcessListBox process_list_box;
+
public MemorySubView()
{
name = "MEMORY";
@@ -18,7 +20,7 @@ namespace Usage
memory_graph_box.width_request = 600;
memory_graph_box.valign = Gtk.Align.START;
- var process_list_box = new ProcessListBox(ProcessListBoxType.MEMORY);
+ process_list_box = new ProcessListBox(ProcessListBoxType.MEMORY);
process_list_box.margin_bottom = 20;
process_list_box.margin_top = 30;
@@ -66,5 +68,10 @@ namespace Usage
add(scrolled_window);
}
+
+ public void search_in_processes(string text)
+ {
+ process_list_box.search(text);
+ }
}
}
diff --git a/src/network-sub-view.vala b/src/network-sub-view.vala
index faff178..de00719 100644
--- a/src/network-sub-view.vala
+++ b/src/network-sub-view.vala
@@ -1,7 +1,9 @@
namespace Usage
{
- public class NetworkSubView : View
+ public class NetworkSubView : View, SubView
{
+ private ProcessListBox process_list_box;
+
public NetworkSubView()
{
name = "NETWORK";
@@ -18,7 +20,7 @@ namespace Usage
network_graph_box.width_request = 600;
network_graph_box.valign = Gtk.Align.START;
- var process_list_box = new ProcessListBox(ProcessListBoxType.NETWORK);
+ process_list_box = new ProcessListBox(ProcessListBoxType.NETWORK);
process_list_box.margin_bottom = 20;
process_list_box.margin_top = 30;
@@ -65,5 +67,10 @@ namespace Usage
add(scrolled_window);
}
+
+ public void search_in_processes(string text)
+ {
+ process_list_box.search(text);
+ }
}
}
diff --git a/src/performance-view.vala b/src/performance-view.vala
index 6a4570d..240cfd8 100644
--- a/src/performance-view.vala
+++ b/src/performance-view.vala
@@ -3,17 +3,17 @@ namespace Usage
public class PerformanceView : View
{
Gtk.Stack performance_stack;
+ Gtk.SearchBar search_bar;
+ View[] sub_views;
public PerformanceView()
{
name = "PERFORMANCE";
title = _("Performance");
- performance_stack = new Gtk.Stack();
- performance_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN);
- performance_stack.set_transition_duration(700);
+ var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
- var sub_views = new View[]
+ sub_views = new View[]
{
new ProcessorSubView(),
new MemorySubView(),
@@ -21,6 +21,24 @@ namespace Usage
new NetworkSubView()
};
+ search_bar = new Gtk.SearchBar();
+ var search_entry = new Gtk.SearchEntry();
+ search_entry.width_request = 350;
+ search_entry.search_changed.connect(() => {
+ foreach(View sub_view in sub_views)
+ ((SubView) sub_view).search_in_processes(search_entry.get_text());
+ });
+ search_bar.add(search_entry);
+ search_bar.connect_entry(search_entry);
+
+ performance_stack = new Gtk.Stack();
+ performance_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN);
+ performance_stack.set_transition_duration(700);
+ performance_stack.vexpand = true;
+
+ box.add(search_bar);
+ box.add(performance_stack);
+
foreach(var sub_view in sub_views)
performance_stack.add_titled(sub_view, sub_view.name, sub_view.name);
@@ -30,8 +48,13 @@ namespace Usage
var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
paned.add1(stackSwitcher);
- paned.add2(performance_stack);
+ paned.add2(box);
add(paned);
}
+
+ public void set_search_mode(bool enable)
+ {
+ search_bar.set_search_mode(enable);
+ }
}
}
diff --git a/src/process-list-box.vala b/src/process-list-box.vala
index 71b4233..d9ef41b 100644
--- a/src/process-list-box.vala
+++ b/src/process-list-box.vala
@@ -17,6 +17,7 @@ namespace Usage
ProcessRow? opened_row = null;
string focused_row_cmdline;
ProcessListBoxType type;
+ string search_text = "";
public ProcessListBox(ProcessListBoxType type)
{
@@ -72,23 +73,35 @@ namespace Usage
public bool update()
{
+ bind_model(null, null);
model.remove_all();
- switch(type)
+ if(search_text == "")
{
- default:
- case ProcessListBoxType.PROCESSOR:
- foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_cpu_processes())
- model.insert_sorted(process, sort);
- break;
- case ProcessListBoxType.MEMORY:
- foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_ram_processes())
- model.insert_sorted(process, sort);
- break;
- case ProcessListBoxType.NETWORK:
- foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_net_processes())
+ switch(type)
+ {
+ default:
+ case ProcessListBoxType.PROCESSOR:
+ foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_cpu_processes())
+ model.insert_sorted(process, sort);
+ break;
+ case ProcessListBoxType.MEMORY:
+ foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_ram_processes())
+ model.insert_sorted(process, sort);
+ break;
+ case ProcessListBoxType.NETWORK:
+ foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_net_processes())
+ model.insert_sorted(process, sort);
+ break;
+ }
+ }
+ else
+ {
+ foreach(unowned Process process in (GLib.Application.get_default() as
Application).get_system_monitor().get_ram_processes()) //because ram contains all processes
+ {
+ if(process.get_cmdline().down().contains(search_text.down())) //TODO Search in
DisplayName too
model.insert_sorted(process, sort);
- break;
+ }
}
if(model.get_n_items() == 0)
@@ -102,9 +115,16 @@ namespace Usage
filled();
}
+ bind_model(model, on_row_created);
return true;
}
+ public void search(string text)
+ {
+ search_text = text;
+ update();
+ }
+
private Gtk.Widget on_row_created (Object item)
{
Process process = (Process) item;
diff --git a/src/view.vala b/src/view.vala
index e34a59c..a701767 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -11,4 +11,8 @@ namespace Usage
visible = true;
}
}
+
+ public interface SubView {
+ public abstract void search_in_processes(string text);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]