[empathy] CallWindow: add a 'Swap camera' item to the preview menu



commit 0e00979f11c465a755b9dd29b2247a8f3ec1c51d
Author: Emilio Pozuelo Monfort <emilio pozuelo collabora co uk>
Date:   Tue Aug 2 12:34:55 2011 +0100

    CallWindow: add a 'Swap camera' item to the preview menu

 src/empathy-call-window.c  |   69 ++++++++++++++++++++++++++++++++++++++++++++
 src/empathy-call-window.ui |    8 +++++
 2 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index bf208d5..eb88d85 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -148,6 +148,7 @@ struct _EmpathyCallWindowPriv
   ClutterActor *floating_toolbar;
   GtkWidget *pane;
   GtkAction *menu_fullscreen;
+  GtkAction *menu_swap_camera;
 
   ClutterState *transitions;
 
@@ -499,6 +500,67 @@ empathy_call_window_maximise_camera_cb (GtkAction *action,
 }
 
 static void
+empathy_call_window_swap_camera_cb (GtkAction *action,
+    EmpathyCallWindow *self)
+{
+  const GList *cameras, *l;
+  gchar *current_cam;
+
+  DEBUG ("Swapping the camera");
+
+  cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
+  current_cam = empathy_video_src_dup_device (
+      EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
+
+  for (l = cameras; l != NULL; l = l->next)
+    {
+      EmpathyCamera *camera = l->data;
+
+      if (!tp_strdiff (camera->device, current_cam))
+        {
+          EmpathyCamera *next;
+
+          if (l->next != NULL)
+            next = l->next->data;
+          else
+            next = cameras->data;
+
+          /* EmpathyCameraMenu will update itself and do the actual change
+           * for us */
+          g_settings_set_string (self->priv->settings,
+              EMPATHY_PREFS_CALL_CAMERA_DEVICE,
+              next->device);
+
+          break;
+        }
+    }
+
+  g_free (current_cam);
+}
+
+static void
+empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
+    EmpathyCamera *camera,
+    EmpathyCallWindow *self)
+{
+  const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
+
+  gtk_action_set_visible (self->priv->menu_swap_camera,
+      g_list_length ((GList *) cameras) >= 2);
+}
+
+static void
+empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
+    EmpathyCamera *camera,
+    EmpathyCallWindow *self)
+{
+  const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
+
+  gtk_action_set_visible (self->priv->menu_swap_camera,
+      g_list_length ((GList *) cameras) >= 2);
+}
+
+static void
 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
     EmpathyCallWindow *self)
 {
@@ -892,6 +954,7 @@ empathy_call_window_init (EmpathyCallWindow *self)
     "bottom_toolbar", &priv->bottom_toolbar,
     "ui_manager", &priv->ui_manager,
     "menufullscreen", &priv->menu_fullscreen,
+    "menupreviewswap", &priv->menu_swap_camera,
     "details_vbox",  &priv->details_vbox,
     "vcodec_encoding_label", &priv->vcodec_encoding_label,
     "acodec_encoding_label", &priv->acodec_encoding_label,
@@ -924,6 +987,7 @@ empathy_call_window_init (EmpathyCallWindow *self)
     "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
     "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
     "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
+    "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
     NULL);
 
   gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
@@ -934,6 +998,11 @@ empathy_call_window_init (EmpathyCallWindow *self)
       priv->camera_button, "sensitive",
       G_BINDING_SYNC_CREATE);
 
+  g_signal_connect (priv->camera_monitor, "added",
+      G_CALLBACK (empathy_call_window_camera_added_cb), self);
+  g_signal_connect (priv->camera_monitor, "removed",
+      G_CALLBACK (empathy_call_window_camera_removed_cb), self);
+
   priv->lock = g_mutex_new ();
 
   gtk_container_add (GTK_CONTAINER (self), top_vbox);
diff --git a/src/empathy-call-window.ui b/src/empathy-call-window.ui
index 3c9ba77..6e89cb3 100644
--- a/src/empathy-call-window.ui
+++ b/src/empathy-call-window.ui
@@ -77,6 +77,12 @@
           </object>
         </child>
         <child>
+          <object class="GtkAction" id="menupreviewswap">
+            <property name="name">menupreviewswap</property>
+            <property name="label" translatable="yes">Swap camera</property>
+          </object>
+        </child>
+        <child>
           <object class="GtkAction" id="menupreviewminimise">
             <property name="name">menupreviewminimise</property>
             <property name="label" translatable="yes">Minimise me</property>
@@ -116,10 +122,12 @@
           <menuitem name="menufullscreen" action="menufullscreen"/>
       </popup>
       <popup name="preview-menu">
+          <menuitem name="menupreviewswap" action="menupreviewswap"/>
           <menuitem name="menupreviewminimise" action="menupreviewminimise"/>
           <menuitem name="menupreviewdisable" action="menupreviewdisable"/>
       </popup>
       <popup name="preview-hidden-menu">
+          <menuitem name="menupreviewswap" action="menupreviewswap"/>
           <menuitem name="menupreviewmaximise" action="menupreviewmaximise"/>
           <menuitem name="menupreviewdisable" action="menupreviewdisable"/>
       </popup>



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