[gnome-boxes/wip/ui-files: 3/4] Sidebar handles its content for properties view



commit 7cd3d85beafd0113274d7183bcef5178fc6be14f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sat Feb 1 17:47:37 2014 +0100

    Sidebar handles its content for properties view
    
    Instead of Properties class setting up all the UI of sidebar for its own
    view, Sidebar now handles that itself. This implies moving of most of
    this UI setup to a .ui file.

 data/ui/sidebar.ui  |  200 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/machine.vala    |   10 ++--
 src/properties.vala |   94 +++----------------------
 src/sidebar.vala    |   34 +++++++++
 4 files changed, 248 insertions(+), 90 deletions(-)
---
diff --git a/data/ui/sidebar.ui b/data/ui/sidebar.ui
index 0e169a8..8b66283 100644
--- a/data/ui/sidebar.ui
+++ b/data/ui/sidebar.ui
@@ -121,7 +121,207 @@
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
         <property name="spacing">10</property>
+
+        <child>
+          <object class="GtkTreeView" id="props_tree_view">
+            <property name="visible">True</property>
+            <property name="headers-visible">False</property>
+            <property name="activate-on-single-click">True</property>
+            <property name="model">props_model_filter</property>
+            <signal name="row_activated" handler="on_props_row_activated"/>
+            <style>
+              <class name="boxes-bg"/>
+            </style>
+
+            <child>
+              <object class="GtkTreeViewColumn" id="text-column">
+                <property name="title"></property>
+                <child>
+                  <object class="GtkCellRendererText" id="text-renderer">
+                    <property name="visible">True</property>
+                    <property name="xpad">20</property>
+                    <property name="weight">700</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+
+            <child internal-child="selection">
+              <object class="GtkTreeSelection" id="props_selection">
+                <property name="mode">browse</property>
+              </object>
+            </child>
+          </object>
+
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="padding">0</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkGrid" id="props_grid">
+            <property name="visible">True</property>
+            <property name="column-homogeneous">False</property>
+            <property name="column-spacing">2</property>
+            <property name="row-spacing">10</property>
+            <property name="margin-left">10</property>
+            <property name="margin-right">10</property>
+            <property name="margin-top">10</property>
+            <property name="margin-bottom">30</property>
+
+            <child>
+              <object class="GtkAlignment" id="screenshot_placeholder">
+                <property name="visible">True</property>
+                <property name="xalign">0.0</property>
+                <property name="yalign">0.0</property>
+                <property name="xscale">0.0</property>
+                <property name="yscale">0.0</property>
+                <property name="width-request">180</property>
+                <property name="height-request">130</property>
+              </object>
+
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">0</property>
+                <property name="width">6</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="GtkLabel" id="cpu_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">CPU:</property>
+                <style>
+                  <class name="boxes-graph-label"/>
+                </style>
+              </object>
+
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="BoxesMiniGraph" id="cpu_graph">
+                <property name="visible">True</property>
+                <property name="ymax">100</property>
+                <property name="npoints">20</property>
+              </object>
+
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="GtkLabel" id="io_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">I/O:</property>
+                <style>
+                  <class name="boxes-graph-label"/>
+                </style>
+              </object>
+
+              <packing>
+                <property name="left-attach">2</property>
+                <property name="top-attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="BoxesMiniGraph" id="io_graph">
+                <property name="visible">True</property>
+                <property name="ymax">20</property>
+              </object>
+
+              <packing>
+                <property name="left-attach">3</property>
+                <property name="top-attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="GtkLabel" id="net_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Net:</property>
+                <style>
+                  <class name="boxes-graph-label"/>
+                </style>
+              </object>
+
+              <packing>
+                <property name="left-attach">4</property>
+                <property name="top-attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="BoxesMiniGraph" id="net_graph">
+                <property name="visible">True</property>
+                <property name="ymax">20</property>
+              </object>
+
+              <packing>
+                <property name="left-attach">5</property>
+                <property name="top-attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="GtkButton" id="shutdown_button">
+                <property name="visible">True</property>
+                <property name="use-underline">True</property>
+                <property name="label" translatable="yes">Force Shutdown</property>
+                <signal name="clicked" handler="on_shutdown_button_clicked"/>
+              </object>
+
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">2</property>
+                <property name="width">6</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">0</property>
+          </packing>
+        </child>
       </object>
     </child>
   </template>
+
+  <object class="GtkListStore" id="props_listmodel">
+    <columns>
+      <column type="gchararray"/>
+      <column type="gboolean"/>
+    </columns>
+  </object>
+
+  <object class="GtkTreeModelFilter" id="props_model_filter">
+    <property name="child-model">props_listmodel</property>
+  </object>
 </interface>
diff --git a/src/machine.vala b/src/machine.vala
index 128f9b8..f5dd9e5 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -549,7 +549,7 @@ private class Boxes.MachineActor: GLib.Object, Boxes.UI {
 
     ~MachineActor() {
         if (track_screenshot_id != 0)
-            App.app.properties.screenshot_placeholder.disconnect (track_screenshot_id);
+            App.app.sidebar.screenshot_placeholder.disconnect (track_screenshot_id);
     }
 
     public MachineActor (Machine machine) {
@@ -656,7 +656,7 @@ private class Boxes.MachineActor: GLib.Object, Boxes.UI {
 
     public void update_thumbnail (Gtk.Widget? display_widget, bool zoom = true) {
         if (track_screenshot_id != 0)
-            App.app.properties.screenshot_placeholder.disconnect (track_screenshot_id);
+            App.app.sidebar.screenshot_placeholder.disconnect (track_screenshot_id);
         track_screenshot_id = 0;
 
         if (thumbnail != null) {
@@ -721,7 +721,7 @@ private class Boxes.MachineActor: GLib.Object, Boxes.UI {
             Boxes.ActorFunc update_screenshot_alloc = (thumbnail) => {
                 Gtk.Allocation alloc;
 
-                App.app.properties.screenshot_placeholder.get_allocation (out alloc);
+                App.app.sidebar.screenshot_placeholder.get_allocation (out alloc);
 
                 // We disable implicit animations while setting the
                 // properties because we don't want to animate these individually
@@ -739,7 +739,7 @@ private class Boxes.MachineActor: GLib.Object, Boxes.UI {
                 thumbnail.set_easing_duration (d);
             };
 
-            track_screenshot_id = App.app.properties.screenshot_placeholder.size_allocate.connect (() => {
+            track_screenshot_id = App.app.sidebar.screenshot_placeholder.size_allocate.connect (() => {
                 // We need to update in an idle to avoid changing layout stuff in a layout cycle
                 // (i.e. inside the size_allocate)
                 Idle.add_full (Priority.HIGH, () => {
@@ -786,7 +786,7 @@ private class Boxes.MachineActor: GLib.Object, Boxes.UI {
                 if (thumbnail != null) {
                     // zoom in, back from properties
 
-                    App.app.properties.screenshot_placeholder.disconnect (track_screenshot_id);
+                    App.app.sidebar.screenshot_placeholder.disconnect (track_screenshot_id);
                     track_screenshot_id = 0;
 
                     var transition = animate_actor_geometry (x, y, width, height);
diff --git a/src/properties.vala b/src/properties.vala
index 9f18481..50c4887 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -15,16 +15,8 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
-    public Gtk.Widget screenshot_placeholder;
     private GtkClutter.Actor gtk_actor;
-    private Gtk.Notebook notebook;
-    private Gtk.ListStore listmodel;
-    private Gtk.TreeModelFilter model_filter;
-    private Gtk.TreeView tree_view;
-    private Gtk.Button shutdown_button;
-    private MiniGraph cpu;
-    private MiniGraph io;
-    private MiniGraph net;
+    public Gtk.Notebook notebook;
     private ulong stats_id;
     private bool restore_fullscreen;
 
@@ -156,14 +148,14 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
     }
 
     private void populate () {
-        listmodel.clear ();
+        App.app.sidebar.props_listmodel.clear ();
         for (var i = 0; i < PropertiesPage.LAST; i++)
             notebook.remove_page (-1);
 
         var machine = App.app.current_item as Machine;
         var libvirt_machine = App.app.current_item as LibvirtMachine;
 
-        shutdown_button.sensitive = libvirt_machine != null && libvirt_machine.is_running ();
+        App.app.sidebar.shutdown_button.sensitive = libvirt_machine != null && libvirt_machine.is_running ();
 
         if (machine == null)
             return;
@@ -177,11 +169,11 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
                 var current_page = notebook.page;
                 this.populate ();
                 var path = new Gtk.TreePath.from_indices (current_page);
-                tree_view.get_selection ().select_path (path);
+                App.app.sidebar.props_selection.select_path (path);
                 notebook.page = current_page;
             });
 
-            list_append (listmodel, page.name, !page.empty);
+            list_append (App.app.sidebar.props_listmodel, page.name, !page.empty);
         }
 
         PropertiesPage current_page;
@@ -192,7 +184,7 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
             current_page = PropertiesPage.LOGIN;
 
         var path = new Gtk.TreePath.from_indices (current_page);
-        tree_view.get_selection ().select_path (path);
+        App.app.sidebar.props_selection.select_path (path);
         notebook.set_current_page (current_page);
     }
 
@@ -209,74 +201,6 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
         gtk_actor.x_expand = true;
         gtk_actor.y_expand = true;
 
-        /* sidebar */
-        var vbox = App.app.sidebar.get_nth_page (Boxes.SidebarPage.PROPERTIES) as Gtk.Box;
-
-        tree_view = new Gtk.TreeView ();
-        tree_view.get_style_context ().add_class ("boxes-bg");
-        var selection = tree_view.get_selection ();
-        selection.set_mode (Gtk.SelectionMode.BROWSE);
-        tree_view.activate_on_single_click = true;
-        tree_view.row_activated.connect ( (treeview, path, column) => {
-            Gtk.TreeIter filter_iter, iter;
-            model_filter.get_iter (out filter_iter, path);
-            model_filter.convert_iter_to_child_iter (out iter, filter_iter);
-            notebook.page = listmodel.get_path (iter).get_indices ()[0];
-        });
-
-        listmodel = new Gtk.ListStore (2, typeof (string), typeof (bool));
-        model_filter = new Gtk.TreeModelFilter (listmodel, null);
-        model_filter.set_visible_column (1);
-
-        tree_view.set_model (model_filter);
-        tree_view.headers_visible = false;
-        var renderer = new CellRendererText ();
-        renderer.xpad = 20;
-        renderer.weight = Pango.Weight.BOLD;
-        tree_view.insert_column_with_attributes (-1, "", renderer, "text", 0);
-        vbox.pack_start (tree_view, true, true, 0);
-
-        var grid = new Gtk.Grid ();
-        vbox.pack_start (grid, false, false, 0);
-        grid.column_homogeneous = false;
-        grid.column_spacing = 2;
-        grid.row_spacing = 10;
-        grid.margin_left = 10;
-        grid.margin_right = 10;
-        grid.margin_bottom = 30;
-        grid.margin_top = 10;
-
-        screenshot_placeholder = new Gtk.Alignment (0.0f, 0.0f, 0.0f, 0.0f);
-        screenshot_placeholder.set_size_request (180, 130);
-        grid.attach (screenshot_placeholder, 0, 0, 6, 1);
-
-        var label = new Gtk.Label (_("CPU:"));
-        label.get_style_context ().add_class ("boxes-graph-label");
-        grid.attach (label, 0, 1, 1, 1);
-        cpu = new MiniGraph.with_ymax (100.0, 20);
-        grid.attach (cpu, 1, 1, 1, 1);
-
-        label = new Gtk.Label (_("I/O:"));
-        label.get_style_context ().add_class ("boxes-graph-label");
-        grid.attach (label, 2, 1, 1, 1);
-        io = new MiniGraph (20);
-        grid.attach (io, 3, 1, 1, 1);
-
-        label = new Gtk.Label (_("Net:"));
-        label.get_style_context ().add_class ("boxes-graph-label");
-        grid.attach (label, 4, 1, 1, 1);
-        net = new MiniGraph (20);
-        grid.attach (net, 5, 1, 1, 1);
-
-        shutdown_button = new Button.with_label (_("Force Shutdown"));
-        shutdown_button.clicked.connect ( () => {
-            var machine = App.app.current_item as LibvirtMachine;
-            if (machine != null)
-                machine.force_shutdown ();
-        });
-        grid.attach (shutdown_button, 0, 2, 6, 1);
-
-        vbox.show_all ();
         notebook.show_all ();
     }
 
@@ -293,9 +217,9 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
             if (App.app.current_item is LibvirtMachine) {
                 var libvirt_machine = App.app.current_item as LibvirtMachine;
                 stats_id = libvirt_machine.stats_updated.connect (() => {
-                    cpu.points = libvirt_machine.cpu_stats;
-                    net.points = libvirt_machine.net_stats;
-                    io.points = libvirt_machine.io_stats;
+                    App.app.sidebar.cpu_graph.points = libvirt_machine.cpu_stats;
+                    App.app.sidebar.net_graph.points = libvirt_machine.net_stats;
+                    App.app.sidebar.io_graph.points = libvirt_machine.io_stats;
                 });
             }
 
diff --git a/src/sidebar.vala b/src/sidebar.vala
index 8305bda..3cde1ea 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -30,6 +30,23 @@ private class Boxes.Sidebar: Gtk.Notebook, Boxes.UI {
     [GtkChild]
     private Gtk.Label wizard_review_label;
 
+    [GtkChild]
+    public Gtk.Widget screenshot_placeholder;
+    [GtkChild]
+    public Gtk.ListStore props_listmodel;
+    [GtkChild]
+    private Gtk.TreeModelFilter props_model_filter;
+    [GtkChild]
+    public Gtk.TreeSelection props_selection;
+    [GtkChild]
+    public Gtk.Button shutdown_button;
+    [GtkChild]
+    public MiniGraph cpu_graph;
+    [GtkChild]
+    public MiniGraph io_graph;
+    [GtkChild]
+    public MiniGraph net_graph;
+
     public Sidebar () {
         notify["ui-state"].connect (ui_state_changed);
         setup_sidebar ();
@@ -75,10 +92,27 @@ private class Boxes.Sidebar: Gtk.Notebook, Boxes.UI {
     }
 
     private void setup_sidebar () {
+        props_model_filter.set_visible_column (1);
+
         gtk_actor = new GtkClutter.Actor.with_contents (this);
         gtk_actor.get_widget ().get_style_context ().add_class ("boxes-bg");
         gtk_actor.name = "sidebar";
         gtk_actor.x_expand = true;
         gtk_actor.y_expand = true;
     }
+
+    [GtkCallback]
+    private void on_props_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn 
column) {
+        Gtk.TreeIter filter_iter, iter;
+        props_model_filter.get_iter (out filter_iter, path);
+        props_model_filter.convert_iter_to_child_iter (out iter, filter_iter);
+        App.app.properties.notebook.page = props_listmodel.get_path (iter).get_indices ()[0];
+    }
+
+    [GtkCallback]
+    private void on_shutdown_button_clicked () {
+        var machine = App.app.current_item as LibvirtMachine;
+        if (machine != null)
+            machine.force_shutdown ();
+    }
 }


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