[gnome-boxes] Allow ignoring saved state if restore fails



commit 22b81611293850d004a0ef4089d19a7bf06e28b7
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Feb 22 15:06:56 2013 +0100

    Allow ignoring saved state if restore fails
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687626

 src/app.vala                        |   17 ++++++++++++++---
 src/libvirt-machine-properties.vala |    2 +-
 src/libvirt-machine.vala            |   28 ++++++++++++++++++++++------
 src/machine.vala                    |   10 ++++++++--
 src/ovirt-machine.vala              |    2 +-
 src/remote-machine.vala             |    2 +-
 src/util.vala                       |    1 +
 7 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 0fed3af..a880459 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -860,7 +860,7 @@ private class Boxes.App: Boxes.UI {
         return false;
     }
 
-    public void connect_to (Machine machine, float x, float y) {
+    public void connect_to (Machine machine, float x, float y, Machine.ConnectFlags flags = 
Machine.ConnectFlags.NONE) {
         current_item = machine;
 
         // Set up actor for CREDS animation
@@ -888,13 +888,24 @@ private class Boxes.App: Boxes.UI {
         ui_state = UIState.CREDS;
 
         // Connect to the display
-        machine.connect_display.begin ( (obj, res) => {
+        machine.connect_display.begin (flags, (obj, res) => {
             try {
                 machine.connect_display.end (res);
             } catch (GLib.Error e) {
                 ui_state = UIState.COLLECTION;
-                App.app.notificationbar.display_error (_("Connection to '%s' failed").printf (machine.name));
                 debug ("connect display failed: %s", e.message);
+                var bar = App.app.notificationbar;
+
+                if (e is Boxes.Error.RESTORE_FAILED &&
+                    !(Machine.ConnectFlags.IGNORE_SAVED_STATE in flags)) {
+                    var message =
+                        _("'%s' could not be restored from disk\nTry without saved state?").printf 
(machine.name);
+                    bar.display_for_action (message, _("Restart"), () => {
+                        connect_to (machine, x, y,
+                                    flags | Machine.ConnectFlags.IGNORE_SAVED_STATE);
+                    });
+                } else
+                    bar.display_error (_("Connection to '%s' failed").printf (machine.name));
             }
             });
 
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 1d18204..677fcf0 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -442,7 +442,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
                 if (machine.state == Machine.MachineState.STOPPED ||
                     machine.state == Machine.MachineState.FORCE_STOPPED) {
                     debug ("'%s' stopped.", machine.name);
-                    machine.start.begin ((obj, res) => {
+                    machine.start.begin (Machine.ConnectFlags.NONE, (obj, res) => {
                         try {
                             machine.start.end (res);
                         } catch (GLib.Error error) {
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 8846421..1a5b4f7 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -22,8 +22,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         base.disconnect_display ();
     }
 
-    public override async void connect_display () throws GLib.Error {
-        yield start ();
+    public override async void connect_display (Machine.ConnectFlags flags) throws GLib.Error {
+        yield start (flags);
 
         if (update_display ()) {
             display.connect_it ();
@@ -78,7 +78,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             return;
 
         disconnect_display ();
-        connect_display.begin ();
+        connect_display.begin (Machine.ConnectFlags.NONE);
     }
 
     public LibvirtMachine (CollectionSource source,
@@ -488,7 +488,14 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         return net;
     }
 
-    public async void start () throws GLib.Error {
+    private GVir.DomainStartFlags connect_flags_to_gvir (Machine.ConnectFlags flags) {
+        GVir.DomainStartFlags gvir_flags = 0;
+        if (Machine.ConnectFlags.IGNORE_SAVED_STATE in flags)
+            gvir_flags |= GVir.DomainStartFlags.FORCE_BOOT;
+        return gvir_flags;
+    }
+
+    public async void start (Machine.ConnectFlags flags) throws GLib.Error {
         if (state == MachineState.RUNNING)
             return;
 
@@ -497,13 +504,22 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         else if (state == MachineState.SLEEPING) {
             yield domain.wakeup_async (0, null);
         } else {
-            if (domain.get_saved ())
+            var restore = domain.get_saved () &&
+                !(Machine.ConnectFlags.IGNORE_SAVED_STATE in flags);
+            if (restore)
                 // Translators: The %s will be expanded with the name of the vm
                 status = _("Restoring %s from disk").printf (name);
             else
                 // Translators: The %s will be expanded with the name of the vm
                 status = _("Starting %s").printf (name);
-            yield domain.start_async (0, null);
+            try {
+                yield domain.start_async (connect_flags_to_gvir (flags), null);
+            } catch (GLib.Error error) {
+                if (restore)
+                    throw new Boxes.Error.RESTORE_FAILED ("Restore failed");
+                else
+                    throw error;
+            }
         }
     }
 }
diff --git a/src/machine.vala b/src/machine.vala
index 454237e..195d032 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -42,6 +42,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         SLEEPING
     }
 
+    [Flags]
+    public enum ConnectFlags {
+        NONE = 0,
+        IGNORE_SAVED_STATE
+    }
+
     // The current screenshot without running status applied
     private Gdk.Pixbuf? orig_pixbuf;
 
@@ -251,7 +257,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
 
     public abstract List<Boxes.Property> get_properties (Boxes.PropertiesPage page, PropertyCreationFlag 
flags);
 
-    public abstract async void connect_display () throws GLib.Error;
+    public abstract async void connect_display (ConnectFlags flags) throws GLib.Error;
 
     public virtual void disconnect_display () {
         if (display == null)
@@ -561,7 +567,7 @@ private class Boxes.MachineActor: Boxes.UI {
             if (event.keyval == Gdk.Key.KP_Enter ||
                 event.keyval == Gdk.Key.ISO_Enter ||
                 event.keyval == Gdk.Key.Return) {
-                machine.connect_display.begin ();
+                machine.connect_display.begin (Machine.ConnectFlags.NONE);
 
                 return true;
             }
diff --git a/src/ovirt-machine.vala b/src/ovirt-machine.vala
index d96e0ae..2b95ca7 100644
--- a/src/ovirt-machine.vala
+++ b/src/ovirt-machine.vala
@@ -22,7 +22,7 @@ private class Boxes.OvirtMachine: Boxes.Machine {
         set_screenshot_enable (true);
     }
 
-    public override async void connect_display () throws GLib.Error {
+    public override async void connect_display (Machine.ConnectFlags flags) throws GLib.Error {
         if (display != null)
             return;
 
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index 822d257..06018eb 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -34,7 +34,7 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
         }
     }
 
-    public override async void connect_display () throws GLib.Error {
+    public override async void connect_display (Machine.ConnectFlags flags) throws GLib.Error {
         if (display == null) {
             display = create_display ();
             display.connect_it ();
diff --git a/src/util.vala b/src/util.vala
index e16c1ef..e31a49c 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -3,6 +3,7 @@ using Config;
 
 public errordomain Boxes.Error {
     INVALID,
+    RESTORE_FAILED,
     COMMAND_FAILED
 }
 


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