aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-08-01 18:58:03 +0800
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-08-15 20:02:21 +0800
commitab58c837e285f16b639444865c47c0bc286ed4e7 (patch)
tree851a835126e28135c03d7deb2237c6f7e9720112 /libempathy
parent6881301b5474f90a297b07aa63156d71171f2621 (diff)
downloadgsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.tar
gsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.tar.gz
gsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.tar.bz2
gsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.tar.lz
gsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.tar.xz
gsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.tar.zst
gsoc2013-empathy-ab58c837e285f16b639444865c47c0bc286ed4e7.zip
CameraMonitor: add API to get all cameras
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-camera-monitor.c71
-rw-r--r--libempathy/empathy-camera-monitor.h9
2 files changed, 80 insertions, 0 deletions
diff --git a/libempathy/empathy-camera-monitor.c b/libempathy/empathy-camera-monitor.c
index 3d80d40b7..98d021867 100644
--- a/libempathy/empathy-camera-monitor.c
+++ b/libempathy/empathy-camera-monitor.c
@@ -34,6 +34,7 @@
struct _EmpathyCameraMonitorPrivate
{
CheeseCameraDeviceMonitor *cheese_monitor;
+ GQueue cameras;
gint num_cameras;
};
@@ -47,6 +48,47 @@ G_DEFINE_TYPE (EmpathyCameraMonitor, empathy_camera_monitor, G_TYPE_OBJECT);
static EmpathyCameraMonitor *manager_singleton = NULL;
+static EmpathyCamera *
+empathy_camera_new (const gchar *id,
+ const gchar *device,
+ const gchar *name)
+{
+ EmpathyCamera *camera = g_slice_new (EmpathyCamera);
+
+ camera->id = g_strdup (id);
+ camera->device = g_strdup (device);
+ camera->name = g_strdup (name);
+
+ return camera;
+}
+
+static void
+empathy_camera_free (EmpathyCamera *camera)
+{
+ g_free (camera->id);
+ g_free (camera->device);
+ g_free (camera->name);
+
+ g_slice_free (EmpathyCamera, camera);
+}
+
+static gint
+empathy_camera_find (gconstpointer a,
+ gconstpointer b)
+{
+ const EmpathyCamera *camera = a;
+ const gchar *id = b;
+
+ return g_strcmp0 (camera->id, id);
+}
+
+static void
+empathy_camera_monitor_free_camera_foreach (gpointer data,
+ gpointer user_data)
+{
+ empathy_camera_free (data);
+}
+
static void
on_camera_added (CheeseCameraDeviceMonitor *device,
gchar *id,
@@ -55,6 +97,10 @@ on_camera_added (CheeseCameraDeviceMonitor *device,
gint api_version,
EmpathyCameraMonitor *self)
{
+ EmpathyCamera *camera = empathy_camera_new (id, filename, product_name);
+
+ g_queue_push_tail (&self->priv->cameras, camera);
+
self->priv->num_cameras++;
if (self->priv->num_cameras == 1)
@@ -66,10 +112,29 @@ on_camera_removed (CheeseCameraDeviceMonitor *device,
gchar *id,
EmpathyCameraMonitor *self)
{
+ EmpathyCamera *camera;
+ GList *l;
+
+ l = g_queue_find_custom (&self->priv->cameras, id, empathy_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");
+
+ empathy_camera_free (camera);
+}
+
+const GList *
+empathy_camera_monitor_get_cameras (EmpathyCameraMonitor *self)
+{
+ return self->priv->cameras.head;
}
static void
@@ -98,6 +163,10 @@ empathy_camera_monitor_dispose (GObject *object)
tp_clear_object (&self->priv->cheese_monitor);
+ g_queue_foreach (&self->priv->cameras,
+ empathy_camera_monitor_free_camera_foreach, NULL);
+ g_queue_clear (&self->priv->cameras);
+
G_OBJECT_CLASS (empathy_camera_monitor_parent_class)->dispose (object);
}
@@ -159,6 +228,8 @@ empathy_camera_monitor_init (EmpathyCameraMonitor *self)
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_CAMERA_MONITOR, EmpathyCameraMonitorPrivate);
+ g_queue_init (&self->priv->cameras);
+
self->priv->cheese_monitor = cheese_camera_device_monitor_new ();
g_signal_connect (self->priv->cheese_monitor, "added",
diff --git a/libempathy/empathy-camera-monitor.h b/libempathy/empathy-camera-monitor.h
index d2d9bb89e..19fbafa2e 100644
--- a/libempathy/empathy-camera-monitor.h
+++ b/libempathy/empathy-camera-monitor.h
@@ -46,11 +46,20 @@ struct _EmpathyCameraMonitorClass
GObjectClass parent_class;
};
+typedef struct
+{
+ gchar *id;
+ gchar *device;
+ gchar *name;
+} EmpathyCamera;
+
GType empathy_camera_monitor_get_type (void) G_GNUC_CONST;
EmpathyCameraMonitor *empathy_camera_monitor_dup_singleton (void);
gboolean empathy_camera_monitor_get_available (EmpathyCameraMonitor *self);
+const GList * empathy_camera_monitor_get_cameras (EmpathyCameraMonitor *self);
+
G_END_DECLS
#endif /* __EMPATHY_CAMERA_MONITOR_H__ */