diff options
author | Marco Barisione <marco.barisione@collabora.co.uk> | 2013-07-29 16:20:24 +0100 |
---|---|---|
committer | Marco Barisione <marco.barisione@collabora.co.uk> | 2013-08-20 11:03:06 +0100 |
commit | f6d827a6b1006858de979d6627598fa17098ee62 (patch) | |
tree | 8ac85d9a2035213aed5e9e194bfe1047ee3094c1 /tp-account-widgets | |
parent | 6400b739ecdf0e14ad3cc1c6c7032a4eb486bb0e (diff) | |
download | telepathy-account-widgets-f6d827a6b1006858de979d6627598fa17098ee62.tar.gz |
camera-monitor: move from Empathy to tp-account-widgets
https://bugzilla.gnome.org/show_bug.cgi?id=699492
Diffstat (limited to 'tp-account-widgets')
-rw-r--r-- | tp-account-widgets/Makefile.am | 2 | ||||
-rw-r--r-- | tp-account-widgets/tpaw-camera-monitor.c | 295 | ||||
-rw-r--r-- | tp-account-widgets/tpaw-camera-monitor.h | 69 |
3 files changed, 366 insertions, 0 deletions
diff --git a/tp-account-widgets/Makefile.am b/tp-account-widgets/Makefile.am index 7bbe9f1c..26e80340 100644 --- a/tp-account-widgets/Makefile.am +++ b/tp-account-widgets/Makefile.am @@ -28,6 +28,7 @@ libtp_account_widgets_sources = \ tpaw-account-widget-sip.c \ tpaw-builder.c \ tpaw-calendar-button.c \ + tpaw-camera-monitor.c \ tpaw-connection-managers.c \ tpaw-contactinfo-utils.c \ tpaw-keyring.c \ @@ -51,6 +52,7 @@ libtp_account_widgets_headers = \ tpaw-account-widget-sip.h \ tpaw-builder.h \ tpaw-calendar-button.h \ + tpaw-camera-monitor.h \ tpaw-connection-managers.h \ tpaw-contactinfo-utils.h \ tpaw-keyring.h \ diff --git a/tp-account-widgets/tpaw-camera-monitor.c b/tp-account-widgets/tpaw-camera-monitor.c new file mode 100644 index 00000000..fac91d0e --- /dev/null +++ b/tp-account-widgets/tpaw-camera-monitor.c @@ -0,0 +1,295 @@ +/* + * 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 + * + * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> + */ + +#include "config.h" +#include "tpaw-camera-monitor.h" + +#include <tp-account-widgets/cheese-camera-device-monitor.h> + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include "empathy-debug.h" + +struct _TpawCameraMonitorPrivate +{ + TpawCameraDeviceMonitor *tpaw_monitor; + GQueue *cameras; + gint num_cameras; +}; + +enum +{ + PROP_0, + PROP_AVAILABLE, +}; + +enum +{ + CAMERA_ADDED, + CAMERA_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (TpawCameraMonitor, tpaw_camera_monitor, G_TYPE_OBJECT); + +static TpawCameraMonitor *manager_singleton = NULL; + +static TpawCamera * +tpaw_camera_new (const gchar *id, + const gchar *device, + const gchar *name) +{ + TpawCamera *camera = g_slice_new (TpawCamera); + + camera->id = g_strdup (id); + camera->device = g_strdup (device); + camera->name = g_strdup (name); + + return camera; +} + +static TpawCamera * +tpaw_camera_copy (TpawCamera *camera) +{ + return tpaw_camera_new (camera->id, camera->device, camera->name); +} + +static void +tpaw_camera_free (TpawCamera *camera) +{ + g_free (camera->id); + g_free (camera->device); + g_free (camera->name); + + g_slice_free (TpawCamera, camera); +} + +G_DEFINE_BOXED_TYPE (TpawCamera, tpaw_camera, + tpaw_camera_copy, tpaw_camera_free) + +static gint +tpaw_camera_find (gconstpointer a, + gconstpointer b) +{ + const TpawCamera *camera = a; + const gchar *id = b; + + return g_strcmp0 (camera->id, id); +} + +static void +tpaw_camera_monitor_free_camera_foreach (gpointer data, + gpointer user_data) +{ + tpaw_camera_free (data); +} + +static void +on_camera_added (TpawCameraDeviceMonitor *device, + gchar *id, + gchar *filename, + gchar *product_name, + gint api_version, + TpawCameraMonitor *self) +{ + TpawCamera *camera; + + if (self->priv->cameras == NULL) + return; + + camera = tpaw_camera_new (id, filename, product_name); + + g_queue_push_tail (self->priv->cameras, camera); + + self->priv->num_cameras++; + + if (self->priv->num_cameras == 1) + g_object_notify (G_OBJECT (self), "available"); + + g_signal_emit (self, signals[CAMERA_ADDED], 0, camera); +} + +static void +on_camera_removed (TpawCameraDeviceMonitor *device, + gchar *id, + TpawCameraMonitor *self) +{ + TpawCamera *camera; + GList *l; + + if (self->priv->cameras == NULL) + return; + + l = g_queue_find_custom (self->priv->cameras, id, tpaw_camera_find); + + g_return_if_fail (l != NULL); + + camera = l->data; + + g_queue_delete_link (self->priv->cameras, l); + + self->priv->num_cameras--; + + if (self->priv->num_cameras == 0) + g_object_notify (G_OBJECT (self), "available"); + + g_signal_emit (self, signals[CAMERA_REMOVED], 0, camera); + + tpaw_camera_free (camera); +} + +const GList * +tpaw_camera_monitor_get_cameras (TpawCameraMonitor *self) +{ + if (self->priv->cameras != NULL) + return self->priv->cameras->head; + else + return NULL; +} + +static void +tpaw_camera_monitor_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TpawCameraMonitor *self = (TpawCameraMonitor *) object; + + switch (prop_id) + { + case PROP_AVAILABLE: + g_value_set_boolean (value, self->priv->num_cameras > 0); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +tpaw_camera_monitor_dispose (GObject *object) +{ + TpawCameraMonitor *self = TPAW_CAMERA_MONITOR (object); + + tp_clear_object (&self->priv->tpaw_monitor); + + g_queue_foreach (self->priv->cameras, + tpaw_camera_monitor_free_camera_foreach, NULL); + tp_clear_pointer (&self->priv->cameras, g_queue_free); + + G_OBJECT_CLASS (tpaw_camera_monitor_parent_class)->dispose (object); +} + +static void +tpaw_camera_monitor_constructed (GObject *object) +{ + TpawCameraMonitor *self = (TpawCameraMonitor *) object; + + G_OBJECT_CLASS (tpaw_camera_monitor_parent_class)->constructed (object); + + tpaw_camera_device_monitor_coldplug (self->priv->tpaw_monitor); +} + +static void +tpaw_camera_monitor_class_init (TpawCameraMonitorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = tpaw_camera_monitor_dispose; + object_class->constructed = tpaw_camera_monitor_constructed; + object_class->get_property = tpaw_camera_monitor_get_property; + + g_object_class_install_property (object_class, PROP_AVAILABLE, + g_param_spec_boolean ("available", "Available", + "Camera available", TRUE, G_PARAM_READABLE)); + + signals[CAMERA_ADDED] = + g_signal_new ("added", G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + 0, NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, 1, TPAW_TYPE_CAMERA); + + signals[CAMERA_REMOVED] = + g_signal_new ("removed", G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + 0, NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, 1, TPAW_TYPE_CAMERA); + + g_type_class_add_private (object_class, + sizeof (TpawCameraMonitorPrivate)); +} + +static void +tpaw_camera_monitor_init (TpawCameraMonitor *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPAW_TYPE_CAMERA_MONITOR, TpawCameraMonitorPrivate); + + self->priv->cameras = g_queue_new (); + + self->priv->tpaw_monitor = tpaw_camera_device_monitor_new (); + + g_signal_connect (self->priv->tpaw_monitor, "added", + G_CALLBACK (on_camera_added), self); + g_signal_connect (self->priv->tpaw_monitor, "removed", + G_CALLBACK (on_camera_removed), self); + +#ifndef HAVE_UDEV + /* No udev, assume there are cameras present */ + self->priv->num_cameras = 1; +#endif +} + +TpawCameraMonitor * +tpaw_camera_monitor_dup_singleton (void) +{ + GObject *retval; + + if (manager_singleton) + { + retval = g_object_ref (manager_singleton); + } + else + { + retval = g_object_new (TPAW_TYPE_CAMERA_MONITOR, NULL); + + manager_singleton = TPAW_CAMERA_MONITOR (retval); + g_object_add_weak_pointer (retval, (gpointer) &manager_singleton); + } + + return TPAW_CAMERA_MONITOR (retval); +} + +TpawCameraMonitor * +tpaw_camera_monitor_new (void) +{ + return TPAW_CAMERA_MONITOR ( + g_object_new (TPAW_TYPE_CAMERA_MONITOR, NULL)); +} + +gboolean tpaw_camera_monitor_get_available (TpawCameraMonitor *self) +{ + g_return_val_if_fail (TPAW_IS_CAMERA_MONITOR (self), FALSE); + + return self->priv->num_cameras > 0; +} diff --git a/tp-account-widgets/tpaw-camera-monitor.h b/tp-account-widgets/tpaw-camera-monitor.h new file mode 100644 index 00000000..773e19ce --- /dev/null +++ b/tp-account-widgets/tpaw-camera-monitor.h @@ -0,0 +1,69 @@ +/* + * 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 + * + * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> + */ + +#ifndef __TPAW_CAMERA_MONITOR_H__ +#define __TPAW_CAMERA_MONITOR_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS +#define TPAW_TYPE_CAMERA_MONITOR (tpaw_camera_monitor_get_type ()) +#define TPAW_CAMERA_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TPAW_TYPE_CAMERA_MONITOR, TpawCameraMonitor)) +#define TPAW_CAMERA_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TPAW_TYPE_CAMERA_MONITOR, TpawCameraMonitorClass)) +#define TPAW_IS_CAMERA_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TPAW_TYPE_CAMERA_MONITOR)) +#define TPAW_IS_CAMERA_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TPAW_TYPE_CAMERA_MONITOR)) +#define TPAW_CAMERA_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPAW_TYPE_CAMERA_MONITOR, TpawCameraMonitorClass)) + +typedef struct _TpawCameraMonitor TpawCameraMonitor; +typedef struct _TpawCameraMonitorClass TpawCameraMonitorClass; +typedef struct _TpawCameraMonitorPrivate TpawCameraMonitorPrivate; + +struct _TpawCameraMonitor +{ + GObject parent; + TpawCameraMonitorPrivate *priv; +}; + +struct _TpawCameraMonitorClass +{ + GObjectClass parent_class; +}; + +typedef struct +{ + gchar *id; + gchar *device; + gchar *name; +} TpawCamera; + +#define TPAW_TYPE_CAMERA (tpaw_camera_get_type ()) +GType tpaw_camera_get_type (void) G_GNUC_CONST; + +GType tpaw_camera_monitor_get_type (void) G_GNUC_CONST; + +TpawCameraMonitor *tpaw_camera_monitor_dup_singleton (void); +TpawCameraMonitor *tpaw_camera_monitor_new (void); + +gboolean tpaw_camera_monitor_get_available (TpawCameraMonitor *self); + +const GList * tpaw_camera_monitor_get_cameras (TpawCameraMonitor *self); + +G_END_DECLS +#endif /* __TPAW_CAMERA_MONITOR_H__ */ |