[cheese/cheese-window-refactor: 7/8] Some CheeseWindow reorder and cleanup



commit de62f3e76d2c7c3dd45ba8f36cf78f680b4d5f0c
Author: Filippo Argiolas <filippo argiolas gmail com>
Date:   Wed Jan 27 19:49:36 2010 +0100

    Some CheeseWindow reorder and cleanup
    
    Move some code up and down, remove redundant calls, clean up.

 src/cheese-dbus.c   |    3 +-
 src/cheese-window.c |  572 ++++++++++++++++++++++++---------------------------
 2 files changed, 273 insertions(+), 302 deletions(-)
---
diff --git a/src/cheese-dbus.c b/src/cheese-dbus.c
index fb03938..3562937 100644
--- a/src/cheese-dbus.c
+++ b/src/cheese-dbus.c
@@ -33,6 +33,7 @@
 #include <gtk/gtk.h>
 #include "cheese-dbus.h"
 #include "cheese-dbus-infos.h"
+#include "cheese-commands.h"
 
 CheeseWindow *window_pointer = NULL;
 
@@ -48,7 +49,7 @@ cheese_dbus_set_window (CheeseWindow *window)
 gboolean
 cheese_dbus_notify ()
 {
-  cheese_window_bring_to_front (window_pointer);
+  cheese_cmd_bring_to_front (window_pointer);
   return TRUE;
 }
 
diff --git a/src/cheese-window.c b/src/cheese-window.c
index f220ee0..4cfa576 100644
--- a/src/cheese-window.c
+++ b/src/cheese-window.c
@@ -30,7 +30,6 @@
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk/gdkkeysyms.h>
-#include <gdk/gdkx.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gio/gio.h>
@@ -56,6 +55,13 @@
 #define DEFAULT_WINDOW_WIDTH       600
 #define DEFAULT_WINDOW_HEIGHT      450
 
+#define PHOTO_LABEL _("_Take a Photo")
+#define VIDEO_START_LABEL _("_Start Recording")
+#define VIDEO_STOP_LABEL _("_Stop Recording")
+#define BURST_LABEL _("_Take multiple Photos")
+
+#define _BOLD(s) g_strconcat ("<b>", s, "</b>", NULL)
+
 enum
 {
   PROP_0,
@@ -91,8 +97,6 @@ typedef struct
   CheeseGConf *gconf;
   CheeseFileUtil *fileutil;
 
-//  CheeseDbus *server;
-
   GtkWidget *window;
   GtkWidget *fullscreen_popup;
 
@@ -303,17 +307,6 @@ cheese_window_spinner_invert (GtkWidget *spinner, GtkWidget *parent)
   }
 }
 
-void
-cheese_window_bring_to_front (CheeseWindow *window)
-{
-  CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (window);
-  guint32       startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window)));
-
-  gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)), startup_timestamp);
-
-  gtk_window_present (GTK_WINDOW (window));
-}
-
 static gboolean
 cheese_window_key_press_event_cb (GtkWidget *win, GdkEventKey *event, CheeseWindow *cheese_window)
 {
@@ -420,77 +413,6 @@ cheese_window_fullscreen_motion_notify_cb (GtkWidget      *widget,
 }
 
 void
-cheese_window_toggle_wide_mode (GtkWidget *widget, CheeseWindow *cheese_window)
-{
-  CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
-  gboolean toggled = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (widget));
-
-  gtk_widget_set_size_request (priv->notebook,
-                               GTK_WIDGET (priv->notebook)->allocation.width,
-                               GTK_WIDGET (priv->notebook)->allocation.height);
-
-  /* set a single column in wide mode */
-  gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumb_view), toggled ? 1 : G_MAXINT);
-
-  /* switch thumb_nav mode */
-  eog_thumb_nav_set_vertical (EOG_THUMB_NAV (priv->thumb_nav), toggled);
-
-  /* reparent thumb_view */
-  g_object_ref (priv->thumb_scrollwindow);
-  if (toggled)
-  {
-    gtk_container_remove (GTK_CONTAINER (priv->video_vbox), priv->thumb_scrollwindow);
-    gtk_container_add (GTK_CONTAINER (priv->netbook_alignment), priv->thumb_scrollwindow);
-    g_object_unref (priv->thumb_scrollwindow);
-  }
-  else
-  {
-    gtk_container_remove (GTK_CONTAINER (priv->netbook_alignment), priv->thumb_scrollwindow);
-    gtk_box_pack_end (GTK_BOX (priv->video_vbox), priv->thumb_scrollwindow, FALSE, FALSE, 0);
-    g_object_unref (priv->thumb_scrollwindow);
-    eog_thumb_nav_set_policy (EOG_THUMB_NAV (priv->thumb_nav),
-                              GTK_POLICY_AUTOMATIC,
-                              GTK_POLICY_NEVER);
-  }
-
-  /* update spacing */
-
-  /* NOTE: be really carefull when changing the ui file to update spacing
-   * values here too! */
-  if (toggled)
-  {
-    g_object_set (G_OBJECT (priv->toolbar_alignment),
-                  "bottom-padding", 10, NULL);
-    g_object_set (G_OBJECT (priv->togglegroup_alignment),
-                  "left-padding", 6, NULL);
-    g_object_set (G_OBJECT (priv->effect_button_alignment),
-                  "right-padding", 0, NULL);
-    g_object_set (G_OBJECT (priv->netbook_alignment),
-                  "left-padding", 6, NULL);
-  }
-  else
-  {
-    g_object_set (G_OBJECT (priv->toolbar_alignment),
-                  "bottom-padding", 6, NULL);
-    g_object_set (G_OBJECT (priv->togglegroup_alignment),
-                  "left-padding", 24, NULL);
-    g_object_set (G_OBJECT (priv->effect_button_alignment),
-                  "right-padding", 24, NULL);
-    g_object_set (G_OBJECT (priv->netbook_alignment),
-                  "left-padding", 0, NULL);
-  }
-
-  gtk_container_resize_children (GTK_CONTAINER (priv->thumb_scrollwindow));
-
-  GtkRequisition req;
-  gtk_widget_size_request (GTK_WIDGET (cheese_window), &req);
-  gtk_window_resize (GTK_WINDOW (cheese_window), req.width, req.height);
-  gtk_widget_set_size_request (priv->notebook, -1, -1);
-
-  g_object_set (priv->gconf, "gconf_prop_wide_mode", toggled, NULL);
-}
-
-void
 cheese_window_toggle_fullscreen (GtkWidget *widget, CheeseWindow *cheese_window)
 {
   CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
@@ -565,6 +487,77 @@ cheese_window_fullscreen_leave_notify_cb (GtkWidget        *widget,
   return FALSE;
 }
 
+void
+cheese_window_toggle_wide_mode (GtkWidget *widget, CheeseWindow *cheese_window)
+{
+  CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
+  gboolean toggled = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (widget));
+
+  gtk_widget_set_size_request (priv->notebook,
+                               GTK_WIDGET (priv->notebook)->allocation.width,
+                               GTK_WIDGET (priv->notebook)->allocation.height);
+
+  /* set a single column in wide mode */
+  gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumb_view), toggled ? 1 : G_MAXINT);
+
+  /* switch thumb_nav mode */
+  eog_thumb_nav_set_vertical (EOG_THUMB_NAV (priv->thumb_nav), toggled);
+
+  /* reparent thumb_view */
+  g_object_ref (priv->thumb_scrollwindow);
+  if (toggled)
+  {
+    gtk_container_remove (GTK_CONTAINER (priv->video_vbox), priv->thumb_scrollwindow);
+    gtk_container_add (GTK_CONTAINER (priv->netbook_alignment), priv->thumb_scrollwindow);
+    g_object_unref (priv->thumb_scrollwindow);
+  }
+  else
+  {
+    gtk_container_remove (GTK_CONTAINER (priv->netbook_alignment), priv->thumb_scrollwindow);
+    gtk_box_pack_end (GTK_BOX (priv->video_vbox), priv->thumb_scrollwindow, FALSE, FALSE, 0);
+    g_object_unref (priv->thumb_scrollwindow);
+    eog_thumb_nav_set_policy (EOG_THUMB_NAV (priv->thumb_nav),
+                              GTK_POLICY_AUTOMATIC,
+                              GTK_POLICY_NEVER);
+  }
+
+  /* update spacing */
+
+  /* NOTE: be really carefull when changing the ui file to update spacing
+   * values here too! */
+  if (toggled)
+  {
+    g_object_set (G_OBJECT (priv->toolbar_alignment),
+                  "bottom-padding", 10, NULL);
+    g_object_set (G_OBJECT (priv->togglegroup_alignment),
+                  "left-padding", 6, NULL);
+    g_object_set (G_OBJECT (priv->effect_button_alignment),
+                  "right-padding", 0, NULL);
+    g_object_set (G_OBJECT (priv->netbook_alignment),
+                  "left-padding", 6, NULL);
+  }
+  else
+  {
+    g_object_set (G_OBJECT (priv->toolbar_alignment),
+                  "bottom-padding", 6, NULL);
+    g_object_set (G_OBJECT (priv->togglegroup_alignment),
+                  "left-padding", 24, NULL);
+    g_object_set (G_OBJECT (priv->effect_button_alignment),
+                  "right-padding", 24, NULL);
+    g_object_set (G_OBJECT (priv->netbook_alignment),
+                  "left-padding", 0, NULL);
+  }
+
+  gtk_container_resize_children (GTK_CONTAINER (priv->thumb_scrollwindow));
+
+  GtkRequisition req;
+  gtk_widget_size_request (GTK_WIDGET (cheese_window), &req);
+  gtk_window_resize (GTK_WINDOW (cheese_window), req.width, req.height);
+  gtk_widget_set_size_request (priv->notebook, -1, -1);
+
+  g_object_set (priv->gconf, "gconf_prop_wide_mode", toggled, NULL);
+}
+
 static void
 cheese_window_photo_saved_cb (CheeseCamera *camera, CheeseWindow *cheese_window)
 {
@@ -760,13 +753,10 @@ cheese_window_stop_recording (CheeseWindow *cheese_window)
     gtk_action_group_set_sensitive (priv->actions_effects, TRUE);
     gtk_action_group_set_sensitive (priv->actions_toggle, TRUE);
     gtk_widget_set_sensitive (priv->take_picture, FALSE);
-    gchar *str = g_strconcat ("<b>", _("_Start Recording"), "</b>", NULL);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo), str);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), str);
-    g_free (str);
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo), TRUE);
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo), _BOLD(VIDEO_START_LABEL));
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), _BOLD(VIDEO_START_LABEL));
+
     gtk_image_set_from_stock (GTK_IMAGE (priv->image_take_photo), GTK_STOCK_MEDIA_RECORD, GTK_ICON_SIZE_BUTTON);
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo_fullscreen), TRUE);
     gtk_image_set_from_stock (GTK_IMAGE (priv->image_take_photo_fullscreen),
                               GTK_STOCK_MEDIA_RECORD, GTK_ICON_SIZE_BUTTON);
 
@@ -908,7 +898,6 @@ void
 cheese_window_action_button_clicked_cb (GtkWidget *widget, CheeseWindow *cheese_window)
 {
   CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
-  char *str;
 
   switch (priv->camera_mode)
   {
@@ -931,14 +920,10 @@ cheese_window_action_button_clicked_cb (GtkWidget *widget, CheeseWindow *cheese_
       {
         gtk_action_group_set_sensitive (priv->actions_effects, FALSE);
         gtk_action_group_set_sensitive (priv->actions_toggle, FALSE);
-        str = g_strconcat ("<b>", _("_Stop Recording"), "</b>", NULL);
-        gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo), str);
-        gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), str);
-        g_free (str);
-        gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo), TRUE);
+        gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo), _BOLD(VIDEO_START_LABEL));
+        gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), _BOLD(VIDEO_START_LABEL));
         gtk_image_set_from_stock (GTK_IMAGE (
                                     priv->image_take_photo), GTK_STOCK_MEDIA_STOP, GTK_ICON_SIZE_BUTTON);
-        gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo_fullscreen), TRUE);
         gtk_image_set_from_stock (GTK_IMAGE (priv->image_take_photo_fullscreen),
                                   GTK_STOCK_MEDIA_STOP, GTK_ICON_SIZE_BUTTON);
 
@@ -1016,51 +1001,55 @@ cheese_window_toggle_countdown (GtkWidget *widget, CheeseWindow *window)
 }
 
 static void
-cheese_window_activate_radio_action (GtkAction *action, GtkRadioAction *current, CheeseWindow *cheese_window)
+cheese_window_set_mode (CheeseWindow *cheese_window, CameraMode mode)
 {
   CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
-  gchar *str;
 
-  if (strcmp (gtk_action_get_name (GTK_ACTION (current)), "Photo") == 0)
+  switch (mode)
   {
-    priv->camera_mode = CAMERA_MODE_PHOTO;
-
-    str = g_strconcat ("<b>", _("_Take a Photo"), "</b>", NULL);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo), g_strdup (str));
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo), TRUE);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), g_strdup (str));
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo_fullscreen), TRUE);
+  case CAMERA_MODE_PHOTO:
     gtk_action_group_set_sensitive (priv->actions_photo, TRUE);
     gtk_action_group_set_sensitive (priv->actions_video, FALSE);
     gtk_action_group_set_sensitive (priv->actions_burst, FALSE);
-  }
-  else if (strcmp (gtk_action_get_name (GTK_ACTION (current)), "Burst") == 0)
-  {
-    priv->camera_mode = CAMERA_MODE_BURST;
 
-    str = g_strconcat ("<b>", _("_Take multiple Photos"), "</b>", NULL);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo), g_strdup (str));
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo), TRUE);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), g_strdup (str));
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo_fullscreen), TRUE);
-    gtk_action_group_set_sensitive (priv->actions_photo, FALSE);
-    gtk_action_group_set_sensitive (priv->actions_video, FALSE);
-    gtk_action_group_set_sensitive (priv->actions_burst, TRUE);
-  }
-  else
-  {
-    priv->camera_mode = CAMERA_MODE_VIDEO;
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo), _BOLD(PHOTO_LABEL));
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), _BOLD(PHOTO_LABEL));
 
-    str = g_strconcat ("<b>", _("_Start recording"), "</b>", NULL);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo), g_strdup (str));
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo), TRUE);
-    gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), g_strdup (str));
-    gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo_fullscreen), TRUE);
+    break;
+  case CAMERA_MODE_VIDEO:
     gtk_action_group_set_sensitive (priv->actions_photo, FALSE);
     gtk_action_group_set_sensitive (priv->actions_video, TRUE);
     gtk_action_group_set_sensitive (priv->actions_burst, FALSE);
+
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo), _BOLD(VIDEO_START_LABEL));
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), _BOLD(VIDEO_START_LABEL));
+
+    break;
+  case CAMERA_MODE_BURST:
+    gtk_action_group_set_sensitive (priv->actions_photo, FALSE);
+    gtk_action_group_set_sensitive (priv->actions_video, FALSE);
+    gtk_action_group_set_sensitive (priv->actions_burst, TRUE);
+
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo), _BOLD(BURST_LABEL));
+    gtk_label_set_markup_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), _BOLD(BURST_LABEL));
+
+    break;
+  default:
+    g_assert_not_reached ();
   }
-  g_free (str);
+
+  priv->camera_mode = mode;
+}
+
+static void
+cheese_window_activate_radio_action (GtkAction *action, GtkRadioAction *current, CheeseWindow *cheese_window)
+{
+  if (strcmp (gtk_action_get_name (GTK_ACTION (current)), "Photo") == 0)
+    cheese_window_set_mode (cheese_window, CAMERA_MODE_PHOTO);
+  else if (strcmp (gtk_action_get_name (GTK_ACTION (current)), "Burst") == 0)
+    cheese_window_set_mode (cheese_window, CAMERA_MODE_BURST);
+  else
+    cheese_window_set_mode (cheese_window, CAMERA_MODE_VIDEO);
 }
 
 GtkActionGroup *
@@ -1160,15 +1149,12 @@ setup_widgets_from_builder (CheeseWindow *cheese_window)
   priv->button_video_fullscreen     = GTK_WIDGET (gtk_builder_get_object (builder, "button_video_fullscreen"));
   priv->button_burst_fullscreen     = GTK_WIDGET (gtk_builder_get_object (builder, "button_burst_fullscreen"));
   priv->take_picture_fullscreen     = GTK_WIDGET (gtk_builder_get_object (builder, "take_picture_fullscreen"));
-  priv->label_take_photo_fullscreen =
-    GTK_WIDGET (gtk_builder_get_object (builder, "label_take_photo_fullscreen"));
-  priv->image_take_photo_fullscreen =
-    GTK_WIDGET (gtk_builder_get_object (builder, "image_take_photo_fullscreen"));
-  priv->label_photo_fullscreen     = GTK_WIDGET (gtk_builder_get_object (builder, "label_photo_fullscreen"));
-  priv->label_video_fullscreen     = GTK_WIDGET (gtk_builder_get_object (builder, "label_video_fullscreen"));
-  priv->countdown_frame_fullscreen =
-    GTK_WIDGET (gtk_builder_get_object (builder, "countdown_frame_fullscreen"));
-  priv->button_exit_fullscreen = GTK_WIDGET (gtk_builder_get_object (builder, "button_exit_fullscreen"));
+  priv->label_take_photo_fullscreen = GTK_WIDGET (gtk_builder_get_object (builder, "label_take_photo_fullscreen"));
+  priv->image_take_photo_fullscreen = GTK_WIDGET (gtk_builder_get_object (builder, "image_take_photo_fullscreen"));
+  priv->label_photo_fullscreen      = GTK_WIDGET (gtk_builder_get_object (builder, "label_photo_fullscreen"));
+  priv->label_video_fullscreen      = GTK_WIDGET (gtk_builder_get_object (builder, "label_video_fullscreen"));
+  priv->countdown_frame_fullscreen  = GTK_WIDGET (gtk_builder_get_object (builder, "countdown_frame_fullscreen"));
+  priv->button_exit_fullscreen      = GTK_WIDGET (gtk_builder_get_object (builder, "button_exit_fullscreen"));
 
   gtk_container_add (GTK_CONTAINER (cheese_window), priv->main_vbox);
 
@@ -1185,58 +1171,56 @@ setup_menubar_and_actions (CheeseWindow *cheese_window)
   priv->ui_manager = gtk_ui_manager_new ();
 
   priv->actions_main = cheese_window_action_group_new (cheese_window,
-                                                                "ActionsMain",
-                                                                action_entries_main,
-                                                                G_N_ELEMENTS (action_entries_main));
+                                                       "ActionsMain",
+                                                       action_entries_main,
+                                                       G_N_ELEMENTS (action_entries_main));
 
   priv->actions_toggle = cheese_window_radio_action_group_new (cheese_window,
-                                                                        "ActionsRadio",
-                                                                        action_entries_toggle,
-                                                                        G_N_ELEMENTS (action_entries_toggle));
+                                                               "ActionsRadio",
+                                                               action_entries_toggle,
+                                                               G_N_ELEMENTS (action_entries_toggle));
 
   priv->actions_countdown = cheese_window_toggle_action_group_new (cheese_window,
-                                                                            "ActionsCountdown",
-                                                                            action_entries_countdown,
-                                                                            G_N_ELEMENTS (action_entries_countdown));
-
+                                                                   "ActionsCountdown",
+                                                                   action_entries_countdown,
+                                                                   G_N_ELEMENTS (action_entries_countdown));
 
   priv->actions_effects = cheese_window_toggle_action_group_new (cheese_window,
-                                                                          "ActionsEffects",
-                                                                          action_entries_effects,
-                                                                          G_N_ELEMENTS (action_entries_effects));
+                                                                 "ActionsEffects",
+                                                                 action_entries_effects,
+                                                                 G_N_ELEMENTS (action_entries_effects));
+  gtk_action_group_set_sensitive (priv->actions_effects, FALSE);
 
   priv->actions_fullscreen = cheese_window_toggle_action_group_new (cheese_window,
-                                                                             "ActionsFullscreen",
-                                                                             action_entries_fullscreen,
-                                                                             G_N_ELEMENTS (action_entries_fullscreen));
+                                                                    "ActionsFullscreen",
+                                                                    action_entries_fullscreen,
+                                                                    G_N_ELEMENTS (action_entries_fullscreen));
 
   priv->actions_wide_mode = cheese_window_toggle_action_group_new (cheese_window,
-                                                                            "ActionsWideMode",
-                                                                            action_entries_wide_mode,
-                                                                            G_N_ELEMENTS (action_entries_fullscreen));
+                                                                   "ActionsWideMode",
+                                                                   action_entries_wide_mode,
+                                                                   G_N_ELEMENTS (action_entries_fullscreen));
 
   priv->actions_file = cheese_window_action_group_new (cheese_window,
-                                                                "ActionsFile",
-                                                                action_entries_file,
-                                                                G_N_ELEMENTS (action_entries_file));
+                                                       "ActionsFile",
+                                                       action_entries_file,
+                                                       G_N_ELEMENTS (action_entries_file));
   gtk_action_group_set_sensitive (priv->actions_file, FALSE);
 
   priv->actions_photo = cheese_window_action_group_new (cheese_window,
-                                                                 "ActionsPhoto",
-                                                                 action_entries_photo,
-                                                                 G_N_ELEMENTS (action_entries_photo));
+                                                        "ActionsPhoto",
+                                                        action_entries_photo,
+                                                        G_N_ELEMENTS (action_entries_photo));
 
   priv->actions_video = cheese_window_toggle_action_group_new (cheese_window,
-                                                                        "ActionsVideo",
-                                                                        action_entries_video,
-                                                                        G_N_ELEMENTS (action_entries_video));
-  gtk_action_group_set_sensitive (priv->actions_video, FALSE);
-  priv->actions_burst = cheese_window_action_group_new (cheese_window,
-                                                                 "ActionsBurst",
-                                                                 action_entries_burst,
-                                                                 G_N_ELEMENTS (action_entries_burst));
-  gtk_action_group_set_sensitive (priv->actions_burst, FALSE);
+                                                               "ActionsVideo",
+                                                               action_entries_video,
+                                                               G_N_ELEMENTS (action_entries_video));
 
+  priv->actions_burst = cheese_window_action_group_new (cheese_window,
+                                                        "ActionsBurst",
+                                                        action_entries_burst,
+                                                        G_N_ELEMENTS (action_entries_burst));
 
   gtk_ui_manager_add_ui_from_file (priv->ui_manager, PACKAGE_DATADIR "/cheese-ui.xml", &error);
 
@@ -1264,7 +1248,7 @@ setup_menubar_and_actions (CheeseWindow *cheese_window)
   gtk_box_pack_start (GTK_BOX (priv->main_vbox), menubar, FALSE, FALSE, 0);
 
   priv->thumb_view_popup_menu = gtk_ui_manager_get_widget (priv->ui_manager,
-                                                                    "/ThumbnailPopup");
+                                                           "/ThumbnailPopup");
 
   gtk_window_add_accel_group (GTK_WINDOW (cheese_window),
                               gtk_ui_manager_get_accel_group (priv->ui_manager));
@@ -1290,10 +1274,118 @@ setup_menubar_and_actions (CheeseWindow *cheese_window)
   gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->button_burst_fullscreen), action);
 }
 
-static void
-cheese_window_create_window (CheeseWindow *cheese_window)
+void
+setup_camera (CheeseWindow *cheese_window)
+{
+  CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
+  char   *camera_device = NULL;
+  int     x_resolution;
+  int     y_resolution;
+  gdouble brightness;
+  gdouble contrast;
+  gdouble saturation;
+  gdouble hue;
+
+  GError *error;
+
+  g_object_get (priv->gconf,
+                "gconf_prop_x_resolution", &x_resolution,
+                "gconf_prop_y_resolution", &y_resolution,
+                "gconf_prop_camera", &camera_device,
+                "gconf_prop_brightness", &brightness,
+                "gconf_prop_contrast", &contrast,
+                "gconf_prop_saturation", &saturation,
+                "gconf_prop_hue", &hue,
+                NULL);
+
+  gdk_threads_enter ();
+  priv->camera = cheese_camera_new (priv->screen,
+                                             camera_device, x_resolution,
+                                             y_resolution);
+  gdk_threads_leave ();
+
+  g_free (camera_device);
+
+  error = NULL;
+  cheese_camera_setup (priv->camera, NULL, &error);
+  if (error != NULL)
+  {
+    if (error->code == CHEESE_CAMERA_ERROR_NO_DEVICE)
+    {
+      gdk_threads_enter ();
+      gtk_spinner_stop (GTK_SPINNER (priv->throbber));
+      cheese_window_set_problem_page (cheese_window, "cheese-no-camera");
+      gdk_threads_leave ();
+      return;
+    }
+    GtkWidget *dialog;
+    gchar     *primary, *secondary;
+
+    primary   = g_strdup (_("Check your GStreamer installation"));
+    secondary = g_strdup (error->message);
+
+    gdk_threads_enter ();
+
+    dialog = gtk_message_dialog_new (NULL,
+                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                     GTK_MESSAGE_ERROR,
+                                     GTK_BUTTONS_OK,
+                                     "%s", primary);
+    gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+                                                "%s", secondary);
+    gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
+    g_error_free (error);
+    g_free (primary);
+    g_free (secondary);
+
+    /* Clean up and exit */
+    /* FIXME: handle errors in the infobar and remove this shit */
+    gtk_widget_destroy (GTK_WIDGET (cheese_window));
+
+    gdk_threads_leave ();
+
+    return;
+  }
+
+  g_signal_connect (priv->camera, "photo-saved",
+                    G_CALLBACK (cheese_window_photo_saved_cb), cheese_window);
+  g_signal_connect (priv->camera, "video-saved",
+                    G_CALLBACK (cheese_window_video_saved_cb), cheese_window);
+
+  cheese_camera_set_effect (priv->camera,
+                            cheese_effect_chooser_get_selection (CHEESE_EFFECT_CHOOSER (priv->effect_chooser)));
+
+  cheese_camera_set_balance_property (priv->camera, "brightness", brightness);
+  cheese_camera_set_balance_property (priv->camera, "contrast", contrast);
+  cheese_camera_set_balance_property (priv->camera, "saturation", saturation);
+  cheese_camera_set_balance_property (priv->camera, "hue", hue);
+
+  cheese_camera_play (priv->camera);
+  gdk_threads_enter ();
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), PAGE_WEBCAM);
+  gtk_spinner_stop (GTK_SPINNER (priv->throbber));
+
+  gtk_widget_set_sensitive (GTK_WIDGET (priv->take_picture), TRUE);
+  gtk_widget_set_sensitive (GTK_WIDGET (priv->take_picture_fullscreen), TRUE);
+  gtk_action_group_set_sensitive (priv->actions_effects, TRUE);
+  gdk_threads_leave ();
+}
+
+void
+cheese_window_init (CheeseWindow *cheese_window)
 {
   CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
+
+  priv->gconf               = cheese_gconf_new ();
+  priv->fileutil            = cheese_fileutil_new ();
+  priv->flash               = cheese_flash_new (NULL);
+  priv->isFullscreen        = FALSE;
+  priv->is_bursting         = FALSE;
+  priv->startup_wide        = FALSE;
+
+  priv->fullscreen_timeout_source = NULL;
+
   setup_widgets_from_builder (cheese_window);
   setup_menubar_and_actions (cheese_window);
 
@@ -1335,14 +1427,7 @@ cheese_window_create_window (CheeseWindow *cheese_window)
                     G_CALLBACK (cheese_window_exit_fullscreen_button_clicked_cb),
                     cheese_window);
 
-
-  char *str = g_strconcat ("<b>", _("_Take a photo"), "</b>", NULL);
-  gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo), str);
-  gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_take_photo_fullscreen), str);
-  g_free (str);
-  gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo), TRUE);
   gtk_widget_set_sensitive (GTK_WIDGET (priv->take_picture), FALSE);
-  gtk_label_set_use_markup (GTK_LABEL (priv->label_take_photo_fullscreen), TRUE);
   gtk_widget_set_sensitive (GTK_WIDGET (priv->take_picture_fullscreen), FALSE);
 
   priv->thumb_view = cheese_thumb_view_new ();
@@ -1412,123 +1497,6 @@ cheese_window_create_window (CheeseWindow *cheese_window)
                     G_CALLBACK (cheese_window_selection_changed_cb), cheese_window);
   g_signal_connect (priv->thumb_view, "button_press_event",
                     G_CALLBACK (cheese_window_button_press_event_cb), cheese_window);
-}
-
-void
-setup_camera (CheeseWindow *cheese_window)
-{
-  CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (cheese_window);
-  char   *camera_device = NULL;
-  int     x_resolution;
-  int     y_resolution;
-  gdouble brightness;
-  gdouble contrast;
-  gdouble saturation;
-  gdouble hue;
-
-  GError *error;
-
-  g_object_get (priv->gconf,
-                "gconf_prop_x_resolution", &x_resolution,
-                "gconf_prop_y_resolution", &y_resolution,
-                "gconf_prop_camera", &camera_device,
-                "gconf_prop_brightness", &brightness,
-                "gconf_prop_contrast", &contrast,
-                "gconf_prop_saturation", &saturation,
-                "gconf_prop_hue", &hue,
-                NULL);
-
-  gdk_threads_enter ();
-  priv->camera = cheese_camera_new (priv->screen,
-                                             camera_device, x_resolution,
-                                             y_resolution);
-  gdk_threads_leave ();
-
-  g_free (camera_device);
-
-  error = NULL;
-  cheese_camera_setup (priv->camera, NULL, &error);
-  if (error != NULL)
-  {
-    if (error->code == CHEESE_CAMERA_ERROR_NO_DEVICE)
-    {
-      gdk_threads_enter ();
-      gtk_spinner_stop (GTK_SPINNER (priv->throbber));
-      cheese_window_set_problem_page (cheese_window, "cheese-no-camera");
-      gdk_threads_leave ();
-      return;
-    }
-    GtkWidget *dialog;
-    gchar     *primary, *secondary;
-
-    primary   = g_strdup (_("Check your GStreamer installation"));
-    secondary = g_strdup (error->message);
-
-    gdk_threads_enter ();
-
-    dialog = gtk_message_dialog_new (NULL,
-                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                     GTK_MESSAGE_ERROR,
-                                     GTK_BUTTONS_OK,
-                                     "%s", primary);
-    gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
-                                                "%s", secondary);
-    gtk_dialog_run (GTK_DIALOG (dialog));
-    gtk_widget_destroy (dialog);
-    g_error_free (error);
-    g_free (primary);
-    g_free (secondary);
-
-    /* Clean up and exit */
-    /* FIXME: handle errors in the infobar and remove this shit */
-    gtk_widget_destroy (GTK_WIDGET (cheese_window));
-
-    gdk_threads_leave ();
-
-    return;
-  }
-
-  g_signal_connect (priv->camera, "photo-saved",
-                    G_CALLBACK (cheese_window_photo_saved_cb), cheese_window);
-  g_signal_connect (priv->camera, "video-saved",
-                    G_CALLBACK (cheese_window_video_saved_cb), cheese_window);
-
-  cheese_camera_set_effect (priv->camera,
-                            cheese_effect_chooser_get_selection (CHEESE_EFFECT_CHOOSER (priv->effect_chooser)));
-
-  cheese_camera_set_balance_property (priv->camera, "brightness", brightness);
-  cheese_camera_set_balance_property (priv->camera, "contrast", contrast);
-  cheese_camera_set_balance_property (priv->camera, "saturation", saturation);
-  cheese_camera_set_balance_property (priv->camera, "hue", hue);
-
-  cheese_camera_play (priv->camera);
-  gdk_threads_enter ();
-  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), PAGE_WEBCAM);
-  gtk_spinner_stop (GTK_SPINNER (priv->throbber));
-
-  gtk_widget_set_sensitive (GTK_WIDGET (priv->take_picture), TRUE);
-  gtk_widget_set_sensitive (GTK_WIDGET (priv->take_picture_fullscreen), TRUE);
-  gtk_action_group_set_sensitive (priv->actions_effects, TRUE);
-  gdk_threads_leave ();
-}
-
-void
-cheese_window_init (CheeseWindow *window)
-{
-  CheeseWindowPrivate *priv = CHEESE_WINDOW_GET_PRIVATE (window);
-
-  priv->gconf               = cheese_gconf_new ();
-  priv->fileutil            = cheese_fileutil_new ();
-  priv->flash               = cheese_flash_new (NULL);
-  priv->isFullscreen        = FALSE;
-  priv->is_bursting         = FALSE;
-  priv->startup_wide        = FALSE;
-
-  priv->fullscreen_timeout_source = NULL;
-
-  cheese_window_create_window (window);
-
-  gtk_action_group_set_sensitive (priv->actions_effects, FALSE);
 
   gtk_spinner_start (GTK_SPINNER (priv->throbber));
 
@@ -1537,9 +1505,11 @@ cheese_window_init (CheeseWindow *window)
   priv->camera_mode = CAMERA_MODE_PHOTO;
   priv->recording   = FALSE;
 
+  cheese_window_set_mode (cheese_window, CAMERA_MODE_PHOTO);
+
   /* Run cam setup in its own thread */
   GError *error = NULL;
-  if (!g_thread_create ((GThreadFunc) setup_camera, window, FALSE, &error))
+  if (!g_thread_create ((GThreadFunc) setup_camera, cheese_window, FALSE, &error))
   {
     g_error ("Failed to create setup thread: %s\n", error->message);
     g_error_free (error);



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