[gnome-boxes] Remove Spice display when disconnect



commit 953104d1b8b81f8884149e15840076eb5adf1885
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Tue Oct 25 12:52:37 2011 +0200

    Remove Spice display when disconnect

 src/app.vala           |   10 ++++++----
 src/display-page.vala  |    3 ++-
 src/machine.vala       |   20 ++++++++++++++------
 src/spice-display.vala |   17 +++++++++++++----
 4 files changed, 35 insertions(+), 15 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 59430e6..bd6d2f7 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -89,19 +89,18 @@ private class Boxes.App: Boxes.UI {
         }
 
         var dir = File.new_for_path (get_pkgconfig_source ());
-
         get_sources_from_dir (dir);
     }
 
     private async void get_sources_from_dir (File dir) {
         try {
             var enumerator = yield dir.enumerate_children_async (FILE_ATTRIBUTE_STANDARD_NAME,
-                                                                 0,
-                                                                 Priority.DEFAULT);
+                                                                 0, Priority.DEFAULT);
             while (true) {
                 var files = yield enumerator.next_files_async (10, Priority.DEFAULT);
                 if (files == null)
                     break;
+
                 foreach (var file in files) {
                     var source = new CollectionSource.with_file (file.get_name ());
                     add_collection_source (source);
@@ -159,11 +158,13 @@ private class Boxes.App: Boxes.UI {
             box.set_layout_manager (new Clutter.FixedLayout ());
             state.set_state ("display");
             break;
+
         case UIState.CREDS:
             notebook.page = Boxes.AppPage.MAIN;
             box.set_layout_manager (box_table);
             state.set_state ("creds");
             break;
+
         case UIState.COLLECTION:
             if (current_item is Machine) {
                 var machine = current_item as Machine;
@@ -175,10 +176,12 @@ private class Boxes.App: Boxes.UI {
             box.set_layout_manager (box_table);
             state.set_state ("collection");
             break;
+
         case UIState.WIZARD:
             notebook.page = Boxes.AppPage.MAIN;
             box.set_layout_manager (box_table);
             break;
+
         default:
             warning ("Unhandled UI state %s".printf (ui_state.to_string ()));
             break;
@@ -211,7 +214,6 @@ private class Boxes.App: Boxes.UI {
 
                 machine.connect_display ();
                 ui_state = UIState.CREDS;
-
             } else
                 warning ("unknown item, fix your code");
         }
diff --git a/src/display-page.vala b/src/display-page.vala
index 73e7676..deabcc9 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -4,6 +4,7 @@ using Gdk;
 
 private class Boxes.DisplayPage: GLib.Object {
     public Widget widget { get { return overlay; } }
+
     private Overlay overlay;
     private Boxes.App app;
     private EventBox event_box;
@@ -127,9 +128,9 @@ private class Boxes.DisplayPage: GLib.Object {
             display.get_window ().disconnect (cursor_id);
             cursor_id = 0;
         }
+
         if (display != null)
             event_box.remove (display);
-
     }
 
 }
diff --git a/src/machine.vala b/src/machine.vala
index 04af477..377b5c4 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -11,6 +11,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
     public Boxes.CollectionSource source;
 
     private ulong show_id;
+    private ulong hide_id;
     private ulong disconnected_id;
     private ulong need_password_id;
     private uint screenshot_id;
@@ -22,6 +23,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
             if (_display != null) {
                 _display.disconnect (show_id);
                 show_id = 0;
+                _display.disconnect (hide_id);
+                hide_id = 0;
                 _display.disconnect (disconnected_id);
                 disconnected_id = 0;
                 _display.disconnect (need_password_id);
@@ -40,6 +43,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
                     Timeout.add (Boxes.App.duration, () => {
                         app.display_page.show_display (this, widget);
                         widget.grab_focus ();
+
                         return false;
                     });
                 } catch (Boxes.Error error) {
@@ -47,6 +51,10 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
                 }
             });
 
+            hide_id = _display.hide.connect ((id) => {
+                app.display_page.remove_display ();
+            });
+
             disconnected_id = _display.disconnected.connect (() => {
                 app.ui_state = Boxes.UIState.COLLECTION;
             });
@@ -81,6 +89,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
             update_screenshot.begin ();
             screenshot_id = Timeout.add_seconds (5, () => {
                 update_screenshot.begin ();
+
                 return true;
             });
         } else {
@@ -217,6 +226,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             return;
 
         _connect_display = false;
+        app.display_page.remove_display ();
         update_display ();
     }
 
@@ -279,7 +289,6 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             ghost = extract_xpath (xmldoc, @"string(/domain/devices/graphics[ type='$type']/@listen)");
         } catch (GLib.Error error) {
             warning (error.message);
-
             return;
         }
 
@@ -289,7 +298,6 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             display = new SpiceDisplay (ghost, int.parse (gport));
         } else {
             warning ("unsupported display of type " + type);
-
             return;
         }
 
@@ -347,6 +355,8 @@ private class Boxes.SpiceMachine: Boxes.Machine {
     public override void disconnect_display () {
         _connect_display = false;
 
+        app.display_page.remove_display ();
+
         if (display != null) {
             display.disconnect_it ();
             display = null;
@@ -404,6 +414,7 @@ private class Boxes.MachineActor: Boxes.UI {
                 event.keyval == Gdk.Key.ISO_Enter ||
                 event.keyval == Gdk.Key.Return) {
                 machine.connect_display ();
+
                 return true;
             }
 
@@ -443,7 +454,7 @@ private class Boxes.MachineActor: Boxes.UI {
             password_entry.show ();
             break;
 
-        case UIState.DISPLAY: {
+        case UIState.DISPLAY:
             int width, height;
 
             password_entry.hide ();
@@ -456,19 +467,16 @@ private class Boxes.MachineActor: Boxes.UI {
                            "x", 0.0f,
                            "y", 0.0f);
             break;
-        }
 
         case UIState.COLLECTION:
             scale_screenshot ();
             password_entry.set_can_focus (false);
             password_entry.hide ();
             label.show ();
-
             break;
 
         default:
             message ("Unhandled UI state " + ui_state.to_string ());
-
             break;
         }
     }
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 96e9392..3d12bf2 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -5,6 +5,7 @@ using Spice;
 private class Boxes.SpiceDisplay: Boxes.Display {
     private Session session;
     private ulong channel_new_id;
+    private ulong channel_destroy_id;
 
     construct {
         need_password = false;
@@ -30,16 +31,15 @@ private class Boxes.SpiceDisplay: Boxes.Display {
             display.scaling = true;
         }
 
-        if (display == null) {
+        if (display == null)
             throw new Boxes.Error.INVALID ("invalid display");
-        }
 
         return display;
     }
 
     public override void connect_it () {
         // FIXME: vala does't want to put this in ctor..
-        if (channel_new_id == 0) {
+        if (channel_new_id == 0)
             channel_new_id = session.channel_new.connect ((channel) => {
                 if (channel is Spice.MainChannel)
                     channel.channel_event.connect (main_event);
@@ -52,7 +52,14 @@ private class Boxes.SpiceDisplay: Boxes.Display {
                     // display.display_mark.connect ((mark) => { show (display.channel_id); });
                 }
             });
-        }
+
+        if (channel_destroy_id == 0)
+            channel_destroy_id = session.channel_destroy.connect ((channel) => {
+                if (channel is Spice.DisplayChannel) {
+                    var display = channel as DisplayChannel;
+                    hide (display.channel_id);
+                }
+            });
 
         session.password = password;
         session.connect ();
@@ -67,9 +74,11 @@ private class Boxes.SpiceDisplay: Boxes.Display {
         case ChannelEvent.CLOSED:
             disconnected ();
             break;
+
         case ChannelEvent.ERROR_AUTH:
             need_password = true;
             break;
+
         default:
             break;
         }



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