Blame SOURCES/0040-cheese-window-Fix-toggle_camera_actions_sensitivitie.patch

ecdf9b
From f9899f78b6bd7f929613f2edf7421101b79ca365 Mon Sep 17 00:00:00 2001
ecdf9b
From: Hans de Goede <hdegoede@redhat.com>
ecdf9b
Date: Tue, 18 Jun 2013 09:12:21 +0200
ecdf9b
Subject: [PATCH 40/50] cheese-window: Fix toggle_camera_actions_sensitivities
ecdf9b
ecdf9b
The action we should disable are part of cheese-main, not of the gtkbuilder
ecdf9b
tree. Also:
ecdf9b
ecdf9b
- Switch to using a whitelist rather then a blacklist, as there are
ecdf9b
  less actions we want to disable/enable then which we don't want to, and
ecdf9b
  having a whitelist allows for much simpler code.
ecdf9b
ecdf9b
- Stop remembering the enabled state before disabling the actions, this is not
ecdf9b
  needed
ecdf9b
ecdf9b
This fixes various controls not being disabled when the user starts cheese
ecdf9b
on a machine with no video devices.
ecdf9b
ecdf9b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ecdf9b
---
ecdf9b
 src/cheese-window.vala | 72 ++++++++++----------------------------------------
ecdf9b
 1 file changed, 14 insertions(+), 58 deletions(-)
ecdf9b
ecdf9b
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
ecdf9b
index 95b4e14..ab383f9 100644
ecdf9b
--- a/src/cheese-window.vala
ecdf9b
+++ b/src/cheese-window.vala
ecdf9b
@@ -78,7 +78,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
ecdf9b
   private uint current_effects_page = 0;
ecdf9b
   private List<Clutter.Box> effects_grids;
ecdf9b
 
ecdf9b
-  private HashTable<string, bool> action_sensitivities;
ecdf9b
   private Gtk.Action       countdown_action;
ecdf9b
   private Gtk.Action       effects_page_prev_action;
ecdf9b
   private Gtk.Action       effects_page_next_action;
ecdf9b
@@ -90,7 +89,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
ecdf9b
   private bool is_recording;       /* Video Recording Flag */
ecdf9b
   private bool is_bursting;
ecdf9b
   private bool is_effects_selector_active;
ecdf9b
-  private bool is_camera_actions_sensitive;
ecdf9b
   private bool action_cancelled;
ecdf9b
   public  bool is_command_line_startup;
ecdf9b
 
ecdf9b
@@ -1296,59 +1294,20 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
ecdf9b
    */
ecdf9b
   public void toggle_camera_actions_sensitivities (bool active)
ecdf9b
   {
ecdf9b
-      is_camera_actions_sensitive = active;
ecdf9b
-      if (active)
ecdf9b
-      {
ecdf9b
-          var keys = action_sensitivities.get_keys ();
ecdf9b
-          foreach (var key in keys)
ecdf9b
-          {
ecdf9b
-              Gtk.Action action = gtk_builder.get_object (key) as Gtk.Action;
ecdf9b
-              action.sensitive = action_sensitivities.get (key);
ecdf9b
-          }
ecdf9b
-      }
ecdf9b
-      else
ecdf9b
-      {
ecdf9b
-          action_sensitivities = new HashTable<string, bool> (GLib.str_hash,
ecdf9b
-                                                              GLib.direct_equal);
ecdf9b
-          GLib.SList<weak GLib.Object> objects = gtk_builder.get_objects ();
ecdf9b
-          foreach (GLib.Object obj in objects)
ecdf9b
-          {
ecdf9b
-              if (obj is Gtk.Action)
ecdf9b
-              {
ecdf9b
-                  Gtk.Action action = (Gtk.Action)obj;
ecdf9b
-                  action_sensitivities.set (action.name, action.sensitive);
ecdf9b
-              }
ecdf9b
-          }
ecdf9b
+    string [] actions = { "shoot", "mode", "effects" };
ecdf9b
 
ecdf9b
-          /* Keep only these actions sensitive. */
ecdf9b
-          string [] active_actions = { "quit",
ecdf9b
-                                       "help",
ecdf9b
-                                       "about",
ecdf9b
-                                       "open",
ecdf9b
-                                       "save_as",
ecdf9b
-                                       "move_to_trash",
ecdf9b
-                                       "delete"};
ecdf9b
-
ecdf9b
-          /* Gross hack because Vala's `in` operator doesn't really work */
ecdf9b
-          bool flag;
ecdf9b
-          foreach (GLib.Object obj in objects)
ecdf9b
-          {
ecdf9b
-              flag = false;
ecdf9b
-              if (obj is Gtk.Action)
ecdf9b
-              {
ecdf9b
-                  Gtk.Action action = (Gtk.Action)obj;
ecdf9b
-                  foreach (string s in active_actions)
ecdf9b
-                  {
ecdf9b
-                      if (action.name == s)
ecdf9b
-                      {
ecdf9b
-                          flag = true;
ecdf9b
-                      }
ecdf9b
-                  }
ecdf9b
-                  if (!flag)
ecdf9b
-                      ((Gtk.Action)obj).sensitive = false;
ecdf9b
-              }
ecdf9b
-          }
ecdf9b
-      }
ecdf9b
+    /* If inactive, hide the effects selector, stop recording, etc. */
ecdf9b
+    if (!active) {
ecdf9b
+      if (is_effects_selector_active)
ecdf9b
+        effects_toggle_button.set_active (false);
ecdf9b
+      cancel_running_action ();
ecdf9b
+    }
ecdf9b
+
ecdf9b
+    foreach (string name in actions)
ecdf9b
+    {
ecdf9b
+      var action = this.application.lookup_action (name) as SimpleAction;
ecdf9b
+      action.set_enabled (active);
ecdf9b
+    }
ecdf9b
   }
ecdf9b
 
ecdf9b
     /**
ecdf9b
@@ -1356,10 +1315,7 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
ecdf9b
      */
ecdf9b
     public void camera_state_change_playing ()
ecdf9b
     {
ecdf9b
-        if (!is_camera_actions_sensitive)
ecdf9b
-        {
ecdf9b
-            toggle_camera_actions_sensitivities (true);
ecdf9b
-        }
ecdf9b
+        toggle_camera_actions_sensitivities (true);
ecdf9b
 
ecdf9b
         Effect effect = effects_manager.get_effect (settings.get_string ("selected-effect"));
ecdf9b
         if (effect != null)
ecdf9b
-- 
ecdf9b
1.8.2.1
ecdf9b