[baobab] Rework Location Widget



commit 90a6bab370064ca6e5954d1161e2f849784f3c19
Author: Paolo Borelli <paolo borelli nice-software com>
Date:   Sat Jul 21 22:43:49 2012 +0200

    Rework Location Widget
    
    Use GtkLevelBar and rework layout.

 src/baobab-location-widget.vala |   83 ++++++++++++++++++++------------------
 1 files changed, 44 insertions(+), 39 deletions(-)
---
diff --git a/src/baobab-location-widget.vala b/src/baobab-location-widget.vala
index 727cbdd..883b390 100644
--- a/src/baobab-location-widget.vala
+++ b/src/baobab-location-widget.vala
@@ -1,6 +1,7 @@
 /* -*- indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* Baobab - disk usage analyzer
  *
+ * Copyright (C) 2012  Paolo Borelli <pborelli gnome org>
  * Copyright (C) 2012  Stefano Facchini <stefano facchini gmail com>
  *
  * This program is free software; you can redistribute it and/or
@@ -22,27 +23,22 @@ namespace Baobab {
 
     public class LocationWidget : Gtk.Grid {
         private static Gtk.SizeGroup name_size_group = null;
-        private static Gtk.SizeGroup mount_point_size_group = null;
-        private static Gtk.SizeGroup size_size_group = null;
-        private static Gtk.SizeGroup used_size_group = null;
+        private static Gtk.SizeGroup usage_size_group = null;
         private static Gtk.SizeGroup button_size_group = null;
 
         public delegate void ActionOnClick (Location location);
 
         void ensure_size_groups () {
-            if (name_size_group != null)
-                return;
-
-            name_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-            mount_point_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-            size_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-            used_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-            button_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+            if (name_size_group == null) {
+                name_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+                usage_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+                button_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+            }
         }
 
         public LocationWidget (Location location, ActionOnClick action) {
             orientation = Gtk.Orientation.HORIZONTAL;
-            column_spacing = 10;
+            column_spacing = 12;
             margin = 6;
 
             ensure_size_groups ();
@@ -53,45 +49,54 @@ namespace Baobab {
             try {
                 var pixbuf = icon_info.load_icon ();
                 var image = new Gtk.Image.from_pixbuf (pixbuf);
-                add (image);
+                attach (image, 0, 0, 1, 2);
             } catch (Error e) {
                 warning ("Failed to load icon %s: %s", location.icon.to_string(), e.message);
             }
 
-            var label = new Gtk.Label (location.name);
-            label.xalign = 0;
+            var label = new Gtk.Label ("<b>%s</b>".printf (location.name));
             name_size_group.add_widget (label);
-            add (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);
 
-            label = new Gtk.Label (location.mount_point != null ? location.mount_point : "");
+            label = new Gtk.Label ("<small>%s</small>".printf (location.mount_point != null ? location.mount_point : ""));
+            name_size_group.add_widget (label);
+            label.use_markup = true;
             label.hexpand = true;
-            label.halign = Gtk.Align.CENTER;
+            label.halign = Gtk.Align.START;
+            label.valign = Gtk.Align.START;
             label.xalign = 0;
             label.get_style_context ().add_class ("dim-label");
-            mount_point_size_group.add_widget (label);
-            add (label);
-
-            label = new Gtk.Label (location.size != null ? format_size (location.size) : "");
-            size_size_group.add_widget (label);
-            add (label);
-
-            if (location.used != null) {
-                var progress = new Gtk.ProgressBar ();
-                progress.valign = Gtk.Align.CENTER;
-                progress.set_fraction ((double) location.used / location.size);
-                used_size_group.add_widget (progress);
-                add (progress);
-            } else {
-                label = new Gtk.Label (_("Usage unknown"));
-                used_size_group.add_widget (label);
-                add (label);
+            attach (label, 1, 1, 1, 1);
+
+            if (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);
+
+                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);
             }
 
-            string button_label = location.mount_point != null ? _("Scan") : _("Mount and scan");
-            var button = new Gtk.Button.with_label (button_label);
-            button.valign = Gtk.Align.CENTER;
+            var button = new Gtk.Button.with_label (location.mount_point != null ? _("Scan") : _("Mount and scan"));
             button_size_group.add_widget (button);
-            add (button);
+            button.valign = Gtk.Align.CENTER;
+            attach (button, 3, 0, 1, 2);
 
             button.clicked.connect(() => { action (location); });
 



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