[baobab] Use a glade template for the location widget



commit 49c06fd94c14430af5e9f61a5c858c119af9b640
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Jun 3 21:51:29 2013 +0200

    Use a glade template for the location widget

 src/Makefile.am                 |    1 +
 src/baobab-location-widget.ui   |   92 +++++++++++++++++++++++++++++++++++++++
 src/baobab-location-widget.vala |   74 ++++++++++++-------------------
 src/baobab-window.vala          |   50 +++++++++++-----------
 src/baobab.gresource.xml        |    1 +
 5 files changed, 147 insertions(+), 71 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 53041e0..74ab8c4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,6 +72,7 @@ MAINTAINERCLEANFILES =        \
 
 EXTRA_DIST = \
        baobab.gresource.xml \
+       baobab-location-widget.ui \
        baobab-main-window.ui \
        baobab-menu.ui
 
diff --git a/src/baobab-location-widget.ui b/src/baobab-location-widget.ui
new file mode 100644
index 0000000..5848369
--- /dev/null
+++ b/src/baobab-location-widget.ui
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="BaobabLocationWidget" parent="Gtk.Grid">
+    <property name="visible">True</property>
+    <property name="orientation">horizontal</property>
+    <property name="column_spacing">12</property>
+    <property name="margin">6</property>
+    <child>
+      <object class="GtkImage" id="image">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="pixel_size">64</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="name_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">start</property>
+        <property name="valign">end</property>
+        <property name="hexpand">True</property>
+        <property name="use_markup">True</property>
+        <property name="xalign">0</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="path_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">start</property>
+        <property name="valign">start</property>
+        <property name="hexpand">True</property>
+        <property name="use_markup">True</property>
+        <property name="xalign">0</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </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="usage_label">
+        <property name="visible">False</property>
+        <property name="can_focus">False</property>
+        <property name="no_show_all">True</property>
+        <property name="halign">end</property>
+        <property name="valign">end</property>
+        <property name="use_markup">True</property>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLevelBar" id="usage_bar">
+        <property name="visible">False</property>
+        <property name="can_focus">False</property>
+        <property name="no_show_all">True</property>
+        <property name="halign">fill</property>
+        <property name="valign">start</property>
+        <property name="hexpand">True</property>
+      </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>
+  </template>
+</interface>
diff --git a/src/baobab-location-widget.vala b/src/baobab-location-widget.vala
index b1d7021..2ff0116 100644
--- a/src/baobab-location-widget.vala
+++ b/src/baobab-location-widget.vala
@@ -21,10 +21,21 @@
 
 namespace Baobab {
 
+    [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-location-widget.ui")]
     public class LocationWidget : Gtk.Grid {
         private static Gtk.SizeGroup name_size_group = null;
         private static Gtk.SizeGroup usage_size_group = null;
-        private static Gtk.IconSize icon_size;
+
+        [GtkChild]
+        private Gtk.Image image;
+        [GtkChild]
+        private Gtk.Label name_label;
+        [GtkChild]
+        private Gtk.Label path_label;
+        [GtkChild]
+        private Gtk.Label usage_label;
+        [GtkChild]
+        private Gtk.LevelBar usage_bar;
 
         public Location? location { get; private set; }
 
@@ -32,67 +43,38 @@ namespace Baobab {
             if (name_size_group == null) {
                 name_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
                 usage_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-                icon_size = Gtk.icon_size_register ("baobab", 64, 64);
             }
         }
 
-        public LocationWidget (Location location_) {
-            location = location_;
-
-            orientation = Gtk.Orientation.HORIZONTAL;
-            column_spacing = 12;
-            margin = 6;
+        public LocationWidget (Location l) {
+            location = l;
 
             ensure_size_groups ();
 
-            var image = new Gtk.Image.from_gicon (location.icon, icon_size);
+            image.gicon = location.icon;
             image.set_pixel_size (64);
-            attach (image, 0, 0, 1, 2);
 
             var escaped = GLib.Markup.escape_text (location.name, -1);
-            var label = new Gtk.Label ("<b>%s</b>".printf (escaped));
-            name_size_group.add_widget (label);
-            label.use_markup = true;
-            label.hexpand = true;
-            label.halign = Gtk.Align.START;
-            label.valign = Gtk.Align.END;
-            label.xalign = 0;
-            attach (label, 1, 0, 1, 1);
+            name_label.label = "<b>%s</b>".printf (escaped);
+            name_size_group.add_widget (name_label);
 
             escaped = location.file != null ? GLib.Markup.escape_text (location.file.get_parse_name (), -1) 
: "";
-            label = new Gtk.Label ("<small>%s</small>".printf (escaped));
-            name_size_group.add_widget (label);
-            label.use_markup = true;
-            label.hexpand = true;
-            label.halign = Gtk.Align.START;
-            label.valign = Gtk.Align.START;
-            label.xalign = 0;
-            label.get_style_context ().add_class ("dim-label");
-            attach (label, 1, 1, 1, 1);
+            path_label.label = "<small>%s</small>".printf (escaped);
+            name_size_group.add_widget (path_label);
 
             if (location.is_volume && location.used != null && location.size != null) {
-                label = new Gtk.Label ("<small>%s / %s</small>".printf (format_size (location.used), 
format_size (location.size)));
-                usage_size_group.add_widget (label);
-                label.use_markup = true;
-                label.halign = Gtk.Align.END;
-                label.valign = Gtk.Align.END;
-                attach (label, 2, 0, 1, 1);
+                usage_label.label = "<small>%s / %s</small>".printf (format_size (location.used), 
format_size (location.size));
+                usage_size_group.add_widget (usage_label);
+                usage_label.show ();
+
+                usage_size_group.add_widget (usage_bar);
+                usage_bar.set_max_value (location.size);
 
-                var usagebar = new Gtk.LevelBar ();
-                usage_size_group.add_widget (usagebar);
-                usagebar.set_max_value (location.size);
                 // Set critical color at 90% of the size
-                usagebar.add_offset_value (Gtk.LEVEL_BAR_OFFSET_LOW, 0.9 * location.size);
-                usagebar.set_value (location.used);
-                usagebar.hexpand = true;
-                usagebar.halign = Gtk.Align.FILL;
-                usagebar.valign = Gtk.Align.START;
-                attach (usagebar, 2, 1, 1, 1);
+                usage_bar.add_offset_value (Gtk.LEVEL_BAR_OFFSET_LOW, 0.9 * location.size);
+                usage_bar.set_value (location.used);
+                usage_bar.show ();
             }
-
-            attach (new Gtk.Arrow (Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE), 3, 0, 1, 2);
-
-            show_all ();
         }
     }
 }
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 56c5d8d..8721777 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -24,53 +24,53 @@ namespace Baobab {
 
     [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-main-window.ui")]
     public class Window : Gtk.ApplicationWindow {
-        Settings ui_settings;
+        private Settings ui_settings;
         [GtkChild]
-        Gtk.HeaderBar header_bar;
+        private Gtk.HeaderBar header_bar;
         [GtkChild]
-        Gtk.Button back_button;
+        private Gtk.Button back_button;
         [GtkChild]
-        Gtk.Button reload_button;
+        private Gtk.Button reload_button;
         [GtkChild]
-        Gtk.MenuButton menu_button;
+        private Gtk.MenuButton menu_button;
         [GtkChild]
-        Gtk.Stack main_stack;
+        private Gtk.Stack main_stack;
         [GtkChild]
-        Gtk.Widget home_page;
+        private Gtk.Widget home_page;
         [GtkChild]
-        Gtk.Widget result_page;
+        private Gtk.Widget result_page;
         [GtkChild]
-        Gtk.InfoBar infobar;
+        private Gtk.InfoBar infobar;
         [GtkChild]
-        Gtk.Label infobar_primary_label;
+        private Gtk.Label infobar_primary_label;
         [GtkChild]
-        Gtk.Label infobar_secondary_label;
+        private Gtk.Label infobar_secondary_label;
         [GtkChild]
-        Gtk.Button infobar_close_button;
+        private Gtk.Button infobar_close_button;
         [GtkChild]
-        Gtk.ScrolledWindow location_scrolled_window;
+        private Gtk.ScrolledWindow location_scrolled_window;
         [GtkChild]
-        LocationList location_list;
+        private LocationList location_list;
         [GtkChild]
-        Gtk.TreeView treeview;
+        private Gtk.TreeView treeview;
         [GtkChild]
-        Gtk.Menu treeview_popup_menu;
+        private Gtk.Menu treeview_popup_menu;
         [GtkChild]
-        Gtk.MenuItem treeview_popup_open;
+        private Gtk.MenuItem treeview_popup_open;
         [GtkChild]
-        Gtk.MenuItem treeview_popup_copy;
+        private Gtk.MenuItem treeview_popup_copy;
         [GtkChild]
-        Gtk.MenuItem treeview_popup_trash;
+        private Gtk.MenuItem treeview_popup_trash;
         [GtkChild]
-        Gtk.Stack chart_stack;
+        private Gtk.Stack chart_stack;
         [GtkChild]
-        Chart rings_chart;
+        private Chart rings_chart;
         [GtkChild]
-        Chart treemap_chart;
+        private Chart treemap_chart;
         [GtkChild]
-        Gtk.Spinner spinner;
-        Location? active_location;
-        ulong scan_completed_handler;
+        private Gtk.Spinner spinner;
+        private Location? active_location;
+        private ulong scan_completed_handler;
 
         static Gdk.Cursor busy_cursor;
 
diff --git a/src/baobab.gresource.xml b/src/baobab.gresource.xml
index d0789b8..82b80c1 100644
--- a/src/baobab.gresource.xml
+++ b/src/baobab.gresource.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/baobab/ui">
+    <file preprocess="xml-stripblanks">baobab-location-widget.ui</file>
     <file preprocess="xml-stripblanks">baobab-main-window.ui</file>
     <file preprocess="xml-stripblanks">baobab-menu.ui</file>
   </gresource>


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