[gnome-boxes/wip/image-import: 26/27] selectionbar: Don't let user delete under-construction VMs



commit 3af153e332920ac2c4740284ff1284494cda87c5
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Jun 7 02:59:11 2013 +0300

    selectionbar: Don't let user delete under-construction VMs
    
    While the ideal solution is probably to make it possible for user to
    delete under construciton VMs too, it would be pretty difficult to
    implement with us launching external processes as part of such
    construction. Keeping in mind also that this only affects imported (from
    installed media) VMs and importing usually takes much less time than
    installations, I think this is not bad at least as a temporary work
    around.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690757

 src/libvirt-machine.vala |   12 +++++++++++-
 src/machine.vala         |    1 +
 src/selectionbar.vala    |   25 +++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 23e6fa3..54d0173 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -7,7 +7,17 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     public GVirConfig.Domain domain_config { get; set; }
     public GVir.Connection connection { get; set; }
     public GVir.StorageVol? storage_volume { get; set; }
-    public VMCreator? vm_creator { get; set; } // Under installation if this is set to non-null
+    private VMCreator? _vm_creator;
+    public VMCreator? vm_creator { // Under installation if this is set to non-null
+        get {
+            return _vm_creator;
+        }
+
+        set {
+            _vm_creator = value;
+            can_delete = !importing;
+        }
+    }
     // If this machine is currently being imported
     public bool importing { get { return vm_creator != null && vm_creator is VMImporter; } }
 
diff --git a/src/machine.vala b/src/machine.vala
index e1885b9..f1aa497 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -15,6 +15,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     public bool suspend_at_exit;
 
     public bool can_save { get; protected set; default = false; }
+    public bool can_delete { get; protected set; default = true; }
 
     public signal void got_error (string message);
 
diff --git a/src/selectionbar.vala b/src/selectionbar.vala
index 0fc24cc..0ce1ab0 100644
--- a/src/selectionbar.vala
+++ b/src/selectionbar.vala
@@ -102,6 +102,7 @@ private class Boxes.Selectionbar: GLib.Object {
             update_favorite_btn ();
             update_properties_btn ();
             update_pause_btn ();
+            update_delete_btn ();
         });
     }
 
@@ -157,6 +158,30 @@ private class Boxes.Selectionbar: GLib.Object {
         pause_btn.sensitive = sensitive;
     }
 
+    private void update_delete_btn () {
+        foreach (var item in App.app.collection.items.data) {
+            var can_delete_id = item.get_data<ulong> ("can_delete_id");
+            if (can_delete_id > 0) {
+                    item.disconnect (can_delete_id);
+                    item.set_data<ulong> ("can_delete_id", 0);
+            }
+        }
+
+        var sensitive = true;
+        foreach (var item in App.app.selected_items) {
+            ulong can_delete_id = 0;
+            can_delete_id = item.notify["can-delete"].connect (() => {
+                update_delete_btn ();
+            });
+            item.set_data<ulong> ("can_delete_id", can_delete_id);
+
+            if (item is Machine && !(item as Machine).can_delete)
+                sensitive = false;
+        }
+
+        remove_btn.sensitive = sensitive;
+    }
+
     private bool visible {
         set {
             fade_actor (actor, value ? 255 : 0);


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