[gnome-boxes/improve-storage-management-ux: 7/7] preferences, storage-row: Present external storage disks properly




commit 4672196139492d031a4964fb5337f5e8ed8c64ce
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Dec 13 16:03:58 2021 +0100

    preferences, storage-row: Present external storage disks properly
    
    Instead of showing 0 bytes and making the spin_button useless for
    extenal disks, let's show the backing file and its estimated size.

 src/preferences/storage-row.vala | 54 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)
---
diff --git a/src/preferences/storage-row.vala b/src/preferences/storage-row.vala
index a0ec9a45..5e9a0b14 100644
--- a/src/preferences/storage-row.vala
+++ b/src/preferences/storage-row.vala
@@ -3,15 +3,39 @@
 private class Boxes.StorageRow : Boxes.MemoryRow {
     private LibvirtMachine machine;
 
+    private GVir.DomainDisk? external_disk;
+
     public void setup (LibvirtMachine machine) {
         this.machine = machine;
 
-        if (machine.importing || machine.storage_volume == null) {
-            sensitive = false;
+        bool storage_is_internal = (machine.storage_volume != null);
+        if (!storage_is_internal) {
+            try {
+                external_disk = machine.get_domain_disk ();
+            } catch (GLib.Error error) {
+                warning ("Failed to obtain domain disk: %s", error.message);
+                visible = false;
+
+                return;
+            }
+
+        }
+
+        bool has_disk = storage_is_internal || (external_disk != null);
+        if (machine.importing || !has_disk) {
+            visible = false;
 
             return;
         }
 
+        if (storage_is_internal) {
+            setup_internal_storage ();
+        } else {
+            setup_external_storage ();
+        }
+    }
+
+    private void setup_internal_storage () {
         try {
             var volume_info = machine.storage_volume.get_info ();
             var pool = get_storage_pool (machine.connection);
@@ -37,7 +61,31 @@ public void setup (LibvirtMachine machine) {
         spin_button.value_changed.connect (on_spin_button_changed);
     }
 
-    [GtkCallback]
+    private void setup_external_storage () {
+        var disk_config = external_disk.config as GVirConfig.DomainDisk;
+        var disk = File.new_for_path (disk_config.get_source ());
+
+        title = _("Storage disk");
+        subtitle = disk.get_path ();
+
+        disk.query_info_async.begin (FileAttribute.STANDARD_SIZE,
+                               FileQueryInfoFlags.NONE,
+                               Priority.LOW,
+                               null, (obj, res) => {
+            try {
+                FileInfo info = disk.query_info_async.end (res);
+                used_label.label = _("Used %s").printf (GLib.format_size (info.get_size ()));
+            } catch (GLib.Error error) {
+                warning ("Failed to calculate disk size for '%s': %s", disk.get_path (),
+                                                                       error.message);
+
+                used_label.visible = false;
+            }
+        });
+
+        stack.set_visible_child (used_label);
+    }
+
     private async void on_spin_button_changed () {
         uint64 storage = (uint64)spin_button.get_value ();
 


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