[gnome-usage] process-row: Simplify ProcessRow according to backend
- From: Petr Štětka <pstetka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] process-row: Simplify ProcessRow according to backend
- Date: Wed, 19 Dec 2018 12:49:19 +0000 (UTC)
commit c9c31bf089e2204f2cfbd7304cb4de178f8f3e1c
Author: Petr Štětka <pstetka redhat com>
Date: Sun May 20 14:40:01 2018 +0200
process-row: Simplify ProcessRow according to backend
src/process-row.vala | 120 +++++++++------------------------------------------
1 file changed, 21 insertions(+), 99 deletions(-)
---
diff --git a/src/process-row.vala b/src/process-row.vala
index f657c12..b9de945 100644
--- a/src/process-row.vala
+++ b/src/process-row.vala
@@ -23,7 +23,12 @@ namespace Usage
[GtkTemplate (ui = "/org/gnome/Usage/ui/process-row.ui")]
public class ProcessRow : Gtk.ListBoxRow
{
- ProcessListBoxType type;
+ public AppItem app { get; private set; }
+ public bool max_usage { get; private set; }
+
+ private const string CSS_TAG_USER = "tag-user";
+ private const string CSS_TAG_ROOT = "tag-root";
+ private const string CSS_TAG_SYSTEM = "tag-system";
[GtkChild]
private Gtk.Image icon;
@@ -40,93 +45,40 @@ namespace Usage
[GtkChild]
private Gtk.Label load_label;
- private Fdo.AccountsUser user;
-
- public Process process { get; private set; }
- public bool max_usage { get; private set; }
- public bool group {
- get {
- return process.sub_processes != null;
- }
- }
-
- private const int MAX_CPU_USAGE_LIMIT = 90;
- private const int MAX_MEMORY_USAGE_LIMIT = 90;
+ private ProcessListBoxType type;
- private const string CSS_TAG_USER = "tag-user";
- private const string CSS_TAG_ROOT = "tag-root";
- private const string CSS_TAG_SYSTEM = "tag-system";
-
- public ProcessRow(Process process, ProcessListBoxType type, bool opened = false)
+ public ProcessRow(AppItem app, ProcessListBoxType type)
{
this.type = type;
- this.process = process;
-
- load_icon(process.display_name);
+ this.app = app;
+ this.icon.gicon = app.get_icon();
update();
-
- load_user_account();
- }
-
- private async void load_user_account() {
- try {
- Fdo.Accounts accounts = yield Bus.get_proxy (BusType.SYSTEM,
- "org.freedesktop.Accounts",
- "/org/freedesktop/Accounts");
- var user_account_path = yield accounts.FindUserById ((int64)process.uid);
- this.user = yield Bus.get_proxy (BusType.SYSTEM,
- "org.freedesktop.Accounts",
- user_account_path);
- update_user_tag();
- } catch (Error e) {
- warning ("Unable to obtain user account: %s", e.message);
- }
- }
-
- private void load_icon(string display_name)
- {
- var app_info = SystemMonitor.get_default().get_app_info(display_name);
- var app_icon = (app_info == null) ? null : app_info.get_icon();
-
- if (app_info == null || app_icon == null)
- icon.gicon = new GLib.ThemedIcon("system-run-symbolic");
- else
- icon.gicon = app_icon;
}
private void update()
{
update_load_label();
update_user_tag();
- check_max_usage();
- set_styles();
- if(group)
- title_label.label = process.display_name + " (" + process.sub_processes.size().to_string() +
")";
- else
- title_label.label = process.display_name;
+ title_label.label = app.display_name;
}
private void update_load_label()
{
- CompareFunc<uint64?> sort = (a, b) => {
- return (int) ((uint64) (a < b) - (uint64) (a > b));
- };
-
switch(type)
{
case ProcessListBoxType.PROCESSOR:
- load_label.label = ((int) process.cpu_load).to_string() + " %";
+ load_label.label = ((int) app.cpu_load).to_string() + " %";
break;
case ProcessListBoxType.MEMORY:
- load_label.label = Utils.format_size_values(process.mem_usage);
+ load_label.label = Utils.format_size_values(app.mem_usage);
break;
}
}
private void update_user_tag()
{
- if (user == null)
+ if (app.user == null)
return;
remove_user_tag();
@@ -144,67 +96,37 @@ namespace Usage
private void create_user_tag()
{
string class_name = "";
- if(user.LocalAccount)
+ if(app.user.LocalAccount)
{
class_name = CSS_TAG_USER;
}
- else if(user.AccountType == UserAccountType.ADMINISTRATOR)
+ else if(app.user.AccountType == UserAccountType.ADMINISTRATOR)
{
class_name = CSS_TAG_ROOT;
}
- else if(user.SystemAccount)
+ else if(app.user.SystemAccount)
{
class_name = CSS_TAG_SYSTEM;
}
user_tag_box.get_style_context().add_class(class_name);
- user_tag_label.label = user.UserName;
+ user_tag_label.label = app.user.UserName;
user_tag_box.visible = !is_logged_in();
}
private bool is_logged_in(){
- return user.UserName == GLib.Environment.get_user_name();
- }
-
- private void check_max_usage()
- {
- switch(type)
- {
- case ProcessListBoxType.PROCESSOR:
- if(process.cpu_load >= MAX_CPU_USAGE_LIMIT)
- max_usage = true;
- else
- max_usage = false;
- break;
-
- case ProcessListBoxType.MEMORY:
- SystemMonitor monitor = SystemMonitor.get_default();
-
- if((((double) process.mem_usage / monitor.ram_total) * 100) >= MAX_MEMORY_USAGE_LIMIT)
- max_usage = true;
- else
- max_usage = false;
- break;
- }
+ return app.user.UserName == GLib.Environment.get_user_name();
}
public new void activate()
{
var settings = Settings.get_default();
- if (process.cmdline in settings.get_strv ("unkillable-processes"))
+ if (app.representative_cmdline in settings.get_strv ("unkillable-processes"))
return;
- var dialog = new QuitProcessDialog(process);
+ var dialog = new QuitProcessDialog(app);
dialog.set_transient_for(get_toplevel() as Gtk.Window);
dialog.show_all();
}
-
- private void set_styles()
- {
- if(max_usage)
- get_style_context().add_class("max");
- else
- get_style_context().remove_class("max");
- }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]