[gnome-usage] code style: stop using the `namespace` keyword
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] code style: stop using the `namespace` keyword
- Date: Fri, 10 Dec 2021 12:34:54 +0000 (UTC)
commit 0c245c87610ba57dd54fecc5961fa7a93e17c92d
Author: Nahuel Gomez <contact nahuelgomez com ar>
Date: Fri Dec 3 13:46:10 2021 -0300
code style: stop using the `namespace` keyword
Vala has had for some time a way to set the namespace of classes, enums,
structs, and delegates directly in the class name. Use that.
This allows us to get rid of an unnecessary level of indentation.
src/animated-scrolled-window.vala | 78 ++++---
src/app-item.vala | 428 ++++++++++++++++++-------------------
src/application.vala | 146 +++++++------
src/color-rectangle.vala | 79 ++++---
src/cpu-graph-model.vala | 161 +++++++-------
src/cpu-graph.vala | 182 ++++++++--------
src/cpu-monitor.vala | 96 ++++-----
src/cpu-sub-view.vala | 94 ++++----
src/graph-box.vala | 15 +-
src/graph-stack-switcher.vala | 92 ++++----
src/graph-stacked-renderer.vala | 151 +++++++------
src/graph-switcher-button.vala | 70 +++---
src/loading-notification.vala | 37 ++--
src/memory-graph-model.vala | 87 ++++----
src/memory-graph.vala | 84 ++++----
src/memory-monitor.vala | 72 +++----
src/memory-speedometer.vala | 48 ++---
src/memory-sub-view.vala | 98 +++++----
src/no-results-found-view.vala | 6 +-
src/notification-bar.vala | 32 ++-
src/performance-view.vala | 70 +++---
src/pie-chart.vala | 117 +++++-----
src/primary-menu.vala | 34 ++-
src/process-list-box.vala | 168 +++++++--------
src/process-row.vala | 154 +++++++------
src/process.vala | 336 +++++++++++++++--------------
src/quit-process-dialog.vala | 36 ++--
src/settings.vala | 33 ++-
src/speedometer.vala | 118 +++++-----
src/storage/storage-actionbar.vala | 96 ++++-----
src/storage/storage-graph.vala | 280 ++++++++++++------------
src/swap-speedometer.vala | 52 +++--
src/system-monitor.vala | 366 ++++++++++++++++---------------
src/utils.vala | 136 ++++++------
src/view.vala | 18 +-
src/window.vala | 180 ++++++++--------
36 files changed, 2085 insertions(+), 2165 deletions(-)
---
diff --git a/src/animated-scrolled-window.vala b/src/animated-scrolled-window.vala
index 0002dd0..7e58ac5 100644
--- a/src/animated-scrolled-window.vala
+++ b/src/animated-scrolled-window.vala
@@ -1,51 +1,49 @@
using Gtk;
-namespace Usage {
- public class AnimatedScrolledWindow : Gtk.ScrolledWindow {
- public signal void scroll_changed(double y);
- private const uint DURATION = 400;
+public class Usage.AnimatedScrolledWindow : Gtk.ScrolledWindow {
+ public signal void scroll_changed(double y);
+ private const uint DURATION = 400;
- construct {
- get_vadjustment().value_changed.connect(() => {
- scroll_changed(get_vadjustment().get_value());
- });
- }
-
- public void animated_scroll_vertically(int y) {
- var clock = get_frame_clock();
- int64 start_time = clock.get_frame_time();
- int64 end_time = start_time + 1000 * DURATION;
- double source = vadjustment.get_value();
- double target = y;
- ulong tick_id = 0;
+ construct {
+ get_vadjustment().value_changed.connect(() => {
+ scroll_changed(get_vadjustment().get_value());
+ });
+ }
- tick_id = clock.update.connect(() => {
- int64 now = clock.get_frame_time();
+ public void animated_scroll_vertically(int y) {
+ var clock = get_frame_clock();
+ int64 start_time = clock.get_frame_time();
+ int64 end_time = start_time + 1000 * DURATION;
+ double source = vadjustment.get_value();
+ double target = y;
+ ulong tick_id = 0;
- if (!animate_step (now, start_time, end_time, source, target)) {
- clock.disconnect(tick_id);
- tick_id = 0;
- clock.end_updating();
- }
- });
- clock.begin_updating();
- }
+ tick_id = clock.update.connect(() => {
+ int64 now = clock.get_frame_time();
- private bool animate_step (int64 now, int64 start_time, int64 end_time, double source, double
target) {
- if (now < end_time) {
- double t = (now - start_time) / (double) (end_time - start_time);
- t = ease_out_cubic (t);
- vadjustment.set_value(source + t * (target - source));
- return true;
- } else {
- vadjustment.set_value(target);
- return false;
+ if (!animate_step (now, start_time, end_time, source, target)) {
+ clock.disconnect(tick_id);
+ tick_id = 0;
+ clock.end_updating();
}
- }
+ });
+ clock.begin_updating();
+ }
- private double ease_out_cubic (double t) {
- double p = t - 1;
- return p * p * p + 1;
+ private bool animate_step (int64 now, int64 start_time, int64 end_time, double source, double target) {
+ if (now < end_time) {
+ double t = (now - start_time) / (double) (end_time - start_time);
+ t = ease_out_cubic (t);
+ vadjustment.set_value(source + t * (target - source));
+ return true;
+ } else {
+ vadjustment.set_value(target);
+ return false;
}
}
+
+ private double ease_out_cubic (double t) {
+ double p = t - 1;
+ return p * p * p + 1;
+ }
}
diff --git a/src/app-item.vala b/src/app-item.vala
index c7e70f0..fa93128 100644
--- a/src/app-item.vala
+++ b/src/app-item.vala
@@ -1,258 +1,256 @@
-namespace Usage {
- public class AppItem : Object {
- public HashTable<Pid?, Process>? processes { get; set; }
- public string display_name { get; private set; }
- public string representative_cmdline { get; private set; }
- public uint representative_uid { get; private set; }
- public double cpu_load { get; private set; }
- public uint64 mem_usage { get; private set; }
- public Fdo.AccountsUser? user { get; private set; default = null; }
- public bool gamemode {get; private set; }
-
- private static HashTable<string, AppInfo>? apps_info;
- private static HashTable<string, AppInfo>? appid_map;
- private AppInfo? app_info = null;
-
- public static void init() {
- apps_info = new HashTable<string, AppInfo> (str_hash, str_equal);
- appid_map = new HashTable<string, AppInfo> (str_hash, str_equal);
-
- var _apps_info = AppInfo.get_all ();
-
- foreach (AppInfo info in _apps_info) {
- GLib.DesktopAppInfo? dai = info as GLib.DesktopAppInfo;
- string ?id = null;
-
- if (dai != null) {
- id = dai.get_string ("X-Flatpak");
- if (id != null)
- appid_map.insert (id, info);
- }
-
- if (id == null) {
- id = info.get_id();
- if (id != null && id.has_suffix (".desktop"))
- id = id[0:id.length - 8];
- if (id != null)
- appid_map.insert (id, info);
- }
-
- string cmd = info.get_commandline ();
-
- if (cmd == null)
- continue;
-
- sanitize_cmd (ref cmd);
- apps_info.insert (cmd, info);
- }
- }
-
- public static string? appid_from_unit (string ?systemd_unit) {
- string ?escaped_id = null;
+public class Usage.AppItem : Object {
+ public HashTable<Pid?, Process>? processes { get; set; }
+ public string display_name { get; private set; }
+ public string representative_cmdline { get; private set; }
+ public uint representative_uid { get; private set; }
+ public double cpu_load { get; private set; }
+ public uint64 mem_usage { get; private set; }
+ public Fdo.AccountsUser? user { get; private set; default = null; }
+ public bool gamemode {get; private set; }
+
+ private static HashTable<string, AppInfo>? apps_info;
+ private static HashTable<string, AppInfo>? appid_map;
+ private AppInfo? app_info = null;
+
+ public static void init() {
+ apps_info = new HashTable<string, AppInfo> (str_hash, str_equal);
+ appid_map = new HashTable<string, AppInfo> (str_hash, str_equal);
+
+ var _apps_info = AppInfo.get_all ();
+
+ foreach (AppInfo info in _apps_info) {
+ GLib.DesktopAppInfo? dai = info as GLib.DesktopAppInfo;
string ?id = null;
- if (systemd_unit == null)
- return null;
-
- /* This is gnome-launched-APPID.desktop-RAND.scope */
- if (systemd_unit.has_prefix ("gnome-launched-")) {
- int index = -1;
-
- index = systemd_unit.index_of (".desktop-");
- // This is just argv[0] name encoded, we could also decode it
- // and look it up differently.
- // There is no standardization though for such a scheme.
- if (index == -1)
- return null;
-
- return systemd_unit[15:index];
+ if (dai != null) {
+ id = dai.get_string ("X-Flatpak");
+ if (id != null)
+ appid_map.insert (id, info);
}
- /* In other cases, assume compliance with spec, i.e. for
- * .scope units we fetch the second to last dashed item,
- * for .service units the last (as they use @ to separate
- * any required) */
- string[] segments = systemd_unit.split ("-");
-
- if (systemd_unit.has_suffix (".scope") && segments.length >= 2) {
- escaped_id = segments[segments.length - 2];
- } else if (systemd_unit.has_suffix (".service") && segments.length >= 1) {
- string tmp = segments[segments.length - 1];
- /* Strip .service */
- tmp = tmp[0:tmp.length-8];
- /* Remove any @ element (if there) */
- escaped_id = tmp.split("@", 2)[0];
+ if (id == null) {
+ id = info.get_id();
+ if (id != null && id.has_suffix (".desktop"))
+ id = id[0:id.length - 8];
+ if (id != null)
+ appid_map.insert (id, info);
}
- if (escaped_id == null)
- return null;
+ string cmd = info.get_commandline ();
- /* Now, unescape any \xXX escapes, which should only be dashes
- * from the reverse domain name. */
- id = escaped_id.compress();
- if (id == null)
- return null;
+ if (cmd == null)
+ continue;
- return id;
+ sanitize_cmd (ref cmd);
+ apps_info.insert (cmd, info);
}
+ }
- public static AppInfo? app_info_for_process (Process p) {
- AppInfo? info = null;
- string ?cgroup = null;
-
- cgroup = Process.read_cgroup(p.pid);
- if (cgroup != null) {
- /* Try to extract an application ID, this is a bit "magic".
- * See https://systemd.io/DESKTOP_ENVIRONMENTS/
- * and we also have some special cases for GNOME which is not
- * currently compliant to the specification. */
- string ?systemd_unit = null;
- string ?appid = null;
- string[] components;
-
- components = cgroup.split("/");
- systemd_unit = components[components.length - 1];
- appid = appid_from_unit (systemd_unit);
- if (appid != null)
- info = appid_map[appid];
-
- if (info != null)
- return info;
- }
+ public static string? appid_from_unit (string ?systemd_unit) {
+ string ?escaped_id = null;
+ string ?id = null;
- if (p.cmdline != null)
- info = apps_info[p.cmdline];
+ if (systemd_unit == null)
+ return null;
- if (info == null && p.app_id != null)
- info = appid_map[p.app_id];
+ /* This is gnome-launched-APPID.desktop-RAND.scope */
+ if (systemd_unit.has_prefix ("gnome-launched-")) {
+ int index = -1;
- return info;
- }
+ index = systemd_unit.index_of (".desktop-");
+ // This is just argv[0] name encoded, we could also decode it
+ // and look it up differently.
+ // There is no standardization though for such a scheme.
+ if (index == -1)
+ return null;
- public static bool have_app_info (Process p) {
- AppInfo? info = app_info_for_process (p);
- return info != null;
+ return systemd_unit[15:index];
}
- public AppItem(Process process) {
- app_info = app_info_for_process (process);
- representative_cmdline = process.cmdline;
- representative_uid = process.uid;
- display_name = find_display_name();
- processes.insert(process.pid, process);
- load_user_account.begin();
- gamemode = process.gamemode;
+ /* In other cases, assume compliance with spec, i.e. for
+ * .scope units we fetch the second to last dashed item,
+ * for .service units the last (as they use @ to separate
+ * any required) */
+ string[] segments = systemd_unit.split ("-");
+
+ if (systemd_unit.has_suffix (".scope") && segments.length >= 2) {
+ escaped_id = segments[segments.length - 2];
+ } else if (systemd_unit.has_suffix (".service") && segments.length >= 1) {
+ string tmp = segments[segments.length - 1];
+ /* Strip .service */
+ tmp = tmp[0:tmp.length-8];
+ /* Remove any @ element (if there) */
+ escaped_id = tmp.split("@", 2)[0];
}
- public AppItem.system() {
- display_name = _("System");
- representative_cmdline = "system";
- }
+ if (escaped_id == null)
+ return null;
- construct {
- processes = new HashTable<Pid?, Process>(int_hash, int_equal);
- }
+ /* Now, unescape any \xXX escapes, which should only be dashes
+ * from the reverse domain name. */
+ id = escaped_id.compress();
+ if (id == null)
+ return null;
+
+ return id;
+ }
- public bool contains_process(Pid pid) {
- return processes.contains(pid);
+ public static AppInfo? app_info_for_process (Process p) {
+ AppInfo? info = null;
+ string ?cgroup = null;
+
+ cgroup = Process.read_cgroup(p.pid);
+ if (cgroup != null) {
+ /* Try to extract an application ID, this is a bit "magic".
+ * See https://systemd.io/DESKTOP_ENVIRONMENTS/
+ * and we also have some special cases for GNOME which is not
+ * currently compliant to the specification. */
+ string ?systemd_unit = null;
+ string ?appid = null;
+ string[] components;
+
+ components = cgroup.split("/");
+ systemd_unit = components[components.length - 1];
+ appid = appid_from_unit (systemd_unit);
+ if (appid != null)
+ info = appid_map[appid];
+
+ if (info != null)
+ return info;
}
- public Icon get_icon() {
- var app_icon = (app_info == null) ? null : app_info.get_icon();
+ if (p.cmdline != null)
+ info = apps_info[p.cmdline];
- if (app_info == null || app_icon == null)
- return new GLib.ThemedIcon("system-run-symbolic");
- else
- return app_icon;
- }
+ if (info == null && p.app_id != null)
+ info = appid_map[p.app_id];
- public Process get_process_by_pid(Pid pid) {
- return processes.get(pid);
- }
+ return info;
+ }
- public void insert_process(Process process) {
- processes.insert(process.pid, process);
- }
+ public static bool have_app_info (Process p) {
+ AppInfo? info = app_info_for_process (p);
+ return info != null;
+ }
- public void kill() {
- foreach (var process in processes.get_values()) {
- debug ("Terminating %d", (int) process.pid);
- Posix.kill(process.pid, Posix.Signal.KILL);
- }
- }
+ public AppItem(Process process) {
+ app_info = app_info_for_process (process);
+ representative_cmdline = process.cmdline;
+ representative_uid = process.uid;
+ display_name = find_display_name();
+ processes.insert(process.pid, process);
+ load_user_account.begin();
+ gamemode = process.gamemode;
+ }
- public void mark_as_not_updated() {
- foreach (var process in processes.get_values())
- process.mark_as_updated = false;
- }
+ public AppItem.system() {
+ display_name = _("System");
+ representative_cmdline = "system";
+ }
- public void remove_processes() {
- cpu_load = 0;
- mem_usage = 0;
- int games = 0;
-
- foreach (var process in processes.get_values()) {
- if (!process.mark_as_updated) {
- processes.remove(process.pid);
- } else {
- cpu_load += process.cpu_load;
- mem_usage += process.mem_usage;
- }
- if (process.gamemode)
- games++;
- }
+ construct {
+ processes = new HashTable<Pid?, Process>(int_hash, int_equal);
+ }
- gamemode = games > 0;
- cpu_load = double.min(100, cpu_load);
- }
+ public bool contains_process(Pid pid) {
+ return processes.contains(pid);
+ }
- public void remove_process (Process process) {
- processes.remove (process.pid);
- }
+ public Icon get_icon() {
+ var app_icon = (app_info == null) ? null : app_info.get_icon();
- public void replace_process(Process process) {
- processes.replace(process.pid, process);
- }
+ if (app_info == null || app_icon == null)
+ return new GLib.ThemedIcon("system-run-symbolic");
+ else
+ return app_icon;
+ }
- private string find_display_name() {
- if (app_info != null)
- return app_info.get_display_name();
- else
- return representative_cmdline;
+ public Process get_process_by_pid(Pid pid) {
+ return processes.get(pid);
+ }
+
+ public void insert_process(Process process) {
+ processes.insert(process.pid, process);
+ }
+
+ public void kill() {
+ foreach (var process in processes.get_values()) {
+ debug ("Terminating %d", (int) process.pid);
+ Posix.kill(process.pid, Posix.Signal.KILL);
}
+ }
+
+ public void mark_as_not_updated() {
+ foreach (var process in processes.get_values())
+ process.mark_as_updated = false;
+ }
- 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) representative_uid);
- user = yield Bus.get_proxy (BusType.SYSTEM,
- "org.freedesktop.Accounts",
- user_account_path);
- } catch (Error e) {
- warning ("Unable to obtain user account: %s", e.message);
+ public void remove_processes() {
+ cpu_load = 0;
+ mem_usage = 0;
+ int games = 0;
+
+ foreach (var process in processes.get_values()) {
+ if (!process.mark_as_updated) {
+ processes.remove(process.pid);
+ } else {
+ cpu_load += process.cpu_load;
+ mem_usage += process.mem_usage;
}
+ if (process.gamemode)
+ games++;
}
- private static void sanitize_cmd(ref string? commandline) {
- if (commandline == null)
- return;
+ gamemode = games > 0;
+ cpu_load = double.min(100, cpu_load);
+ }
- // flatpak: parse the command line of the containerized program
- if (commandline.contains("flatpak run")) {
- var index = commandline.index_of ("--command=") + 10;
- commandline = commandline.substring (index);
- }
+ public void remove_process (Process process) {
+ processes.remove (process.pid);
+ }
- // TODO: unify this with the logic in get_full_process_cmd
- commandline = Process.first_component (commandline);
- commandline = Path.get_basename (commandline);
- commandline = Process.sanitize_name (commandline);
+ public void replace_process(Process process) {
+ processes.replace(process.pid, process);
+ }
+
+ private string find_display_name() {
+ if (app_info != null)
+ return app_info.get_display_name();
+ else
+ return representative_cmdline;
+ }
- // Workaround for google-chrome
- if (commandline.contains ("google-chrome-stable"))
- commandline = "chrome";
+ 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) representative_uid);
+ user = yield Bus.get_proxy (BusType.SYSTEM,
+ "org.freedesktop.Accounts",
+ user_account_path);
+ } catch (Error e) {
+ warning ("Unable to obtain user account: %s", e.message);
}
}
+
+ private static void sanitize_cmd(ref string? commandline) {
+ if (commandline == null)
+ return;
+
+ // flatpak: parse the command line of the containerized program
+ if (commandline.contains("flatpak run")) {
+ var index = commandline.index_of ("--command=") + 10;
+ commandline = commandline.substring (index);
+ }
+
+ // TODO: unify this with the logic in get_full_process_cmd
+ commandline = Process.first_component (commandline);
+ commandline = Path.get_basename (commandline);
+ commandline = Process.sanitize_name (commandline);
+
+ // Workaround for google-chrome
+ if (commandline.contains ("google-chrome-stable"))
+ commandline = "chrome";
+ }
}
diff --git a/src/application.vala b/src/application.vala
index 81c7ed6..895dde0 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -20,82 +20,80 @@
using Gtk;
-namespace Usage {
- public class Application : Gtk.Application {
- private Window window;
+public class Usage.Application : Gtk.Application {
+ private Window window;
- private const GLib.ActionEntry app_entries[] = { { "about", on_about }, { "search", on_search }, {
"quit", on_quit }, { "filter-processes", on_activate_radio, "s", "'group-system'",
change_filter_processes_state }
+ private const GLib.ActionEntry app_entries[] = { { "about", on_about }, { "search", on_search }, {
"quit", on_quit }, { "filter-processes", on_activate_radio, "s", "'group-system'",
change_filter_processes_state }
+ };
+
+ public Application () {
+ application_id = Config.APPLICATION_ID;
+ }
+
+ public Window? get_window() {
+ return window;
+ }
+
+ public override void activate() {
+ if (window != null)
+ return;
+
+ window = new Window(this);
+
+ set_accels_for_action("app.quit", {"<Primary>q"});
+
+ window.show();
+ }
+
+ protected override void startup() {
+ base.startup();
+
+ Hdy.init();
+
+ add_action_entries(app_entries, this);
+ set_accels_for_action ("app.search", {"<Primary>f"});
+
+ var icon_theme = Gtk.IconTheme.get_default ();
+ icon_theme.add_resource_path ("/org/gnome/Usage/icons/hicolor");
+ }
+
+ private void on_about(GLib.SimpleAction action, GLib.Variant? parameter) {
+ string[] authors = {
+ "Petr Štětka <pstetka redhat com>"
};
+ string[] artists = {
+ "Allan Day <aday gnome org>",
+ "Jon McCann <jmccann redhat com>",
+ "Jakub Steiner <jsteiner redhat com>"
+ };
+
+ Gtk.show_about_dialog (window,
+ logo_icon_name: Config.APPLICATION_ID,
+ program_name: _("Usage"),
+ comments: _("A nice way to view information about use of system resources, like memory and disk
space."),
+ authors: authors,
+ artists: artists,
+ translator_credits: _("translator-credits"),
+ website: "https://wiki.gnome.org/Apps/Usage",
+ website_label: _("Websites"),
+ version: Config.VERSION,
+ license_type: License.GPL_3_0);
+ }
+
+ private void on_quit(GLib.SimpleAction action, GLib.Variant? parameter) {
+ window.destroy();
+ }
+
+ private void on_search(GLib.SimpleAction action, GLib.Variant? parameter) {
+ window.action_on_search();
+ }
+
+ private void on_activate_radio (GLib.SimpleAction action, GLib.Variant? state) {
+ action.change_state(state);
+ }
- public Application () {
- application_id = Config.APPLICATION_ID;
- }
-
- public Window? get_window() {
- return window;
- }
-
- public override void activate() {
- if (window != null)
- return;
-
- window = new Window(this);
-
- set_accels_for_action("app.quit", {"<Primary>q"});
-
- window.show();
- }
-
- protected override void startup() {
- base.startup();
-
- Hdy.init();
-
- add_action_entries(app_entries, this);
- set_accels_for_action ("app.search", {"<Primary>f"});
-
- var icon_theme = Gtk.IconTheme.get_default ();
- icon_theme.add_resource_path ("/org/gnome/Usage/icons/hicolor");
- }
-
- private void on_about(GLib.SimpleAction action, GLib.Variant? parameter) {
- string[] authors = {
- "Petr Štětka <pstetka redhat com>"
- };
- string[] artists = {
- "Allan Day <aday gnome org>",
- "Jon McCann <jmccann redhat com>",
- "Jakub Steiner <jsteiner redhat com>"
- };
-
- Gtk.show_about_dialog (window,
- logo_icon_name: Config.APPLICATION_ID,
- program_name: _("Usage"),
- comments: _("A nice way to view information about use of system resources, like memory and
disk space."),
- authors: authors,
- artists: artists,
- translator_credits: _("translator-credits"),
- website: "https://wiki.gnome.org/Apps/Usage",
- website_label: _("Websites"),
- version: Config.VERSION,
- license_type: License.GPL_3_0);
- }
-
- private void on_quit(GLib.SimpleAction action, GLib.Variant? parameter) {
- window.destroy();
- }
-
- private void on_search(GLib.SimpleAction action, GLib.Variant? parameter) {
- window.action_on_search();
- }
-
- private void on_activate_radio (GLib.SimpleAction action, GLib.Variant? state) {
- action.change_state(state);
- }
-
- private void change_filter_processes_state(GLib.SimpleAction action, GLib.Variant? state) {
- action.set_state(state);
- SystemMonitor.get_default().group_system_apps = state.get_string() == "group-system" ? true :
false;
- }
+ private void change_filter_processes_state(GLib.SimpleAction action, GLib.Variant? state) {
+ action.set_state(state);
+ SystemMonitor.get_default().group_system_apps = state.get_string() == "group-system" ? true : false;
}
}
diff --git a/src/color-rectangle.vala b/src/color-rectangle.vala
index 1252b6b..d3209f9 100644
--- a/src/color-rectangle.vala
+++ b/src/color-rectangle.vala
@@ -20,54 +20,51 @@
using Gtk;
-namespace Usage {
+public class Usage.ColorRectangle : Gtk.DrawingArea {
+ public Gdk.RGBA color { get; set; }
- public class ColorRectangle : Gtk.DrawingArea {
- public Gdk.RGBA color { get; set; }
-
- class construct {
- set_css_name("ColorRectangle");
- }
+ class construct {
+ set_css_name("ColorRectangle");
+ }
- construct {
- this.height_request = 17;
- this.width_request = 17;
- this.valign = Gtk.Align.CENTER;
- this.draw.connect ((context) => {
- int height = this.get_allocated_height ();
- int width = this.get_allocated_width ();
+ construct {
+ this.height_request = 17;
+ this.width_request = 17;
+ this.valign = Gtk.Align.CENTER;
+ this.draw.connect ((context) => {
+ int height = this.get_allocated_height ();
+ int width = this.get_allocated_width ();
- double degrees = Math.PI / 180.0;
- double x = 0;
- double y = 0;
- double radius = height / 5;
+ double degrees = Math.PI / 180.0;
+ double x = 0;
+ double y = 0;
+ double radius = height / 5;
- context.new_sub_path();
- context.arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
- context.arc(x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
- context.arc(x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
- context.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
- context.close_path();
+ context.new_sub_path();
+ context.arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
+ context.arc(x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
+ context.arc(x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
+ context.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
+ context.close_path();
- Gdk.cairo_set_source_rgba (context, color);
- context.fill();
- return true;
- });
- }
+ Gdk.cairo_set_source_rgba (context, color);
+ context.fill();
+ return true;
+ });
+ }
- public ColorRectangle.new_from_rgba(Gdk.RGBA color) {
- this.color = color;
- queue_draw_area(0, 0, this.get_allocated_width(), this.get_allocated_height());
- }
+ public ColorRectangle.new_from_rgba(Gdk.RGBA color) {
+ this.color = color;
+ queue_draw_area(0, 0, this.get_allocated_width(), this.get_allocated_height());
+ }
- public ColorRectangle.new_from_css(string css_class) {
- set_color_from_css(css_class);
- }
+ public ColorRectangle.new_from_css(string css_class) {
+ set_color_from_css(css_class);
+ }
- public void set_color_from_css(string css_class) {
- get_style_context().add_class(css_class);
- color = get_style_context().get_color(get_style_context().get_state());
- queue_draw_area(0, 0, this.get_allocated_width(), this.get_allocated_height());
- }
+ public void set_color_from_css(string css_class) {
+ get_style_context().add_class(css_class);
+ color = get_style_context().get_color(get_style_context().get_state());
+ queue_draw_area(0, 0, this.get_allocated_width(), this.get_allocated_height());
}
}
diff --git a/src/cpu-graph-model.vala b/src/cpu-graph-model.vala
index a8a7fa8..fa3131a 100644
--- a/src/cpu-graph-model.vala
+++ b/src/cpu-graph-model.vala
@@ -20,110 +20,107 @@
using Dazzle;
-namespace Usage {
+public class Usage.CpuGraphModel : GraphModel {
+ public signal void big_process_usage (int column);
+ public signal void small_process_usage (int column);
+ private bool[] change_big_process_usage;
+ private bool[] change_small_process_usage;
- public class CpuGraphModel : GraphModel {
- public signal void big_process_usage (int column);
- public signal void small_process_usage (int column);
- private bool[] change_big_process_usage;
- private bool[] change_small_process_usage;
+ public CpuGraphModel () {
+ var settings = Settings.get_default();
+ set_timespan (settings.graph_timespan * 1000);
+ set_max_samples (settings.graph_max_samples);
- public CpuGraphModel () {
- var settings = Settings.get_default();
- set_timespan (settings.graph_timespan * 1000);
- set_max_samples (settings.graph_max_samples);
+ var column_total = new GraphColumn("TOTAL CPU", Type.from_name("gdouble"));
+ add_column(column_total);
- var column_total = new GraphColumn("TOTAL CPU", Type.from_name("gdouble"));
- add_column(column_total);
+ change_big_process_usage = new bool[get_num_processors()];
+ change_small_process_usage = new bool[get_num_processors()];
- change_big_process_usage = new bool[get_num_processors()];
- change_small_process_usage = new bool[get_num_processors()];
+ for (int i = 0; i < get_num_processors(); i++) {
+ var column_x_cpu = new GraphColumn("CPU: " + i.to_string(), Type.from_name("gdouble"));
+ add_column(column_x_cpu);
- for (int i = 0; i < get_num_processors(); i++) {
- var column_x_cpu = new GraphColumn("CPU: " + i.to_string(), Type.from_name("gdouble"));
- add_column(column_x_cpu);
+ change_big_process_usage[i] = true;
+ change_small_process_usage[i] = true;
+ }
- change_big_process_usage[i] = true;
- change_small_process_usage[i] = true;
- }
+ Timeout.add(settings.graph_update_interval, update_data);
+ }
- Timeout.add(settings.graph_update_interval, update_data);
- }
+ bool update_data() {
+ GraphModelIter iter;
+ push (out iter, get_monotonic_time ());
+
+ SystemMonitor monitor = SystemMonitor.get_default();
+
+ for (int i = 0; i < get_num_processors(); i++) {
+ iter_set_value(iter, i, monitor.x_cpu_load[i]);
- bool update_data() {
- GraphModelIter iter;
- push (out iter, get_monotonic_time ());
-
- SystemMonitor monitor = SystemMonitor.get_default();
-
- for (int i = 0; i < get_num_processors(); i++) {
- iter_set_value(iter, i, monitor.x_cpu_load[i]);
-
- if (monitor.x_cpu_load[i] >= 90) {
- if (change_big_process_usage[i]) {
- big_process_usage(i);
- change_big_process_usage[i] = false;
- change_small_process_usage[i] = true;
- }
- } else {
- if (change_small_process_usage[i]) {
- small_process_usage(i);
- change_small_process_usage[i] = false;
- change_big_process_usage[i] = true;
- }
+ if (monitor.x_cpu_load[i] >= 90) {
+ if (change_big_process_usage[i]) {
+ big_process_usage(i);
+ change_big_process_usage[i] = false;
+ change_small_process_usage[i] = true;
+ }
+ } else {
+ if (change_small_process_usage[i]) {
+ small_process_usage(i);
+ change_small_process_usage[i] = false;
+ change_big_process_usage[i] = true;
}
}
-
- return true;
}
+
+ return true;
}
+}
- public class CpuGraphModelMostUsedCore : GraphModel {
- public signal void big_process_usage ();
- public signal void small_process_usage ();
- private bool change_big_process_usage = true;
- private bool change_small_process_usage = true;
+public class Usage.CpuGraphModelMostUsedCore : GraphModel {
+ public signal void big_process_usage ();
+ public signal void small_process_usage ();
+ private bool change_big_process_usage = true;
+ private bool change_small_process_usage = true;
- public CpuGraphModelMostUsedCore () {
- var settings = Settings.get_default();
- set_timespan (settings.graph_timespan * 1000);
- set_max_samples (settings.graph_max_samples);
+ public CpuGraphModelMostUsedCore () {
+ var settings = Settings.get_default();
+ set_timespan (settings.graph_timespan * 1000);
+ set_max_samples (settings.graph_max_samples);
- var column = new GraphColumn("MOST USED CORE", Type.from_name("gdouble"));
- add_column(column);
+ var column = new GraphColumn("MOST USED CORE", Type.from_name("gdouble"));
+ add_column(column);
- Timeout.add(settings.graph_update_interval, update_data);
- }
+ Timeout.add(settings.graph_update_interval, update_data);
+ }
- bool update_data() {
- GraphModelIter iter;
- push (out iter, get_monotonic_time ());
+ bool update_data() {
+ GraphModelIter iter;
+ push (out iter, get_monotonic_time ());
- SystemMonitor monitor = SystemMonitor.get_default();
- double most_used_core = monitor.x_cpu_load[0];
+ SystemMonitor monitor = SystemMonitor.get_default();
+ double most_used_core = monitor.x_cpu_load[0];
- for (int i = 1; i < get_num_processors(); i++) {
- if (monitor.x_cpu_load[i] > most_used_core)
- most_used_core = monitor.x_cpu_load[i];
- }
+ for (int i = 1; i < get_num_processors(); i++) {
+ if (monitor.x_cpu_load[i] > most_used_core)
+ most_used_core = monitor.x_cpu_load[i];
+ }
- iter_set_value(iter, 0, most_used_core);
+ iter_set_value(iter, 0, most_used_core);
- if (most_used_core >= 90) {
- if (change_big_process_usage) {
- big_process_usage();
- change_big_process_usage = false;
- change_small_process_usage = true;
- }
- } else {
- if (change_small_process_usage) {
- small_process_usage();
- change_small_process_usage = false;
- change_big_process_usage = true;
- }
+ if (most_used_core >= 90) {
+ if (change_big_process_usage) {
+ big_process_usage();
+ change_big_process_usage = false;
+ change_small_process_usage = true;
+ }
+ } else {
+ if (change_small_process_usage) {
+ small_process_usage();
+ change_small_process_usage = false;
+ change_big_process_usage = true;
}
-
- return true;
}
+
+ return true;
}
}
diff --git a/src/cpu-graph.vala b/src/cpu-graph.vala
index 2094360..d7843a2 100644
--- a/src/cpu-graph.vala
+++ b/src/cpu-graph.vala
@@ -20,104 +20,102 @@
using Dazzle;
-namespace Usage {
- /**
- * Graph showing most used core
- **/
- public class CpuGraphMostUsedCore : GraphView {
- private static CpuGraphModelMostUsedCore graph_model;
- private GraphStackedRenderer renderer;
- private Gdk.RGBA line_color_max;
- private Gdk.RGBA line_color_normal;
- private Gdk.RGBA color_max;
- private Gdk.RGBA color_normal;
-
- class construct {
- set_css_name("rg-graph");
- }
+/**
+ * Graph showing most used core
+**/
+public class Usage.CpuGraphMostUsedCore : GraphView {
+ private static CpuGraphModelMostUsedCore graph_model;
+ private GraphStackedRenderer renderer;
+ private Gdk.RGBA line_color_max;
+ private Gdk.RGBA line_color_normal;
+ private Gdk.RGBA color_max;
+ private Gdk.RGBA color_normal;
+
+ class construct {
+ set_css_name("rg-graph");
+ }
- public CpuGraphMostUsedCore () {
- get_style_context().add_class("line_max");
- line_color_max = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("line_max");
- get_style_context().add_class("line");
- line_color_normal = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("line");
- get_style_context().add_class("stacked_max");
- color_max = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("stacked_max");
- get_style_context().add_class("stacked");
- color_normal = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("stacked");
-
- if (graph_model == null)
- graph_model = new CpuGraphModelMostUsedCore();
-
- set_model(graph_model);
-
- renderer = new GraphStackedRenderer();
+ public CpuGraphMostUsedCore () {
+ get_style_context().add_class("line_max");
+ line_color_max = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("line_max");
+ get_style_context().add_class("line");
+ line_color_normal = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("line");
+ get_style_context().add_class("stacked_max");
+ color_max = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("stacked_max");
+ get_style_context().add_class("stacked");
+ color_normal = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("stacked");
+
+ if (graph_model == null)
+ graph_model = new CpuGraphModelMostUsedCore();
+
+ set_model(graph_model);
+
+ renderer = new GraphStackedRenderer();
+ renderer.stroke_color_rgba = line_color_normal;
+ renderer.stacked_color_rgba = color_normal;
+ renderer.line_width = 1.0;
+ add_renderer(renderer);
+
+ graph_model.big_process_usage.connect (() => {
+ renderer.stroke_color_rgba = line_color_max;
+ renderer.stacked_color_rgba = color_max;
+ });
+
+ graph_model.small_process_usage.connect (() => {
renderer.stroke_color_rgba = line_color_normal;
renderer.stacked_color_rgba = color_normal;
- renderer.line_width = 1.0;
- add_renderer(renderer);
-
- graph_model.big_process_usage.connect (() => {
- renderer.stroke_color_rgba = line_color_max;
- renderer.stacked_color_rgba = color_max;
- });
-
- graph_model.small_process_usage.connect (() => {
- renderer.stroke_color_rgba = line_color_normal;
- renderer.stacked_color_rgba = color_normal;
- });
- }
+ });
+ }
+}
+
+/**
+ * Graph showing all processor cores.
+**/
+public class Usage.CpuGraph : GraphView {
+ private static CpuGraphModel graph_model;
+ private GraphLineRenderer[] renderers;
+ private Gdk.RGBA line_color_max;
+ private Gdk.RGBA line_color_normal;
+
+ class construct {
+ set_css_name("rg-graph");
}
- /**
- * Graph showing all processor cores.
- **/
- public class CpuGraph : GraphView {
- private static CpuGraphModel graph_model;
- private GraphLineRenderer[] renderers;
- private Gdk.RGBA line_color_max;
- private Gdk.RGBA line_color_normal;
-
- class construct {
- set_css_name("rg-graph");
+ public CpuGraph() {
+ get_style_context().add_class("line_max");
+ line_color_max = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("line_max");
+ get_style_context().add_class("line");
+ line_color_normal = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("line");
+ get_style_context().add_class("big");
+
+ if (graph_model == null)
+ graph_model = new CpuGraphModel();
+
+ set_model(graph_model);
+
+ renderers = new GraphLineRenderer[get_num_processors()];
+ for (int i = 0; i < get_num_processors(); i++) {
+ renderers[i] = new GraphLineRenderer();
+ renderers[i].column = i;
+ renderers[i].stroke_color_rgba = line_color_normal;
+ renderers[i].line_width = 1.5;
+ add_renderer(renderers[i]);
}
- public CpuGraph() {
- get_style_context().add_class("line_max");
- line_color_max = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("line_max");
- get_style_context().add_class("line");
- line_color_normal = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("line");
- get_style_context().add_class("big");
-
- if (graph_model == null)
- graph_model = new CpuGraphModel();
-
- set_model(graph_model);
-
- renderers = new GraphLineRenderer[get_num_processors()];
- for (int i = 0; i < get_num_processors(); i++) {
- renderers[i] = new GraphLineRenderer();
- renderers[i].column = i;
- renderers[i].stroke_color_rgba = line_color_normal;
- renderers[i].line_width = 1.5;
- add_renderer(renderers[i]);
- }
-
- graph_model.big_process_usage.connect ((column) => {
- renderers[column].stroke_color_rgba = line_color_max;
- renderers[column].line_width = 2.5;
- });
-
- graph_model.small_process_usage.connect ((column) => {
- renderers[column].stroke_color_rgba = line_color_normal;
- renderers[column].line_width = 1.5;
- });
- }
+ graph_model.big_process_usage.connect ((column) => {
+ renderers[column].stroke_color_rgba = line_color_max;
+ renderers[column].line_width = 2.5;
+ });
+
+ graph_model.small_process_usage.connect ((column) => {
+ renderers[column].stroke_color_rgba = line_color_normal;
+ renderers[column].line_width = 1.5;
+ });
}
}
diff --git a/src/cpu-monitor.vala b/src/cpu-monitor.vala
index 7cfa0b8..b78ea80 100644
--- a/src/cpu-monitor.vala
+++ b/src/cpu-monitor.vala
@@ -18,63 +18,61 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class CpuMonitor : Monitor {
- private double cpu_load;
- private double[] x_cpu_load;
- private uint64 cpu_last_used = 0;
- private uint64 cpu_last_total = 0;
- private uint64 cpu_last_total_step = 0;
- private uint64[] x_cpu_last_used;
- private uint64[] x_cpu_last_total;
+public class Usage.CpuMonitor : Monitor {
+ private double cpu_load;
+ private double[] x_cpu_load;
+ private uint64 cpu_last_used = 0;
+ private uint64 cpu_last_total = 0;
+ private uint64 cpu_last_total_step = 0;
+ private uint64[] x_cpu_last_used;
+ private uint64[] x_cpu_last_total;
- public CpuMonitor() {
- x_cpu_load = new double[get_num_processors()];
- x_cpu_last_used = new uint64[get_num_processors()];
- x_cpu_last_total = new uint64[get_num_processors()];
- }
-
- public void update() {
- GTop.Cpu cpu_data;
- GTop.get_cpu (out cpu_data);
- var used = cpu_data.user + cpu_data.nice + cpu_data.sys;
- cpu_load = (((double) (used - cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100;
- cpu_last_total_step = cpu_data.total - cpu_last_total;
+ public CpuMonitor() {
+ x_cpu_load = new double[get_num_processors()];
+ x_cpu_last_used = new uint64[get_num_processors()];
+ x_cpu_last_total = new uint64[get_num_processors()];
+ }
- var x_cpu_used = new uint64[get_num_processors()];
- for (int i = 0; i < x_cpu_load.length; i++) {
- x_cpu_used[i] = cpu_data.xcpu_user[i] + cpu_data.xcpu_nice[i] + cpu_data.xcpu_sys[i];
- x_cpu_load[i] = (((double) (x_cpu_used[i] - x_cpu_last_used[i])) / (cpu_data.xcpu_total[i] -
x_cpu_last_total[i])) * 100;
- }
+ public void update() {
+ GTop.Cpu cpu_data;
+ GTop.get_cpu (out cpu_data);
+ var used = cpu_data.user + cpu_data.nice + cpu_data.sys;
+ cpu_load = (((double) (used - cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100;
+ cpu_last_total_step = cpu_data.total - cpu_last_total;
- cpu_last_used = used;
- cpu_last_total = cpu_data.total;
- x_cpu_last_used = x_cpu_used;
- x_cpu_last_total = cpu_data.xcpu_total;
+ var x_cpu_used = new uint64[get_num_processors()];
+ for (int i = 0; i < x_cpu_load.length; i++) {
+ x_cpu_used[i] = cpu_data.xcpu_user[i] + cpu_data.xcpu_nice[i] + cpu_data.xcpu_sys[i];
+ x_cpu_load[i] = (((double) (x_cpu_used[i] - x_cpu_last_used[i])) / (cpu_data.xcpu_total[i] -
x_cpu_last_total[i])) * 100;
}
- public double get_cpu_load() {
- return cpu_load;
- }
+ cpu_last_used = used;
+ cpu_last_total = cpu_data.total;
+ x_cpu_last_used = x_cpu_used;
+ x_cpu_last_total = cpu_data.xcpu_total;
+ }
- public double[] get_x_cpu_load() {
- return x_cpu_load;
- }
+ public double get_cpu_load() {
+ return cpu_load;
+ }
- public void update_process(ref Process process) {
- GTop.ProcTime proc_time;
- GTop.ProcState proc_state;
+ public double[] get_x_cpu_load() {
+ return x_cpu_load;
+ }
- GTop.get_proc_time (out proc_time, process.pid);
- GTop.get_proc_state (out proc_state, process.pid);
+ public void update_process(ref Process process) {
+ GTop.ProcTime proc_time;
+ GTop.ProcState proc_state;
- process.last_processor = proc_state.last_processor;
- double cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / cpu_last_total_step) *
100 * get_num_processors();
- cpu_load = double.min(100, cpu_load);
- process.cpu_load = cpu_load;
- process.cpu_last_used = proc_time.rtime;
- process.x_cpu_last_used = proc_time.xcpu_utime[process.last_processor] +
proc_time.xcpu_stime[process.last_processor];
- process.start_time = proc_time.start_time;
- }
+ GTop.get_proc_time (out proc_time, process.pid);
+ GTop.get_proc_state (out proc_state, process.pid);
+
+ process.last_processor = proc_state.last_processor;
+ double cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / cpu_last_total_step) * 100
* get_num_processors();
+ cpu_load = double.min(100, cpu_load);
+ process.cpu_load = cpu_load;
+ process.cpu_last_used = proc_time.rtime;
+ process.x_cpu_last_used = proc_time.xcpu_utime[process.last_processor] +
proc_time.xcpu_stime[process.last_processor];
+ process.start_time = proc_time.start_time;
}
}
diff --git a/src/cpu-sub-view.vala b/src/cpu-sub-view.vala
index 10a1185..acf6915 100644
--- a/src/cpu-sub-view.vala
+++ b/src/cpu-sub-view.vala
@@ -18,65 +18,63 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class ProcessorSubView : View, SubView {
- private ProcessListBox process_list_box;
- private NoResultsFoundView no_process_view;
+public class Usage.ProcessorSubView : View, SubView {
+ private ProcessListBox process_list_box;
+ private NoResultsFoundView no_process_view;
- public ProcessorSubView() {
- name = "PROCESSOR";
+ public ProcessorSubView() {
+ name = "PROCESSOR";
- var label = new Gtk.Label("<span font_desc=\"14.0\">" + _("Processor") + "</span>");
- label.set_use_markup(true);
- label.margin_top = 25;
- label.margin_bottom = 15;
+ var label = new Gtk.Label("<span font_desc=\"14.0\">" + _("Processor") + "</span>");
+ label.set_use_markup(true);
+ label.margin_top = 25;
+ label.margin_bottom = 15;
- var cpu_graph = new CpuGraph();
- cpu_graph.hexpand = true;
- var cpu_graph_box = new GraphBox(cpu_graph);
- cpu_graph_box.height_request = 225;
- cpu_graph_box.valign = Gtk.Align.START;
+ var cpu_graph = new CpuGraph();
+ cpu_graph.hexpand = true;
+ var cpu_graph_box = new GraphBox(cpu_graph);
+ cpu_graph_box.height_request = 225;
+ cpu_graph_box.valign = Gtk.Align.START;
- process_list_box = new ProcessListBox(ProcessListBoxType.PROCESSOR);
- process_list_box.margin_bottom = 20;
- process_list_box.margin_top = 30;
+ process_list_box = new ProcessListBox(ProcessListBoxType.PROCESSOR);
+ process_list_box.margin_bottom = 20;
+ process_list_box.margin_top = 30;
- var spinner = new Gtk.Spinner();
- spinner.active = true;
- spinner.margin_top = 30;
- spinner.height_request = 250;
+ var spinner = new Gtk.Spinner();
+ spinner.active = true;
+ spinner.margin_top = 30;
+ spinner.height_request = 250;
- no_process_view = new NoResultsFoundView();
+ no_process_view = new NoResultsFoundView();
- var cpu_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
- cpu_box.pack_start(label, false, false, 0);
- cpu_box.pack_start(cpu_graph_box, false, false, 0);
- cpu_box.pack_start(spinner, true, true, 0);
- cpu_box.add(no_process_view);
+ var cpu_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
+ cpu_box.pack_start(label, false, false, 0);
+ cpu_box.pack_start(cpu_graph_box, false, false, 0);
+ cpu_box.pack_start(spinner, true, true, 0);
+ cpu_box.add(no_process_view);
- var system_monitor = SystemMonitor.get_default();
- system_monitor.notify["process-list-ready"].connect ((sender, property) => {
- if (system_monitor.process_list_ready) {
- cpu_box.pack_start(process_list_box, false, false, 0);
- cpu_box.remove(spinner);
- } else {
- cpu_box.pack_start(spinner, true, true, 0);
- cpu_box.remove(process_list_box);
- }
- });
+ var system_monitor = SystemMonitor.get_default();
+ system_monitor.notify["process-list-ready"].connect ((sender, property) => {
+ if (system_monitor.process_list_ready) {
+ cpu_box.pack_start(process_list_box, false, false, 0);
+ cpu_box.remove(spinner);
+ } else {
+ cpu_box.pack_start(spinner, true, true, 0);
+ cpu_box.remove(process_list_box);
+ }
+ });
- process_list_box.bind_property ("empty", no_process_view, "visible", BindingFlags.BIDIRECTIONAL);
+ process_list_box.bind_property ("empty", no_process_view, "visible", BindingFlags.BIDIRECTIONAL);
- add(cpu_box);
- }
+ add(cpu_box);
+ }
- public override void show_all() {
- base.show_all();
- this.no_process_view.hide();
- }
+ public override void show_all() {
+ base.show_all();
+ this.no_process_view.hide();
+ }
- public void search_in_processes(string text) {
- process_list_box.search_text = text;
- }
+ public void search_in_processes(string text) {
+ process_list_box.search_text = text;
}
}
diff --git a/src/graph-box.vala b/src/graph-box.vala
index 78fe4a6..2d88acd 100644
--- a/src/graph-box.vala
+++ b/src/graph-box.vala
@@ -20,16 +20,13 @@
using Gtk;
-namespace Usage {
+public class GraphBox : Gtk.Box {
- public class GraphBox : Gtk.Box {
-
- class construct {
- set_css_name("graph-box");
- }
+ class construct {
+ set_css_name("graph-box");
+ }
- public GraphBox (Dazzle.GraphView graph) {
- add(graph);
- }
+ public GraphBox (Dazzle.GraphView graph) {
+ add(graph);
}
}
diff --git a/src/graph-stack-switcher.vala b/src/graph-stack-switcher.vala
index 01588e6..c4dd30d 100644
--- a/src/graph-stack-switcher.vala
+++ b/src/graph-stack-switcher.vala
@@ -18,70 +18,68 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class GraphStackSwitcher : Gtk.Box {
- View[] sub_views;
- AnimatedScrolledWindow scrolled_window;
+public class Usage.GraphStackSwitcher : Gtk.Box {
+ View[] sub_views;
+ AnimatedScrolledWindow scrolled_window;
- GraphSwitcherButton[] buttons;
+ GraphSwitcherButton[] buttons;
- class construct {
- set_css_name("graph-stack-switcher");
- }
+ class construct {
+ set_css_name("graph-stack-switcher");
+ }
- public GraphStackSwitcher(AnimatedScrolledWindow scrolled_window, View[] sub_views) {
- Object(orientation: Gtk.Orientation.VERTICAL, spacing: 0);
+ public GraphStackSwitcher(AnimatedScrolledWindow scrolled_window, View[] sub_views) {
+ Object(orientation: Gtk.Orientation.VERTICAL, spacing: 0);
- this.sub_views = sub_views;
- this.scrolled_window = scrolled_window;
+ this.sub_views = sub_views;
+ this.scrolled_window = scrolled_window;
- scrolled_window.scroll_changed.connect(on_scroll_changed);
+ scrolled_window.scroll_changed.connect(on_scroll_changed);
- buttons = {
- new GraphSwitcherButton.processor(_("Processor")),
- new GraphSwitcherButton.memory(_("Memory"))
- };
+ buttons = {
+ new GraphSwitcherButton.processor(_("Processor")),
+ new GraphSwitcherButton.memory(_("Memory"))
+ };
- foreach (GraphSwitcherButton button in buttons) {
- this.pack_start(button, false, true, 0);
+ foreach (GraphSwitcherButton button in buttons) {
+ this.pack_start(button, false, true, 0);
- button.button_release_event.connect(() => {
- var button_number = get_button_number(button);
- scroll_to_view(button_number);
+ button.button_release_event.connect(() => {
+ var button_number = get_button_number(button);
+ scroll_to_view(button_number);
- return false;
- });
- }
+ return false;
+ });
}
+ }
- private int get_button_number(Gtk.Button button) {
- for (int i = 0; i < buttons.length; i++) {
- if (buttons[i] == button)
- return i;
- }
-
- return 0;
+ private int get_button_number(Gtk.Button button) {
+ for (int i = 0; i < buttons.length; i++) {
+ if (buttons[i] == button)
+ return i;
}
- private void scroll_to_view(int button_number) {
- Gtk.Allocation alloc;
+ return 0;
+ }
- this.sub_views[button_number].get_allocation(out alloc);
- scrolled_window.animated_scroll_vertically(alloc.y);
- }
+ private void scroll_to_view(int button_number) {
+ Gtk.Allocation alloc;
- private void on_scroll_changed(double y) {
- Gtk.Allocation alloc;
+ this.sub_views[button_number].get_allocation(out alloc);
+ scrolled_window.animated_scroll_vertically(alloc.y);
+ }
- var button_number = 0;
- for (int i = 1; i < buttons.length; i++) {
- this.sub_views[i].get_allocation(out alloc);
- if (y < alloc.y)
- break;
- button_number = i;
- }
+ private void on_scroll_changed(double y) {
+ Gtk.Allocation alloc;
- buttons[button_number].set_active(true);
+ var button_number = 0;
+ for (int i = 1; i < buttons.length; i++) {
+ this.sub_views[i].get_allocation(out alloc);
+ if (y < alloc.y)
+ break;
+ button_number = i;
}
+
+ buttons[button_number].set_active(true);
}
}
diff --git a/src/graph-stacked-renderer.vala b/src/graph-stacked-renderer.vala
index a27abd2..83b855e 100644
--- a/src/graph-stacked-renderer.vala
+++ b/src/graph-stacked-renderer.vala
@@ -21,103 +21,100 @@
using Dazzle;
using Cairo;
-namespace Usage {
+public class GraphStackedRenderer : Object, GraphRenderer {
- public class GraphStackedRenderer : Object, GraphRenderer {
+ public uint column { get; set; }
+ public double line_width { get; set; default = 1.0; }
+ public Gdk.RGBA stroke_color_rgba { get; set; }
+ public Gdk.RGBA stacked_color_rgba { get; set; }
- public uint column { get; set; }
- public double line_width { get; set; default = 1.0; }
- public Gdk.RGBA stroke_color_rgba { get; set; }
- public Gdk.RGBA stacked_color_rgba { get; set; }
+ public void render(GraphModel model, int64 x_begin, int64 x_end, double y_begin, double y_end, Context
cr, RectangleInt area) {
+ GraphModelIter iter;
+ cr.save();
- public void render(GraphModel model, int64 x_begin, int64 x_end, double y_begin, double y_end,
Context cr, RectangleInt area) {
- GraphModelIter iter;
- cr.save();
+ if (model.get_iter_first(out iter)) {
+ double chunk = area.width / (double) (model.max_samples - 1) / 2.0;
+ double last_x = calc_x (iter, x_begin, x_end, area.width);
+ double last_y = area.height;
- if (model.get_iter_first(out iter)) {
- double chunk = area.width / (double) (model.max_samples - 1) / 2.0;
- double last_x = calc_x (iter, x_begin, x_end, area.width);
- double last_y = area.height;
+ cr.move_to (last_x, area.height);
- cr.move_to (last_x, area.height);
+ while (GraphModel.iter_next (ref iter)) {
+ double x = calc_x (iter, x_begin, x_end, area.width);
+ double y = calc_y (iter, y_begin, y_end, area.height, column);
- while (GraphModel.iter_next (ref iter)) {
- double x = calc_x (iter, x_begin, x_end, area.width);
- double y = calc_y (iter, y_begin, y_end, area.height, column);
+ cr.curve_to (last_x + chunk, last_y, last_x + chunk, y, x, y);
- cr.curve_to (last_x + chunk, last_y, last_x + chunk, y, x, y);
-
- last_x = x;
- last_y = y;
- }
+ last_x = x;
+ last_y = y;
}
+ }
- cr.set_line_width (line_width);
- cr.set_source_rgba (stacked_color_rgba.red, stacked_color_rgba.green, stacked_color_rgba.blue,
stacked_color_rgba.alpha);
- cr.rel_line_to (0, area.height);
- cr.stroke_preserve ();
- cr.close_path();
- cr.fill();
+ cr.set_line_width (line_width);
+ cr.set_source_rgba (stacked_color_rgba.red, stacked_color_rgba.green, stacked_color_rgba.blue,
stacked_color_rgba.alpha);
+ cr.rel_line_to (0, area.height);
+ cr.stroke_preserve ();
+ cr.close_path();
+ cr.fill();
- if (model.get_iter_first(out iter)) {
- double chunk = area.width / (double) (model.max_samples - 1) / 2.0;
- double last_x = calc_x (iter, x_begin, x_end, area.width);
- double last_y = area.height;
+ if (model.get_iter_first(out iter)) {
+ double chunk = area.width / (double) (model.max_samples - 1) / 2.0;
+ double last_x = calc_x (iter, x_begin, x_end, area.width);
+ double last_y = area.height;
- cr.move_to (last_x, last_y);
+ cr.move_to (last_x, last_y);
- while (GraphModel.iter_next (ref iter)) {
- double x = calc_x (iter, x_begin, x_end, area.width);
- double y = calc_y (iter, y_begin, y_end, area.height, column);
+ while (GraphModel.iter_next (ref iter)) {
+ double x = calc_x (iter, x_begin, x_end, area.width);
+ double y = calc_y (iter, y_begin, y_end, area.height, column);
- cr.curve_to (last_x + chunk, last_y, last_x + chunk, y, x, y);
+ cr.curve_to (last_x + chunk, last_y, last_x + chunk, y, x, y);
- last_x = x;
- last_y = y;
- }
+ last_x = x;
+ last_y = y;
}
-
- cr.set_source_rgba (stroke_color_rgba.red, stroke_color_rgba.green, stroke_color_rgba.blue,
stacked_color_rgba.alpha);
- cr.stroke ();
- cr.restore ();
}
- private static double calc_x (GraphModelIter iter, int64 begin, int64 end, uint width) {
- var timestamp = GraphModel.iter_get_timestamp(iter);
-
- return ((timestamp - begin) / (double) (end - begin) * width);
- }
+ cr.set_source_rgba (stroke_color_rgba.red, stroke_color_rgba.green, stroke_color_rgba.blue,
stacked_color_rgba.alpha);
+ cr.stroke ();
+ cr.restore ();
+ }
- private static double calc_y (GraphModelIter iter, double range_begin, double range_end, uint
height, uint column) {
- double y;
-
- var val = GraphModel.iter_get_value(iter, column);
- switch (val.type()) {
- case Type.DOUBLE:
- y = val.get_double();
- break;
- case Type.UINT:
- y = val.get_uint();
- break;
- case Type.UINT64:
- y = val.get_uint64();
- break;
- case Type.INT:
- y = val.get_int();
- break;
- case Type.INT64:
- y = val.get_int64();
- break;
- default:
- y = 0.0;
- break;
- }
+ private static double calc_x (GraphModelIter iter, int64 begin, int64 end, uint width) {
+ var timestamp = GraphModel.iter_get_timestamp(iter);
- y -= range_begin;
- y /= (range_end - range_begin);
- y = height - (y * height);
+ return ((timestamp - begin) / (double) (end - begin) * width);
+ }
- return y;
+ private static double calc_y (GraphModelIter iter, double range_begin, double range_end, uint height,
uint column) {
+ double y;
+
+ var val = GraphModel.iter_get_value(iter, column);
+ switch (val.type()) {
+ case Type.DOUBLE:
+ y = val.get_double();
+ break;
+ case Type.UINT:
+ y = val.get_uint();
+ break;
+ case Type.UINT64:
+ y = val.get_uint64();
+ break;
+ case Type.INT:
+ y = val.get_int();
+ break;
+ case Type.INT64:
+ y = val.get_int64();
+ break;
+ default:
+ y = 0.0;
+ break;
}
+
+ y -= range_begin;
+ y /= (range_end - range_begin);
+ y = height - (y * height);
+
+ return y;
}
}
diff --git a/src/graph-switcher-button.vala b/src/graph-switcher-button.vala
index 5a4e71c..38000af 100644
--- a/src/graph-switcher-button.vala
+++ b/src/graph-switcher-button.vala
@@ -18,50 +18,48 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class GraphSwitcherButton : Gtk.RadioButton {
- private static Gtk.RadioButton? _group = null;
+public class Usage.GraphSwitcherButton : Gtk.RadioButton {
+ private static Gtk.RadioButton? _group = null;
- public GraphSwitcherButton.processor(string label) {
- var processor_graph = new CpuGraphMostUsedCore();
- child = createContent(processor_graph, label);
- }
+ public GraphSwitcherButton.processor(string label) {
+ var processor_graph = new CpuGraphMostUsedCore();
+ child = createContent(processor_graph, label);
+ }
- public GraphSwitcherButton.memory(string label) {
- var memory_graph = new MemoryGraph();
- child = createContent(memory_graph, label);
- }
+ public GraphSwitcherButton.memory(string label) {
+ var memory_graph = new MemoryGraph();
+ child = createContent(memory_graph, label);
+ }
- private Gtk.Box createContent(Dazzle.GraphView graph, string label_text) {
- graph.height_request = 80;
- graph.hexpand = true;
- var graph_box = new GraphBox(graph);
- graph_box.margin_top = 12;
- graph_box.margin_start = 8;
- graph_box.margin_end = 8;
+ private Gtk.Box createContent(Dazzle.GraphView graph, string label_text) {
+ graph.height_request = 80;
+ graph.hexpand = true;
+ var graph_box = new GraphBox(graph);
+ graph_box.margin_top = 12;
+ graph_box.margin_start = 8;
+ graph_box.margin_end = 8;
- var label = new Gtk.Label(label_text);
- label.margin_top = 6;
- label.margin_bottom = 3;
+ var label = new Gtk.Label(label_text);
+ label.margin_top = 6;
+ label.margin_bottom = 3;
- var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
- box.pack_start(graph_box, true, true, 0);
- box.pack_start(label, false, false, 0);
+ var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
+ box.pack_start(graph_box, true, true, 0);
+ box.pack_start(label, false, false, 0);
- return box;
- }
+ return box;
+ }
- construct {
- if (_group == null)
- _group = this;
- else
- join_group(_group);
+ construct {
+ if (_group == null)
+ _group = this;
+ else
+ join_group(_group);
- set_mode(false);
+ set_mode(false);
- var context = get_style_context();
- context.add_class("flat");
- context.add_class("graph-switcher");
- }
+ var context = get_style_context();
+ context.add_class("flat");
+ context.add_class("graph-switcher");
}
}
diff --git a/src/loading-notification.vala b/src/loading-notification.vala
index 28d44ef..3be4099 100644
--- a/src/loading-notification.vala
+++ b/src/loading-notification.vala
@@ -20,30 +20,27 @@
using Gtk;
-namespace Usage {
+[GtkTemplate (ui = "/org/gnome/Usage/ui/loading-notification.ui")]
+private class Usage.LoadingNotification: Gtk.Revealer {
+ public signal void dismissed ();
+ public delegate void DismissFunc ();
- [GtkTemplate (ui = "/org/gnome/Usage/ui/loading-notification.ui")]
- private class LoadingNotification: Gtk.Revealer {
- public signal void dismissed ();
- public delegate void DismissFunc ();
+ [GtkChild]
+ private unowned Gtk.Label message_label;
- [GtkChild]
- private unowned Gtk.Label message_label;
+ public LoadingNotification (string message, owned DismissFunc? dismiss_func) {
+ set_reveal_child (true);
- public LoadingNotification (string message, owned DismissFunc? dismiss_func) {
- set_reveal_child (true);
+ message_label.label = message;
- message_label.label = message;
-
- dismissed.connect ( () => {
- if (dismiss_func != null)
- dismiss_func ();
- set_reveal_child(false);
- });
- }
+ dismissed.connect ( () => {
+ if (dismiss_func != null)
+ dismiss_func ();
+ set_reveal_child(false);
+ });
+ }
- public void dismiss() {
- dismissed();
- }
+ public void dismiss() {
+ dismissed();
}
}
diff --git a/src/memory-graph-model.vala b/src/memory-graph-model.vala
index 50f334f..814eae0 100644
--- a/src/memory-graph-model.vala
+++ b/src/memory-graph-model.vala
@@ -20,60 +20,57 @@
using Dazzle;
-namespace Usage {
+public class Usage.MemoryGraphModel : GraphModel {
+ public const int COLUMN_RAM = 0;
+ public const int COLUMN_SWAP = 1;
+ public signal void big_ram_usage();
+ public signal void small_ram_usage();
+ private bool change_big_ram_usage = true;
+ private bool change_small_ram_usage = true;
- public class MemoryGraphModel : GraphModel {
- public const int COLUMN_RAM = 0;
- public const int COLUMN_SWAP = 1;
- public signal void big_ram_usage();
- public signal void small_ram_usage();
- private bool change_big_ram_usage = true;
- private bool change_small_ram_usage = true;
+ public MemoryGraphModel () {
+ var settings = Settings.get_default();
+ set_timespan (settings.graph_timespan * 1000);
+ set_max_samples (settings.graph_max_samples);
- public MemoryGraphModel () {
- var settings = Settings.get_default();
- set_timespan (settings.graph_timespan * 1000);
- set_max_samples (settings.graph_max_samples);
+ var column_ram = new GraphColumn("RAM", Type.from_name("gdouble"));
+ add_column(column_ram);
+ var column_swap = new GraphColumn("SWAP", Type.from_name("gdouble"));
+ add_column(column_swap);
- var column_ram = new GraphColumn("RAM", Type.from_name("gdouble"));
- add_column(column_ram);
- var column_swap = new GraphColumn("SWAP", Type.from_name("gdouble"));
- add_column(column_swap);
-
- Timeout.add(settings.graph_update_interval, update_data);
- }
+ Timeout.add(settings.graph_update_interval, update_data);
+ }
- bool update_data() {
- GraphModelIter iter;
- push (out iter, get_monotonic_time ());
+ bool update_data() {
+ GraphModelIter iter;
+ push (out iter, get_monotonic_time ());
- SystemMonitor monitor = SystemMonitor.get_default();
- double ram_usage = 0;
- if (monitor.ram_total != 0)
- ram_usage = (((double) monitor.ram_usage / monitor.ram_total) * 100);
+ SystemMonitor monitor = SystemMonitor.get_default();
+ double ram_usage = 0;
+ if (monitor.ram_total != 0)
+ ram_usage = (((double) monitor.ram_usage / monitor.ram_total) * 100);
- double swap_usage = 0;
- if (monitor.ram_total != 0)
- swap_usage = (((double) monitor.swap_usage / monitor.swap_total) * 100);
+ double swap_usage = 0;
+ if (monitor.ram_total != 0)
+ swap_usage = (((double) monitor.swap_usage / monitor.swap_total) * 100);
- iter_set_value(iter, COLUMN_RAM, ram_usage);
- iter_set_value(iter, COLUMN_SWAP, swap_usage);
+ iter_set_value(iter, COLUMN_RAM, ram_usage);
+ iter_set_value(iter, COLUMN_SWAP, swap_usage);
- if (ram_usage >= 90) {
- if (change_big_ram_usage) {
- big_ram_usage();
- change_big_ram_usage = false;
- change_small_ram_usage = true;
- }
- } else {
- if (change_small_ram_usage) {
- small_ram_usage();
- change_small_ram_usage = false;
- change_big_ram_usage = true;
- }
+ if (ram_usage >= 90) {
+ if (change_big_ram_usage) {
+ big_ram_usage();
+ change_big_ram_usage = false;
+ change_small_ram_usage = true;
+ }
+ } else {
+ if (change_small_ram_usage) {
+ small_ram_usage();
+ change_small_ram_usage = false;
+ change_big_ram_usage = true;
}
-
- return true;
}
+
+ return true;
}
}
diff --git a/src/memory-graph.vala b/src/memory-graph.vala
index 18b9615..c33ca72 100644
--- a/src/memory-graph.vala
+++ b/src/memory-graph.vala
@@ -20,55 +20,53 @@
using Dazzle;
-namespace Usage {
- public class MemoryGraph : GraphView {
- private static MemoryGraphModel graph_model;
- private Gdk.RGBA line_color_max;
- private Gdk.RGBA line_color_normal;
- private Gdk.RGBA color_max;
- private Gdk.RGBA color_normal;
+public class Usage.MemoryGraph : GraphView {
+ private static MemoryGraphModel graph_model;
+ private Gdk.RGBA line_color_max;
+ private Gdk.RGBA line_color_normal;
+ private Gdk.RGBA color_max;
+ private Gdk.RGBA color_normal;
- class construct {
- set_css_name("rg-graph");
+ class construct {
+ set_css_name("rg-graph");
+ }
+
+ public MemoryGraph () {
+ get_style_context().add_class("line_max");
+ line_color_max = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("line_max");
+ get_style_context().add_class("line");
+ line_color_normal = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("line");
+ get_style_context().add_class("stacked_max");
+ color_max = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("stacked_max");
+ get_style_context().add_class("stacked");
+ color_normal = get_style_context().get_color(get_style_context().get_state());
+ get_style_context().remove_class("stacked");
+
+ if (graph_model == null) {
+ graph_model = new MemoryGraphModel();
+ set_model(graph_model);
+ } else {
+ set_model(graph_model);
}
- public MemoryGraph () {
- get_style_context().add_class("line_max");
- line_color_max = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("line_max");
- get_style_context().add_class("line");
- line_color_normal = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("line");
- get_style_context().add_class("stacked_max");
- color_max = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("stacked_max");
- get_style_context().add_class("stacked");
- color_normal = get_style_context().get_color(get_style_context().get_state());
- get_style_context().remove_class("stacked");
+ var renderer_ram = new GraphStackedRenderer();
+ renderer_ram.column = MemoryGraphModel.COLUMN_RAM;
+ renderer_ram.stroke_color_rgba = line_color_normal;
+ renderer_ram.stacked_color_rgba = color_normal;
+ renderer_ram.line_width = 1.2;
+ add_renderer(renderer_ram);
- if (graph_model == null) {
- graph_model = new MemoryGraphModel();
- set_model(graph_model);
- } else {
- set_model(graph_model);
- }
+ graph_model.big_ram_usage.connect (() => {
+ renderer_ram.stroke_color_rgba = line_color_max;
+ renderer_ram.stacked_color_rgba = color_max;
+ });
- var renderer_ram = new GraphStackedRenderer();
- renderer_ram.column = MemoryGraphModel.COLUMN_RAM;
+ graph_model.small_ram_usage.connect (() => {
renderer_ram.stroke_color_rgba = line_color_normal;
renderer_ram.stacked_color_rgba = color_normal;
- renderer_ram.line_width = 1.2;
- add_renderer(renderer_ram);
-
- graph_model.big_ram_usage.connect (() => {
- renderer_ram.stroke_color_rgba = line_color_max;
- renderer_ram.stacked_color_rgba = color_max;
- });
-
- graph_model.small_ram_usage.connect (() => {
- renderer_ram.stroke_color_rgba = line_color_normal;
- renderer_ram.stacked_color_rgba = color_normal;
- });
- }
+ });
}
}
diff --git a/src/memory-monitor.vala b/src/memory-monitor.vala
index c906d84..a4669a3 100644
--- a/src/memory-monitor.vala
+++ b/src/memory-monitor.vala
@@ -18,48 +18,46 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class MemoryMonitor : Monitor {
- private uint64 ram_usage;
- private uint64 ram_total;
- private uint64 swap_usage;
- private uint64 swap_total;
+public class Usage.MemoryMonitor : Monitor {
+ private uint64 ram_usage;
+ private uint64 ram_total;
+ private uint64 swap_usage;
+ private uint64 swap_total;
- public void update() {
- /* Memory */
- GTop.Mem mem;
- GTop.get_mem (out mem);
- ram_usage = mem.user;
- ram_total = mem.total;
+ public void update() {
+ /* Memory */
+ GTop.Mem mem;
+ GTop.get_mem (out mem);
+ ram_usage = mem.user;
+ ram_total = mem.total;
- /* Swap */
- GTop.Swap swap;
- GTop.get_swap (out swap);
- swap_usage = swap.used;
- swap_total = swap.total;
- }
+ /* Swap */
+ GTop.Swap swap;
+ GTop.get_swap (out swap);
+ swap_usage = swap.used;
+ swap_total = swap.total;
+ }
- public uint64 get_ram_usage() {
- return ram_usage;
- }
- public uint64 get_swap_usage() {
- return swap_usage;
- }
- public uint64 get_ram_total() {
- return ram_total;
- }
- public uint64 get_swap_total() {
- return swap_total;
- }
+ public uint64 get_ram_usage() {
+ return ram_usage;
+ }
+ public uint64 get_swap_usage() {
+ return swap_usage;
+ }
+ public uint64 get_ram_total() {
+ return ram_total;
+ }
+ public uint64 get_swap_total() {
+ return swap_total;
+ }
- public void update_process(ref Process process) {
- GTop.Mem mem;
- GTop.ProcMem proc_mem;
+ public void update_process(ref Process process) {
+ GTop.Mem mem;
+ GTop.ProcMem proc_mem;
- GTop.get_mem (out mem);
- GTop.get_proc_mem (out proc_mem, process.pid);
+ GTop.get_mem (out mem);
+ GTop.get_proc_mem (out proc_mem, process.pid);
- process.mem_usage = proc_mem.resident - proc_mem.share;
- }
+ process.mem_usage = proc_mem.resident - proc_mem.share;
}
}
diff --git a/src/memory-speedometer.vala b/src/memory-speedometer.vala
index 1d841ad..17245cf 100644
--- a/src/memory-speedometer.vala
+++ b/src/memory-speedometer.vala
@@ -20,40 +20,38 @@
using Gtk;
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/memory-speedometer.ui")]
- public class MemorySpeedometer : Gtk.Bin {
- [GtkChild]
- private unowned Usage.Speedometer speedometer;
+[GtkTemplate (ui = "/org/gnome/Usage/ui/memory-speedometer.ui")]
+public class Usage.MemorySpeedometer : Gtk.Bin {
+ [GtkChild]
+ private unowned Usage.Speedometer speedometer;
- [GtkChild]
- private unowned Gtk.Label label;
+ [GtkChild]
+ private unowned Gtk.Label label;
- [GtkChild]
- private unowned Gtk.Label ram_used;
+ [GtkChild]
+ private unowned Gtk.Label ram_used;
- [GtkChild]
- private unowned Gtk.Label ram_available;
+ [GtkChild]
+ private unowned Gtk.Label ram_available;
- private double ram_usage { get; set; }
+ private double ram_usage { get; set; }
- construct {
- var monitor = SystemMonitor.get_default();
- Timeout.add_seconds(1, () => {
- var percentage = (((double) monitor.ram_usage / monitor.ram_total) * 100);
+ construct {
+ var monitor = SystemMonitor.get_default();
+ Timeout.add_seconds(1, () => {
+ var percentage = (((double) monitor.ram_usage / monitor.ram_total) * 100);
- this.speedometer.percentage = (int)percentage;
- label.label = "%d".printf((int)percentage) + "%";
+ this.speedometer.percentage = (int)percentage;
+ label.label = "%d".printf((int)percentage) + "%";
- var available = (monitor.ram_total - monitor.ram_usage);
+ var available = (monitor.ram_total - monitor.ram_usage);
- ram_used.label = Utils.format_size_values(monitor.ram_usage);
- ram_available.label = Utils.format_size_values(available);
+ ram_used.label = Utils.format_size_values(monitor.ram_usage);
+ ram_available.label = Utils.format_size_values(available);
- return true;
- });
+ return true;
+ });
- this.show_all();
- }
+ this.show_all();
}
}
diff --git a/src/memory-sub-view.vala b/src/memory-sub-view.vala
index 45d9031..a99dc23 100644
--- a/src/memory-sub-view.vala
+++ b/src/memory-sub-view.vala
@@ -18,67 +18,65 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class MemorySubView : View, SubView {
- private ProcessListBox process_list_box;
- private NoResultsFoundView no_process_view;
+public class Usage.MemorySubView : View, SubView {
+ private ProcessListBox process_list_box;
+ private NoResultsFoundView no_process_view;
- public MemorySubView() {
- name = "MEMORY";
+ public MemorySubView() {
+ name = "MEMORY";
- var label = new Gtk.Label("<span font_desc=\"14.0\">" + _("Memory") + "</span>");
- label.set_use_markup(true);
- label.margin_top = 25;
- label.margin_bottom = 15;
+ var label = new Gtk.Label("<span font_desc=\"14.0\">" + _("Memory") + "</span>");
+ label.set_use_markup(true);
+ label.margin_top = 25;
+ label.margin_bottom = 15;
- process_list_box = new ProcessListBox(ProcessListBoxType.MEMORY);
- process_list_box.margin_bottom = 20;
- process_list_box.margin_top = 30;
+ process_list_box = new ProcessListBox(ProcessListBoxType.MEMORY);
+ process_list_box.margin_bottom = 20;
+ process_list_box.margin_top = 30;
- var spinner = new Gtk.Spinner();
- spinner.active = true;
- spinner.margin_top = 30;
- spinner.height_request = 250;
+ var spinner = new Gtk.Spinner();
+ spinner.active = true;
+ spinner.margin_top = 30;
+ spinner.height_request = 250;
- no_process_view = new NoResultsFoundView();
+ no_process_view = new NoResultsFoundView();
- var memory_graph = new MemorySpeedometer();
- var swap_graph = new SwapSpeedometer();
- swap_graph.valign = Gtk.Align.END;
+ var memory_graph = new MemorySpeedometer();
+ var swap_graph = new SwapSpeedometer();
+ swap_graph.valign = Gtk.Align.END;
- var speedometers = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
- speedometers.pack_start(memory_graph, false, false, 0);
- speedometers.pack_end(swap_graph, false, false, 0);
- speedometers.margin_top = 30;
+ var speedometers = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+ speedometers.pack_start(memory_graph, false, false, 0);
+ speedometers.pack_end(swap_graph, false, false, 0);
+ speedometers.margin_top = 30;
- var memory_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
- memory_box.pack_start(label, false, false, 0);
- memory_box.pack_start(speedometers, false, false, 0);
- memory_box.pack_start(spinner, true, true, 0);
- memory_box.add(no_process_view);
+ var memory_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
+ memory_box.pack_start(label, false, false, 0);
+ memory_box.pack_start(speedometers, false, false, 0);
+ memory_box.pack_start(spinner, true, true, 0);
+ memory_box.add(no_process_view);
- var system_monitor = SystemMonitor.get_default();
- system_monitor.notify["process-list-ready"].connect ((sender, property) => {
- if (system_monitor.process_list_ready) {
- memory_box.pack_start(process_list_box, false, false, 0);
- memory_box.remove(spinner);
- } else {
- memory_box.pack_start(spinner, true, true, 0);
- memory_box.remove(process_list_box);
- }
- });
+ var system_monitor = SystemMonitor.get_default();
+ system_monitor.notify["process-list-ready"].connect ((sender, property) => {
+ if (system_monitor.process_list_ready) {
+ memory_box.pack_start(process_list_box, false, false, 0);
+ memory_box.remove(spinner);
+ } else {
+ memory_box.pack_start(spinner, true, true, 0);
+ memory_box.remove(process_list_box);
+ }
+ });
- process_list_box.bind_property ("empty", no_process_view, "visible", BindingFlags.BIDIRECTIONAL);
- add(memory_box);
- }
+ process_list_box.bind_property ("empty", no_process_view, "visible", BindingFlags.BIDIRECTIONAL);
+ add(memory_box);
+ }
- public override void show_all() {
- base.show_all();
- this.no_process_view.hide();
- }
+ public override void show_all() {
+ base.show_all();
+ this.no_process_view.hide();
+ }
- public void search_in_processes(string text) {
- process_list_box.search_text = text;
- }
+ public void search_in_processes(string text) {
+ process_list_box.search_text = text;
}
}
diff --git a/src/no-results-found-view.vala b/src/no-results-found-view.vala
index b50c43f..8c54129 100644
--- a/src/no-results-found-view.vala
+++ b/src/no-results-found-view.vala
@@ -16,7 +16,5 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/no-results-found-view.ui")]
- public class NoResultsFoundView : View { }
-}
+[GtkTemplate (ui = "/org/gnome/Usage/ui/no-results-found-view.ui")]
+public class Usage.NoResultsFoundView : View { }
diff --git a/src/notification-bar.vala b/src/notification-bar.vala
index 5d560a5..876519a 100644
--- a/src/notification-bar.vala
+++ b/src/notification-bar.vala
@@ -20,26 +20,24 @@
using Gtk;
-namespace Usage {
- private class NotificationBar: Gtk.Grid {
- public const int DEFAULT_TIMEOUT = 6;
- private const int MAX_NOTIFICATIONS = 5;
- private GLib.List<Widget> active_notifications = new GLib.List<Widget> ();
+private class Usage.NotificationBar: Gtk.Grid {
+ public const int DEFAULT_TIMEOUT = 6;
+ private const int MAX_NOTIFICATIONS = 5;
+ private GLib.List<Widget> active_notifications = new GLib.List<Widget> ();
- public LoadingNotification display_loading (string message, owned LoadingNotification.DismissFunc?
dismiss_func) {
- var notification = new LoadingNotification (message, (owned) dismiss_func);
- active_notifications.prepend (notification);
+ public LoadingNotification display_loading (string message, owned LoadingNotification.DismissFunc?
dismiss_func) {
+ var notification = new LoadingNotification (message, (owned) dismiss_func);
+ active_notifications.prepend (notification);
- notification.dismissed.connect ( () => {
- active_notifications.remove (notification);
- });
+ notification.dismissed.connect ( () => {
+ active_notifications.remove (notification);
+ });
- add_notification (notification);
- return notification;
- }
+ add_notification (notification);
+ return notification;
+ }
- private void add_notification (Widget widget) {
- add (widget);
- }
+ private void add_notification (Widget widget) {
+ add (widget);
}
}
diff --git a/src/performance-view.vala b/src/performance-view.vala
index a3b3b76..5de2e4c 100644
--- a/src/performance-view.vala
+++ b/src/performance-view.vala
@@ -20,53 +20,51 @@
using Gtk;
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/performance-view.ui")]
- public class PerformanceView : View {
- [GtkChild]
- private unowned Gtk.Box switcher_box;
+[GtkTemplate (ui = "/org/gnome/Usage/ui/performance-view.ui")]
+public class Usage.PerformanceView : View {
+ [GtkChild]
+ private unowned Gtk.Box switcher_box;
- [GtkChild]
- private unowned Gtk.Box performance_content;
+ [GtkChild]
+ private unowned Gtk.Box performance_content;
- [GtkChild]
- private unowned Hdy.SearchBar search_bar;
+ [GtkChild]
+ private unowned Hdy.SearchBar search_bar;
- [GtkChild]
- private unowned Gtk.SearchEntry search_entry;
+ [GtkChild]
+ private unowned Gtk.SearchEntry search_entry;
- [GtkChild]
- private unowned AnimatedScrolledWindow scrolled_window;
+ [GtkChild]
+ private unowned AnimatedScrolledWindow scrolled_window;
- View[] sub_views;
+ View[] sub_views;
- public PerformanceView () {
- name = "PERFORMANCE";
- title = _("Performance");
- icon_name = "speedometer-symbolic";
+ public PerformanceView () {
+ name = "PERFORMANCE";
+ title = _("Performance");
+ icon_name = "speedometer-symbolic";
- sub_views = new View[] {
- new ProcessorSubView(),
- new MemorySubView()
- };
+ sub_views = new View[] {
+ new ProcessorSubView(),
+ new MemorySubView()
+ };
- foreach (var sub_view in sub_views)
- performance_content.pack_start(sub_view, true, true, 0);
+ foreach (var sub_view in sub_views)
+ performance_content.pack_start(sub_view, true, true, 0);
- var stackSwitcher = new GraphStackSwitcher(scrolled_window, sub_views);
- switcher_box.add (stackSwitcher);
+ var stackSwitcher = new GraphStackSwitcher(scrolled_window, sub_views);
+ switcher_box.add (stackSwitcher);
- show_all ();
- }
+ show_all ();
+ }
- [GtkCallback]
- private void on_search_entry_changed () {
- foreach (View sub_view in sub_views)
- ((SubView) sub_view).search_in_processes(search_entry.get_text());
- }
+ [GtkCallback]
+ private void on_search_entry_changed () {
+ foreach (View sub_view in sub_views)
+ ((SubView) sub_view).search_in_processes(search_entry.get_text());
+ }
- public void set_search_mode(bool enable) {
- search_bar.set_search_mode(enable);
- }
+ public void set_search_mode(bool enable) {
+ search_bar.set_search_mode(enable);
}
}
diff --git a/src/pie-chart.vala b/src/pie-chart.vala
index f94eff0..14b1fd8 100644
--- a/src/pie-chart.vala
+++ b/src/pie-chart.vala
@@ -20,77 +20,74 @@
using Gtk;
-namespace Usage {
+public class Usage.PieChart : Gtk.DrawingArea {
+ int used_percentages = 0;
+ int other_percentages = 0;
+ Gdk.RGBA used_color;
+ Gdk.RGBA others_color;
+ Gdk.RGBA available;
- public class PieChart : Gtk.DrawingArea {
- int used_percentages = 0;
- int other_percentages = 0;
- Gdk.RGBA used_color;
- Gdk.RGBA others_color;
- Gdk.RGBA available;
-
- class construct {
- set_css_name("PieChart");
- }
-
- public PieChart() {
- set_styles();
+ class construct {
+ set_css_name("PieChart");
+ }
- this.draw.connect ((context) => {
- int height = this.get_allocated_height ();
- int width = this.get_allocated_width ();
+ public PieChart() {
+ set_styles();
- double xc = width / 2.0;
- double yc = height / 2.0;
- double radius = int.min (width, height) / 2.0;
- double angle1 = - Math.PI / 2.0;
- double ratio;
- double angle2 = - Math.PI / 2.0;
+ this.draw.connect ((context) => {
+ int height = this.get_allocated_height ();
+ int width = this.get_allocated_width ();
- if (used_percentages > 0) {
- angle1 = - Math.PI / 2.0;
- ratio = (double) used_percentages / 100;
- angle2 = ratio * 2 * Math.PI - Math.PI / 2.0;
- context.move_to (xc, yc);
- Gdk.cairo_set_source_rgba (context, used_color);
- context.arc (xc, yc, radius, angle1, angle2);
- context.fill();
- }
+ double xc = width / 2.0;
+ double yc = height / 2.0;
+ double radius = int.min (width, height) / 2.0;
+ double angle1 = - Math.PI / 2.0;
+ double ratio;
+ double angle2 = - Math.PI / 2.0;
- if (other_percentages > 0) {
- angle1 = angle2;
- ratio = (double) other_percentages / 100;
- angle2 = ratio * 2 * Math.PI - Math.PI / 2.0;
- context.move_to (xc, yc);
- Gdk.cairo_set_source_rgba (context, others_color);
- context.arc (xc, yc, radius, angle1, angle2);
- context.fill();
- }
+ if (used_percentages > 0) {
+ angle1 = - Math.PI / 2.0;
+ ratio = (double) used_percentages / 100;
+ angle2 = ratio * 2 * Math.PI - Math.PI / 2.0;
+ context.move_to (xc, yc);
+ Gdk.cairo_set_source_rgba (context, used_color);
+ context.arc (xc, yc, radius, angle1, angle2);
+ context.fill();
+ }
+ if (other_percentages > 0) {
angle1 = angle2;
- angle2 = 2 * Math.PI - Math.PI / 2.0;
+ ratio = (double) other_percentages / 100;
+ angle2 = ratio * 2 * Math.PI - Math.PI / 2.0;
context.move_to (xc, yc);
- Gdk.cairo_set_source_rgba (context, available);
+ Gdk.cairo_set_source_rgba (context, others_color);
context.arc (xc, yc, radius, angle1, angle2);
context.fill();
- return true;
- });
- }
+ }
+
+ angle1 = angle2;
+ angle2 = 2 * Math.PI - Math.PI / 2.0;
+ context.move_to (xc, yc);
+ Gdk.cairo_set_source_rgba (context, available);
+ context.arc (xc, yc, radius, angle1, angle2);
+ context.fill();
+ return true;
+ });
+ }
- private void set_styles() {
- var context = get_style_context();
- context.add_class("used");
- used_color = context.get_color(context.get_state());
- context.add_class("others");
- others_color = context.get_color(context.get_state());
- context.add_class("available");
- available = context.get_color(context.get_state());
- }
+ private void set_styles() {
+ var context = get_style_context();
+ context.add_class("used");
+ used_color = context.get_color(context.get_state());
+ context.add_class("others");
+ others_color = context.get_color(context.get_state());
+ context.add_class("available");
+ available = context.get_color(context.get_state());
+ }
- public void update(int used_percentages, int other_percentages) {
- this.used_percentages = used_percentages;
- this.other_percentages = used_percentages + other_percentages;
- this.queue_draw();
- }
+ public void update(int used_percentages, int other_percentages) {
+ this.used_percentages = used_percentages;
+ this.other_percentages = used_percentages + other_percentages;
+ this.queue_draw();
}
}
diff --git a/src/primary-menu.vala b/src/primary-menu.vala
index cc5a5ef..4b304fc 100644
--- a/src/primary-menu.vala
+++ b/src/primary-menu.vala
@@ -20,26 +20,24 @@
using Gtk;
-namespace Usage {
- [GtkTemplate (ui="/org/gnome/Usage/ui/primary-menu.ui")]
- public class PrimaryMenu : Gtk.Popover {
+[GtkTemplate (ui="/org/gnome/Usage/ui/primary-menu.ui")]
+public class Usage.PrimaryMenu : Gtk.Popover {
- [GtkChild]
- private unowned Gtk.Box performance_container;
+ [GtkChild]
+ private unowned Gtk.Box performance_container;
- public HeaderBarMode mode { get; set; }
+ public HeaderBarMode mode { get; set; }
- public PrimaryMenu() {
- notify["mode"].connect ((sender, property) => {
- switch (mode) {
- case HeaderBarMode.PERFORMANCE:
- performance_container.show();
- break;
- case HeaderBarMode.STORAGE:
- performance_container.hide();
- break;
- }
- });
- }
+ public PrimaryMenu() {
+ notify["mode"].connect ((sender, property) => {
+ switch (mode) {
+ case HeaderBarMode.PERFORMANCE:
+ performance_container.show();
+ break;
+ case HeaderBarMode.STORAGE:
+ performance_container.hide();
+ break;
+ }
+ });
}
}
diff --git a/src/process-list-box.vala b/src/process-list-box.vala
index f6af921..2fda550 100644
--- a/src/process-list-box.vala
+++ b/src/process-list-box.vala
@@ -18,106 +18,104 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public enum ProcessListBoxType {
- PROCESSOR,
- MEMORY
- }
+public enum Usage.ProcessListBoxType {
+ PROCESSOR,
+ MEMORY
+}
- public class ProcessListBox : Gtk.ListBox {
- public bool empty { get; set; default = true; }
- public string search_text { get; set; default = ""; }
+public class Usage.ProcessListBox : Gtk.ListBox {
+ public bool empty { get; set; default = true; }
+ public string search_text { get; set; default = ""; }
- private const double APP_CPU_MIN_LOAD_LIMIT = 1;
- private const double APP_MEM_MIN_USAGE_LIMIT = 0;
- private ListStore model;
- private ProcessListBoxType type;
+ private const double APP_CPU_MIN_LOAD_LIMIT = 1;
+ private const double APP_MEM_MIN_USAGE_LIMIT = 0;
+ private ListStore model;
+ private ProcessListBoxType type;
- public ProcessListBox(ProcessListBoxType type) {
- set_selection_mode (Gtk.SelectionMode.NONE);
- set_header_func (update_header);
+ public ProcessListBox(ProcessListBoxType type) {
+ set_selection_mode (Gtk.SelectionMode.NONE);
+ set_header_func (update_header);
- this.type = type;
- model = new ListStore(typeof(AppItem));
- bind_model(model, on_row_created);
+ this.type = type;
+ model = new ListStore(typeof(AppItem));
+ bind_model(model, on_row_created);
- row_activated.connect((row) => {
- var process_row = (ProcessRow) row;
- process_row.activate();
- });
+ row_activated.connect((row) => {
+ var process_row = (ProcessRow) row;
+ process_row.activate();
+ });
- this.notify["search-text"].connect ((sender, property) => {
+ this.notify["search-text"].connect ((sender, property) => {
+ update();
+ });
+
+ var system_monitor = SystemMonitor.get_default();
+ system_monitor.notify["process-list-ready"].connect (() => {
+ if (system_monitor.process_list_ready)
update();
- });
+ });
- var system_monitor = SystemMonitor.get_default();
- system_monitor.notify["process-list-ready"].connect (() => {
- if (system_monitor.process_list_ready)
- update();
- });
+ var settings = Settings.get_default();
+ Timeout.add(settings.list_update_interval_UI, update);
- var settings = Settings.get_default();
- Timeout.add(settings.list_update_interval_UI, update);
+ bind_property ("empty", this, "visible", BindingFlags.INVERT_BOOLEAN);
+ }
- bind_property ("empty", this, "visible", BindingFlags.INVERT_BOOLEAN);
- }
+ private bool update() {
+ model.remove_all();
- private bool update() {
- model.remove_all();
-
- CompareDataFunc<AppItem> app_cmp = (a, b) => {
- AppItem app_a = (AppItem) a;
- AppItem app_b = (AppItem) b;
-
- switch (type) {
- default:
- case ProcessListBoxType.PROCESSOR:
- return (int) ((uint64) (app_a.cpu_load < app_b.cpu_load) - (uint64) (app_a.cpu_load
app_b.cpu_load));
- case ProcessListBoxType.MEMORY:
- return (int) ((uint64) (app_a.mem_usage < app_b.mem_usage) - (uint64)
(app_a.mem_usage > app_b.mem_usage));
- }
- };
-
- var system_monitor = SystemMonitor.get_default();
- if (search_text == "") {
- switch (type) {
- default:
- case ProcessListBoxType.PROCESSOR:
- foreach (unowned AppItem app in system_monitor.get_apps()) {
- if (app.cpu_load > APP_CPU_MIN_LOAD_LIMIT)
- model.insert_sorted(app, app_cmp);
- }
- break;
- case ProcessListBoxType.MEMORY:
- foreach (unowned AppItem app in system_monitor.get_apps())
- if (app.mem_usage > APP_MEM_MIN_USAGE_LIMIT)
- model.insert_sorted(app, app_cmp);
- break;
- }
- } else {
- foreach (unowned AppItem app in system_monitor.get_apps()) {
- if (app.display_name.down().contains(search_text.down()) ||
app.representative_cmdline.down().contains(search_text.down()))
- model.insert_sorted(app, app_cmp);
- }
- }
+ CompareDataFunc<AppItem> app_cmp = (a, b) => {
+ AppItem app_a = (AppItem) a;
+ AppItem app_b = (AppItem) b;
- empty = (model.get_n_items() == 0);
- return true;
+ switch (type) {
+ default:
+ case ProcessListBoxType.PROCESSOR:
+ return (int) ((uint64) (app_a.cpu_load < app_b.cpu_load) - (uint64) (app_a.cpu_load >
app_b.cpu_load));
+ case ProcessListBoxType.MEMORY:
+ return (int) ((uint64) (app_a.mem_usage < app_b.mem_usage) - (uint64) (app_a.mem_usage >
app_b.mem_usage));
+ }
+ };
+
+ var system_monitor = SystemMonitor.get_default();
+ if (search_text == "") {
+ switch (type) {
+ default:
+ case ProcessListBoxType.PROCESSOR:
+ foreach (unowned AppItem app in system_monitor.get_apps()) {
+ if (app.cpu_load > APP_CPU_MIN_LOAD_LIMIT)
+ model.insert_sorted(app, app_cmp);
+ }
+ break;
+ case ProcessListBoxType.MEMORY:
+ foreach (unowned AppItem app in system_monitor.get_apps())
+ if (app.mem_usage > APP_MEM_MIN_USAGE_LIMIT)
+ model.insert_sorted(app, app_cmp);
+ break;
+ }
+ } else {
+ foreach (unowned AppItem app in system_monitor.get_apps()) {
+ if (app.display_name.down().contains(search_text.down()) ||
app.representative_cmdline.down().contains(search_text.down()))
+ model.insert_sorted(app, app_cmp);
+ }
}
- private Gtk.Widget on_row_created (Object item) {
- return new ProcessRow((AppItem) item, type);
- }
+ empty = (model.get_n_items() == 0);
+ return true;
+ }
- private void update_header(Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
- if (before_row == null) {
- row.set_header(null);
- } else {
- var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
- separator.get_style_context().add_class("list");
- separator.show();
- row.set_header(separator);
- }
+ private Gtk.Widget on_row_created (Object item) {
+ return new ProcessRow((AppItem) item, type);
+ }
+
+ private void update_header(Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
+ if (before_row == null) {
+ row.set_header(null);
+ } else {
+ var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
+ separator.get_style_context().add_class("list");
+ separator.show();
+ row.set_header(separator);
}
}
}
diff --git a/src/process-row.vala b/src/process-row.vala
index 4d53535..2565d8a 100644
--- a/src/process-row.vala
+++ b/src/process-row.vala
@@ -18,104 +18,102 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/process-row.ui")]
- public class ProcessRow : Gtk.ListBoxRow {
- public AppItem app { get; private set; }
- public bool max_usage { get; private set; }
+[GtkTemplate (ui = "/org/gnome/Usage/ui/process-row.ui")]
+public class Usage.ProcessRow : Gtk.ListBoxRow {
+ 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";
+ 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 unowned Gtk.Image icon;
+ [GtkChild]
+ private unowned Gtk.Image icon;
- [GtkChild]
- private unowned Gtk.Label title_label;
+ [GtkChild]
+ private unowned Gtk.Label title_label;
- [GtkChild]
- private unowned Gtk.Box user_tag_box;
+ [GtkChild]
+ private unowned Gtk.Box user_tag_box;
- [GtkChild]
- private unowned Gtk.Image gamemode;
+ [GtkChild]
+ private unowned Gtk.Image gamemode;
- [GtkChild]
- private unowned Gtk.Label user_tag_label;
+ [GtkChild]
+ private unowned Gtk.Label user_tag_label;
- [GtkChild]
- private unowned Gtk.Label load_label;
+ [GtkChild]
+ private unowned Gtk.Label load_label;
- private ProcessListBoxType type;
+ private ProcessListBoxType type;
- public ProcessRow(AppItem app, ProcessListBoxType type) {
- this.type = type;
- this.app = app;
- this.icon.gicon = app.get_icon();
- this.app.bind_property("gamemode", gamemode, "visible", BindingFlags.SYNC_CREATE);
- update();
- }
+ public ProcessRow(AppItem app, ProcessListBoxType type) {
+ this.type = type;
+ this.app = app;
+ this.icon.gicon = app.get_icon();
+ this.app.bind_property("gamemode", gamemode, "visible", BindingFlags.SYNC_CREATE);
+ update();
+ }
- private void update() {
- update_load_label();
- update_user_tag();
+ private void update() {
+ update_load_label();
+ update_user_tag();
- title_label.label = app.display_name;
- }
+ title_label.label = app.display_name;
+ }
- private void update_load_label() {
- switch (type) {
- case ProcessListBoxType.PROCESSOR:
- load_label.label = ((int) app.cpu_load).to_string() + " %";
- break;
- case ProcessListBoxType.MEMORY:
- load_label.label = Utils.format_size_values(app.mem_usage);
- break;
- }
+ private void update_load_label() {
+ switch (type) {
+ case ProcessListBoxType.PROCESSOR:
+ load_label.label = ((int) app.cpu_load).to_string() + " %";
+ break;
+ case ProcessListBoxType.MEMORY:
+ load_label.label = Utils.format_size_values(app.mem_usage);
+ break;
}
+ }
- private void update_user_tag() {
- if (app.user == null)
- return;
+ private void update_user_tag() {
+ if (app.user == null)
+ return;
- remove_user_tag();
- create_user_tag();
- }
+ remove_user_tag();
+ create_user_tag();
+ }
- private void remove_user_tag() {
- user_tag_box.visible = false;
- user_tag_box.get_style_context().remove_class(CSS_TAG_USER);
- user_tag_box.get_style_context().remove_class(CSS_TAG_ROOT);
- user_tag_box.get_style_context().remove_class(CSS_TAG_SYSTEM);
- }
+ private void remove_user_tag() {
+ user_tag_box.visible = false;
+ user_tag_box.get_style_context().remove_class(CSS_TAG_USER);
+ user_tag_box.get_style_context().remove_class(CSS_TAG_ROOT);
+ user_tag_box.get_style_context().remove_class(CSS_TAG_SYSTEM);
+ }
- private void create_user_tag() {
- string class_name = "";
- if (app.user.LocalAccount) {
- class_name = CSS_TAG_USER;
- } else if (app.user.AccountType == UserAccountType.ADMINISTRATOR) {
- class_name = CSS_TAG_ROOT;
- } else if (app.user.SystemAccount) {
- class_name = CSS_TAG_SYSTEM;
- }
-
- user_tag_box.get_style_context().add_class(class_name);
- user_tag_label.label = app.user.UserName;
- user_tag_box.visible = !is_logged_in();
+ private void create_user_tag() {
+ string class_name = "";
+ if (app.user.LocalAccount) {
+ class_name = CSS_TAG_USER;
+ } else if (app.user.AccountType == UserAccountType.ADMINISTRATOR) {
+ class_name = CSS_TAG_ROOT;
+ } else if (app.user.SystemAccount) {
+ class_name = CSS_TAG_SYSTEM;
}
- private bool is_logged_in(){
- return app.user.UserName == GLib.Environment.get_user_name();
- }
+ user_tag_box.get_style_context().add_class(class_name);
+ user_tag_label.label = app.user.UserName;
+ user_tag_box.visible = !is_logged_in();
+ }
- public new void activate() {
- var settings = Settings.get_default();
- if (app.representative_cmdline in settings.get_strv ("unkillable-processes"))
- return;
+ private bool is_logged_in(){
+ return app.user.UserName == GLib.Environment.get_user_name();
+ }
- var dialog = new QuitProcessDialog(app);
- dialog.set_transient_for(get_toplevel() as Gtk.Window);
- dialog.show_all();
- }
+ public new void activate() {
+ var settings = Settings.get_default();
+ if (app.representative_cmdline in settings.get_strv ("unkillable-processes"))
+ return;
+
+ var dialog = new QuitProcessDialog(app);
+ dialog.set_transient_for(get_toplevel() as Gtk.Window);
+ dialog.show_all();
}
}
diff --git a/src/process.vala b/src/process.vala
index bd3a517..946b2e2 100644
--- a/src/process.vala
+++ b/src/process.vala
@@ -18,230 +18,228 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class Process : Object {
- public Pid pid { get; private set; }
- public string cmdline { get; private set; }
- public uint uid { get; private set; }
- public uint64 start_time { get; set; default = 0; }
+public class Usage.Process : Object {
+ public Pid pid { get; private set; }
+ public string cmdline { get; private set; }
+ public uint uid { get; private set; }
+ public uint64 start_time { get; set; default = 0; }
- public double cpu_load { get; set; default = 0; }
- public double x_cpu_load { get; set; default = 0; }
- public uint64 cpu_last_used { get; set; default = 0; }
- public uint64 x_cpu_last_used { get; set; default = 0; }
- public uint last_processor { get; set; default = 0; }
+ public double cpu_load { get; set; default = 0; }
+ public double x_cpu_load { get; set; default = 0; }
+ public uint64 cpu_last_used { get; set; default = 0; }
+ public uint64 x_cpu_last_used { get; set; default = 0; }
+ public uint last_processor { get; set; default = 0; }
- public uint64 mem_usage { get; set; default = 0; }
+ public uint64 mem_usage { get; set; default = 0; }
- public bool gamemode { get; set; }
+ public bool gamemode { get; set; }
- public bool mark_as_updated { get; set; default = true; }
- public ProcessStatus status { get; private set; default = ProcessStatus.SLEEPING; }
+ public bool mark_as_updated { get; set; default = true; }
+ public ProcessStatus status { get; private set; default = ProcessStatus.SLEEPING; }
- private string? _app_id = null;
- private bool _app_id_checked = false;
+ private string? _app_id = null;
+ private bool _app_id_checked = false;
- public Process(Pid pid) {
- this.pid = pid;
- this.cmdline = get_full_process_cmd (pid);
- this.uid = _get_uid();
- }
+ public Process(Pid pid) {
+ this.pid = pid;
+ this.cmdline = get_full_process_cmd (pid);
+ this.uid = _get_uid();
+ }
- public void update_status () {
- GTop.ProcState proc_state;
- GTop.get_proc_state (out proc_state, pid);
-
- switch (proc_state.state) {
- case GTop.PROCESS_RUNNING:
- case GTop.PROCESS_UNINTERRUPTIBLE:
- status = ProcessStatus.RUNNING;
- break;
- case GTop.PROCESS_SWAPPING:
- case GTop.PROCESS_INTERRUPTIBLE:
- case GTop.PROCESS_STOPPED:
- status = ProcessStatus.SLEEPING;
- break;
- case GTop.PROCESS_DEAD:
- case GTop.PROCESS_ZOMBIE:
- default:
- status = ProcessStatus.DEAD;
- break;
- }
+ public void update_status () {
+ GTop.ProcState proc_state;
+ GTop.get_proc_state (out proc_state, pid);
- if (cpu_load > 0)
+ switch (proc_state.state) {
+ case GTop.PROCESS_RUNNING:
+ case GTop.PROCESS_UNINTERRUPTIBLE:
status = ProcessStatus.RUNNING;
-
- mark_as_updated = true;
+ break;
+ case GTop.PROCESS_SWAPPING:
+ case GTop.PROCESS_INTERRUPTIBLE:
+ case GTop.PROCESS_STOPPED:
+ status = ProcessStatus.SLEEPING;
+ break;
+ case GTop.PROCESS_DEAD:
+ case GTop.PROCESS_ZOMBIE:
+ default:
+ status = ProcessStatus.DEAD;
+ break;
}
- private uint _get_uid() {
- GTop.ProcUid procUid;
- GTop.get_proc_uid(out procUid, pid);
- return procUid.uid;
- }
+ if (cpu_load > 0)
+ status = ProcessStatus.RUNNING;
- public string? app_id {
- get {
- if (!_app_id_checked)
- _app_id = read_app_id (pid);
+ mark_as_updated = true;
+ }
- return _app_id;
- }
- }
+ private uint _get_uid() {
+ GTop.ProcUid procUid;
+ GTop.get_proc_uid(out procUid, pid);
+ return procUid.uid;
+ }
- /* static pid related methods */
- public static string get_full_process_cmd (Pid pid) {
- GTop.ProcArgs proc_args;
- GTop.ProcState proc_state;
- string[] args = GTop.get_proc_argv (out proc_args, pid, 0);
- GTop.get_proc_state (out proc_state, pid);
- string cmd = (string) proc_state.cmd;
-
- /* cmd is most likely a truncated version, therefore
- * we check the first two arguments of the full argv
- * vector if they match cmd and if so, use that */
- for (int i = 0; i < uint.min (args.length, 2); i++) {
- if (args[i] == null)
- continue;
-
- /* TODO: this will fail if args[i] is a commandline,
- * i.e. composed of multiple segments and one of the
- * later ones is a unix path */
- var name = Path.get_basename (args[i]);
- if (!name.has_prefix (cmd))
- continue;
-
- name = Process.first_component (name);
- return Process.sanitize_name (name);
- }
+ public string? app_id {
+ get {
+ if (!_app_id_checked)
+ _app_id = read_app_id (pid);
- return Process.sanitize_name (cmd);
+ return _app_id;
}
+ }
- public static string? read_cgroup (Pid pid) {
- string path = "/proc/%u/cgroup".printf ((uint) pid);
- int flags = Posix.O_RDONLY | StopGap.O_CLOEXEC | Posix.O_NOCTTY;
+ /* static pid related methods */
+ public static string get_full_process_cmd (Pid pid) {
+ GTop.ProcArgs proc_args;
+ GTop.ProcState proc_state;
+ string[] args = GTop.get_proc_argv (out proc_args, pid, 0);
+ GTop.get_proc_state (out proc_state, pid);
+ string cmd = (string) proc_state.cmd;
+
+ /* cmd is most likely a truncated version, therefore
+ * we check the first two arguments of the full argv
+ * vector if they match cmd and if so, use that */
+ for (int i = 0; i < uint.min (args.length, 2); i++) {
+ if (args[i] == null)
+ continue;
+
+ /* TODO: this will fail if args[i] is a commandline,
+ * i.e. composed of multiple segments and one of the
+ * later ones is a unix path */
+ var name = Path.get_basename (args[i]);
+ if (!name.has_prefix (cmd))
+ continue;
+
+ name = Process.first_component (name);
+ return Process.sanitize_name (name);
+ }
- int fd = StopGap.openat (StopGap.AT_FDCWD, path, flags);
+ return Process.sanitize_name (cmd);
+ }
- if (fd == -1)
- return null;
+ public static string? read_cgroup (Pid pid) {
+ string path = "/proc/%u/cgroup".printf ((uint) pid);
+ int flags = Posix.O_RDONLY | StopGap.O_CLOEXEC | Posix.O_NOCTTY;
- try {
- string? data = null;
- string[] lines;
- string? cgroup = null;
- size_t len;
+ int fd = StopGap.openat (StopGap.AT_FDCWD, path, flags);
- // TODO use MappedFile.from_fd, requires vala 0.46
- IOChannel ch = new IOChannel.unix_new (fd);
- ch.set_close_on_unref (true);
+ if (fd == -1)
+ return null;
- var status = ch.read_to_end (out data, out len);
- if (status != IOStatus.NORMAL)
- return null;
+ try {
+ string? data = null;
+ string[] lines;
+ string? cgroup = null;
+ size_t len;
- lines = data.split("\n");
+ // TODO use MappedFile.from_fd, requires vala 0.46
+ IOChannel ch = new IOChannel.unix_new (fd);
+ ch.set_close_on_unref (true);
- // Only do anything with cgroup v2
- if (!lines[0].has_prefix("0::"))
- return null;
+ var status = ch.read_to_end (out data, out len);
+ if (status != IOStatus.NORMAL)
+ return null;
- cgroup = lines[0][3:lines[0].length];
+ lines = data.split("\n");
- return cgroup;
- } catch (Error e) {
+ // Only do anything with cgroup v2
+ if (!lines[0].has_prefix("0::"))
return null;
- }
- }
- public static string? read_app_id (Pid pid) {
- KeyFile? kf = read_flatpak_info (pid);
+ cgroup = lines[0][3:lines[0].length];
- if (kf == null)
- return null;
+ return cgroup;
+ } catch (Error e) {
+ return null;
+ }
+ }
- string? name = null;
- try {
- if (kf.has_key ("Application", "name"))
- name = kf.get_string ("Application", "name");
- } catch (Error e) {
- warning (@"Failed to parse faltpak info for: $pid");
- }
+ public static string? read_app_id (Pid pid) {
+ KeyFile? kf = read_flatpak_info (pid);
- return name;
+ if (kf == null)
+ return null;
+
+ string? name = null;
+ try {
+ if (kf.has_key ("Application", "name"))
+ name = kf.get_string ("Application", "name");
+ } catch (Error e) {
+ warning (@"Failed to parse faltpak info for: $pid");
}
- public static KeyFile? read_flatpak_info (Pid pid) {
- string path = "/proc/%u/root".printf ((uint) pid);
- int flags = Posix.O_RDONLY | StopGap.O_CLOEXEC | Posix.O_NOCTTY;
+ return name;
+ }
- int root = StopGap.openat (StopGap.AT_FDCWD, path, flags | Posix.O_NONBLOCK |
StopGap.O_DIRECTORY);
+ public static KeyFile? read_flatpak_info (Pid pid) {
+ string path = "/proc/%u/root".printf ((uint) pid);
+ int flags = Posix.O_RDONLY | StopGap.O_CLOEXEC | Posix.O_NOCTTY;
- if (root == -1)
- return null;
+ int root = StopGap.openat (StopGap.AT_FDCWD, path, flags | Posix.O_NONBLOCK | StopGap.O_DIRECTORY);
- int fd = StopGap.openat (root, ".flatpak-info", flags);
+ if (root == -1)
+ return null;
- Posix.close (root);
+ int fd = StopGap.openat (root, ".flatpak-info", flags);
- if (fd == -1)
- return null;
+ Posix.close (root);
- KeyFile kf = new KeyFile ();
+ if (fd == -1)
+ return null;
- try {
- string? data = null;
- size_t len;
+ KeyFile kf = new KeyFile ();
- // TODO use MappedFile.from_fd, requires vala 0.46
- IOChannel ch = new IOChannel.unix_new (fd);
- ch.set_close_on_unref (true);
+ try {
+ string? data = null;
+ size_t len;
- var status = ch.read_to_end (out data, out len);
- if (status != IOStatus.NORMAL)
- return null;
+ // TODO use MappedFile.from_fd, requires vala 0.46
+ IOChannel ch = new IOChannel.unix_new (fd);
+ ch.set_close_on_unref (true);
- kf.load_from_data (data, len, 0);
- } catch (Error e) {
+ var status = ch.read_to_end (out data, out len);
+ if (status != IOStatus.NORMAL)
return null;
- }
- return kf;
+ kf.load_from_data (data, len, 0);
+ } catch (Error e) {
+ return null;
}
- /* static utility methods */
- public static string? sanitize_name (string name) {
- string? result = null;
+ return kf;
+ }
- if (name == null)
- return null;
+ /* static utility methods */
+ public static string? sanitize_name (string name) {
+ string? result = null;
- try {
- var rgx = new Regex ("[^a-zA-Z0-9._-]");
- result = rgx.replace (name, name.length, 0, "");
- } catch (RegexError e) {
- warning ("Unable to sanitize name: %s", e.message);
- }
+ if (name == null)
+ return null;
- return result;
+ try {
+ var rgx = new Regex ("[^a-zA-Z0-9._-]");
+ result = rgx.replace (name, name.length, 0, "");
+ } catch (RegexError e) {
+ warning ("Unable to sanitize name: %s", e.message);
}
- public static string first_component (string str) {
+ return result;
+ }
- for (int i = 0; i < str.length; i++) {
- if (str[i] == ' ') {
- return str.substring(0, i);
- }
- }
+ public static string first_component (string str) {
- return str;
+ for (int i = 0; i < str.length; i++) {
+ if (str[i] == ' ') {
+ return str.substring(0, i);
+ }
}
- }
- public enum ProcessStatus {
- RUNNING,
- SLEEPING,
- DEAD
+ return str;
}
}
+
+public enum Usage.ProcessStatus {
+ RUNNING,
+ SLEEPING,
+ DEAD
+}
diff --git a/src/quit-process-dialog.vala b/src/quit-process-dialog.vala
index 9225097..04e5378 100644
--- a/src/quit-process-dialog.vala
+++ b/src/quit-process-dialog.vala
@@ -21,27 +21,25 @@
using Gtk;
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/quit-process-dialog.ui")]
- public class QuitProcessDialog : Gtk.MessageDialog {
- private AppItem app;
+[GtkTemplate (ui = "/org/gnome/Usage/ui/quit-process-dialog.ui")]
+public class Usage.QuitProcessDialog : Gtk.MessageDialog {
+ private AppItem app;
- public QuitProcessDialog(AppItem app) {
- this.app = app;
- this.text = this.text.printf(app.display_name);
- }
+ public QuitProcessDialog(AppItem app) {
+ this.app = app;
+ this.text = this.text.printf(app.display_name);
+ }
- [GtkCallback]
- private void on_force_quit_button_clicked () {
- app.kill();
- this.destroy();
- }
+ [GtkCallback]
+ private void on_force_quit_button_clicked () {
+ app.kill();
+ this.destroy();
+ }
- [GtkCallback]
- public void cancel () {
- /* FIXME: For some reason we are not able to connect to the
- * destroy signal right from the .ui file. */
- this.destroy();
- }
+ [GtkCallback]
+ public void cancel () {
+ /* FIXME: For some reason we are not able to connect to the
+ * destroy signal right from the .ui file. */
+ this.destroy();
}
}
diff --git a/src/settings.vala b/src/settings.vala
index e459659..b86c56b 100644
--- a/src/settings.vala
+++ b/src/settings.vala
@@ -20,27 +20,24 @@
using Gtk;
-namespace Usage {
+public class Usage.Settings : GLib.Settings {
+ public uint graph_timespan { get; set; default = 15000;}
+ public uint graph_max_samples { get; set; default = 20; }
+ public uint graph_update_interval { get { return 1000; }}
+ public uint list_update_interval_UI { get; set; default = 5000; }
+ public uint list_update_pie_charts_UI { get; set; default = 1000; }
+ public uint data_update_interval { get; set; default = 1000; }
- public class Settings : GLib.Settings {
- public uint graph_timespan { get; set; default = 15000;}
- public uint graph_max_samples { get; set; default = 20; }
- public uint graph_update_interval { get { return 1000; }}
- public uint list_update_interval_UI { get; set; default = 5000; }
- public uint list_update_pie_charts_UI { get; set; default = 1000; }
- public uint data_update_interval { get; set; default = 1000; }
+ private static Settings settings;
- private static Settings settings;
+ public static Settings get_default() {
+ if (settings == null)
+ settings = new Settings ();
- public static Settings get_default() {
- if (settings == null)
- settings = new Settings ();
-
- return settings;
- }
+ return settings;
+ }
- public Settings() {
- Object(schema_id: Config.APPLICATION_ID);
- }
+ public Settings() {
+ Object(schema_id: Config.APPLICATION_ID);
}
}
diff --git a/src/speedometer.vala b/src/speedometer.vala
index 2fb98bd..6a29738 100644
--- a/src/speedometer.vala
+++ b/src/speedometer.vala
@@ -20,74 +20,72 @@
using Gtk;
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/speedometer.ui")]
- public class Speedometer : Buildable, Gtk.Bin {
- [GtkChild]
- private unowned Gtk.Box inner;
-
- [GtkChild]
- private unowned Gtk.Box content_area;
-
- private Gtk.CssProvider css_provider;
-
- private int _percentage = 0;
- public int percentage {
- get {
- return _percentage;
- }
- set {
- on_percentage_changed(value);
-
- _percentage = value;
- }
- }
+[GtkTemplate (ui = "/org/gnome/Usage/ui/speedometer.ui")]
+public class Usage.Speedometer : Buildable, Gtk.Bin {
+ [GtkChild]
+ private unowned Gtk.Box inner;
+
+ [GtkChild]
+ private unowned Gtk.Box content_area;
- construct {
- css_provider = new Gtk.CssProvider();
- inner.get_style_context().add_provider(css_provider,
- Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
+ private Gtk.CssProvider css_provider;
- bind_property("width-request", content_area, "width-request", BindingFlags.BIDIRECTIONAL);
- bind_property("height-request", content_area, "height-request", BindingFlags.BIDIRECTIONAL);
+ private int _percentage = 0;
+ public int percentage {
+ get {
+ return _percentage;
}
+ set {
+ on_percentage_changed(value);
- private void on_percentage_changed(int new_value) {
- if (new_value <= 0 && new_value >= 100)
- return;
-
- double new_angle = 90 + (360 * (new_value/100.0));
- var filling_color = "@theme_base_color";
-
- if (new_value > 50) {
- new_angle -= 180;
- filling_color = "@theme_selected_bg_color";
- }
-
- var css =
- @".speedometer-inner {
- background: linear-gradient($(new_angle)deg, transparent 50%, $filling_color 50%),
- linear-gradient(90deg, @theme_base_color 50%, transparent 50%);
- }";
-
- try {
- css_provider.load_from_data(css);
- }
- catch (GLib.Error error) {
- warning("Failed to animate speedometer: %s", error.message);
- }
+ _percentage = value;
}
+ }
+
+ construct {
+ css_provider = new Gtk.CssProvider();
+ inner.get_style_context().add_provider(css_provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
- public void add_child(Builder builder, Object child, string? type) {
- /* This is a Vala bug. It will cause a "warning".
- (content_area as Buildable).add_child(builder, child, type);*/
- if (child is Gtk.Label) {
- content_area.add(child as Gtk.Widget);
+ bind_property("width-request", content_area, "width-request", BindingFlags.BIDIRECTIONAL);
+ bind_property("height-request", content_area, "height-request", BindingFlags.BIDIRECTIONAL);
+ }
+
+ private void on_percentage_changed(int new_value) {
+ if (new_value <= 0 && new_value >= 100)
+ return;
- return;
- }
+ double new_angle = 90 + (360 * (new_value/100.0));
+ var filling_color = "@theme_base_color";
- base.add_child(builder, child, type);
+ if (new_value > 50) {
+ new_angle -= 180;
+ filling_color = "@theme_selected_bg_color";
}
+
+ var css =
+ @".speedometer-inner {
+ background: linear-gradient($(new_angle)deg, transparent 50%, $filling_color 50%),
+ linear-gradient(90deg, @theme_base_color 50%, transparent 50%);
+ }";
+
+ try {
+ css_provider.load_from_data(css);
+ }
+ catch (GLib.Error error) {
+ warning("Failed to animate speedometer: %s", error.message);
+ }
+ }
+
+ public void add_child(Builder builder, Object child, string? type) {
+ /* This is a Vala bug. It will cause a "warning".
+ (content_area as Buildable).add_child(builder, child, type);*/
+ if (child is Gtk.Label) {
+ content_area.add(child as Gtk.Widget);
+
+ return;
+ }
+
+ base.add_child(builder, child, type);
}
}
diff --git a/src/storage/storage-actionbar.vala b/src/storage/storage-actionbar.vala
index d471323..fa197d4 100644
--- a/src/storage/storage-actionbar.vala
+++ b/src/storage/storage-actionbar.vala
@@ -18,71 +18,69 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/storage-actionbar.ui")]
- public class StorageActionBar : Gtk.ActionBar {
- private unowned List<StorageViewItem> selected_items;
+[GtkTemplate (ui = "/org/gnome/Usage/ui/storage-actionbar.ui")]
+public class Usage.StorageActionBar : Gtk.ActionBar {
+ private unowned List<StorageViewItem> selected_items;
- [GtkChild]
- private unowned Gtk.Label size_label;
+ [GtkChild]
+ private unowned Gtk.Label size_label;
- public signal void refresh_listbox ();
+ public signal void refresh_listbox ();
- public void update_selected_items(List<StorageViewItem> selected_items) {
- this.selected_items = selected_items;
+ public void update_selected_items(List<StorageViewItem> selected_items) {
+ this.selected_items = selected_items;
- uint64 size = 0;
- foreach (var item in selected_items) {
- size += item.size;
- }
- size_label.label = _("%s selected").printf(Utils.format_size_values(size));
+ uint64 size = 0;
+ foreach (var item in selected_items) {
+ size += item.size;
}
+ size_label.label = _("%s selected").printf(Utils.format_size_values(size));
+ }
- [GtkCallback]
- private void delete_clicked() {
- var application = GLib.Application.get_default() as Application;
- string display_message = _("Are you sure you want to permanently delete selected items?");
+ [GtkCallback]
+ private void delete_clicked() {
+ var application = GLib.Application.get_default() as Application;
+ string display_message = _("Are you sure you want to permanently delete selected items?");
- if (application == null)
- return;
+ if (application == null)
+ return;
- var dialog = new Gtk.MessageDialog (application.get_window(), Gtk.DialogFlags.MODAL,
- Gtk.MessageType.WARNING, Gtk.ButtonsType.OK_CANCEL, display_message);
- dialog.secondary_text = _("If you delete these items, they will be permanently lost.");
+ var dialog = new Gtk.MessageDialog (application.get_window(), Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.WARNING, Gtk.ButtonsType.OK_CANCEL, display_message);
+ dialog.secondary_text = _("If you delete these items, they will be permanently lost.");
- if (dialog.run() == Gtk.ResponseType.OK) {
- foreach (var item in selected_items) {
- if (item.type == FileType.DIRECTORY && item.custom_type == StorageViewType.ROOT_ITEM)
- delete_file(item.uri, false);
- else
- delete_file(item.uri, true);
- }
- refresh_listbox();
+ if (dialog.run() == Gtk.ResponseType.OK) {
+ foreach (var item in selected_items) {
+ if (item.type == FileType.DIRECTORY && item.custom_type == StorageViewType.ROOT_ITEM)
+ delete_file(item.uri, false);
+ else
+ delete_file(item.uri, true);
}
- dialog.destroy();
+ refresh_listbox();
}
+ dialog.destroy();
+ }
- private void delete_file(string uri, bool delete_basefile) {
- var file = File.new_for_uri(uri);
- var type = file.query_file_type (FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
+ private void delete_file(string uri, bool delete_basefile) {
+ var file = File.new_for_uri(uri);
+ var type = file.query_file_type (FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
- try {
- if (type == FileType.DIRECTORY) {
- FileInfo info;
- FileEnumerator enumerator = file.enumerate_children("standard::*",
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
+ try {
+ if (type == FileType.DIRECTORY) {
+ FileInfo info;
+ FileEnumerator enumerator = file.enumerate_children("standard::*",
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
- while((info = enumerator.next_file(null)) != null) {
- var child = file.get_child(info.get_name());
- delete_file(child.get_uri(), true);
- }
+ while((info = enumerator.next_file(null)) != null) {
+ var child = file.get_child(info.get_name());
+ delete_file(child.get_uri(), true);
}
-
- if (delete_basefile)
- file.delete();
- }
- catch (Error e) {
- stderr.printf ("Error: %s\n", e.message);
}
+
+ if (delete_basefile)
+ file.delete();
+ }
+ catch (Error e) {
+ stderr.printf ("Error: %s\n", e.message);
}
}
}
diff --git a/src/storage/storage-graph.vala b/src/storage/storage-graph.vala
index 8011373..f8c8d79 100644
--- a/src/storage/storage-graph.vala
+++ b/src/storage/storage-graph.vala
@@ -20,181 +20,179 @@
using Gtk;
-namespace Usage {
- public class StorageGraph : Gtk.DrawingArea {
- private unowned List<StorageViewItem> selected_items;
- private unowned GLib.ListStore _model;
- private uint64 selected_size = 0;
- private bool root { get; private set; }
-
- public unowned GLib.ListStore model {
- get { return _model; }
- set {
- _model = value;
- this.draw.connect(draw_storage_graph);
- this.queue_draw ();
- root = false;
-
- for (int i = 0; i < value.get_n_items(); i++) {
- var item = model.get_item(i) as StorageViewItem;
- if (item.custom_type == StorageViewType.OS) {
- root = true;
- break;
- }
+public class Usage.StorageGraph : Gtk.DrawingArea {
+ private unowned List<StorageViewItem> selected_items;
+ private unowned GLib.ListStore _model;
+ private uint64 selected_size = 0;
+ private bool root { get; private set; }
+
+ public unowned GLib.ListStore model {
+ get { return _model; }
+ set {
+ _model = value;
+ this.draw.connect(draw_storage_graph);
+ this.queue_draw ();
+ root = false;
+
+ for (int i = 0; i < value.get_n_items(); i++) {
+ var item = model.get_item(i) as StorageViewItem;
+ if (item.custom_type == StorageViewType.OS) {
+ root = true;
+ break;
}
}
}
+ }
- public uint min_percentage_shown_files { get; set; }
+ public uint min_percentage_shown_files { get; set; }
- class construct {
- set_css_name("StorageGraph");
- }
+ class construct {
+ set_css_name("StorageGraph");
+ }
- public enum Circle {
- HOME,
- ROOT,
- BASE
- }
+ public enum Circle {
+ HOME,
+ ROOT,
+ BASE
+ }
- public void update_selected_items(List<StorageViewItem> selected_items) {
- this.selected_items = selected_items;
+ public void update_selected_items(List<StorageViewItem> selected_items) {
+ this.selected_items = selected_items;
- uint64 size = 0;
- foreach (var item in selected_items)
- size += item.size;
+ uint64 size = 0;
+ foreach (var item in selected_items)
+ size += item.size;
- selected_size = size;
- this.queue_draw();
- }
+ selected_size = size;
+ this.queue_draw();
+ }
- private void draw_circle(Cairo.Context context, double x, double y, double radius, int section,
Circle circle) {
- double start_angle = 0;
- double final_angle = - Math.PI / 2.0;
- double ratio = 0;
- uint shown_items_number = 1;
- var background_color =
get_toplevel().get_style_context().get_background_color(get_toplevel().get_style_context().get_state());
- var foreground_color = get_style_context().get_color(get_style_context().get_state());
+ private void draw_circle(Cairo.Context context, double x, double y, double radius, int section, Circle
circle) {
+ double start_angle = 0;
+ double final_angle = - Math.PI / 2.0;
+ double ratio = 0;
+ uint shown_items_number = 1;
+ var background_color =
get_toplevel().get_style_context().get_background_color(get_toplevel().get_style_context().get_state());
+ var foreground_color = get_style_context().get_color(get_style_context().get_state());
- for (int i = 1; i < model.get_n_items(); i++) {
- var item = (model.get_item(i) as StorageViewItem);
+ for (int i = 1; i < model.get_n_items(); i++) {
+ var item = (model.get_item(i) as StorageViewItem);
- if (i > 0 && i < 3 && (item.percentage < min_percentage_shown_files)) {
- shown_items_number = model.get_n_items();
+ if (i > 0 && i < 3 && (item.percentage < min_percentage_shown_files)) {
+ shown_items_number = model.get_n_items();
+ continue;
+ }
+
+ if (item.percentage > min_percentage_shown_files)
+ shown_items_number = shown_items_number + 1;
+ }
+
+ if (shown_items_number > 1) {
+ if (shown_items_number < 3)
+ shown_items_number = 3;
+
+ for (int i = 0; i < model.get_n_items(); i++) {
+ var item = model.get_item(i) as StorageViewItem;
+ var item_radius = radius;
+ if (item.custom_type == StorageViewType.UP_FOLDER || item.size == 0)
continue;
- }
- if (item.percentage > min_percentage_shown_files)
- shown_items_number = shown_items_number + 1;
- }
+ var style_context = get_style_context();
+ style_context.add_class(item.style_class);
+ var base_color = style_context.get_background_color(style_context.get_state());
+ style_context.remove_class(item.style_class);
- if (shown_items_number > 1) {
- if (shown_items_number < 3)
- shown_items_number = 3;
-
- for (int i = 0; i < model.get_n_items(); i++) {
- var item = model.get_item(i) as StorageViewItem;
- var item_radius = radius;
- if (item.custom_type == StorageViewType.UP_FOLDER || item.size == 0)
- continue;
-
- var style_context = get_style_context();
- style_context.add_class(item.style_class);
- var base_color = style_context.get_background_color(style_context.get_state());
- style_context.remove_class(item.style_class);
-
- Gdk.RGBA fill_color = base_color;
-
- if (!root) {
- fill_color = Utils.generate_color(base_color, i, shown_items_number, true);
- item.color = fill_color;
- }
-
- if (selected_items.find(item) != null)
- item_radius += radius / 6;
-
- context.set_line_width (2.0);
- start_angle = final_angle;
-
- if (item.percentage < 0.3)
- ratio = ratio + ((double) 0.3 / 100);
- else
- ratio = ratio + ((double) item.percentage / 100);
-
- final_angle = ratio * 2 * Math.PI - Math.PI / 2.0;
- if (final_angle >= (2 * Math.PI - Math.PI / 2.0))
- final_angle = 2 * Math.PI - Math.PI / 2.0;
-
- context.move_to (x, y);
- Gdk.cairo_set_source_rgba (context, fill_color);
- context.arc (x, y, item_radius, start_angle, final_angle);
- context.line_to (x, y);
- context.fill_preserve();
- Gdk.cairo_set_source_rgba (context, foreground_color);
- context.stroke();
-
- if (start_angle >= (2 * Math.PI - Math.PI / 2.0))
- break;
+ Gdk.RGBA fill_color = base_color;
+
+ if (!root) {
+ fill_color = Utils.generate_color(base_color, i, shown_items_number, true);
+ item.color = fill_color;
}
- context.move_to (x, y);
- context.line_to (x, y-(radius));
- context.stroke();
+ if (selected_items.find(item) != null)
+ item_radius += radius / 6;
+
+ context.set_line_width (2.0);
+ start_angle = final_angle;
- context.arc (x, y, radius/1.8, 0, 2 * Math.PI);
- Gdk.cairo_set_source_rgba (context, background_color);
+ if (item.percentage < 0.3)
+ ratio = ratio + ((double) 0.3 / 100);
+ else
+ ratio = ratio + ((double) item.percentage / 100);
+
+ final_angle = ratio * 2 * Math.PI - Math.PI / 2.0;
+ if (final_angle >= (2 * Math.PI - Math.PI / 2.0))
+ final_angle = 2 * Math.PI - Math.PI / 2.0;
+
+ context.move_to (x, y);
+ Gdk.cairo_set_source_rgba (context, fill_color);
+ context.arc (x, y, item_radius, start_angle, final_angle);
+ context.line_to (x, y);
context.fill_preserve();
Gdk.cairo_set_source_rgba (context, foreground_color);
context.stroke();
+
+ if (start_angle >= (2 * Math.PI - Math.PI / 2.0))
+ break;
}
+
+ context.move_to (x, y);
+ context.line_to (x, y-(radius));
+ context.stroke();
+
+ context.arc (x, y, radius/1.8, 0, 2 * Math.PI);
+ Gdk.cairo_set_source_rgba (context, background_color);
+ context.fill_preserve();
+ Gdk.cairo_set_source_rgba (context, foreground_color);
+ context.stroke();
}
+ }
- private bool draw_storage_graph(Cairo.Context context) {
- int height = this.get_allocated_height ();
- int width = this.get_allocated_width ();
+ private bool draw_storage_graph(Cairo.Context context) {
+ int height = this.get_allocated_height ();
+ int width = this.get_allocated_width ();
- double x = 0;
- double y = 0;
- double radius = 0;
+ double x = 0;
+ double y = 0;
+ double radius = 0;
- radius = int.min (width, height) / 2.0;
- radius -= radius / 4;
- x = width / 2.0;
- y = height / 2.0;
+ radius = int.min (width, height) / 2.0;
+ radius -= radius / 4;
+ x = width / 2.0;
+ y = height / 2.0;
- draw_circle(context, x, y, radius, 0, Circle.BASE);
- draw_selected_size_text(context);
+ draw_circle(context, x, y, radius, 0, Circle.BASE);
+ draw_selected_size_text(context);
- return true;
- }
+ return true;
+ }
- private void draw_selected_size_text(Cairo.Context context) {
- if (selected_size == 0)
- return;
+ private void draw_selected_size_text(Cairo.Context context) {
+ if (selected_size == 0)
+ return;
- var layout = create_pango_layout (null);
- var text = Utils.format_size_values(selected_size);
+ var layout = create_pango_layout (null);
+ var text = Utils.format_size_values(selected_size);
- int height = get_allocated_height ();
- int width = get_allocated_width ();
- double radius = int.min (width, height) / 22;
+ int height = get_allocated_height ();
+ int width = get_allocated_width ();
+ double radius = int.min (width, height) / 22;
- var text_color =
get_toplevel().get_style_context().get_color(get_toplevel().get_style_context().get_state());
- var text_color_string = "#%02x%02x%02x".printf(
- (uint)(Math.round(text_color.red*255)),
- (uint)(Math.round(text_color.green*255)),
- (uint)(Math.round(text_color.blue*255))).up();
+ var text_color =
get_toplevel().get_style_context().get_color(get_toplevel().get_style_context().get_state());
+ var text_color_string = "#%02x%02x%02x".printf(
+ (uint)(Math.round(text_color.red*255)),
+ (uint)(Math.round(text_color.green*255)),
+ (uint)(Math.round(text_color.blue*255))).up();
- var markup = "<span foreground='" + text_color_string + "' font='" + radius.to_string() +
"'><b>" + text + "</b></span>";
- layout.set_markup (markup, -1);
+ var markup = "<span foreground='" + text_color_string + "' font='" + radius.to_string() + "'><b>" +
text + "</b></span>";
+ layout.set_markup (markup, -1);
- Pango.Rectangle layout_rect;
- layout.get_pixel_extents (null, out layout_rect);
- layout.set_alignment(Pango.Alignment.CENTER);
+ Pango.Rectangle layout_rect;
+ layout.get_pixel_extents (null, out layout_rect);
+ layout.set_alignment(Pango.Alignment.CENTER);
- var x = (width - layout_rect.width) / 2;
- var y = (height - layout_rect.height) / 2;
- get_style_context().render_layout (context, x, y, layout);
- }
+ var x = (width - layout_rect.width) / 2;
+ var y = (height - layout_rect.height) / 2;
+ get_style_context().render_layout (context, x, y, layout);
}
}
diff --git a/src/swap-speedometer.vala b/src/swap-speedometer.vala
index 7db466f..4b7b5e5 100644
--- a/src/swap-speedometer.vala
+++ b/src/swap-speedometer.vala
@@ -20,41 +20,39 @@
using Gtk;
-namespace Usage {
- [GtkTemplate (ui = "/org/gnome/Usage/ui/swap-speedometer.ui")]
- public class SwapSpeedometer : Gtk.Bin {
- [GtkChild]
- private unowned Usage.Speedometer speedometer;
+[GtkTemplate (ui = "/org/gnome/Usage/ui/swap-speedometer.ui")]
+public class Usage.SwapSpeedometer : Gtk.Bin {
+ [GtkChild]
+ private unowned Usage.Speedometer speedometer;
- [GtkChild]
- private unowned Gtk.Label label;
+ [GtkChild]
+ private unowned Gtk.Label label;
- [GtkChild]
- private unowned Gtk.Label swap_used;
+ [GtkChild]
+ private unowned Gtk.Label swap_used;
- [GtkChild]
- private unowned Gtk.Label swap_available;
+ [GtkChild]
+ private unowned Gtk.Label swap_available;
- private double swap_usage { get; set; }
+ private double swap_usage { get; set; }
- construct {
- var monitor = SystemMonitor.get_default();
- Timeout.add_seconds(1, () => {
- var available = (monitor.swap_total - monitor.swap_usage);
- var percentage = 0.0;
- if (available > 0)
- percentage = (((double) monitor.swap_usage / monitor.swap_total) * 100);
+ construct {
+ var monitor = SystemMonitor.get_default();
+ Timeout.add_seconds(1, () => {
+ var available = (monitor.swap_total - monitor.swap_usage);
+ var percentage = 0.0;
+ if (available > 0)
+ percentage = (((double) monitor.swap_usage / monitor.swap_total) * 100);
- this.speedometer.percentage = (int)percentage;
- label.label = "%d".printf((int)percentage) + "%";
+ this.speedometer.percentage = (int)percentage;
+ label.label = "%d".printf((int)percentage) + "%";
- swap_used.label = Utils.format_size_values(monitor.swap_usage);
- swap_available.label = Utils.format_size_values(available);
+ swap_used.label = Utils.format_size_values(monitor.swap_usage);
+ swap_available.label = Utils.format_size_values(available);
- return true;
- });
+ return true;
+ });
- this.show_all();
- }
+ this.show_all();
}
}
diff --git a/src/system-monitor.vala b/src/system-monitor.vala
index b87676a..b69c494 100644
--- a/src/system-monitor.vala
+++ b/src/system-monitor.vala
@@ -18,227 +18,225 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class SystemMonitor : Object {
- public bool process_list_ready { get; private set; default = false; }
- public double cpu_load { get; private set; }
- public double[] x_cpu_load { get; private set; }
- public uint64 ram_usage { get; private set; }
- public uint64 ram_total { get; private set; }
- public uint64 swap_usage { get; private set; }
- public uint64 swap_total { get; private set; }
- public bool group_system_apps { get; set; default = true; }
-
- private CpuMonitor cpu_monitor;
- private MemoryMonitor memory_monitor;
- private GameMode.PidList gamemode_pids;
-
- private HashTable<string, AppItem> app_table;
- private HashTable<GLib.Pid, Process> process_table;
- private int process_mode = GTop.KERN_PROC_ALL;
- private static SystemMonitor system_monitor;
-
- public static SystemMonitor get_default() {
- if (system_monitor == null)
- system_monitor = new SystemMonitor ();
-
- return system_monitor;
- }
+public class Usage.SystemMonitor : Object {
+ public bool process_list_ready { get; private set; default = false; }
+ public double cpu_load { get; private set; }
+ public double[] x_cpu_load { get; private set; }
+ public uint64 ram_usage { get; private set; }
+ public uint64 ram_total { get; private set; }
+ public uint64 swap_usage { get; private set; }
+ public uint64 swap_total { get; private set; }
+ public bool group_system_apps { get; set; default = true; }
+
+ private CpuMonitor cpu_monitor;
+ private MemoryMonitor memory_monitor;
+ private GameMode.PidList gamemode_pids;
+
+ private HashTable<string, AppItem> app_table;
+ private HashTable<GLib.Pid, Process> process_table;
+ private int process_mode = GTop.KERN_PROC_ALL;
+ private static SystemMonitor system_monitor;
+
+ public static SystemMonitor get_default() {
+ if (system_monitor == null)
+ system_monitor = new SystemMonitor ();
+
+ return system_monitor;
+ }
- public List<unowned AppItem> get_apps() {
- return app_table.get_values();
- }
+ public List<unowned AppItem> get_apps() {
+ return app_table.get_values();
+ }
- public unowned AppItem get_app_by_name(string name) {
- return app_table.get(name);
- }
+ public unowned AppItem get_app_by_name(string name) {
+ return app_table.get(name);
+ }
- public SystemMonitor() {
- GTop.init();
- AppItem.init();
+ public SystemMonitor() {
+ GTop.init();
+ AppItem.init();
- cpu_monitor = new CpuMonitor();
- memory_monitor = new MemoryMonitor();
- gamemode_pids = new GameMode.PidList();
+ cpu_monitor = new CpuMonitor();
+ memory_monitor = new MemoryMonitor();
+ gamemode_pids = new GameMode.PidList();
- app_table = new HashTable<string, AppItem>(str_hash, str_equal);
- process_table = new HashTable<GLib.Pid, Process>(direct_hash, direct_equal);
- var settings = Settings.get_default();
+ app_table = new HashTable<string, AppItem>(str_hash, str_equal);
+ process_table = new HashTable<GLib.Pid, Process>(direct_hash, direct_equal);
+ var settings = Settings.get_default();
+ init();
+ this.notify["group-system-apps"].connect ((sender, property) => {
init();
- this.notify["group-system-apps"].connect ((sender, property) => {
- init();
- });
-
- Timeout.add(settings.data_update_interval, update_data);
- }
-
- private void init() {
- var settings = Settings.get_default();
- app_table.remove_all();
- process_list_ready = false;
+ });
- if (group_system_apps) {
- var system = new AppItem.system();
- app_table.insert("system" , system);
- }
+ Timeout.add(settings.data_update_interval, update_data);
+ }
- foreach (var p in process_table.get_values ()) {
- process_added (p);
- }
+ private void init() {
+ var settings = Settings.get_default();
+ app_table.remove_all();
+ process_list_ready = false;
- update_data();
- Timeout.add(settings.data_update_interval, () => {
- process_list_ready = true;
- return false;
- });
+ if (group_system_apps) {
+ var system = new AppItem.system();
+ app_table.insert("system" , system);
}
- private bool update_data() {
- cpu_monitor.update();
- memory_monitor.update();
-
- cpu_load = cpu_monitor.get_cpu_load();
- x_cpu_load = cpu_monitor.get_x_cpu_load();
- ram_usage = memory_monitor.get_ram_usage();
- ram_total = memory_monitor.get_ram_total();
- swap_usage = memory_monitor.get_swap_usage();
- swap_total = memory_monitor.get_swap_total();
-
- foreach (var app in app_table.get_values ())
- app.mark_as_not_updated();
-
- /* Try to find the difference between the old list of pids,
- * and the new ones, i.e. the one that got added and removed */
- GTop.Proclist proclist;
- var pids = GTop.get_proclist (out proclist, process_mode);
- intptr[] old = (intptr[]) process_table.get_keys_as_array ();
-
- size_t new_len = (size_t) proclist.number;
- size_t old_len = process_table.length;
-
- sort_pids (pids, sizeof (GLib.Pid), new_len);
- sort_pids (old, sizeof (intptr), old_len);
-
- debug ("new_len: %lu, old_len: %lu\n", new_len, old_len);
- uint removed = 0;
- uint added = 0;
- for (size_t i = 0, j = 0; i < new_len || j < old_len; ) {
- uint32 n = i < new_len ? pids[i] : uint32.MAX;
- uint32 o = j < old_len ? (uint32) old[j] : uint32.MAX;
-
- /* pids: [ 1, 3, 4 ]
- * old: [ 1, 2, 4, 5 ] → 2,5 removed, 3 added
- * i [for pids]: 0 | 1 | 1 | 2 | 3
- * j [for old]: 0 | 1 | 2 | 2 | 3
- * n = pids[i]: 1 | 3 | 3 | 4 | MAX [oob]
- * o = old[j]: 1 | 2 | 4 | 4 | 5
- * = | n > o | n < o | = | n > o
- * increment: i,j | j | i | i,j | j
- * Process op: chk | del | add | chk | del
- */
-
- if (n > o) {
- /* delete to process not in the new array */
- Process p = process_table[(GLib.Pid) o];
- debug ("process removed: %u\n", o);
-
- process_removed (p);
- removed++;
+ foreach (var p in process_table.get_values ()) {
+ process_added (p);
+ }
- j++; /* let o := old[j] catch up */
- } else if (n < o) {
- /* new process */
- var p = new Process ((GLib.Pid) n);
- update_process (ref p); // state, time
+ update_data();
+ Timeout.add(settings.data_update_interval, () => {
+ process_list_ready = true;
+ return false;
+ });
+ }
- debug ("process added: %u\n", n);
+ private bool update_data() {
+ cpu_monitor.update();
+ memory_monitor.update();
+
+ cpu_load = cpu_monitor.get_cpu_load();
+ x_cpu_load = cpu_monitor.get_x_cpu_load();
+ ram_usage = memory_monitor.get_ram_usage();
+ ram_total = memory_monitor.get_ram_total();
+ swap_usage = memory_monitor.get_swap_usage();
+ swap_total = memory_monitor.get_swap_total();
+
+ foreach (var app in app_table.get_values ())
+ app.mark_as_not_updated();
+
+ /* Try to find the difference between the old list of pids,
+ * and the new ones, i.e. the one that got added and removed */
+ GTop.Proclist proclist;
+ var pids = GTop.get_proclist (out proclist, process_mode);
+ intptr[] old = (intptr[]) process_table.get_keys_as_array ();
+
+ size_t new_len = (size_t) proclist.number;
+ size_t old_len = process_table.length;
+
+ sort_pids (pids, sizeof (GLib.Pid), new_len);
+ sort_pids (old, sizeof (intptr), old_len);
+
+ debug ("new_len: %lu, old_len: %lu\n", new_len, old_len);
+ uint removed = 0;
+ uint added = 0;
+ for (size_t i = 0, j = 0; i < new_len || j < old_len; ) {
+ uint32 n = i < new_len ? pids[i] : uint32.MAX;
+ uint32 o = j < old_len ? (uint32) old[j] : uint32.MAX;
+
+ /* pids: [ 1, 3, 4 ]
+ * old: [ 1, 2, 4, 5 ] → 2,5 removed, 3 added
+ * i [for pids]: 0 | 1 | 1 | 2 | 3
+ * j [for old]: 0 | 1 | 2 | 2 | 3
+ * n = pids[i]: 1 | 3 | 3 | 4 | MAX [oob]
+ * o = old[j]: 1 | 2 | 4 | 4 | 5
+ * = | n > o | n < o | = | n > o
+ * increment: i,j | j | i | i,j | j
+ * Process op: chk | del | add | chk | del
+ */
+
+ if (n > o) {
+ /* delete to process not in the new array */
+ Process p = process_table[(GLib.Pid) o];
+ debug ("process removed: %u\n", o);
+
+ process_removed (p);
+ removed++;
+
+ j++; /* let o := old[j] catch up */
+ } else if (n < o) {
+ /* new process */
+ var p = new Process ((GLib.Pid) n);
+ update_process (ref p); // state, time
+
+ debug ("process added: %u\n", n);
- process_added (p);
- added++;
+ process_added (p);
+ added++;
- i++; /* let n := pids[i] catch up */
- } else {
- /* equal pids, might have rolled over though
- * better check, match start time */
- Process p = process_table[(GLib.Pid) n];
+ i++; /* let n := pids[i] catch up */
+ } else {
+ /* equal pids, might have rolled over though
+ * better check, match start time */
+ Process p = process_table[(GLib.Pid) n];
- GTop.ProcTime ptime;
- GTop.get_proc_time (out ptime, p.pid);
+ GTop.ProcTime ptime;
+ GTop.get_proc_time (out ptime, p.pid);
- /* no match: -> old removed, new added */
- if (ptime.start_time != p.start_time) {
- debug ("start time mismtach: %u\n", n);
- process_removed (p);
+ /* no match: -> old removed, new added */
+ if (ptime.start_time != p.start_time) {
+ debug ("start time mismtach: %u\n", n);
+ process_removed (p);
- p = new Process ((GLib.Pid) n);
- process_added (p);
- }
+ p = new Process ((GLib.Pid) n);
+ process_added (p);
+ }
- update_process (ref p);
+ update_process (ref p);
- i++; j++; /* both indices move */
- }
+ i++; j++; /* both indices move */
}
+ }
- foreach (var app in app_table.get_values ())
- app.remove_processes ();
-
- debug ("removed: %u, added: %u\n", removed, added);
- debug ("app table size: %u\n", app_table.length);
- debug ("process table size: %u\n", process_table.length);
+ foreach (var app in app_table.get_values ())
+ app.remove_processes ();
- return true;
- }
+ debug ("removed: %u, added: %u\n", removed, added);
+ debug ("app table size: %u\n", app_table.length);
+ debug ("process table size: %u\n", process_table.length);
- private void process_added (Process p) {
- string app_id = get_app_id_for_process (p);
+ return true;
+ }
- AppItem? item = app_table[app_id];
+ private void process_added (Process p) {
+ string app_id = get_app_id_for_process (p);
- if (item == null) {
- item = new AppItem (p);
- app_table.insert (app_id, item);
- } else if (! item.contains_process (p.pid)) {
- item.insert_process (p);
- }
+ AppItem? item = app_table[app_id];
- process_table.insert (p.pid, p);
+ if (item == null) {
+ item = new AppItem (p);
+ app_table.insert (app_id, item);
+ } else if (! item.contains_process (p.pid)) {
+ item.insert_process (p);
}
- private void process_removed (Process p) {
- string app_id = get_app_id_for_process (p);
+ process_table.insert (p.pid, p);
+ }
- AppItem? item = app_table[app_id];
+ private void process_removed (Process p) {
+ string app_id = get_app_id_for_process (p);
- if (item != null)
- item.remove_process (p);
+ AppItem? item = app_table[app_id];
- process_table.remove (p.pid);
- }
+ if (item != null)
+ item.remove_process (p);
- private string get_app_id_for_process (Process p) {
- AppInfo? info = AppItem.app_info_for_process (p);
+ process_table.remove (p.pid);
+ }
- if (info != null)
- return info.get_id ();
- else if (group_system_apps)
- return "system";
+ private string get_app_id_for_process (Process p) {
+ AppInfo? info = AppItem.app_info_for_process (p);
- return p.cmdline;
- }
+ if (info != null)
+ return info.get_id ();
+ else if (group_system_apps)
+ return "system";
- private void update_process(ref Process process) {
- cpu_monitor.update_process(ref process);
- memory_monitor.update_process(ref process);
- process.update_status();
- process.gamemode = gamemode_pids.contains((int) process.pid);
- }
+ return p.cmdline;
+ }
- public static void sort_pids (void *pids, size_t elm, size_t length) {
- Posix.qsort (pids, length, elm, (a, b) => {
- return (*(GLib.Pid *) a) - (* (GLib.Pid *) b);
- });
- }
+ private void update_process(ref Process process) {
+ cpu_monitor.update_process(ref process);
+ memory_monitor.update_process(ref process);
+ process.update_status();
+ process.gamemode = gamemode_pids.contains((int) process.pid);
+ }
+
+ public static void sort_pids (void *pids, size_t elm, size_t length) {
+ Posix.qsort (pids, length, elm, (a, b) => {
+ return (*(GLib.Pid *) a) - (* (GLib.Pid *) b);
+ });
}
}
diff --git a/src/utils.vala b/src/utils.vala
index 5767502..1f8a588 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -18,88 +18,86 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public class Utils {
- public static string format_size_values(uint64 value) {
- if (value >= 1000)
- return GLib.format_size(value);
- else
- return _("%llu B").printf(value);
- }
-
- public static string format_size_speed_values(uint64 value) {
- if (value >= 1000)
- return _("%s/s").printf(GLib.format_size(value));
- else
- return _("%llu B/s").printf(value);
- }
-
- public static Gdk.RGBA generate_color(Gdk.RGBA default_color, uint order, uint all_count, bool
reverse = false) {
- double step = 100 / (double) all_count;
- uint half_count = all_count / 2;
+public class Usage.Utils {
+ public static string format_size_values(uint64 value) {
+ if (value >= 1000)
+ return GLib.format_size(value);
+ else
+ return _("%llu B").printf(value);
+ }
- if (order >= all_count)
- order = all_count - 1;
+ public static string format_size_speed_values(uint64 value) {
+ if (value >= 1000)
+ return _("%s/s").printf(GLib.format_size(value));
+ else
+ return _("%llu B/s").printf(value);
+ }
- if (order > (all_count / 2)) {
- double percentage = step * (order - half_count);
- if (reverse)
- return Utils.color_lighter(default_color, percentage);
- else
- return Utils.color_darker(default_color, percentage);
- } else {
- double percentage = step * (half_count - (order-1));
- if (reverse)
- return Utils.color_darker(default_color, percentage);
- else
- return Utils.color_lighter(default_color, percentage);
- }
- }
+ public static Gdk.RGBA generate_color(Gdk.RGBA default_color, uint order, uint all_count, bool reverse =
false) {
+ double step = 100 / (double) all_count;
+ uint half_count = all_count / 2;
- public static Gdk.RGBA color_darker(Gdk.RGBA color, double percentage) {
- color.red = color_field_darker(color.red, percentage);
- color.green = color_field_darker(color.green, percentage);
- color.blue = color_field_darker(color.blue, percentage);
+ if (order >= all_count)
+ order = all_count - 1;
- return color;
+ if (order > (all_count / 2)) {
+ double percentage = step * (order - half_count);
+ if (reverse)
+ return Utils.color_lighter(default_color, percentage);
+ else
+ return Utils.color_darker(default_color, percentage);
+ } else {
+ double percentage = step * (half_count - (order-1));
+ if (reverse)
+ return Utils.color_darker(default_color, percentage);
+ else
+ return Utils.color_lighter(default_color, percentage);
}
+ }
- public static Gdk.RGBA color_lighter(Gdk.RGBA color, double percentage) {
- color.red = color_field_lighter(color.red, percentage);
- color.green = color_field_lighter(color.green, percentage);
- color.blue = color_field_lighter(color.blue, percentage);
+ public static Gdk.RGBA color_darker(Gdk.RGBA color, double percentage) {
+ color.red = color_field_darker(color.red, percentage);
+ color.green = color_field_darker(color.green, percentage);
+ color.blue = color_field_darker(color.blue, percentage);
- return color;
- }
+ return color;
+ }
- private static double color_field_darker(double field, double percentage) {
- field = field * 255;
- return (field - ((field / 100) * percentage)) / 255;
- }
+ public static Gdk.RGBA color_lighter(Gdk.RGBA color, double percentage) {
+ color.red = color_field_lighter(color.red, percentage);
+ color.green = color_field_lighter(color.green, percentage);
+ color.blue = color_field_lighter(color.blue, percentage);
- private static double color_field_lighter(double field, double percentage) {
- field = field * 255;
- return (field + (((255 - field) / 100) * percentage)) / 255;
- }
+ return color;
}
- public enum UserAccountType {
- STANDARD,
- ADMINISTRATOR,
+ private static double color_field_darker(double field, double percentage) {
+ field = field * 255;
+ return (field - ((field / 100) * percentage)) / 255;
}
- [DBus (name = "org.freedesktop.Accounts")]
- public interface Fdo.Accounts : Object {
- public abstract async string FindUserById (int64 id) throws GLib.Error;
+ private static double color_field_lighter(double field, double percentage) {
+ field = field * 255;
+ return (field + (((255 - field) / 100) * percentage)) / 255;
}
+}
- [DBus (name = "org.freedesktop.Accounts.User")]
- public interface Fdo.AccountsUser : Object {
- public abstract bool SystemAccount { get; }
- public abstract bool LocalAccount { get; }
- public abstract int32 AccountType { get; }
- public abstract string RealName { owned get; }
- public abstract string UserName { owned get; }
- public abstract uint64 Uid { get; }
- }
+public enum Usage.UserAccountType {
+ STANDARD,
+ ADMINISTRATOR,
+}
+
+[DBus (name = "org.freedesktop.Accounts")]
+public interface Usage.Fdo.Accounts : Object {
+ public abstract async string FindUserById (int64 id) throws GLib.Error;
+}
+
+[DBus (name = "org.freedesktop.Accounts.User")]
+public interface Usage.Fdo.AccountsUser : Object {
+ public abstract bool SystemAccount { get; }
+ public abstract bool LocalAccount { get; }
+ public abstract int32 AccountType { get; }
+ public abstract string RealName { owned get; }
+ public abstract string UserName { owned get; }
+ public abstract uint64 Uid { get; }
}
diff --git a/src/view.vala b/src/view.vala
index ed75eb8..2e39a2b 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -18,17 +18,15 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public abstract class View : Gtk.Bin {
- public string title;
- public string icon_name;
+public abstract class Usage.View : Gtk.Bin {
+ public string title;
+ public string icon_name;
- protected View () {
- visible = true;
- }
+ protected View () {
+ visible = true;
}
+}
- public interface SubView {
- public abstract void search_in_processes(string text);
- }
+public interface Usage.SubView {
+ public abstract void search_in_processes(string text);
}
diff --git a/src/window.vala b/src/window.vala
index 6fb1211..95b4e9c 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -19,124 +19,122 @@
* Authors: Petr Štětka <pstetka redhat com>
*/
-namespace Usage {
- public enum Views {
- PERFORMANCE,
- STORAGE,
- }
+public enum Usage.Views {
+ PERFORMANCE,
+ STORAGE,
+}
- public enum HeaderBarMode {
- PERFORMANCE,
- STORAGE,
- }
+public enum Usage.HeaderBarMode {
+ PERFORMANCE,
+ STORAGE,
+}
- [GtkTemplate (ui = "/org/gnome/Usage/ui/window.ui")]
- public class Window : Hdy.ApplicationWindow {
- [GtkChild]
- private unowned Gtk.Stack stack;
+[GtkTemplate (ui = "/org/gnome/Usage/ui/window.ui")]
+public class Usage.Window : Hdy.ApplicationWindow {
+ [GtkChild]
+ private unowned Gtk.Stack stack;
- [GtkChild]
- private unowned Gtk.Revealer performance_search_revealer;
+ [GtkChild]
+ private unowned Gtk.Revealer performance_search_revealer;
- [GtkChild]
- private unowned Gtk.ToggleButton performance_search_button;
+ [GtkChild]
+ private unowned Gtk.ToggleButton performance_search_button;
- [GtkChild]
- private unowned Gtk.MenuButton primary_menu_button;
+ [GtkChild]
+ private unowned Gtk.MenuButton primary_menu_button;
- private HeaderBarMode mode;
- private Usage.PrimaryMenu menu;
+ private HeaderBarMode mode;
+ private Usage.PrimaryMenu menu;
- private View[] views;
+ private View[] views;
- public Window(Gtk.Application application) {
- GLib.Object(application : application);
+ public Window(Gtk.Application application) {
+ GLib.Object(application : application);
- if (Config.PROFILE == "Devel") {
- get_style_context().add_class("devel");
- }
+ if (Config.PROFILE == "Devel") {
+ get_style_context().add_class("devel");
+ }
+ load_css();
+ Gtk.Settings.get_for_screen(get_screen()).notify["gtk-application-prefer-dark-theme"].connect(() => {
load_css();
- Gtk.Settings.get_for_screen(get_screen()).notify["gtk-application-prefer-dark-theme"].connect(()
=> {
- load_css();
- });
+ });
- mode = HeaderBarMode.PERFORMANCE;
- menu = new Usage.PrimaryMenu();
- this.primary_menu_button.set_popover(menu);
+ mode = HeaderBarMode.PERFORMANCE;
+ menu = new Usage.PrimaryMenu();
+ this.primary_menu_button.set_popover(menu);
- set_mode(HeaderBarMode.PERFORMANCE);
+ set_mode(HeaderBarMode.PERFORMANCE);
- views = new View[] {
- new PerformanceView(),
- new StorageView(),
- };
+ views = new View[] {
+ new PerformanceView(),
+ new StorageView(),
+ };
- foreach (var view in views) {
- stack.add_titled(view, view.name, view.title);
- stack.child_set (view, "icon-name", view.icon_name, null);
- }
+ foreach (var view in views) {
+ stack.add_titled(view, view.name, view.title);
+ stack.child_set (view, "icon-name", view.icon_name, null);
}
+ }
- public void set_mode(HeaderBarMode mode) {
- switch (this.mode) {
- case HeaderBarMode.PERFORMANCE:
- performance_search_revealer.reveal_child = false;
- break;
- case HeaderBarMode.STORAGE:
- break;
- }
-
- switch (mode) {
- case HeaderBarMode.PERFORMANCE:
- performance_search_revealer.reveal_child = true;
- break;
- case HeaderBarMode.STORAGE:
- break;
- }
- menu.mode = mode;
- this.mode = mode;
+ public void set_mode(HeaderBarMode mode) {
+ switch (this.mode) {
+ case HeaderBarMode.PERFORMANCE:
+ performance_search_revealer.reveal_child = false;
+ break;
+ case HeaderBarMode.STORAGE:
+ break;
}
- public void action_on_search() {
- switch (mode) {
- case HeaderBarMode.PERFORMANCE:
- performance_search_button.set_active(!performance_search_button.get_active());
- break;
- case HeaderBarMode.STORAGE:
- break;
- }
+ switch (mode) {
+ case HeaderBarMode.PERFORMANCE:
+ performance_search_revealer.reveal_child = true;
+ break;
+ case HeaderBarMode.STORAGE:
+ break;
}
+ menu.mode = mode;
+ this.mode = mode;
+ }
- public View[] get_views() {
- return views;
+ public void action_on_search() {
+ switch (mode) {
+ case HeaderBarMode.PERFORMANCE:
+ performance_search_button.set_active(!performance_search_button.get_active());
+ break;
+ case HeaderBarMode.STORAGE:
+ break;
}
+ }
- private void load_css() {
- var provider = new Gtk.CssProvider();
- Gtk.StyleContext.reset_widgets(get_screen());
- provider.load_from_resource("/org/gnome/Usage/interface/adwaita.css");
- Gtk.StyleContext.add_provider_for_screen(get_screen(), provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
+ public View[] get_views() {
+ return views;
+ }
+
+ private void load_css() {
+ var provider = new Gtk.CssProvider();
+ Gtk.StyleContext.reset_widgets(get_screen());
+ provider.load_from_resource("/org/gnome/Usage/interface/adwaita.css");
+ Gtk.StyleContext.add_provider_for_screen(get_screen(), provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
- [GtkCallback]
- private void on_performance_search_button_toggled () {
- var application = GLib.Application.get_default() as Application;
+ [GtkCallback]
+ private void on_performance_search_button_toggled () {
+ var application = GLib.Application.get_default() as Application;
- if (application == null)
- return;
+ if (application == null)
+ return;
- /* TODO: Implement a saner way of toggling this mode. */
- ((PerformanceView)
application.get_window().get_views()[Views.PERFORMANCE]).set_search_mode(performance_search_button.active);
- }
+ /* TODO: Implement a saner way of toggling this mode. */
+ ((PerformanceView)
application.get_window().get_views()[Views.PERFORMANCE]).set_search_mode(performance_search_button.active);
+ }
- [GtkCallback]
- private void on_visible_child_changed() {
- if (stack.visible_child_name == views[Views.PERFORMANCE].name) {
- set_mode(HeaderBarMode.PERFORMANCE);
- } else if (stack.visible_child_name == views[Views.STORAGE].name) {
- set_mode(HeaderBarMode.STORAGE);
- }
+ [GtkCallback]
+ private void on_visible_child_changed() {
+ if (stack.visible_child_name == views[Views.PERFORMANCE].name) {
+ set_mode(HeaderBarMode.PERFORMANCE);
+ } else if (stack.visible_child_name == views[Views.STORAGE].name) {
+ set_mode(HeaderBarMode.STORAGE);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]