[gnome-usage] sub-process-sub-row: Port to Gtk+ widget template
- From: Petr Štětka <pstetka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] sub-process-sub-row: Port to Gtk+ widget template
- Date: Tue, 24 Oct 2017 14:58:12 +0000 (UTC)
commit 4a72be06521a962bf75e4716b5d08c8cc4e34f79
Author: Petr Štětka <pstetka redhat com>
Date: Fri Aug 4 11:00:55 2017 +0200
sub-process-sub-row: Port to Gtk+ widget template
https://bugzilla.gnome.org/show_bug.cgi?id=785675
data/org.gnome.Usage.gresource.xml | 1 +
data/ui/sub-process-sub-row.ui | 54 ++++++++++++++++++++++++++++++++++++
src/sub-process-sub-row.vala | 47 ++++++++++++++++--------------
3 files changed, 80 insertions(+), 22 deletions(-)
---
diff --git a/data/org.gnome.Usage.gresource.xml b/data/org.gnome.Usage.gresource.xml
index 651b9d4..13b4f16 100644
--- a/data/org.gnome.Usage.gresource.xml
+++ b/data/org.gnome.Usage.gresource.xml
@@ -7,5 +7,6 @@
<file preprocess="xml-stripblanks">ui/performance-view.ui</file>
<file preprocess="xml-stripblanks">ui/process-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/storage-view.ui</file>
+ <file preprocess="xml-stripblanks">ui/sub-process-sub-row.ui</file>
</gresource>
</gresources>
diff --git a/data/ui/sub-process-sub-row.ui b/data/ui/sub-process-sub-row.ui
new file mode 100644
index 0000000..f01956c
--- /dev/null
+++ b/data/ui/sub-process-sub-row.ui
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="UsageSubProcessSubRow" parent="GtkListBoxRow">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin">10</property>
+ <child>
+ <object class="GtkImage" id="icon">
+ <property name="can_focus">False</property>
+ <property name="visible">True</property>
+ <property name="margin_right">10</property>
+ <property name="margin_left">10</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="title_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="load_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="ellipsize">end</property>
+ <property name="max_width_chars">30</property>
+ <property name="margin_right">10</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/sub-process-sub-row.vala b/src/sub-process-sub-row.vala
index e0f88ea..48ac96a 100644
--- a/src/sub-process-sub-row.vala
+++ b/src/sub-process-sub-row.vala
@@ -20,59 +20,62 @@
namespace Usage
{
+ [GtkTemplate (ui = "/org/gnome/Usage/ui/sub-process-sub-row.ui")]
public class SubProcessSubRow : Gtk.ListBoxRow
{
- Gtk.Label load_label;
ProcessListBoxType type;
+
+ [GtkChild]
+ private Gtk.Image icon;
+
+ [GtkChild]
+ private Gtk.Label title_label;
+
+ [GtkChild]
+ private Gtk.Label load_label;
+
public Process process { get; private set; }
public bool max_usage { get; private set; }
+ private const int MAX_CPU_USAGE_LIMIT = 90;
+ private const int MAX_MEMORY_USAGE_LIMIT = 90;
+
public SubProcessSubRow(Process process, ProcessListBoxType type)
{
this.type = type;
this.process = process;
- var row_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
- row_box.margin = 10;
- load_label = new Gtk.Label(null);
- load_label.ellipsize = Pango.EllipsizeMode.END;
- load_label.max_width_chars = 30;
-
- var icon = new Gtk.Image.from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON);
- icon.width_request = 24;
- icon.height_request = 24;
- icon.margin_left = 10;
- icon.margin_right = 10;
- var title_label = new Gtk.Label(process.get_cmdline());
- row_box.pack_start(icon, false, false, 0);
- row_box.pack_start(title_label, false, true, 5);
- row_box.pack_end(load_label, false, true, 10);
- this.add(row_box);
+ icon.set_from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON);
+ title_label.label = process.get_display_name();
notify["max-usage"].connect (() => {
set_styles();
});
update();
- show_all();
}
private void update()
{
+ update_load_label();
+ }
+
+ private void update_load_label()
+ {
switch(type)
{
case ProcessListBoxType.PROCESSOR:
- load_label.set_label(((uint64) process.get_cpu_load()).to_string() + " %");
+ load_label.label = ((uint64) process.get_cpu_load()).to_string() + " %";
- if(process.get_cpu_load() >= 90)
+ if(process.get_cpu_load() >= MAX_CPU_USAGE_LIMIT)
max_usage = true;
else
max_usage = false;
break;
case ProcessListBoxType.MEMORY:
SystemMonitor monitor = SystemMonitor.get_default();
- load_label.set_label(Utils.format_size_values(process.get_mem_usage()));
+ load_label.label = Utils.format_size_values(process.get_mem_usage());
- if((((double) process.get_mem_usage() / monitor.ram_total) * 100) >= 90)
+ if((((double) process.get_mem_usage() / monitor.ram_total) * 100) >=
MAX_MEMORY_USAGE_LIMIT)
max_usage = true;
else
max_usage = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]