[gnome-boxes/gnome-3-4] Simplify creation of VMs a bit



commit 412d86d3371eaf99784e30900e3f818dcea7f764
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Mar 21 17:59:36 2012 +0200

    Simplify creation of VMs a bit
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672567

 src/app.vala        |   11 +++++++----
 src/vm-creator.vala |   25 +++++++------------------
 src/wizard.vala     |    3 +--
 3 files changed, 15 insertions(+), 24 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 6c16e8f..602f944 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -149,17 +149,20 @@ private class Boxes.App: Boxes.UI {
         view.category = category;
     }
 
-    public void add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain) {
-        if (domain.get_data<LibvirtMachine> ("machine") != null)
-            return; // Already added
+    public LibvirtMachine? add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain) {
+        var machine = domain.get_data<LibvirtMachine> ("machine");
+        if (machine != null)
+            return machine; // Already added
 
         try {
-            var machine = new LibvirtMachine (source, this, connection, domain);
+            machine = new LibvirtMachine (source, this, connection, domain);
             collection.add_item (machine);
             domain.set_data<LibvirtMachine> ("machine", machine);
         } catch (GLib.Error error) {
             warning ("Failed to create source '%s': %s", source.name, error.message);
         }
+
+        return machine;
     }
 
     private async void setup_libvirt (CollectionSource source) {
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 6881db0..b7ddab2 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -40,8 +40,7 @@ private class Boxes.VMCreator {
         }
     }
 
-    public async Domain create_and_launch_vm (InstallerMedia install_media,
-                                              Cancellable?   cancellable) throws GLib.Error {
+    public async void create_and_launch_vm (InstallerMedia install_media, Cancellable? cancellable) throws GLib.Error {
         var fullscreen = true;
         if (install_media is UnattendedInstaller) {
             var unattended = install_media as UnattendedInstaller;
@@ -55,24 +54,14 @@ private class Boxes.VMCreator {
         var config = configurator.create_domain_config (install_media, name, volume.get_path ());
 
         var domain = connection.create_domain (config);
-        ulong added_signal_id = 0;
-        ulong selected_signal_id = 0;
-        added_signal_id = app.collection.item_added.connect ((collection, item) => {
-            if (fullscreen && item is LibvirtMachine && (item as LibvirtMachine).domain == domain) {
-                app.select_item (item);
-                app.fullscreen = true;
-                app.collection.disconnect (added_signal_id);
-                app.disconnect (selected_signal_id);
-            }
-        });
-        selected_signal_id = app.item_selected.connect (() => {
-            app.collection.disconnect (added_signal_id);
-            app.disconnect (selected_signal_id);
-        });
-
         domain.start (0);
 
-        return domain;
+        var machine = app.add_domain (app.default_source, app.default_connection, domain);
+
+        if (machine != null && fullscreen) {
+            app.select_item (machine);
+            app.fullscreen = true;
+        }
     }
 
     private void on_domain_stopped (LibvirtMachine machine) {
diff --git a/src/wizard.vala b/src/wizard.vala
index d31817e..f996f12 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -148,8 +148,7 @@ private class Boxes.Wizard: Boxes.UI {
 
             next_button.sensitive = false;
             try {
-                var domain = yield vm_creator.create_and_launch_vm (install_media, null);
-                app.add_domain (app.default_source, app.default_connection, domain);
+                yield vm_creator.create_and_launch_vm (install_media, null);
             } catch (IOError.CANCELLED cancel_error) { // We did this, so ignore!
             } catch (GLib.Error error) {
                 warning (error.message);



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