[empathy] Add EmpathyCameraMonitor



commit 5c5890caba5e3ddc4298f138f3bb802993b21b4d
Author: Emilio Pozuelo Monfort <emilio pozuelo collabora co uk>
Date:   Tue May 10 10:32:33 2011 +0100

    Add EmpathyCameraMonitor

 libempathy/Makefile.am              |    6 +-
 libempathy/empathy-camera-monitor.c |  174 +++++++++++++++++++++++++++++++++++
 libempathy/empathy-camera-monitor.h |   54 +++++++++++
 3 files changed, 232 insertions(+), 2 deletions(-)
---
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index 460026e..b20c49b 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -31,7 +31,8 @@ libempathy_headers =				\
 	action-chain-internal.h			\
 	empathy-account-settings.h		\
 	empathy-auth-factory.h			\
-	empathy-channel-factory.h \
+	empathy-camera-monitor.h		\
+	empathy-channel-factory.h		\
 	empathy-chatroom-manager.h		\
 	empathy-chatroom.h			\
 	empathy-connection-managers.h		\
@@ -73,7 +74,8 @@ libempathy_handwritten_source =				\
 	action-chain.c					\
 	empathy-account-settings.c			\
 	empathy-auth-factory.c				\
-	empathy-channel-factory.c \
+	empathy-camera-monitor.c			\
+	empathy-channel-factory.c			\
 	empathy-chatroom-manager.c			\
 	empathy-chatroom.c				\
 	empathy-connection-managers.c			\
diff --git a/libempathy/empathy-camera-monitor.c b/libempathy/empathy-camera-monitor.c
new file mode 100644
index 0000000..7028381
--- /dev/null
+++ b/libempathy/empathy-camera-monitor.c
@@ -0,0 +1,174 @@
+/*
+ * 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 <string.h>
+
+#include <telepathy-glib/util.h>
+
+#include "empathy-camera-monitor.h"
+#include "cheese-camera-device-monitor.h"
+#include "empathy-utils.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
+
+struct _EmpathyCameraMonitorPrivate
+{
+  CheeseCameraDeviceMonitor *cheese_monitor;
+  gint num_cameras;
+};
+
+enum
+{
+  PROP_0,
+  PROP_AVAILABLE,
+};
+
+G_DEFINE_TYPE (EmpathyCameraMonitor, empathy_camera_monitor, G_TYPE_OBJECT);
+
+static EmpathyCameraMonitor *manager_singleton = NULL;
+
+static void
+on_camera_added (CheeseCameraDeviceMonitor *device,
+    gchar *id,
+    gchar *filename,
+    gchar *product_name,
+    gint api_version,
+    EmpathyCameraMonitor *self)
+{
+  self->priv->num_cameras++;
+
+  if (self->priv->num_cameras == 1)
+    g_object_notify (G_OBJECT (self), "available");
+}
+
+static void
+on_camera_removed (CheeseCameraDeviceMonitor *device,
+    gchar *id,
+    EmpathyCameraMonitor *self)
+{
+  self->priv->num_cameras--;
+
+  if (self->priv->num_cameras == 0)
+    g_object_notify (G_OBJECT (self), "available");
+}
+
+static void
+empathy_camera_monitor_get_property (GObject *object,
+    guint prop_id,
+    GValue *value,
+    GParamSpec *pspec)
+{
+  EmpathyCameraMonitor *self = (EmpathyCameraMonitor *) 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
+empathy_camera_monitor_dispose (GObject *object)
+{
+  EmpathyCameraMonitor *self = EMPATHY_CAMERA_MONITOR (object);
+
+  tp_clear_object (&self->priv->cheese_monitor);
+
+  G_OBJECT_CLASS (empathy_camera_monitor_parent_class)->dispose (object);
+}
+
+static GObject *
+empathy_camera_monitor_constructor (GType type,
+    guint n_props,
+    GObjectConstructParam *props)
+{
+  GObject *retval;
+
+  if (manager_singleton)
+    {
+      retval = g_object_ref (manager_singleton);
+    }
+  else
+    {
+      retval =
+          G_OBJECT_CLASS (empathy_camera_monitor_parent_class)->
+          constructor (type, n_props, props);
+
+      manager_singleton = EMPATHY_CAMERA_MONITOR (retval);
+      g_object_add_weak_pointer (retval, (gpointer) & manager_singleton);
+    }
+
+  return retval;
+}
+
+static void
+empathy_camera_monitor_constructed (GObject *object)
+{
+  EmpathyCameraMonitor *self = (EmpathyCameraMonitor *) object;
+
+  G_OBJECT_CLASS (empathy_camera_monitor_parent_class)->constructed (object);
+
+  cheese_camera_device_monitor_coldplug (self->priv->cheese_monitor);
+}
+
+static void
+empathy_camera_monitor_class_init (EmpathyCameraMonitorClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = empathy_camera_monitor_dispose;
+  object_class->constructor = empathy_camera_monitor_constructor;
+  object_class->constructed = empathy_camera_monitor_constructed;
+  object_class->get_property = empathy_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));
+
+  g_type_class_add_private (object_class,
+      sizeof (EmpathyCameraMonitorPrivate));
+}
+
+static void
+empathy_camera_monitor_init (EmpathyCameraMonitor *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+      EMPATHY_TYPE_CAMERA_MONITOR, EmpathyCameraMonitorPrivate);
+
+  self->priv->cheese_monitor = cheese_camera_device_monitor_new ();
+
+  g_signal_connect (self->priv->cheese_monitor, "added",
+      G_CALLBACK (on_camera_added), self);
+  g_signal_connect (self->priv->cheese_monitor, "removed",
+      G_CALLBACK (on_camera_removed), self);
+}
+
+EmpathyCameraMonitor *
+empathy_camera_monitor_dup_singleton (void)
+{
+  return g_object_new (EMPATHY_TYPE_CAMERA_MONITOR, NULL);
+}
diff --git a/libempathy/empathy-camera-monitor.h b/libempathy/empathy-camera-monitor.h
new file mode 100644
index 0000000..0a9a498
--- /dev/null
+++ b/libempathy/empathy-camera-monitor.h
@@ -0,0 +1,54 @@
+/*
+ * 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 __EMPATHY_CAMERA_MONITOR_H__
+#define __EMPATHY_CAMERA_MONITOR_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+#define EMPATHY_TYPE_CAMERA_MONITOR         (empathy_camera_monitor_get_type ())
+#define EMPATHY_CAMERA_MONITOR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CAMERA_MONITOR, EmpathyCameraMonitor))
+#define EMPATHY_CAMERA_MONITOR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_CAMERA_MONITOR, EmpathyCameraMonitorClass))
+#define EMPATHY_IS_CAMERA_MONITOR(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CAMERA_MONITOR))
+#define EMPATHY_IS_CAMERA_MONITOR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CAMERA_MONITOR))
+#define EMPATHY_CAMERA_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CAMERA_MONITOR, EmpathyCameraMonitorClass))
+
+typedef struct _EmpathyCameraMonitor EmpathyCameraMonitor;
+typedef struct _EmpathyCameraMonitorClass EmpathyCameraMonitorClass;
+typedef struct _EmpathyCameraMonitorPrivate EmpathyCameraMonitorPrivate;
+
+struct _EmpathyCameraMonitor
+{
+  GObject parent;
+  EmpathyCameraMonitorPrivate *priv;
+};
+
+struct _EmpathyCameraMonitorClass
+{
+  GObjectClass parent_class;
+};
+
+GType empathy_camera_monitor_get_type (void) G_GNUC_CONST;
+
+EmpathyCameraMonitor *empathy_camera_monitor_dup_singleton (void);
+
+G_END_DECLS
+#endif /* __EMPATHY_CAMERA_MONITOR_H__ */



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