Added QtCamMute
authorMohammed Sameer <msameer@foolab.org>
Fri, 14 Sep 2012 15:34:25 +0000 (18:34 +0300)
committerMohammed Sameer <msameer@foolab.org>
Fri, 14 Sep 2012 15:34:25 +0000 (18:34 +0300)
imports/imports.pro
imports/mute.cpp [new file with mode: 0644]
imports/mute.h [new file with mode: 0644]
imports/plugin.cpp
imports/videotorch.h
lib/lib.pro
lib/qtcamdevice.h
lib/qtcammute.cpp [new file with mode: 0644]
lib/qtcammute.h [new file with mode: 0644]

index 908648b..fbd3da2 100644 (file)
@@ -13,9 +13,9 @@ QT += declarative
 HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \
            capability.h zoom.h flash.h scene.h evcomp.h videotorch.h whitebalance.h \
            colortone.h exposure.h aperture.h iso.h noisereduction.h \
-           flickerreduction.h
+           flickerreduction.h mute.h
 
 SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp videomode.cpp \
            capability.cpp zoom.cpp flash.cpp scene.cpp evcomp.cpp videotorch.cpp whitebalance.cpp \
            colortone.cpp exposure.cpp aperture.cpp iso.cpp noisereduction.cpp \
-           flickerreduction.cpp
+           flickerreduction.cpp mute.cpp
diff --git a/imports/mute.cpp b/imports/mute.cpp
new file mode 100644 (file)
index 0000000..8f07e30
--- /dev/null
@@ -0,0 +1,60 @@
+#include "mute.h"
+#include "qtcammute.h"
+#include "camera.h"
+#include "qtcamdevice.h"
+
+Mute::Mute(QObject *parent) :
+  QObject(parent), m_cam(0), m_mute(0) {
+
+}
+
+Mute::~Mute() {
+  m_cam = 0;
+}
+
+Camera *Mute::camera() {
+  return m_cam;
+}
+
+void Mute::setCamera(Camera *camera) {
+  if (camera == m_cam) {
+    return;
+  }
+
+  if (m_cam) {
+    QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  m_cam = camera;
+
+  if (m_cam) {
+    QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  emit cameraChanged();
+
+  deviceChanged();
+}
+
+bool Mute::isEnabled() const {
+  return m_mute ? m_mute->isEnabled() : false;
+}
+
+void Mute::setEnabled(bool enabled) {
+  if (m_mute) {
+    m_mute->setEnabled(enabled);
+  }
+}
+
+void Mute::deviceChanged() {
+  if (m_mute) {
+    delete m_mute; m_mute = 0;
+  }
+
+  if (m_cam->device()) {
+    m_mute = new QtCamMute(m_cam->device(), this);
+    QObject::connect(m_mute, SIGNAL(stateChanged()), this, SIGNAL(stateChanged()));
+
+    emit stateChanged();
+  }
+}
diff --git a/imports/mute.h b/imports/mute.h
new file mode 100644 (file)
index 0000000..fb47117
--- /dev/null
@@ -0,0 +1,37 @@
+// -*- c++ -*-
+#ifndef MUTE_H
+#define MUTE_H
+
+#include <QObject>
+
+class Camera;
+class QtCamMute;
+
+class Mute : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged);
+  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY stateChanged);
+
+public:
+  Mute(QObject *parent = 0);
+  ~Mute();
+
+  Camera *camera();
+  void setCamera(Camera *camera);
+
+  bool isEnabled() const;
+  void setEnabled(bool enabled);
+
+signals:
+  void stateChanged();
+  void cameraChanged();
+
+private slots:
+  void deviceChanged();
+
+private:
+  Camera *m_cam;
+  QtCamMute *m_mute;
+};
+
+#endif /* MUTE_H */
index 36b90f8..48f43c8 100644 (file)
@@ -16,6 +16,7 @@
 #include "iso.h"
 #include "noisereduction.h"
 #include "flickerreduction.h"
+#include "mute.h"
 
 #include <QtDeclarative>
 
@@ -39,6 +40,7 @@ void Plugin::registerTypes(QDeclarativeEngine *engine) {
   qmlRegisterType<Iso>(URI, MAJOR, MINOR, "Iso");
   qmlRegisterType<NoiseReduction>(URI, MAJOR, MINOR, "NoiseReduction");
   qmlRegisterType<FlickerReduction>(URI, MAJOR, MINOR, "FlickerReduction");
+  qmlRegisterType<Mute>(URI, MAJOR, MINOR, "Mute");
 
   qmlRegisterType<Mode>();
   qmlRegisterType<Capability>();
index 776cd21..e5b54a0 100644 (file)
@@ -1,3 +1,4 @@
+// -*- c++ -*-
 #ifndef VIDEO_TORCH_H
 #define VIDEO_TORCH_H
 
index 7bf140e..1356612 100644 (file)
@@ -17,7 +17,8 @@ HEADERS += qtcamconfig.h qtcamera.h qtcamscanner.h qtcamdevice.h qtcamviewfinder
            qtcamimagemode.h qtcamvideomode.h qtcammetadata.h qtcamcapability.h \
            qtcamzoom.h qtcamflash.h qtcamscene.h qtcamevcomp.h qtcamvideotorch.h \
            qtcamwhitebalance.h qtcamcolortone.h qtcamflickerreduction.h \
-           qtcamnoisereduction.h qtcamiso.h qtcamaperture.h qtcamexposure.h
+           qtcamnoisereduction.h qtcamiso.h qtcamaperture.h qtcamexposure.h \
+           qtcammute.h
 
 SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamviewfinder.cpp \
            qtcammode.cpp qtcamgstreamermessagehandler.cpp qtcamgstreamermessagelistener.cpp \
@@ -26,7 +27,8 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi
            qtcamimagemode.cpp qtcamvideomode.cpp qtcammetadata.cpp qtcamcapability.cpp \
            qtcamzoom.cpp qtcamflash.cpp qtcamscene.cpp qtcamevcomp.cpp qtcamvideotorch.cpp \
            qtcamwhitebalance.cpp qtcamcolortone.cpp qtcamflickerreduction.cpp \
-           qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp
+           qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \
+           qtcammute.cpp
 
 HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h
 
index 64702ac..b5cbf23 100644 (file)
@@ -58,6 +58,7 @@ private:
   friend class QtCamMetaData;
   friend class QtCamCapability;
   friend class QtCamVideoTorch;
+  friend class QtCamMute;
 
   QtCamDevicePrivate *d_ptr;
 };
diff --git a/lib/qtcammute.cpp b/lib/qtcammute.cpp
new file mode 100644 (file)
index 0000000..e7d4c1d
--- /dev/null
@@ -0,0 +1,56 @@
+#include "qtcammute.h"
+#include "qtcamdevice.h"
+#include "qtcamdevice_p.h"
+#include <QPointer>
+
+class QtCamMutePrivate {
+public:
+  static void mute_notify(GObject *gobject, GParamSpec *pspec, QtCamMute *q) {
+    Q_UNUSED(gobject);
+    Q_UNUSED(pspec);
+
+    QMetaObject::invokeMethod(q, "stateChanged", Qt::QueuedConnection);
+  }
+
+  QPointer<QtCamDevice> dev;
+  gulong handler;
+};
+
+QtCamMute::QtCamMute(QtCamDevice *dev, QObject *parent) :
+  QObject(parent), d_ptr(new QtCamMutePrivate) {
+
+  d_ptr->dev = dev;
+  d_ptr->handler = 0;
+
+  if (d_ptr->dev->d_ptr->cameraBin) {
+    d_ptr->handler = g_signal_connect(d_ptr->dev->d_ptr->cameraBin,
+                                     "notify::mute",
+                                     G_CALLBACK(QtCamMutePrivate::mute_notify), this);
+  }
+}
+
+QtCamMute::~QtCamMute() {
+  if (d_ptr->dev && d_ptr->handler) {
+    g_signal_handler_disconnect(d_ptr->dev->d_ptr->cameraBin, d_ptr->handler);
+  }
+
+  delete d_ptr; d_ptr = 0;
+}
+
+void QtCamMute::setEnabled(bool enabled) {
+  gboolean val = enabled ? TRUE : FALSE;
+
+  if (d_ptr->dev->d_ptr->cameraBin) {
+    g_object_set(d_ptr->dev->d_ptr->cameraBin, "mute", val, NULL);
+  }
+}
+
+bool QtCamMute::isEnabled() const {
+  gboolean val = FALSE;
+
+  if (d_ptr->dev->d_ptr->cameraBin) {
+    g_object_get(d_ptr->dev->d_ptr->cameraBin, "mute", &val, NULL);
+  }
+
+  return (val == TRUE);
+}
diff --git a/lib/qtcammute.h b/lib/qtcammute.h
new file mode 100644 (file)
index 0000000..df70d9e
--- /dev/null
@@ -0,0 +1,28 @@
+// -*- c++ -*-
+
+#ifndef QT_CAM_MUTE_H
+#define QT_CAM_MUTE_H
+
+#include <QObject>
+
+class QtCamDevice;
+class QtCamMutePrivate;
+
+class QtCamMute : public QObject {
+  Q_OBJECT
+
+public:
+  QtCamMute(QtCamDevice *dev, QObject *parent = 0);
+  ~QtCamMute();
+
+  void setEnabled(bool enabled);
+  bool isEnabled() const;
+
+signals:
+  void stateChanged();
+
+private:
+  QtCamMutePrivate *d_ptr;
+};
+
+#endif /* QT_CAM_MUTE_H */