[gnome-boxes] libvirt-machine-props: Show allocation of storage volume



commit 1e99268223a096ded826beee5142a4a9f782fcca
Author: Fabiano Fidêncio <fidencio redhat com>
Date:   Mon Feb 16 17:31:17 2015 +0100

    libvirt-machine-props: Show allocation of storage volume
    
    Its not very clear to users what 'Maximum disk' means so lets also
    show allocation to help with that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744603

 src/i-properties-provider.vala      |   24 +++++++++++++++++++++---
 src/libvirt-machine-properties.vala |   15 +++++++++++----
 2 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/src/i-properties-provider.vala b/src/i-properties-provider.vala
index b45bb0b..a88f597 100644
--- a/src/i-properties-provider.vala
+++ b/src/i-properties-provider.vala
@@ -74,6 +74,21 @@ private class Boxes.SizeProperty : Boxes.Property {
     private Gtk.Scale scale;
     private FormatSizeFlags format_flags;
 
+    private static void set_size_label_msg (Gtk.Label       label,
+                                            uint64          size,
+                                            uint64          allocation,
+                                            FormatSizeFlags format_flags) {
+        var capacity = format_size (size, format_flags);
+
+        if (allocation == 0) {
+            label.set_text (capacity);
+        } else {
+            var allocation_str = format_size (allocation, format_flags);
+
+            label.set_markup (_("%s <span color=\"grey\">(%s used)</span>").printf (capacity, 
allocation_str));
+        }
+    }
+
     public uint64 recommended  {
         set {
             // FIXME: Better way to ensure recommended mark is not too close to min and max marks?
@@ -90,9 +105,11 @@ private class Boxes.SizeProperty : Boxes.Property {
                          uint64          size,
                          uint64          min,
                          uint64          max,
+                         uint64          allocation,
                          uint64          step,
                          FormatSizeFlags format_flags) {
-        var label = new Gtk.Label (format_size ((uint64) size, format_flags));
+        var label = new Gtk.Label ("");
+        set_size_label_msg (label, size, allocation, format_flags);
         label.halign = Gtk.Align.CENTER;
 
         var scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, min, max, step);
@@ -116,7 +133,7 @@ private class Boxes.SizeProperty : Boxes.Property {
 
         scale.value_changed.connect (() => {
             uint64 v = (uint64) scale.get_value ();
-            label.set_text (format_size (v, format_flags));
+            set_size_label_msg (label, v, allocation, format_flags);
             scale.set_fill_level (v);
 
             changed ((uint64) scale.get_value ());
@@ -187,9 +204,10 @@ private interface Boxes.IPropertiesProvider: GLib.Object {
                                                     uint64                   size,
                                                     uint64                   min,
                                                     uint64                   max,
+                                                    uint64                   allocation,
                                                     uint64                   step,
                                                     FormatSizeFlags          format_flags = 
FormatSizeFlags.DEFAULT) {
-        var property = new SizeProperty (name, size, min, max, step, format_flags);
+        var property = new SizeProperty (name, size, min, max, allocation, step, format_flags);
         list.append (property);
 
         return property;
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 059d915..98fe625 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -447,6 +447,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
                                               machine.domain_config.memory * Osinfo.KIBIBYTES,
                                               64 * Osinfo.MEBIBYTES,
                                               max_ram * Osinfo.KIBIBYTES,
+                                              0,
                                               64 * Osinfo.MEBIBYTES,
                                               FormatSizeFlags.IEC_UNITS);
             property.description_alignment = Gtk.Align.START;
@@ -507,9 +508,14 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             var max_storage = volume_info.allocation + pool_info.available;
 
             if (min_storage >= max_storage) {
-                add_string_property (ref list,
-                                     _("Maximum Disk Size"),
-                                     "%s".printf (format_size (volume_info.capacity, 
FormatSizeFlags.DEFAULT)));
+                var label = new Gtk.Label ("");
+                var capacity = format_size (volume_info.capacity, FormatSizeFlags.DEFAULT);
+                var allocation = format_size (volume_info.allocation, FormatSizeFlags.DEFAULT);
+                var markup = _("<span color=\"grey\">Maximum Disk Size</span>\t\t %s <span 
color=\"grey\">(%s used)</span>").printf (capacity, allocation);
+                label.set_markup (markup);
+                label.halign = Gtk.Align.START;
+
+                add_property (ref list, null, label);
 
                 var infobar = new Gtk.InfoBar ();
                 infobar.message_type = Gtk.MessageType.WARNING;
@@ -522,7 +528,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
                 content.add (image);
 
                 var msg = _("There is not enough space on your machine to increase the maximum disk size.");
-                var label = new Gtk.Label (msg);
+                label = new Gtk.Label (msg);
                 content.add (label);
 
                 add_property (ref list, null, infobar);
@@ -534,6 +540,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
                                               volume_info.capacity,
                                               min_storage,
                                               max_storage,
+                                              volume_info.allocation,
                                               256 * MEGABYTES);
             property.description_alignment = Gtk.Align.START;
             // Disable 'save on timeout' all together since that could lead us to very bad user experience:


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