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



commit e128622b7d285a9aeade90cb4e244d55c6edb6f2
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    |   18 ++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 23e6fa3..cbf781a 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 = (value == null);
+        }
+    }
     // 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 fcdab2f..8db545e 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..bafc099 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,23 @@ private class Boxes.Selectionbar: GLib.Object {
         pause_btn.sensitive = sensitive;
     }
 
+    private void update_delete_btn () {
+        var sensitive = true;
+        foreach (var item in App.app.selected_items) {
+            if (item is Machine && !(item as Machine).can_delete) {
+                sensitive = false;
+
+                ulong can_delete_id = 0;
+                can_delete_id = item.notify["can-delete"].connect (() => {
+                    item.disconnect (can_delete_id);
+                    update_delete_btn ();
+                });
+            }
+        }
+
+        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]