[gnome-usage] sub-process-list-box: Port to Gtk+ widget template



commit f21c39b253571daa5771f6eb896609b8373ea6af
Author: Petr Štětka <pstetka redhat com>
Date:   Fri Aug 4 11:16:43 2017 +0200

    sub-process-list-box: 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-list-box.ui    |    7 ++++++
 src/process-row.vala               |    3 +-
 src/sub-process-list-box.vala      |   42 +++++++++++++++++++----------------
 4 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/data/org.gnome.Usage.gresource.xml b/data/org.gnome.Usage.gresource.xml
index 13b4f16..30867aa 100644
--- a/data/org.gnome.Usage.gresource.xml
+++ b/data/org.gnome.Usage.gresource.xml
@@ -8,5 +8,6 @@
         <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>
+        <file preprocess="xml-stripblanks">ui/sub-process-list-box.ui</file>
     </gresource>
 </gresources>
diff --git a/data/ui/sub-process-list-box.ui b/data/ui/sub-process-list-box.ui
new file mode 100644
index 0000000..9a9c1c2
--- /dev/null
+++ b/data/ui/sub-process-list-box.ui
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="UsageSubProcessListBox" parent="GtkListBox">
+    <property name="visible">True</property>
+  </template>
+</interface>
diff --git a/src/process-row.vala b/src/process-row.vala
index abb8c09..c366b84 100644
--- a/src/process-row.vala
+++ b/src/process-row.vala
@@ -60,7 +60,8 @@ namespace Usage
             if(process.get_sub_processes() != null)
             {
                 group = true;
-                sub_process_list_box = new SubProcessListBox(process, type);
+                sub_process_list_box = new SubProcessListBox();
+                sub_process_list_box.init(process, type);
                 revealer = new Gtk.Revealer();
                 revealer.add(sub_process_list_box);
                 box.pack_end(revealer, false, true, 0);
diff --git a/src/sub-process-list-box.vala b/src/sub-process-list-box.vala
index 5802df4..a001ea9 100644
--- a/src/sub-process-list-box.vala
+++ b/src/sub-process-list-box.vala
@@ -20,6 +20,7 @@
 
 namespace Usage
 {
+    [GtkTemplate (ui = "/org/gnome/Usage/ui/sub-process-list-box.ui")]
     public class SubProcessListBox : Gtk.ListBox
     {
         ListStore model;
@@ -31,10 +32,8 @@ namespace Usage
             set_css_name("subprocess-list");
         }
 
-        public SubProcessListBox(Process process, ProcessListBoxType type)
+        construct
         {
-            this.type = type;
-            parent_process = process;
             set_selection_mode (Gtk.SelectionMode.NONE);
             set_header_func (update_header);
 
@@ -42,27 +41,32 @@ namespace Usage
                 var sub_process_row = (SubProcessSubRow) row;
                 sub_process_row.activate();
             });
+        }
+
+        public void init(Process process, ProcessListBoxType type)
+        {
+            this.type = type;
+            parent_process = process;
 
             model = new ListStore(typeof(Process));
             bind_model(model, on_row_created);
-
             update();
         }
 
         private void update()
         {
-               CompareDataFunc<Process> processcmp = (a, b) => {
-               Process p_a = (Process) a;
-               Process p_b = (Process) b;
+            CompareDataFunc<Process> processcmp = (a, b) => {
+                Process p_a = (Process) a;
+                Process p_b = (Process) b;
 
-               switch(type)
-               {
-                       default:
-                       case ProcessListBoxType.PROCESSOR:
-                               return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) 
(p_a.get_cpu_load() > p_b.get_cpu_load()));
-                   case ProcessListBoxType.MEMORY:
-                       return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) 
(p_a.get_mem_usage() > p_b.get_mem_usage()));
-               }
+                switch(type)
+                {
+                    default:
+                    case ProcessListBoxType.PROCESSOR:
+                        return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) 
(p_a.get_cpu_load() > p_b.get_cpu_load()));
+                    case ProcessListBoxType.MEMORY:
+                        return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) 
(p_a.get_mem_usage() > p_b.get_mem_usage()));
+                }
             };
 
            if(parent_process.get_sub_processes() != null)
@@ -84,14 +88,14 @@ namespace Usage
         private void update_header(Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row)
         {
             if(before_row == null)
-                   row.set_header(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);
-               }
+                separator.show();
+                row.set_header(separator);
+            }
         }
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]