[cheese] Make preferences and mode actions application-wide



commit 044c84fd03992ccd96adb04577c14dd5b64cf701
Author: David King <amigadave amigadave com>
Date:   Sun Jun 24 14:27:27 2012 +0100

    Make preferences and mode actions application-wide
    
    Move PreferencesDialog from MainWindow to Main. Handle app.mode action
    changes and update the state accordingly.

 data/cheese-actions.ui      |   42 -----------
 data/cheese-main-window.ui  |    9 ++-
 src/cheese-main.vala        |   71 ++++++++++++++++--
 src/cheese-preferences.vala |   25 +++---
 src/cheese-window.vala      |  172 +++++++++++++++++++------------------------
 5 files changed, 158 insertions(+), 161 deletions(-)
---
diff --git a/data/cheese-actions.ui b/data/cheese-actions.ui
index 53d37cb..0e94d7c 100644
--- a/data/cheese-actions.ui
+++ b/data/cheese-actions.ui
@@ -106,37 +106,6 @@
       </object>
     </child>
     <child>
-      <object class="GtkActionGroup" id="mode_actions">
-        <child>
-          <object class="GtkRadioAction" id="photo_mode">
-            <property name="name">Photo</property>
-            <property name="label" translatable="yes">_Photo</property>
-            <property name="value">0</property>
-            <property name="active">True</property>
-            <signal name="activate" handler="cheese_main_window_on_mode_change"/>
-          </object>
-        </child>
-        <child>
-          <object class="GtkRadioAction" id="video_mode">
-            <property name="name">Video</property>
-            <property name="label" translatable="yes">_Video</property>
-            <property name="group">photo_mode</property>
-            <property name="value">1</property>
-            <signal name="activate" handler="cheese_main_window_on_mode_change"/>
-          </object>
-        </child>
-        <child>
-          <object class="GtkRadioAction" id="burst_mode">
-            <property name="name">Burst</property>
-            <property name="label" translatable="yes">_Burst</property>
-            <property name="group">photo_mode</property>
-            <property name="value">2</property>
-            <signal name="activate" handler="cheese_main_window_on_mode_change"/>
-          </object>
-        </child>
-      </object>
-    </child>
-    <child>
       <object class="GtkActionGroup" id="effects_actions">
         <child>
           <object class="GtkToggleAction" id="effects_toggle">
@@ -165,17 +134,6 @@
         </child>
       </object>
     </child>
-    <child>
-      <object class="GtkActionGroup" id="preferences_actions">
-        <child>
-          <object class="GtkAction" id="preferences">
-            <property name="name">Preferences</property>
-            <property name="stock-id">gtk-preferences</property>
-            <signal name="activate" handler="cheese_main_window_on_preferences_dialog"/>
-          </object>
-        </child>
-      </object>
-    </child>
     <ui>
       <popup name="thumbnail_popup" id="thumbnail_popup">
         <menuitem action="open"/>
diff --git a/data/cheese-main-window.ui b/data/cheese-main-window.ui
index c99cd1f..ba69160 100644
--- a/data/cheese-main-window.ui
+++ b/data/cheese-main-window.ui
@@ -41,7 +41,8 @@
                         <child>
                           <object class="GtkToggleButton" id="photo_toggle_button">
                             <property name="use-action-appearance">False</property>
-                            <property name="related-action">photo_mode</property>
+                            <property name="action-name">app.mode</property>
+                            <property name="action-target">"photo"</property>
                             <property name="tooltip_text" translatable="yes">Photo mode</property>
                             <child>
                               <object class="GtkImage" id="photo_toggle_button_image">
@@ -53,7 +54,8 @@
                         <child>
                           <object class="GtkToggleButton" id="video_toggle_button">
                             <property name="use-action-appearance">False</property>
-                            <property name="related-action">video_mode</property>
+                            <property name="action-name">app.mode</property>
+                            <property name="action-target">"video"</property>
                             <property name="tooltip_text" translatable="yes">Video mode</property>
                             <child>
                               <object class="GtkImage" id="video_toggle_button_image">
@@ -65,7 +67,8 @@
                         <child>
                           <object class="GtkToggleButton" id="burst_toggle_button">
                             <property name="use-action-appearance">False</property>
-                            <property name="related-action">burst_mode</property>
+                            <property name="action-name">app.mode</property>
+                            <property name="action-target">"burst"</property>
                             <property name="tooltip_text" translatable="yes">Photo burst mode</property>
                             <child>
                               <object class="GtkImage" id="burst_toggle_button_image">
diff --git a/src/cheese-main.vala b/src/cheese-main.vala
index 4668220..865a2be 100644
--- a/src/cheese-main.vala
+++ b/src/cheese-main.vala
@@ -26,14 +26,18 @@ using Gst;
 
 public class Cheese.Main : Gtk.Application
 {
-  static bool   wide;
-  static string device;
-  static bool   version;
-  static bool   fullscreen;
+    static bool wide;
+    static string device;
+    static bool version;
+    static bool fullscreen;
 
-  static Cheese.MainWindow main_window;
+    static MainWindow main_window;
+
+    private PreferencesDialog preferences_dialog;
 
     private const GLib.ActionEntry action_entries[] = {
+        { "mode", on_action_radio, "s", "'photo'", on_mode_change },
+        { "preferences", on_preferences },
         { "help", on_help },
         { "about", on_about },
         { "quit", on_quit }
@@ -111,7 +115,6 @@ public class Cheese.Main : Gtk.Application
       if (fullscreen)
         main_window.set_startup_fullscreen_mode ();
 
-      main_window.set_application (this);
       main_window.show ();
       main_window.setup_camera (device);
      }
@@ -199,6 +202,62 @@ public class Cheese.Main : Gtk.Application
   }
 
     /**
+     * Update the current capture mode in the main window and preferences
+     * dialog.
+     *
+     * @param mode the mode to set
+     */
+    private void update_mode (MediaMode mode)
+    {
+        main_window.set_current_mode (mode);
+        preferences_dialog.set_current_mode (mode);
+    }
+
+    /**
+     * Handle radio actions by setting the new state.
+     *
+     * @param action the action which was triggered
+     * @param parameter the new value to set on the action
+     */
+    private void on_action_radio (SimpleAction action, Variant? parameter)
+    {
+        action.change_state (parameter);
+    }
+
+    /**
+     * Change the media capture mode (photo, video or burst).
+     *
+     * @param action the action that emitted the signal
+     * @param parameter the mode to switch to, or null
+     */
+    private void on_mode_change (SimpleAction action, Variant? value)
+    {
+        return_if_fail (value != null);
+
+        var state = value.get_string ();
+
+        // FIXME: Should be able to get these from the enum.
+        if (state == "photo")
+            update_mode (MediaMode.PHOTO);
+        else if (state == "video")
+            update_mode (MediaMode.VIDEO);
+        else if (state == "burst")
+            update_mode (MediaMode.BURST);
+        else
+            assert_not_reached ();
+
+        action.set_state (value);
+    }
+
+    /**
+     * Show the preferences dialog.
+     */
+    private void on_preferences ()
+    {
+        preferences_dialog.show ();
+    }
+
+    /**
      * Show the Cheese help contents.
      */
     private void on_help ()
diff --git a/src/cheese-preferences.vala b/src/cheese-preferences.vala
index 30bf48b..fdd87c3 100644
--- a/src/cheese-preferences.vala
+++ b/src/cheese-preferences.vala
@@ -550,17 +550,16 @@ public class Cheese.PreferencesDialog : GLib.Object
     this.dialog.show_all ();
   }
   
-  /**
-   * Set the current media mode (photo, video, burst).
-   *
-   * The current mode is used if the photo or video resolution is changed, in
-   * order to propagate that change to the Cheese.Camera.
-   *
-   * @param mode the media mode to set
-   */
-  public void set_current_mode (MediaMode mode)
-  {
-    this.current_mode = mode;
-  }
-  
+    /**
+     * Set the current media mode (photo, video or burst).
+     *
+     * The current mode is used to update the video format on the Cheese.Camera
+     * when the resolution for the current mode is changed.
+     *
+     * @param mode the media mode to set
+     */
+    public void set_current_mode (MediaMode mode)
+    {
+        current_mode = mode;
+    }
 }
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index a3efe13..4b4072a 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -43,13 +43,11 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     // Actions for the app menu.
     private const GLib.ActionEntry entries[] = {
         { "shoot", on_take_action },
-        { "mode", null, "s", "'photo'", on_mode_change },
         { "fullscreen", null, null, "false", on_layout_fullscreen },
-        { "effects", null, null, "false", on_effects_toggle },
-        { "preferences", on_preferences_dialog }
+        { "effects", null, null, "false", on_effects_toggle }
     };
 
-  private MediaMode current_mode;
+    private MediaMode current_mode;
 
   private Gtk.Builder    gtk_builder;
   private Clutter.Script clutter_builder;
@@ -91,9 +89,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
   private Gtk.Action       take_photo_action;
   private Gtk.Action       take_video_action;
   private Gtk.Action       take_burst_action;
-  private Gtk.Action       photo_mode_action;
-  private Gtk.Action       video_mode_action;
-  private Gtk.Action       burst_mode_action;
   private Gtk.ToggleAction effects_toggle_action;
   private Gtk.ToggleAction wide_mode_action;
   private Gtk.ToggleAction fullscreen_action;
@@ -118,7 +113,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
   private Cheese.Flash    flash;
 
   private Cheese.EffectsManager    effects_manager;
-  private Cheese.PreferencesDialog preferences_dialog;
 
   private Cheese.Effect selected_effect;
 
@@ -142,20 +136,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     }
 
   /**
-   * Show the preferences dialog when requested, creating it as necessary.
-   *
-   * @param action the action that emitted the signal
-   */
-  [CCode (instance_pos = -1)]
-  public void on_preferences_dialog (SimpleAction action, Variant? parameter)
-  {
-    if (preferences_dialog == null)
-      preferences_dialog = new Cheese.PreferencesDialog (camera, settings);
-    preferences_dialog.set_current_mode (current_mode);
-    preferences_dialog.show ();
-  }
-
-  /**
    * Popup a context menu when right-clicking on a thumbnail.
    *
    * @param iconview the thumbnail view that emitted the signal
@@ -559,27 +539,23 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
         set_fullscreen_mode (action.state.get_boolean ());
     }
 
-  /**
-   * Make the media capture mode actions sensitive.
-   */
-  private void enable_mode_change ()
-  {
-    photo_mode_action.sensitive = true;
-    video_mode_action.sensitive = true;
-    burst_mode_action.sensitive = true;
-    effects_toggle_action.sensitive = true;
-  }
+    /**
+     * Make the media capture mode actions sensitive.
+     */
+    private void enable_mode_change ()
+    {
+        // FIXME: Set the mode action to be sensitive
+        effects_toggle_action.sensitive = true;
+    }
 
-  /**
-   * Make the media capture mode actions insensitive.
-   */
-  private void disable_mode_change ()
-  {
-     photo_mode_action.sensitive = false;
-     video_mode_action.sensitive = false;
-     burst_mode_action.sensitive = false;
-     effects_toggle_action.sensitive = false;
-  }
+    /**
+     * Make the media capture mode actions insensitive.
+     */
+    private void disable_mode_change ()
+    {
+        // FIXME: Set the mode action to be sensitive
+        effects_toggle_action.sensitive = false;
+    }
 
   /**
    * Set the capture resolution, based on the current capture mode.
@@ -631,42 +607,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
    */
   private void set_mode (MediaMode mode)
   {
-    this.current_mode = mode;
-    
-    set_resolution (current_mode);
-    
-    if (preferences_dialog != null)
-      preferences_dialog.set_current_mode (current_mode);
-
-    timeout_layer.hide ();
-
-    switch (this.current_mode)
-    {
-      case MediaMode.PHOTO:
-        take_photo_action.sensitive       = true;
-        take_video_action.sensitive       = false;
-        take_burst_action.sensitive       = false;
-        take_action_button.related_action = take_photo_action;
-        break;
-
-      case MediaMode.VIDEO:
-        take_photo_action.sensitive       = false;
-        take_video_action.sensitive       = true;
-        take_burst_action.sensitive       = false;
-        take_action_button.related_action = take_video_action;
-        timeout_layer.text = "00:00:00";
-        timeout_layer.show ();
-        break;
-
-      case MediaMode.BURST:
-        take_photo_action.sensitive       = false;
-        take_video_action.sensitive       = false;
-        take_burst_action.sensitive       = true;
-        take_action_button.related_action = take_burst_action;
-        break;
-    }
-    take_action_button_label.label  = "<b>" + take_action_button.related_action.label + "</b>";
-    take_action_button.tooltip_text = take_action_button.related_action.tooltip;
 }
 
   private TimeoutSource fullscreen_timeout;
@@ -1100,22 +1040,20 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     }
   }
 
-  /**
-   * Toggle the display of the effect selector.
-   *
-   * @param action the action that emitted the signal
-   */
-  [CCode (instance_pos = -1)]
-  public void on_effects_toggle (SimpleAction action, Variant value)
-  {
-    toggle_effects_selector (action.enabled);
-    take_photo_action.sensitive = !action.enabled;
-    take_video_action.sensitive = !action.enabled;
-    take_burst_action.sensitive = !action.enabled;
-    photo_mode_action.sensitive = !action.enabled;
-    video_mode_action.sensitive = !action.enabled;
-    burst_mode_action.sensitive = !action.enabled;
-  }
+    /**
+     * Toggle the display of the effect selector.
+     *
+     * @param action the action that emitted the signal
+     */
+    [CCode (instance_pos = -1)]
+    public void on_effects_toggle (SimpleAction action, Variant value)
+    {
+        toggle_effects_selector (action.enabled);
+        take_photo_action.sensitive = !action.enabled;
+        take_video_action.sensitive = !action.enabled;
+        take_burst_action.sensitive = !action.enabled;
+        // FIXME: Set the mode action to be inverse sensitivity to effects.
+    }
 
   /**
    * Change the selected effect, as a new one was selected.
@@ -1479,9 +1417,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     take_photo_action        = gtk_builder.get_object ("take_photo") as Gtk.Action;
     take_video_action        = gtk_builder.get_object ("take_video") as Gtk.Action;
     take_burst_action        = gtk_builder.get_object ("take_burst") as Gtk.Action;
-    photo_mode_action        = gtk_builder.get_object ("photo_mode") as Gtk.Action;
-    video_mode_action        = gtk_builder.get_object ("video_mode") as Gtk.Action;
-    burst_mode_action        = gtk_builder.get_object ("burst_mode") as Gtk.Action;
     effects_toggle_action    = gtk_builder.get_object ("effects_toggle") as Gtk.ToggleAction;
     countdown_action         = gtk_builder.get_object ("countdown") as Gtk.Action;
     wide_mode_action         = gtk_builder.get_object ("wide_mode") as Gtk.ToggleAction;
@@ -1628,4 +1563,47 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     thumb_view.start_monitoring_video_path (fileutil.get_video_path ());
     thumb_view.start_monitoring_photo_path (fileutil.get_photo_path ());
   }
+
+    /**
+     * Set the current media mode (photo, video or burst).
+     *
+     * @param mode the media mode to set
+     */
+    public void set_current_mode (MediaMode mode)
+    {
+        current_mode = mode;
+
+        set_resolution (current_mode);
+
+        timeout_layer.hide ();
+
+        switch (current_mode)
+        {
+            case MediaMode.PHOTO:
+                take_photo_action.sensitive = true;
+                take_video_action.sensitive = false;
+                take_burst_action.sensitive = false;
+                take_action_button.related_action = take_photo_action;
+                break;
+
+            case MediaMode.VIDEO:
+                take_photo_action.sensitive = false;
+                take_video_action.sensitive = true;
+                take_burst_action.sensitive = false;
+                take_action_button.related_action = take_video_action;
+                timeout_layer.text = "00:00:00";
+                timeout_layer.show ();
+                break;
+
+            case MediaMode.BURST:
+                take_photo_action.sensitive = false;
+                take_video_action.sensitive = false;
+                take_burst_action.sensitive = true;
+                take_action_button.related_action = take_burst_action;
+                break;
+        }
+
+        take_action_button_label.label  = "<b>" + take_action_button.related_action.label + "</b>";
+        take_action_button.tooltip_text = take_action_button.related_action.tooltip;
+    }
 }



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