[baobab] Rename LocationWidget to LocationRow



commit 666a8cfbd52346080268449faf946337969fa30c
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jun 8 14:47:14 2013 +0200

    Rename LocationWidget to LocationRow
    
    Also make it private to the location list.

 po/POTFILES.in                                     |    2 +-
 src/Makefile.am                                    |    3 +-
 src/baobab-location-list.vala                      |   61 ++++++++++++++-
 ...b-location-widget.ui => baobab-location-row.ui} |    2 +-
 src/baobab-location-widget.vala                    |   80 --------------------
 src/baobab.gresource.xml                           |    2 +-
 6 files changed, 63 insertions(+), 87 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3760140..6de06ab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,7 +6,7 @@ src/baobab-application.vala
 src/baobab-cellrenderers.vala
 src/baobab-chart.c
 src/baobab-location.vala
-src/baobab-location-widget.vala
+src/baobab-location-row.vala
 [type: gettext/glade]src/baobab-main-window.ui
 [type: gettext/glade]src/baobab-menu.ui
 src/baobab-window.vala
diff --git a/src/Makefile.am b/src/Makefile.am
index 142a2b9..b1ad1c4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,7 +27,6 @@ VALA_SOURCES = \
        baobab-connect-server.vala      \
        baobab-location.vala            \
        baobab-location-list.vala       \
-       baobab-location-widget.vala     \
        baobab-scanner.vala             \
        baobab-window.vala              \
        main.vala                       \
@@ -73,7 +72,7 @@ MAINTAINERCLEANFILES =        \
 
 EXTRA_DIST = \
        baobab.gresource.xml \
-       baobab-location-widget.ui \
+       baobab-location-row.ui \
        baobab-main-window.ui \
        baobab-menu.ui
 
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 6b02aed..7aa9033 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -20,6 +20,63 @@
 
 namespace Baobab {
 
+    [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-location-row.ui")]
+    private class LocationRow : Gtk.Grid {
+        private static Gtk.SizeGroup name_size_group = null;
+        private static Gtk.SizeGroup usage_size_group = null;
+
+        [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; }
+
+        void ensure_size_groups () {
+            if (name_size_group == null) {
+                name_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+                usage_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+            }
+        }
+
+        public LocationRow (Location l) {
+            location = l;
+
+            ensure_size_groups ();
+
+            image.gicon = location.icon;
+            image.set_pixel_size (64);
+
+            var escaped = GLib.Markup.escape_text (location.name, -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) 
: "";
+            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) {
+                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);
+
+                // Set critical color at 90% of the size
+                usage_bar.add_offset_value (Gtk.LEVEL_BAR_OFFSET_LOW, 0.9 * location.size);
+                usage_bar.set_value (location.used);
+                usage_bar.show ();
+            }
+        }
+    }
+
     public class LocationList : Egg.ListBox {
         private const int MAX_RECENT_LOCATIONS = 5;
 
@@ -55,7 +112,7 @@ namespace Baobab {
 
         public override void child_activated (Gtk.Widget? widget) {
             if (location_action != null) {
-                var location_widget = widget as LocationWidget;
+                var location_widget = widget as LocationRow;
                 location_action (location_widget.location);
             }
         }
@@ -195,7 +252,7 @@ namespace Baobab {
             this.foreach ((widget) => { widget.destroy (); });
 
             foreach (var location in locations) {
-                add (new LocationWidget (location));
+                add (new LocationRow (location));
             }
 
             show_all ();
diff --git a/src/baobab-location-widget.ui b/src/baobab-location-row.ui
similarity index 98%
rename from src/baobab-location-widget.ui
rename to src/baobab-location-row.ui
index 5848369..4f50e2a 100644
--- a/src/baobab-location-widget.ui
+++ b/src/baobab-location-row.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="BaobabLocationWidget" parent="Gtk.Grid">
+  <template class="BaobabLocationRow" parent="Gtk.Grid">
     <property name="visible">True</property>
     <property name="orientation">horizontal</property>
     <property name="column_spacing">12</property>
diff --git a/src/baobab.gresource.xml b/src/baobab.gresource.xml
index 82b80c1..f2fcb23 100644
--- a/src/baobab.gresource.xml
+++ b/src/baobab.gresource.xml
@@ -1,7 +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-location-row.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]