[gnome-boxes] Save default libvirt connection machines on quit



commit 25b57ee6adffb3804c6b817f7d563fe4528be6d4
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Dec 23 22:01:51 2011 +0200

    Save default libvirt connection machines on quit
    
    On quit, save and suspend machines belonging to default libvirt
    connection. This setting can be overridden by setting boolean prop
    'save-on-quit' to false in the source file. If disabled, the machines in
    question are only suspended but not saved.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=666366

 data/QEMU_Session          |    1 +
 src/app.vala               |    8 ++++++++
 src/collection-source.vala |   12 ++++++++++++
 src/libvirt-machine.vala   |    9 +++++++++
 4 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/data/QEMU_Session b/data/QEMU_Session
index c3709d1..52fcfd0 100644
--- a/data/QEMU_Session
+++ b/data/QEMU_Session
@@ -2,3 +2,4 @@
 name=QEMU Session
 type=libvirt
 uri=qemu+unix:///session
+save-on-quit=true
diff --git a/src/app.vala b/src/app.vala
index f624e00..c3f9fc1 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -407,6 +407,14 @@ private class Boxes.App: Boxes.UI {
         save_window_geometry ();
         window.destroy ();
 
+        foreach (var item in collection.items.data)
+            if (item is LibvirtMachine) {
+                var machine = item as LibvirtMachine;
+
+                if (machine.connection == default_connection)
+                    machine.suspend.begin ();
+            }
+
         return false;
     }
 
diff --git a/src/collection-source.vala b/src/collection-source.vala
index f5e9832..d45f838 100644
--- a/src/collection-source.vala
+++ b/src/collection-source.vala
@@ -11,6 +11,18 @@ private interface Boxes.IConfig {
         has_file = true;
     }
 
+    public bool get_boolean (string group, string key, bool default_value = false) {
+        try {
+            return keyfile.get_boolean (group, key);
+        } catch (GLib.KeyFileError error) {
+            return default_value;
+        }
+    }
+
+    public void set_boolean (string group, string key, bool value) {
+        keyfile.set_boolean (group, key, value);
+    }
+
     protected void load () throws GLib.Error {
         if (!has_file)
             throw new Boxes.Error.INVALID ("has_file is false");
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 06713a8..c7badc4 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -15,6 +15,11 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         }
     }
 
+    public bool save_on_quit {
+        get { return source.get_boolean ("source", "save-on-quit"); }
+        set { source.set_boolean ("source", "save-on-quit", value); }
+    }
+
     public override void disconnect_display () {
         if (_connect_display == false)
             return;
@@ -331,4 +336,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
 
         set_stats_enable (false);
     }
+
+    public async void suspend () throws GLib.Error {
+        (save_on_quit) ? yield domain.save_async (0, null) : domain.suspend ();
+    }
 }



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