diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/empathy-call-window.c | 18 | ||||
-rw-r--r-- | src/empathy-call-window.h | 2 | ||||
-rw-r--r-- | src/empathy-call-window.ui | 14 | ||||
-rw-r--r-- | src/empathy-camera-menu.c | 331 | ||||
-rw-r--r-- | src/empathy-camera-menu.h | 56 |
6 files changed, 417 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index fbbf989c0..cf5069fc6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -173,6 +173,8 @@ empathy_call_SOURCES = \ empathy-preferences.h \ ev-sidebar.c \ ev-sidebar.h \ + empathy-camera-menu.c \ + empathy-camera-menu.h \ empathy-mic-menu.c \ empathy-mic-menu.h \ empathy-rounded-actor.c \ diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c index ce0483099..bf208d562 100644 --- a/src/empathy-call-window.c +++ b/src/empathy-call-window.c @@ -65,6 +65,7 @@ #include "empathy-mic-menu.h" #include "empathy-preferences.h" #include "empathy-rounded-actor.h" +#include "empathy-camera-menu.h" #define CONTENT_HBOX_BORDER_WIDTH 6 #define CONTENT_HBOX_SPACING 3 @@ -228,6 +229,7 @@ struct _EmpathyCallWindowPriv GSettings *settings; EmpathyMicMenu *mic_menu; + EmpathyCameraMenu *camera_menu; }; #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv) @@ -1094,6 +1096,7 @@ empathy_call_window_init (EmpathyCallWindow *self) priv->sound_mgr = empathy_sound_manager_dup_singleton (); priv->mic_menu = empathy_mic_menu_new (self); + priv->camera_menu = empathy_camera_menu_new (self); empathy_call_window_show_hangup_button (self, TRUE); @@ -1625,7 +1628,9 @@ empathy_call_window_dispose (GObject *object) tp_clear_object (&priv->fullscreen); tp_clear_object (&priv->camera_monitor); tp_clear_object (&priv->settings); - tp_clear_object (&priv->transitions); + tp_clear_object (&priv->sound_mgr); + tp_clear_object (&priv->mic_menu); + tp_clear_object (&priv->camera_menu); g_list_free_full (priv->notifiers, g_object_unref); @@ -1640,11 +1645,6 @@ empathy_call_window_dispose (GObject *object) priv->contact = NULL; } - - tp_clear_object (&priv->sound_mgr); - - tp_clear_object (&priv->mic_menu); - G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object); } @@ -3170,3 +3170,9 @@ empathy_call_window_get_audio_src (EmpathyCallWindow *window) return (EmpathyGstAudioSrc *) priv->audio_input; } + +EmpathyGstVideoSrc * +empathy_call_window_get_video_src (EmpathyCallWindow *self) +{ + return EMPATHY_GST_VIDEO_SRC (self->priv->video_input); +} diff --git a/src/empathy-call-window.h b/src/empathy-call-window.h index 357d6f160..912a79173 100644 --- a/src/empathy-call-window.h +++ b/src/empathy-call-window.h @@ -26,6 +26,7 @@ #include "empathy-call-handler.h" #include "empathy-audio-src.h" +#include "empathy-video-src.h" G_BEGIN_DECLS @@ -66,6 +67,7 @@ EmpathyCallWindow *empathy_call_window_new (EmpathyCallHandler *handler); GtkUIManager *empathy_call_window_get_ui_manager (EmpathyCallWindow *window); EmpathyGstAudioSrc *empathy_call_window_get_audio_src (EmpathyCallWindow *window); +EmpathyGstVideoSrc *empathy_call_window_get_video_src (EmpathyCallWindow *window); G_END_DECLS diff --git a/src/empathy-call-window.ui b/src/empathy-call-window.ui index fbb1b92c6..3c9ba7750 100644 --- a/src/empathy-call-window.ui +++ b/src/empathy-call-window.ui @@ -31,6 +31,13 @@ </object> </child> <child> + <object class="GtkAction" id="menucamera"> + <property name="label" translatable="yes">_Camera</property> + <property name="name">menucamera</property> + <property name="icon_name">camera-web</property> + </object> + </child> + <child> <object class="GtkAction" id="menusettings"> <property name="stock_id">gtk-preferences</property> <property name="name">menusettings</property> @@ -38,6 +45,12 @@ </object> </child> <child> + <object class="GtkAction" id="view"> + <property name="name">view</property> + <property name="label" translatable="yes">_View</property> + </object> + </child> + <child> <object class="GtkAction" id="help"> <property name="name">help</property> <property name="label" translatable="yes">_Help</property> @@ -90,6 +103,7 @@ </menu> <menu action="edit"> <menu action="menumicrophone"/> + <menu action="menucamera"/> <menuitem name="menusettings" action="menusettings"/> </menu> <menu action="help"> diff --git a/src/empathy-camera-menu.c b/src/empathy-camera-menu.c new file mode 100644 index 000000000..a7bc26fa8 --- /dev/null +++ b/src/empathy-camera-menu.c @@ -0,0 +1,331 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * GtkAction code based on gnome-terminal's TerminalTabsMenu object. + * Thanks guys! + */ + +#include <config.h> + +#include <gtk/gtk.h> + +#include <libempathy/empathy-camera-monitor.h> + +#include "empathy-camera-menu.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_VOIP +#include <libempathy/empathy-debug.h> + +struct _EmpathyCameraMenuPrivate +{ + /* Borrowed ref; the call window actually owns us. */ + EmpathyCallWindow *window; + + /* Given away ref; the call window's UI manager now owns this. */ + GtkActionGroup *action_group; + + /* An invisible radio action so new cameras are always in the + * same radio group. */ + GtkAction *anchor_action; + + /* The merge ID used with the UI manager. We need to keep this + * around so in _clean we can remove all the items we've added + * before and start again. */ + guint ui_id; + + /* TRUE if we're in _update and so calling _set_active. */ + gboolean in_update; + + /* Queue of GtkRadioActions. */ + GQueue *cameras; + + EmpathyCameraMonitor *camera_monitor; +}; + +G_DEFINE_TYPE (EmpathyCameraMenu, empathy_camera_menu, G_TYPE_OBJECT); + +enum +{ + PROP_WINDOW = 1, +}; + +static void empathy_camera_menu_update (EmpathyCameraMenu *self); + +static void +empathy_camera_menu_init (EmpathyCameraMenu *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_CAMERA_MENU, EmpathyCameraMenuPrivate); +} + +static void +empathy_camera_menu_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyCameraMenu *self = EMPATHY_CAMERA_MENU (object); + + switch (property_id) + { + case PROP_WINDOW: + self->priv->window = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +empathy_camera_menu_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyCameraMenu *self = EMPATHY_CAMERA_MENU (object); + + switch (property_id) + { + case PROP_WINDOW: + g_value_set_object (value, self->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +empathy_camera_menu_clean (EmpathyCameraMenu *self) +{ + GtkUIManager *ui_manager; + + if (self->priv->ui_id == 0) + return; + + ui_manager = empathy_call_window_get_ui_manager (self->priv->window); + + gtk_ui_manager_remove_ui (ui_manager, self->priv->ui_id); + gtk_ui_manager_ensure_update (ui_manager); + self->priv->ui_id = 0; +} + +static void +empathy_camera_menu_activate_cb (GtkAction *action, + EmpathyCameraMenu *self) +{ + EmpathyGstVideoSrc *video; + const gchar *device; + + if (self->priv->in_update) + return; + + video = empathy_call_window_get_video_src (self->priv->window); + + device = gtk_action_get_name (action); + + empathy_video_src_change_device (video, device); +} + +static void +empathy_camera_menu_update (EmpathyCameraMenu *self) +{ + GList *l; + GtkUIManager *ui_manager; + EmpathyGstVideoSrc *video; + gchar *current_camera; + + ui_manager = empathy_call_window_get_ui_manager (self->priv->window); + + video = empathy_call_window_get_video_src (self->priv->window); + current_camera = empathy_video_src_dup_device (video); + + empathy_camera_menu_clean (self); + self->priv->ui_id = gtk_ui_manager_new_merge_id (ui_manager); + + for (l = self->priv->cameras->head; l != NULL; l = g_list_next (l)) + { + GtkRadioAction *action = l->data; + const gchar *name = gtk_action_get_name (GTK_ACTION (action)); + + if (!tp_strdiff (current_camera, name)) + { + self->priv->in_update = TRUE; + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); + self->priv->in_update = FALSE; + } + + gtk_ui_manager_add_ui (ui_manager, self->priv->ui_id, + /* TODO: this should probably be passed from the call + * window, seeing that it's a reference to + * empathy-call-window.ui. */ + "/menubar1/edit/menucamera", + name, name, GTK_UI_MANAGER_MENUITEM, FALSE); + } + + g_free (current_camera); +} + +static void +empathy_camera_menu_add_camera (EmpathyCameraMenu *self, + EmpathyCamera *camera) +{ + GtkRadioAction *action; + GSList *group; + + action = gtk_radio_action_new (camera->device, camera->name, NULL, NULL, 0); + gtk_action_group_add_action (self->priv->action_group, GTK_ACTION (action)); + + group = gtk_radio_action_get_group ( + GTK_RADIO_ACTION (self->priv->anchor_action)); + gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group); + + g_queue_push_tail (self->priv->cameras, action); + + g_signal_connect (action, "activate", + G_CALLBACK (empathy_camera_menu_activate_cb), self); +} + +static void +empathy_camera_menu_camera_added_cb (EmpathyCameraMonitor *monitor, + EmpathyCamera *camera, + EmpathyCameraMenu *self) +{ + empathy_camera_menu_add_camera (self, camera); + empathy_camera_menu_update (self); +} + +static void +empathy_camera_menu_camera_removed_cb (EmpathyCameraMonitor *monitor, + EmpathyCamera *camera, + EmpathyCameraMenu *self) +{ + GList *l; + + for (l = self->priv->cameras->head; l != NULL; l = g_list_next (l)) + { + GtkAction *action = l->data; + const gchar *device; + + device = gtk_action_get_name (action); + + if (tp_strdiff (device, camera->device)) + continue; + + g_signal_handlers_disconnect_by_func (action, + G_CALLBACK (empathy_camera_menu_activate_cb), self); + + gtk_action_group_remove_action (self->priv->action_group, + action); + g_queue_remove (self->priv->cameras, action); + break; + } + + empathy_camera_menu_update (self); +} + +static void +empathy_camera_menu_get_cameras (EmpathyCameraMenu *self) +{ + const GList *cameras; + + cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor); + + for (; cameras != NULL; cameras = g_list_next (cameras)) + { + EmpathyCamera *camera = cameras->data; + + empathy_camera_menu_add_camera (self, camera); + } + + empathy_camera_menu_update (self); +} + +static void +empathy_camera_menu_constructed (GObject *obj) +{ + EmpathyCameraMenu *self = EMPATHY_CAMERA_MENU (obj); + GtkUIManager *ui_manager; + + g_assert (EMPATHY_IS_CALL_WINDOW (self->priv->window)); + + ui_manager = empathy_call_window_get_ui_manager (self->priv->window); + + g_assert (GTK_IS_UI_MANAGER (ui_manager)); + + /* Okay let's go go go. */ + + self->priv->action_group = gtk_action_group_new ("EmpathyCameraMenu"); + gtk_ui_manager_insert_action_group (ui_manager, self->priv->action_group, -1); + /* the UI manager now owns this */ + g_object_unref (self->priv->action_group); + + self->priv->anchor_action = g_object_new (GTK_TYPE_RADIO_ACTION, + "name", "EmpathyCameraMenuAnchorAction", + NULL); + gtk_action_group_add_action (self->priv->action_group, + self->priv->anchor_action); + g_object_unref (self->priv->anchor_action); + + self->priv->camera_monitor = empathy_camera_monitor_dup_singleton (); + + tp_g_signal_connect_object (self->priv->camera_monitor, "added", + G_CALLBACK (empathy_camera_menu_camera_added_cb), self, 0); + tp_g_signal_connect_object (self->priv->camera_monitor, "removed", + G_CALLBACK (empathy_camera_menu_camera_removed_cb), self, 0); + + self->priv->cameras = g_queue_new (); + + empathy_camera_menu_get_cameras (self); +} + +static void +empathy_camera_menu_dispose (GObject *obj) +{ + EmpathyCameraMenu *self = EMPATHY_CAMERA_MENU (obj); + + tp_clear_pointer (&self->priv->cameras, g_queue_free); + + tp_clear_object (&self->priv->camera_monitor); + + G_OBJECT_CLASS (empathy_camera_menu_parent_class)->dispose (obj); +} + +static void +empathy_camera_menu_class_init (EmpathyCameraMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = empathy_camera_menu_set_property; + object_class->get_property = empathy_camera_menu_get_property; + object_class->constructed = empathy_camera_menu_constructed; + object_class->dispose = empathy_camera_menu_dispose; + + g_object_class_install_property (object_class, PROP_WINDOW, + g_param_spec_object ("window", "window", "window", + EMPATHY_TYPE_CALL_WINDOW, + G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (object_class, sizeof (EmpathyCameraMenuPrivate)); +} + +EmpathyCameraMenu * +empathy_camera_menu_new (EmpathyCallWindow *window) +{ + return g_object_new (EMPATHY_TYPE_CAMERA_MENU, + "window", window, + NULL); +} diff --git a/src/empathy-camera-menu.h b/src/empathy-camera-menu.h new file mode 100644 index 000000000..f105baf22 --- /dev/null +++ b/src/empathy-camera-menu.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __EMPATHY_CAMERA_MENU_H__ +#define __EMPATHY_CAMERA_MENU_H__ + +#include <glib-object.h> + +#include "empathy-call-window.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CAMERA_MENU (empathy_camera_menu_get_type ()) +#define EMPATHY_CAMERA_MENU(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CAMERA_MENU, EmpathyCameraMenu)) +#define EMPATHY_CAMERA_MENU_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_CAMERA_MENU, EmpathyCameraMenuClass)) +#define EMPATHY_IS_CAMERA_MENU(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CAMERA_MENU)) +#define EMPATHY_IS_CAMERA_MENU_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CAMERA_MENU)) +#define EMPATHY_CAMERA_MENU_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CAMERA_MENU, EmpathyCameraMenuClass)) + +typedef struct _EmpathyCameraMenu EmpathyCameraMenu; +typedef struct _EmpathyCameraMenuPrivate EmpathyCameraMenuPrivate; +typedef struct _EmpathyCameraMenuClass EmpathyCameraMenuClass; + +struct _EmpathyCameraMenu +{ + GObject parent; + EmpathyCameraMenuPrivate *priv; +}; + +struct _EmpathyCameraMenuClass +{ + GObjectClass parent_class; +}; + +GType empathy_camera_menu_get_type (void) G_GNUC_CONST; + +EmpathyCameraMenu * empathy_camera_menu_new (EmpathyCallWindow *window); + +G_END_DECLS + +#endif /* __EMPATHY_CAMERA_MENU_H__ */ |