[gnome-usage] Implemented searching in processes by display name too.
- From: Petr Štětka <pstetka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] Implemented searching in processes by display name too.
- Date: Thu, 9 Mar 2017 14:05:47 +0000 (UTC)
commit 7d194afad7bf287e0477d3e95302e359e1a771e3
Author: Petr Štětka <pstetka redhat com>
Date: Thu Mar 9 15:05:36 2017 +0100
Implemented searching in processes by display name too.
README.md | 4 +-
src/process-list-box.vala | 2 +-
src/process-row.vala | 100 +++++++++++++--------------------------------
src/process.vala | 14 ++++++-
src/system-monitor.vala | 61 +++++++++++++++++++++++++--
5 files changed, 101 insertions(+), 80 deletions(-)
---
diff --git a/README.md b/README.md
index 26290a0..7aedc32 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ New GNOME Usage!
- [x] Memory usage
- [x] Network usage
- [x] Search in processes
-- [ ] Fix bug with refreshing ProcessListBox 50% (focus, and click when refresh)
+- [ ] Fix bug with refreshing ProcessListBox - 50% (focus, and click when refresh)
- [ ] Storage view - 75%
- [ ] Power view (Design?)
- [ ] Disk usage (What library we can use?)
@@ -40,7 +40,7 @@ sudo setcap cap_net_raw,cap_net_admin=eip /usr/local/bin/gnome-usage
Code is under GNU GPLv3 license.
##Screenshots:
-More screenshots is in screenshots subdirectory (sorry screenshots may not be current).
+More screenshots is in screenshots subdirectory (However screenshots may not be current).
![Screenshot](screenshots/screenshot11.png?raw=true )
diff --git a/src/process-list-box.vala b/src/process-list-box.vala
index d9ef41b..7407632 100644
--- a/src/process-list-box.vala
+++ b/src/process-list-box.vala
@@ -99,7 +99,7 @@ namespace Usage
{
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
+ if(process.get_display_name().down().contains(search_text.down()) ||
process.get_cmdline().down().contains(search_text.down()))
model.insert_sorted(process, sort);
}
}
diff --git a/src/process-row.vala b/src/process-row.vala
index 8a63147..bc5299b 100644
--- a/src/process-row.vala
+++ b/src/process-row.vala
@@ -9,8 +9,6 @@ namespace Usage
Gtk.Label title_label;
Gtk.Revealer revealer;
SubProcessListBox sub_process_list_box;
- string display_name;
- static GLib.List<AppInfo> apps_info;
ProcessListBoxType type;
bool group;
@@ -22,8 +20,6 @@ namespace Usage
{
this.type = type;
showing_details = opened;
- if(apps_info == null)
- apps_info = AppInfo.get_all(); //Because it takes too long
this.process = process;
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
@@ -34,9 +30,11 @@ namespace Usage
load_label.ellipsize = Pango.EllipsizeMode.END;
load_label.max_width_chars = 30;
- Gtk.Image icon;
- load_icon_and_name(out icon, out display_name);
- title_label = new Gtk.Label(display_name);
+ Gtk.Image icon = load_icon(process.get_display_name());
+ icon.margin_left = 10;
+ icon.margin_right = 10;
+
+ title_label = new Gtk.Label(process.get_display_name());
row_box.pack_start(icon, false, false, 0);
row_box.pack_start(title_label, false, true, 5);
row_box.pack_end(load_label, false, true, 10);
@@ -65,81 +63,41 @@ namespace Usage
show_details();
}
- private void load_icon_and_name(out Gtk.Image icon, out string display_name)
+ private Gtk.Image load_icon(string display_name)
{
- icon = null;
- AppInfo app_info = null;
- foreach (AppInfo info in apps_info)
+ Gtk.Image icon = null;
+ foreach (AppInfo app_info in (GLib.Application.get_default() as
Application).get_system_monitor().get_apps_info())
{
- string commandline = info.get_commandline();
- for (int i = 0; i < commandline.length; i++)
+ if(app_info.get_display_name() == display_name)
{
- if(commandline[i] == ' ' && commandline[i] == '%')
- commandline = commandline.substring(0, i);
- }
-
- commandline = Path.get_basename(commandline);
- string process_full_cmd = process.get_cmdline() + " " + process.get_cmdline_parameter();
- if(commandline == process_full_cmd)
- app_info = info;
- else if(commandline.contains("google-" + process.get_cmdline() + "-")) //Fix for Google
Chrome naming
- app_info = info;
-
- if(app_info == null)
- {
- commandline = info.get_commandline();
- for (int i = 0; i < commandline.length; i++)
+ if(app_info.get_icon() != null)
{
- if(commandline[i] == ' ')
- commandline = commandline.substring(0, i);
- }
-
- if(info.get_commandline().has_prefix(commandline + " " + commandline + "://")) //Fix for
Steam naming
- commandline = info.get_commandline();
-
- commandline = Path.get_basename(commandline);
- if(commandline == process.get_cmdline())
- app_info = info;
- }
- }
-
- if(app_info != null)
- {
- display_name = app_info.get_display_name();
-
- if(app_info.get_icon() != null)
- {
- var icon_theme = new Gtk.IconTheme();
- var icon_info = icon_theme.lookup_by_gicon_for_scale(app_info.get_icon(), 24, 1,
Gtk.IconLookupFlags.FORCE_SIZE);
- if(icon_info != null)
- {
- try
+ var icon_theme = new Gtk.IconTheme();
+ var icon_info = icon_theme.lookup_by_gicon_for_scale(app_info.get_icon(), 24, 1,
Gtk.IconLookupFlags.FORCE_SIZE);
+ if(icon_info != null)
{
- var pixbuf = icon_info.load_icon();
- icon = new Gtk.Image.from_pixbuf(pixbuf);
- }
- catch(Error e) {
- GLib.stderr.printf ("Could not load icon for application %s: %s\n",
display_name, e.message);
- }
+ try
+ {
+ var pixbuf = icon_info.load_icon();
+ icon = new Gtk.Image.from_pixbuf(pixbuf);
+ }
+ catch(Error e) {
+ GLib.stderr.printf ("Could not load icon for application %s: %s\n",
display_name, e.message);
+ }
+ }
}
}
}
- else
- {
- display_name = process.get_cmdline();
- }
if(icon == null)
- {
- icon = new Gtk.Image.from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON);
- icon.width_request = 24;
- icon.height_request = 24;
- }
-
- icon.margin_left = 10;
- icon.margin_right = 10;
+ {
+ icon = new Gtk.Image.from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON);
+ icon.width_request = 24;
+ icon.height_request = 24;
+ }
+ return icon;
}
private void update()
@@ -249,7 +207,7 @@ namespace Usage
}
else
{
- var dialog = new ProcessDialog(process.get_pid(), display_name, process.get_cmdline());
+ var dialog = new ProcessDialog(process.get_pid(), process.get_display_name(),
process.get_cmdline());
dialog.show_all();
}
}
diff --git a/src/process.vala b/src/process.vala
index 21d6f12..0b94343 100644
--- a/src/process.vala
+++ b/src/process.vala
@@ -7,6 +7,7 @@ namespace Usage
pid_t pid;
string cmdline;
string cmdline_parameter; //Isn't parameters as "-p" etc, but parameter for running app, for ex.
"--writer' with libreoffice, or "privacy" with gnome-control-center
+ string display_name;
double cpu_load;
double x_cpu_load;
uint64 cpu_last_used;
@@ -20,11 +21,12 @@ namespace Usage
bool alive;
ProcessStatus status;
- public Process(pid_t pid, string cmdline, string cmdline_parameter)
+ public Process(pid_t pid, string cmdline, string cmdline_parameter, string display_name)
{
this.pid = pid;
this.cmdline = cmdline;
this.cmdline_parameter = cmdline_parameter;
+ this.display_name = display_name;
this.cpu_load = 0;
this.x_cpu_load = 0;
this.cpu_last_used = 0;
@@ -84,6 +86,16 @@ namespace Usage
this.cmdline_parameter = cmdline_parameter;
}
+ public string get_display_name()
+ {
+ return display_name;
+ }
+
+ public void set_display_name(string display_name)
+ {
+ this.display_name = display_name;
+ }
+
public double get_cpu_load()
{
return cpu_load;
diff --git a/src/system-monitor.vala b/src/system-monitor.vala
index 2af8c29..46b80ff 100644
--- a/src/system-monitor.vala
+++ b/src/system-monitor.vala
@@ -25,6 +25,7 @@ namespace Usage
private HashTable<string, Process> net_process_table;
private int process_mode = GTop.KERN_PROC_UID;
+ private GLib.List<AppInfo> apps_info;
public enum ProcessMode
{
@@ -73,6 +74,11 @@ namespace Usage
return net_process_table[cmdline];
}
+ public unowned GLib.List<AppInfo> get_apps_info()
+ {
+ return apps_info;
+ }
+
public SystemMonitor()
{
GTop.init();
@@ -87,6 +93,7 @@ namespace Usage
net_process_table = new HashTable<string, Process>(str_hash, str_equal);
var settings = (GLib.Application.get_default() as Application).settings;
+ apps_info = AppInfo.get_all();
update_data();
Timeout.add(settings.data_update_interval, update_data);
@@ -132,7 +139,8 @@ namespace Usage
{
string cmdline_parameter;
string cmdline = get_full_process_cmd_for_pid(pids[i], out cmdline_parameter);
- var process = new Process(pids[i], cmdline, cmdline_parameter);
+ string display_name = get_display_name(cmdline, cmdline_parameter);
+ var process = new Process(pids[i], cmdline, cmdline_parameter, display_name);
cpu_monitor.update_process_info(ref process);
process_table_pid.insert (pids[i], (owned) process);
}
@@ -199,6 +207,49 @@ namespace Usage
}
}
+ private string get_display_name(string cmdline, string cmdline_parameter)
+ {
+ AppInfo app_info = null;
+ foreach (AppInfo info in apps_info)
+ {
+ string commandline = info.get_commandline();
+ for (int i = 0; i < commandline.length; i++)
+ {
+ if(commandline[i] == ' ' && commandline[i] == '%')
+ commandline = commandline.substring(0, i);
+ }
+
+ commandline = Path.get_basename(commandline);
+ string process_full_cmd = cmdline + " " + cmdline_parameter;
+ if(commandline == process_full_cmd)
+ app_info = info;
+ else if(commandline.contains("google-" + cmdline + "-")) //Fix for Google Chrome naming
+ app_info = info;
+
+ if(app_info == null)
+ {
+ commandline = info.get_commandline();
+ for (int i = 0; i < commandline.length; i++)
+ {
+ if(commandline[i] == ' ')
+ commandline = commandline.substring(0, i);
+ }
+
+ if(info.get_commandline().has_prefix(commandline + " " + commandline + "://")) //Fix for
Steam naming
+ commandline = info.get_commandline();
+
+ commandline = Path.get_basename(commandline);
+ if(commandline == cmdline)
+ app_info = info;
+ }
+ }
+
+ if(app_info != null)
+ return app_info.get_display_name();
+ else
+ return cmdline;
+ }
+
private string get_full_process_cmd_for_pid (pid_t pid, out string cmd_parameter)
{
GTop.ProcArgs proc_args;
@@ -306,7 +357,7 @@ namespace Usage
}
else //add subrow
{
- var process = new Process(process_it.get_pid(), process_it.get_cmdline(),
process_it.get_cmdline_parameter());
+ var process = new Process(process_it.get_pid(), process_it.get_cmdline(),
process_it.get_cmdline_parameter(), process_it.get_display_name());
process.update_from_process(process_it);
to_table[process.get_cmdline()].get_sub_processes().insert(process.get_pid(),
(owned) process);
}
@@ -323,12 +374,12 @@ namespace Usage
to_table[process_it.get_cmdline()].set_sub_processes(new HashTable<pid_t?,
Process>(int_hash, int_equal));
unowned Process process = to_table[process_it.get_cmdline()];
- var sub_process_one = new Process(process.get_pid(), process.get_cmdline(),
process.get_cmdline_parameter());
+ var sub_process_one = new Process(process.get_pid(), process.get_cmdline(),
process.get_cmdline_parameter(), process.get_display_name());
sub_process_one.update_from_process(process);
to_table[process_it.get_cmdline()].get_sub_processes().insert(sub_process_one.get_pid(), (owned)
sub_process_one);
process.set_cmdline_parameter("");
- var sub_process = new Process(process_it.get_pid(), process_it.get_cmdline(),
process_it.get_cmdline_parameter());
+ var sub_process = new Process(process_it.get_pid(), process_it.get_cmdline(),
process_it.get_cmdline_parameter(), process_it.get_display_name());
sub_process.update_from_process(process_it);
to_table[process_it.get_cmdline()].get_sub_processes().insert(process_it.get_pid(), (owned) sub_process);
}
@@ -336,7 +387,7 @@ namespace Usage
}
else //add process
{
- var process = new Process(process_it.get_pid(), process_it.get_cmdline(),
process_it.get_cmdline_parameter());
+ var process = new Process(process_it.get_pid(), process_it.get_cmdline(),
process_it.get_cmdline_parameter(), process_it.get_display_name());
process.update_from_process(process_it);
to_table.insert(process.get_cmdline(), (owned) process);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]