9b94ca0
From 8c401d7fe5c85e60e84d08f1562fd721bef01be0 Mon Sep 17 00:00:00 2001
9b94ca0
From: Hans de Goede <hdegoede@redhat.com>
9b94ca0
Date: Tue, 18 Jun 2013 09:05:19 +0200
9b94ca0
Subject: [PATCH 02/13] cheese-window: Add cancel_running_action () method
9b94ca0
9b94ca0
And use it to stop recording / the photo countdown when we get an error
9b94ca0
while either one is active.
9b94ca0
9b94ca0
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
9b94ca0
---
9b94ca0
 src/cheese-window.vala | 47 +++++++++++++++++++++++++++++++----------------
9b94ca0
 1 file changed, 31 insertions(+), 16 deletions(-)
9b94ca0
9b94ca0
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
9b94ca0
index bc53b4e..675a92e 100644
9b94ca0
--- a/src/cheese-window.vala
9b94ca0
+++ b/src/cheese-window.vala
9b94ca0
@@ -724,6 +724,34 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
9b94ca0
   }
9b94ca0
 
9b94ca0
   /**
9b94ca0
+   * Cancel the current action (if any)
9b94ca0
+   */
9b94ca0
+  private bool cancel_running_action ()
9b94ca0
+  {
9b94ca0
+    if ((current_countdown != null && current_countdown.running) ||
9b94ca0
+        is_bursting || is_recording)
9b94ca0
+    {
9b94ca0
+      action_cancelled = true;
9b94ca0
+      switch (current_mode)
9b94ca0
+      {
9b94ca0
+        case MediaMode.PHOTO:
9b94ca0
+         current_countdown.stop ();
9b94ca0
+         finish_countdown_callback ();
9b94ca0
+         break;
9b94ca0
+        case MediaMode.BURST:
9b94ca0
+          toggle_photo_bursting (false);
9b94ca0
+          break;
9b94ca0
+        case MediaMode.VIDEO:
9b94ca0
+          toggle_video_recording (false);
9b94ca0
+          break;
9b94ca0
+      }
9b94ca0
+      action_cancelled = false;
9b94ca0
+      return true;
9b94ca0
+    }
9b94ca0
+    return false;
9b94ca0
+  }
9b94ca0
+
9b94ca0
+  /**
9b94ca0
    * Cancel the current activity if the escape key is pressed.
9b94ca0
    *
9b94ca0
    * @param event the key event, to check which key was pressed
9b94ca0
@@ -736,23 +764,9 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
9b94ca0
     key = Gdk.keyval_name (event.keyval);
9b94ca0
     if (strcmp (key, "Escape") == 0)
9b94ca0
     {
9b94ca0
-      if ((current_countdown != null && current_countdown.running) || is_bursting || is_recording)
9b94ca0
+      if (cancel_running_action())
9b94ca0
       {
9b94ca0
-        action_cancelled = true;
9b94ca0
-        switch (current_mode)
9b94ca0
-        {
9b94ca0
-          case MediaMode.PHOTO:
9b94ca0
-           current_countdown.stop ();
9b94ca0
-           finish_countdown_callback ();
9b94ca0
-           break;
9b94ca0
-          case MediaMode.BURST:
9b94ca0
-            toggle_photo_bursting (false);
9b94ca0
-            break;
9b94ca0
-          case MediaMode.VIDEO:
9b94ca0
-            toggle_video_recording (false);
9b94ca0
-            break;
9b94ca0
-        }
9b94ca0
-        action_cancelled = false;
9b94ca0
+        return false;
9b94ca0
       }
9b94ca0
       else if (is_effects_selector_active)
9b94ca0
       {
9b94ca0
@@ -1154,6 +1168,7 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
9b94ca0
      */
9b94ca0
     public void camera_state_change_null ()
9b94ca0
     {
9b94ca0
+        cancel_running_action();
9b94ca0
         if (!error_layer.visible)
9b94ca0
         {
9b94ca0
             show_error (_("There was an error playing video from the webcam"));
9b94ca0
-- 
9b94ca0
1.8.3.1
9b94ca0