[gnome-boxes] machine: Make connecting process cancellable



commit dffb512534c5e3f568c0b969518156d6ed0de31f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Mar 28 03:31:00 2013 +0200

    machine: Make connecting process cancellable
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683465

 src/libvirt-machine.vala |    9 ++++++++-
 src/machine.vala         |    3 +++
 src/ovirt-machine.vala   |    8 ++++++--
 3 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index ef7929d..c0d5799 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -23,7 +23,12 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     }
 
     public override async void connect_display (Machine.ConnectFlags flags) throws GLib.Error {
-        yield start (flags);
+        yield start (flags, connecting_cancellable);
+        if (connecting_cancellable.is_cancelled ()) {
+            connecting_cancellable.reset ();
+
+            return;
+        }
 
         if (update_display ()) {
             display.connect_it ();
@@ -514,6 +519,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                 status = _("Starting %s").printf (name);
             try {
                 yield domain.start_async (connect_flags_to_gvir (flags), cancellable);
+            } catch (IOError.CANCELLED error) {
+                debug ("starting of %s was cancelled", name);
             } catch (GLib.Error error) {
                 if (restore)
                     throw new Boxes.Error.RESTORE_FAILED ("Restore failed");
diff --git a/src/machine.vala b/src/machine.vala
index d616e56..5a3a852 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -32,6 +32,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     private static Cairo.Surface grid_surface;
     private bool updating_screenshot;
 
+    public Cancellable connecting_cancellable { get; protected set; }
+
     public enum MachineState {
         UNKNOWN,
         STOPPED,
@@ -178,6 +180,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     public Machine (Boxes.CollectionSource source, string name) {
         this.name = name;
         this.source = source;
+        this.connecting_cancellable = new Cancellable ();
 
         pixbuf = draw_fallback_vm ();
         machine_actor = new MachineActor (this);
diff --git a/src/ovirt-machine.vala b/src/ovirt-machine.vala
index 9ed536b..0b39ca2 100644
--- a/src/ovirt-machine.vala
+++ b/src/ovirt-machine.vala
@@ -28,8 +28,10 @@ private class Boxes.OvirtMachine: Boxes.Machine {
 
         if (state == MachineState.STOPPED)
             try {
-                yield vm.start_async (proxy, null);
+                yield vm.start_async (proxy, connecting_cancellable);
                 this.update_state ();
+            } catch (IOError.CANCELLED error) {
+                debug ("connection to %s was cancelled", name);
             } catch (GLib.Error error) {
                 throw new Boxes.Error.INVALID ("Couldn't start oVirt VM '%s': %s", vm.name, error.message);
             }
@@ -40,11 +42,13 @@ private class Boxes.OvirtMachine: Boxes.Machine {
         try {
             display = create_display_connection ();
             if (vm.display.type == Ovirt.VmDisplayType.SPICE) {
-                yield vm.get_ticket_async (proxy, null);
+                yield vm.get_ticket_async (proxy, connecting_cancellable);
                 display.password = vm.display.ticket;
             }
 
             display.connect_it ();
+        } catch (IOError.CANCELLED error) {
+            debug ("connection to %s was cancelled", name);
         } catch (GLib.Error e) {
             throw new Boxes.Error.INVALID ("Error opening display: %s", e.message);
         }


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