[cheese/wip/gtkapplication-refactor: 7/7] Move action sensitivity handling to Application
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese/wip/gtkapplication-refactor: 7/7] Move action sensitivity handling to Application
- Date: Sun, 30 Jun 2013 07:20:35 +0000 (UTC)
commit ee5a305de5d6c9b401e8b5031737d4c22c156006
Author: David King <amigadave amigadave com>
Date: Sat Jun 29 20:15:40 2013 +0100
Move action sensitivity handling to Application
src/cheese-application.vala | 32 ++++++++++++++++++-
src/cheese-window.vala | 72 -------------------------------------------
2 files changed, 31 insertions(+), 73 deletions(-)
---
diff --git a/src/cheese-application.vala b/src/cheese-application.vala
index 671b7f7..133d40e 100644
--- a/src/cheese-application.vala
+++ b/src/cheese-application.vala
@@ -324,6 +324,13 @@ public class Cheese.Application : Gtk.Application
camera.set_balance_property ("saturation", value);
}
+ var effects = this.lookup_action ("effects") as SimpleAction;
+ var mode = this.lookup_action ("mode") as SimpleAction;
+ var shoot = this.lookup_action ("shoot") as SimpleAction;
+ effects.set_enabled (false);
+ mode.set_enabled (false);
+ shoot.set_enabled (false);
+
camera.state_flags_changed.connect (on_camera_state_flags_changed);
main_window.set_camera (camera);
camera.play ();
@@ -366,12 +373,33 @@ public class Cheese.Application : Gtk.Application
*/
private void on_camera_state_flags_changed (Gst.State new_state)
{
+ var effects = this.lookup_action ("effects") as SimpleAction;
+ var mode = this.lookup_action ("mode") as SimpleAction;
+ var shoot = this.lookup_action ("shoot") as SimpleAction;
+
switch (new_state)
{
case Gst.State.PLAYING:
+ if (effects.state.get_boolean ())
+ {
+ mode.set_enabled (false);
+ shoot.set_enabled (false);
+ }
+ else
+ {
+ mode.set_enabled (true);
+ shoot.set_enabled (true);
+ }
+
+ effects.set_enabled (true);
+
main_window.camera_state_change_playing ();
break;
case Gst.State.NULL:
+ effects.set_enabled (false);
+ mode.set_enabled (false);
+ shoot.set_enabled (false);
+
main_window.camera_state_change_null ();
break;
default:
@@ -478,9 +506,11 @@ public class Cheese.Application : Gtk.Application
var state = value.get_boolean ();
var shoot = this.lookup_action ("shoot") as SimpleAction;
+ var mode = this.lookup_action ("mode") as SimpleAction;
- // The effects selector and shooting are mutually exclusive.
+ // Effects selection and shooting/mode changes are mutually exclusive.
shoot.set_enabled (!state);
+ mode.set_enabled (!state);
main_window.set_effects (state);
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index 63e6303..cf52e4a 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -72,7 +72,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
private uint current_effects_page = 0;
private List<Clutter.Actor> effects_grids;
- private HashTable<string, bool> action_sensitivities;
private Gtk.Action countdown_action;
private Gtk.Action effects_page_prev_action;
private Gtk.Action effects_page_next_action;
@@ -82,7 +81,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
private bool is_recording; /* Video Recording Flag */
private bool is_bursting;
private bool is_effects_selector_active;
- private bool is_camera_actions_sensitive;
private bool action_cancelled;
private Gtk.Button[] buttons;
@@ -1128,68 +1126,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
}
}
- /**
- * Toggle the sensitvity of the camera actions.
- *
- * @param active whether the camera actions should be sensitive
- */
- public void toggle_camera_actions_sensitivities (bool active)
- {
- is_camera_actions_sensitive = active;
- if (active)
- {
- var keys = action_sensitivities.get_keys ();
- foreach (var key in keys)
- {
- Gtk.Action action = gtk_builder.get_object (key) as Gtk.Action;
- action.sensitive = action_sensitivities.get (key);
- }
- }
- else
- {
- action_sensitivities = new HashTable<string, bool> (GLib.str_hash,
- GLib.direct_equal);
- GLib.SList<weak GLib.Object> objects = gtk_builder.get_objects ();
- foreach (GLib.Object obj in objects)
- {
- if (obj is Gtk.Action)
- {
- Gtk.Action action = (Gtk.Action)obj;
- action_sensitivities.set (action.name, action.sensitive);
- }
- }
-
- /* Keep only these actions sensitive. */
- string [] active_actions = { "quit",
- "help_contents",
- "about",
- "open",
- "save_as",
- "move_to_trash",
- "delete" };
-
- /* Gross hack because Vala's `in` operator doesn't really work */
- bool flag;
- foreach (GLib.Object obj in objects)
- {
- flag = false;
- if (obj is Gtk.Action)
- {
- Gtk.Action action = (Gtk.Action)obj;
- foreach (string s in active_actions)
- {
- if (action.name == s)
- {
- flag = true;
- }
- }
- if (!flag)
- ((Gtk.Action)obj).sensitive = false;
- }
- }
- }
- }
-
/**
* Update the UI when the camera starts playing.
*/
@@ -1197,11 +1133,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
{
show_error (null);
- if (!is_camera_actions_sensitive)
- {
- toggle_camera_actions_sensitivities (true);
- }
-
Effect effect = effects_manager.get_effect (settings.get_string ("selected-effect"));
if (effect != null)
{
@@ -1215,7 +1146,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
public void camera_state_change_null ()
{
show_error (_("There was an error playing video from the webcam"));
- toggle_camera_actions_sensitivities (false);
}
/**
@@ -1319,8 +1249,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
set_mode (MediaMode.PHOTO);
setup_effects_selector ();
- toggle_camera_actions_sensitivities (false);
-
this.key_release_event.connect (on_key_release);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]