Commit a0afa590 authored by Petr Štětka's avatar Petr Štětka
Browse files

Implemented searching in processes

parent bc96ac7c
......@@ -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?)
......
......@@ -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();
}
}
}
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);
}
}
}
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)
{
}
}
}
......@@ -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
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);
}
}
}
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);
}
}
}
......@@ -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);
}
}
}
......@@ -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;
......
......@@ -11,4 +11,8 @@ namespace Usage
visible = true;
}
}
public interface SubView {
public abstract void search_in_processes(string text);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment