[gnome-boxes] Actually delete machine or source on removal



commit cdd9b32eedbd0cd4690c6e4064c84d2073631bc2
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Mon Nov 7 01:34:47 2011 +0100

    Actually delete machine or source on removal

 src/app.vala               |    6 +++++-
 src/collection-source.vala |   11 +++++++++--
 src/libvirt-machine.vala   |    9 +++++++++
 src/machine.vala           |    2 ++
 src/remote-machine.vala    |    4 ++++
 5 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index dd79942..c03260c 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -326,7 +326,11 @@ private class Boxes.App: Boxes.UI {
     }
 
     public void remove_item (CollectionItem item) {
-        debug ("FIXME: this is not yet fully implemented");
+        var machine = item as Machine;
+
+        if (machine != null)
+            machine.delete ();
+
         view.remove_item (item);
     }
 
diff --git a/src/collection-source.vala b/src/collection-source.vala
index fb2f0f2..f5e9832 100644
--- a/src/collection-source.vala
+++ b/src/collection-source.vala
@@ -56,8 +56,7 @@ private class Boxes.CollectionSource: GLib.Object, Boxes.IConfig {
         owned get { return get_string ("source", "name"); }
         set {
             keyfile.set_string ("source", "name", value);
-            if (has_file)
-                FileUtils.unlink (get_pkgconfig_source (filename));
+            this.delete ();
             _filename = null;
             save ();
         }
@@ -86,4 +85,12 @@ private class Boxes.CollectionSource: GLib.Object, Boxes.IConfig {
         has_file = true;
         load ();
     }
+
+    public void delete () {
+        if (!has_file)
+            return;
+
+        FileUtils.unlink (get_pkgconfig_source (filename));
+        has_file = false;
+    }
 }
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index dc0c13c..0df5f28 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -156,4 +156,13 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
 
         return true;
     }
+
+    public override void delete () {
+        try {
+            domain.stop (0);
+            domain.delete (0);
+        } catch (GLib.Error err) {
+            warning (err.message);
+        }
+    }
 }
diff --git a/src/machine.vala b/src/machine.vala
index 5cf3ac9..7c851fb 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -222,6 +222,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IProperties {
         return Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
     }
 
+    public abstract void delete ();
+
     public override void ui_state_changed () {
         machine_actor.ui_state = ui_state;
     }
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index 213aa17..6bc88b3 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -81,4 +81,8 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IProperties {
         // assume the remote is running for now
         return true;
     }
+
+    public override void delete () {
+        source.delete ();
+    }
 }



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