[gnome-boxes] Enable screenshot only if ui_state is COLLECTION



commit 35cb2a32e37b2fba5c0e5aded9de3dbca70b7152
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Mon Oct 10 19:45:02 2011 +0200

    Enable screenshot only if ui_state is COLLECTION

 src/app.vala     |    9 ++-------
 src/machine.vala |   28 +++++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 2950f7f..0a20ee1 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -189,16 +189,11 @@ private abstract class Boxes.UI: GLib.Object {
         set {
             if (_ui_state != value) {
                 _ui_state = value;
-                notify_property("ui_state");
+                ui_state_changed ();
+                notify_property ("ui-state");
             }
         }
     }
 
-    public UI () {
-        notify["ui-state"].connect ( (s, p) => {
-            ui_state_changed ();
-        });
-    }
-
     public abstract void ui_state_changed ();
 }
diff --git a/src/machine.vala b/src/machine.vala
index 6d07188..dc962d0 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -21,6 +21,7 @@ private class Boxes.Machine: Boxes.CollectionItem {
 
     private ulong show_id;
     private ulong disconnected_id;
+    private uint screenshot_id;
 
     private Display? _display;
     private Display? display {
@@ -55,14 +56,31 @@ private class Boxes.Machine: Boxes.CollectionItem {
         name = domain.get_name ();
         machine_actor = new MachineActor (this);
 
-        update_screenshot.begin ();
-        Timeout.add_seconds (5, () => {
-            update_screenshot.begin ();
-
-            return true;
+        set_screenshot_enable (true);
+        app.notify["ui-state"].connect (() => {
+            if (app.ui_state == UIState.DISPLAY)
+                set_screenshot_enable (false);
+            else
+                set_screenshot_enable (true);
         });
     }
 
+    public void set_screenshot_enable (bool enable) {
+        if (enable) {
+            if (screenshot_id != 0)
+                return;
+            update_screenshot.begin ();
+            screenshot_id = Timeout.add_seconds (5, () => {
+                update_screenshot.begin ();
+                return true;
+            });
+        } else {
+            if (screenshot_id != 0)
+                Source.remove (screenshot_id);
+            screenshot_id = 0;
+        }
+    }
+
     public async bool take_screenshot () throws GLib.Error {
         if (state != DomainState.RUNNING &&
             state != DomainState.PAUSED)



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