Added notification when focus gets acquired
authorMohammed Sameer <msameer@foolab.org>
Sat, 15 Dec 2012 01:15:10 +0000 (03:15 +0200)
committerMohammed Sameer <msameer@foolab.org>
Sat, 15 Dec 2012 01:15:10 +0000 (03:15 +0200)
13 files changed:
data/n9/qtcamera.ini
imports/notifications.h
imports/notificationscontainer.cpp
imports/notificationscontainer.h
imports/sounds.cpp
imports/sounds.h
lib/lib.pro
lib/qtcamautofocus_p.h
lib/qtcamconfig.cpp
lib/qtcamconfig.h
lib/qtcamnotifications.cpp
lib/qtcamnotifications.h
lib/qtcamnotifications_p.h [new file with mode: 0644]

index 95d5d9d..c3515e8 100644 (file)
@@ -171,3 +171,4 @@ imageCaptureStarted = /usr/share/sounds/ui-tones//snd_camera_shutter.wav
 imageCaptureEnded = 
 videoRecordingStarted = /usr/share/sounds/ui-tones//snd_camera_video_record_start.wav
 videoRecordingEnded = /usr/share/sounds/ui-tones//snd_camera_video_record_stop.wav
 imageCaptureEnded = 
 videoRecordingStarted = /usr/share/sounds/ui-tones//snd_camera_video_record_start.wav
 videoRecordingEnded = /usr/share/sounds/ui-tones//snd_camera_video_record_stop.wav
+autoFocusAcquired = /usr/share/sounds/ui-tones//snd_camera_af.wav
index 6b429f7..071c5df 100644 (file)
@@ -34,6 +34,7 @@ public:
   virtual void imageCaptureEnded() = 0;
   virtual void videoRecordingStarted() = 0;
   virtual void videoRecordingEnded() = 0;
   virtual void imageCaptureEnded() = 0;
   virtual void videoRecordingStarted() = 0;
   virtual void videoRecordingEnded() = 0;
+  virtual void autoFocusAcquired() = 0;
 };
 Q_DECLARE_INTERFACE(Notifications, "org.foolab.qml.CameraPlus/1.0");
 
 };
 Q_DECLARE_INTERFACE(Notifications, "org.foolab.qml.CameraPlus/1.0");
 
index 4f5ee5f..309baff 100644 (file)
@@ -42,6 +42,7 @@ void NotificationsContainer::setDevice(QtCamDevice *dev) {
     QObject::disconnect(n, SIGNAL(imageCaptureEnded()), this, SLOT(imageCaptureEnded()));
     QObject::disconnect(n, SIGNAL(videoRecordingStarted()), this, SLOT(videoRecordingStarted()));
     QObject::disconnect(n, SIGNAL(videoRecordingEnded()), this, SLOT(videoRecordingEnded()));
     QObject::disconnect(n, SIGNAL(imageCaptureEnded()), this, SLOT(imageCaptureEnded()));
     QObject::disconnect(n, SIGNAL(videoRecordingStarted()), this, SLOT(videoRecordingStarted()));
     QObject::disconnect(n, SIGNAL(videoRecordingEnded()), this, SLOT(videoRecordingEnded()));
+    QObject::disconnect(n, SIGNAL(autoFocusAcquired()), this, SLOT(autoFocusAcquired()));
   }
 
   m_dev = dev;
   }
 
   m_dev = dev;
@@ -56,6 +57,8 @@ void NotificationsContainer::setDevice(QtCamDevice *dev) {
                     this, SLOT(videoRecordingStarted()), Qt::DirectConnection);
     QObject::connect(n, SIGNAL(videoRecordingEnded()),
                     this, SLOT(videoRecordingEnded()), Qt::DirectConnection);
                     this, SLOT(videoRecordingStarted()), Qt::DirectConnection);
     QObject::connect(n, SIGNAL(videoRecordingEnded()),
                     this, SLOT(videoRecordingEnded()), Qt::DirectConnection);
+    QObject::connect(n, SIGNAL(autoFocusAcquired()),
+                    this, SLOT(autoFocusAcquired()), Qt::DirectConnection);
   }
 }
 
   }
 }
 
@@ -105,3 +108,11 @@ void NotificationsContainer::videoRecordingEnded() {
     m_notifications->videoRecordingEnded();
   }
 }
     m_notifications->videoRecordingEnded();
   }
 }
+
+void NotificationsContainer::autoFocusAcquired() {
+  QMutexLocker l(&m_mutex);
+
+  if (m_notifications) {
+    m_notifications->autoFocusAcquired();
+  }
+}
index b59038d..b6adda3 100644 (file)
@@ -46,6 +46,7 @@ private slots:
   void imageCaptureEnded();
   void videoRecordingStarted();
   void videoRecordingEnded();
   void imageCaptureEnded();
   void videoRecordingStarted();
   void videoRecordingEnded();
+  void autoFocusAcquired();
 
 private:
   QPointer<QtCamDevice> m_dev;
 
 private:
   QPointer<QtCamDevice> m_dev;
index 87d80cd..46b9984 100644 (file)
 #include <QMutex>
 #include <QWaitCondition>
 
 #include <QMutex>
 #include <QWaitCondition>
 
-#define CAMERA_IMAGE_START_SOUND_ID "camera-image-start"
-#define CAMERA_IMAGE_END_SOUND_ID "camera-image-end"
-#define CAMERA_VIDEO_START_SOUND_ID "camera-video-start"
-#define CAMERA_VIDEO_STOP_SOUND_ID "camera-video-stop"
+#define CAMERA_IMAGE_START_SOUND_ID  "camera-image-start"
+#define CAMERA_IMAGE_END_SOUND_ID    "camera-image-end"
+#define CAMERA_VIDEO_START_SOUND_ID  "camera-video-start"
+#define CAMERA_VIDEO_STOP_SOUND_ID   "camera-video-stop"
+#define CAMERA_FOCUS_SOUND_ID        "camera-focus"
 
 // Odd, volume has to be a char *
 #define CANBERRA_FULL_VOLUME "0.0"
 
 // Odd, volume has to be a char *
 #define CANBERRA_FULL_VOLUME "0.0"
@@ -88,6 +89,14 @@ void Sounds::videoRecordingEnded() {
   play(CAMERA_VIDEO_STOP_SOUND_ID);
 }
 
   play(CAMERA_VIDEO_STOP_SOUND_ID);
 }
 
+void Sounds::autoFocusAcquired() {
+  if (isMuted() || !m_ctx) {
+    return;
+  }
+
+  play(CAMERA_FOCUS_SOUND_ID);
+}
+
 bool Sounds::isMuted() const {
   return m_muted;
 }
 bool Sounds::isMuted() const {
   return m_muted;
 }
@@ -137,6 +146,7 @@ void Sounds::reload() {
   cache(m_conf->imageCaptureEndedSound(), CAMERA_IMAGE_END_SOUND_ID);
   cache(m_conf->videoRecordingStartedSound(), CAMERA_VIDEO_START_SOUND_ID);
   cache(m_conf->videoRecordingEndedSound(), CAMERA_VIDEO_STOP_SOUND_ID);
   cache(m_conf->imageCaptureEndedSound(), CAMERA_IMAGE_END_SOUND_ID);
   cache(m_conf->videoRecordingStartedSound(), CAMERA_VIDEO_START_SOUND_ID);
   cache(m_conf->videoRecordingEndedSound(), CAMERA_VIDEO_STOP_SOUND_ID);
+  cache(m_conf->autoFocusAcquiredSound(), CAMERA_FOCUS_SOUND_ID);
 }
 
 void Sounds::cache(const QString& path, const char *id) {
 }
 
 void Sounds::cache(const QString& path, const char *id) {
index 5f1c0eb..dfa56db 100644 (file)
@@ -43,6 +43,7 @@ public:
   void imageCaptureEnded();
   void videoRecordingStarted();
   void videoRecordingEnded();
   void imageCaptureEnded();
   void videoRecordingStarted();
   void videoRecordingEnded();
+  void autoFocusAcquired();
 
   bool isMuted() const;
   void setMuted(bool mute);
 
   bool isMuted() const;
   void setMuted(bool mute);
index 17f6b05..b0531f5 100644 (file)
@@ -30,7 +30,7 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi
            qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \
            qtcamvideomute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp
 
            qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \
            qtcamvideomute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp
 
-HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h
+HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h qtcamnotifications_p.h
 
 LIBS += -lgstphotography-0.10
 
 
 LIBS += -lgstphotography-0.10
 
index deade4c..64aabb5 100644 (file)
@@ -103,7 +103,6 @@ public:
   bool setStatus(QtCamAutoFocus::Status *status, GstMessage *message) {
     const GstStructure *s = gst_message_get_structure(message);
     int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
   bool setStatus(QtCamAutoFocus::Status *status, GstMessage *message) {
     const GstStructure *s = gst_message_get_structure(message);
     int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
-
     if (gst_structure_get_int(s, "status", &st)) {
       if (*status != st) {
        *status = (QtCamAutoFocus::Status) st;
     if (gst_structure_get_int(s, "status", &st)) {
       if (*status != st) {
        *status = (QtCamAutoFocus::Status) st;
index 31afe41..89ffbd3 100644 (file)
@@ -207,3 +207,7 @@ QString QtCamConfig::videoRecordingStartedSound() const {
 QString QtCamConfig::videoRecordingEndedSound() const {
   return d_ptr->conf->value("sounds/videoRecordingEnded").toString();
 }
 QString QtCamConfig::videoRecordingEndedSound() const {
   return d_ptr->conf->value("sounds/videoRecordingEnded").toString();
 }
+
+QString QtCamConfig::autoFocusAcquiredSound() const {
+  return d_ptr->conf->value("sounds/autoFocusAcquired").toString();
+}
index ec9b8f6..650f479 100644 (file)
@@ -74,6 +74,7 @@ public:
   QString imageCaptureEndedSound() const;
   QString videoRecordingStartedSound() const;
   QString videoRecordingEndedSound() const;
   QString imageCaptureEndedSound() const;
   QString videoRecordingStartedSound() const;
   QString videoRecordingEndedSound() const;
+  QString autoFocusAcquiredSound() const;
 
 private:
   QtCamConfigPrivate *d_ptr;
 
 private:
   QtCamConfigPrivate *d_ptr;
index 5b50c0e..a147ade 100644 (file)
  */
 
 #include "qtcamnotifications.h"
  */
 
 #include "qtcamnotifications.h"
-#include "qtcamgstreamermessagehandler.h"
-#include "qtcamgstreamermessagelistener.h"
+#include "qtcamnotifications_p.h"
 #include "qtcamdevice.h"
 #include "qtcamdevice.h"
-#include <QPointer>
-
-class QtCamNotificationsPrivate {
-public:
-  QtCamDevice *dev;
-  QPointer<QtCamGStreamerMessageHandler> imageStart;
-  QPointer<QtCamGStreamerMessageHandler> imageEnd;
-
-  QPointer<QtCamGStreamerMessageHandler> videoDone;
-  QPointer<QtCamGStreamerMessageListener> listener;
-};
 
 QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
   QObject(parent), d_ptr(new QtCamNotificationsPrivate) {
 
 QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
   QObject(parent), d_ptr(new QtCamNotificationsPrivate) {
+
+  d_ptr->q_ptr = this;
   d_ptr->dev = dev;
 
   d_ptr->listener = dev->listener();
   d_ptr->dev = dev;
 
   d_ptr->listener = dev->listener();
@@ -43,6 +33,8 @@ QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
   d_ptr->imageEnd = new QtCamGStreamerMessageHandler("photo-capture-end", this);
   d_ptr->videoDone = new QtCamGStreamerMessageHandler("video-done", this);
 
   d_ptr->imageEnd = new QtCamGStreamerMessageHandler("photo-capture-end", this);
   d_ptr->videoDone = new QtCamGStreamerMessageHandler("video-done", this);
 
+  d_ptr->af = new QtCamAutoFocus(dev, this);
+
   if (d_ptr->listener) {
     d_ptr->listener->addSyncHandler(d_ptr->imageStart);
     d_ptr->listener->addHandler(d_ptr->imageEnd);
   if (d_ptr->listener) {
     d_ptr->listener->addSyncHandler(d_ptr->imageStart);
     d_ptr->listener->addHandler(d_ptr->imageEnd);
@@ -57,6 +49,8 @@ QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
 
   QObject::connect(d_ptr->videoDone, SIGNAL(messageSent(GstMessage *)),
                   this, SIGNAL(videoRecordingEnded()), Qt::DirectConnection);
 
   QObject::connect(d_ptr->videoDone, SIGNAL(messageSent(GstMessage *)),
                   this, SIGNAL(videoRecordingEnded()), Qt::DirectConnection);
+
+  QObject::connect(d_ptr->af, SIGNAL(statusChanged()), this, SLOT(autoFocusStatusChanged()));
 }
 
 QtCamNotifications::~QtCamNotifications() {
 }
 
 QtCamNotifications::~QtCamNotifications() {
@@ -69,5 +63,9 @@ QtCamNotifications::~QtCamNotifications() {
   delete d_ptr->imageStart.data();
   delete d_ptr->imageEnd.data();
 
   delete d_ptr->imageStart.data();
   delete d_ptr->imageEnd.data();
 
+  delete d_ptr->af;
+
   delete d_ptr; d_ptr = 0;
 }
   delete d_ptr; d_ptr = 0;
 }
+
+#include "moc_qtcamnotifications.cpp"
index 395d004..784ab61 100644 (file)
@@ -31,6 +31,8 @@ class QtCamDevice;
 class QtCamNotifications : public QObject {
   Q_OBJECT
 
 class QtCamNotifications : public QObject {
   Q_OBJECT
 
+  friend class QtCamNotificationsPrivate;
+
 public:
   QtCamNotifications(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamNotifications();
 public:
   QtCamNotifications(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamNotifications();
@@ -44,7 +46,11 @@ signals:
   void videoRecordingStarted();
   void videoRecordingEnded();
 
   void videoRecordingStarted();
   void videoRecordingEnded();
 
+  void autoFocusAcquired();
+
 private:
 private:
+  Q_PRIVATE_SLOT(d_ptr, void autoFocusStatusChanged());
+
   QtCamNotificationsPrivate *d_ptr;
 };
 
   QtCamNotificationsPrivate *d_ptr;
 };
 
diff --git a/lib/qtcamnotifications_p.h b/lib/qtcamnotifications_p.h
new file mode 100644 (file)
index 0000000..c61c535
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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 Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef QT_CAM_NOTIFICATIONS_P_H
+#define QT_CAM_NOTIFICATIONS_P_H
+
+#include <QPointer>
+#include "qtcamautofocus.h"
+#include "qtcamgstreamermessagehandler.h"
+#include "qtcamgstreamermessagelistener.h"
+#include "qtcamnotifications.h"
+
+class QtCamNotificationsPrivate : public QObject {
+  Q_OBJECT
+
+public:
+  QtCamDevice *dev;
+  QPointer<QtCamGStreamerMessageHandler> imageStart;
+  QPointer<QtCamGStreamerMessageHandler> imageEnd;
+
+  QPointer<QtCamGStreamerMessageHandler> videoDone;
+  QPointer<QtCamGStreamerMessageListener> listener;
+  QPointer<QtCamAutoFocus> af;
+
+  QtCamNotifications *q_ptr;
+
+public slots:
+  void autoFocusStatusChanged() {
+    if (af->status() == QtCamAutoFocus::Success) {
+      emit q_ptr->autoFocusAcquired();
+    }
+  }
+};
+
+#endif /* QT_CAM_NOTIFICATIONS_P_H */