[gnome-boxes] Keep Display objects alive if needed



commit f21e3a58b3d1120b53fa08fdf3e09bfba1a1f5d7
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Nov 9 11:53:48 2012 +0100

    Keep Display objects alive if needed
    
    If Display.should_keep_alive() returns true when we leave
    the VM we keep the display widget around for later and reuse
    it when connecting again.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672268

 src/app.vala             |    5 +++--
 src/libvirt-machine.vala |   12 +++++++++---
 src/machine.vala         |   10 +++++++---
 src/remote-machine.vala  |    9 ++++++---
 4 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 648ecec..b7b34b3 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -738,6 +738,9 @@ private class Boxes.App: Boxes.UI {
                 topbar.set_status (machine.status);
         });
 
+        // Start the CREDS state
+        ui_state = UIState.CREDS;
+
         // Connect to the display
         machine.connect_display.begin ( (obj, res) => {
             try {
@@ -749,8 +752,6 @@ private class Boxes.App: Boxes.UI {
             }
             });
 
-        // Start the CREDS state
-        ui_state = UIState.CREDS;
     }
 
     public void select_item (CollectionItem item) {
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 61537e2..70eb32d 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -23,8 +23,12 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     public override async void connect_display () throws GLib.Error {
         yield start ();
 
-        update_display ();
-        display.connect_it ();
+        if (update_display ()) {
+            display.connect_it ();
+        } else {
+            show_display ();
+            display.set_enable_audio (true);
+        }
     }
 
     struct MachineStat {
@@ -393,11 +397,13 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         return list;
     }
 
-    private void update_display () throws GLib.Error {
+    private bool update_display () throws GLib.Error {
         update_domain_config ();
 
+        var created_display = display == null;
         if (display == null)
             display = create_display ();
+        return created_display;
     }
 
     private Display? create_display () throws Boxes.Error {
diff --git a/src/machine.vala b/src/machine.vala
index e6f3898..a001c00 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -55,7 +55,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         }
     }
 
-    private void show_display () {
+    protected void show_display () {
         Gtk.Widget widget;
 
         widget = display.get_display (0);
@@ -223,8 +223,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         }
 
         App.app.display_page.remove_display ();
-        display.disconnect_it ();
-        display = null;
+        if (!display.should_keep_alive ()) {
+            display.disconnect_it ();
+            display = null;
+        } else {
+            display.set_enable_audio (false);
+        }
     }
 
     protected void create_display_config (string? uuid = null)
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index 5a5e5f7..2e3c412 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -35,10 +35,13 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
     }
 
     public override async void connect_display () throws GLib.Error {
-        if (display == null)
+        if (display == null) {
             display = create_display ();
-
-        display.connect_it ();
+            display.connect_it ();
+        } else {
+            show_display ();
+            display.set_enable_audio (true);
+        }
     }
 
     public override List<Boxes.Property> get_properties (Boxes.PropertiesPage page, PropertyCreationFlag flags) {



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