From 895498a17049de7244e8bc6e6f8031388a1da209 Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Sat, 15 Dec 2012 03:15:10 +0200 Subject: [PATCH] Added notification when focus gets acquired --- data/n9/qtcamera.ini | 1 + imports/notifications.h | 1 + imports/notificationscontainer.cpp | 11 ++++++ imports/notificationscontainer.h | 1 + imports/sounds.cpp | 18 +++++++--- imports/sounds.h | 1 + lib/lib.pro | 2 +- lib/qtcamautofocus_p.h | 1 - lib/qtcamconfig.cpp | 4 +++ lib/qtcamconfig.h | 1 + lib/qtcamnotifications.cpp | 24 ++++++------- lib/qtcamnotifications.h | 6 ++++ lib/qtcamnotifications_p.h | 54 ++++++++++++++++++++++++++++++ 13 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 lib/qtcamnotifications_p.h diff --git a/data/n9/qtcamera.ini b/data/n9/qtcamera.ini index 95d5d9d..c3515e8 100644 --- a/data/n9/qtcamera.ini +++ b/data/n9/qtcamera.ini @@ -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 +autoFocusAcquired = /usr/share/sounds/ui-tones//snd_camera_af.wav diff --git a/imports/notifications.h b/imports/notifications.h index 6b429f7..071c5df 100644 --- a/imports/notifications.h +++ b/imports/notifications.h @@ -34,6 +34,7 @@ public: 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"); diff --git a/imports/notificationscontainer.cpp b/imports/notificationscontainer.cpp index 4f5ee5f..309baff 100644 --- a/imports/notificationscontainer.cpp +++ b/imports/notificationscontainer.cpp @@ -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(autoFocusAcquired()), this, SLOT(autoFocusAcquired())); } 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); + QObject::connect(n, SIGNAL(autoFocusAcquired()), + this, SLOT(autoFocusAcquired()), Qt::DirectConnection); } } @@ -105,3 +108,11 @@ void NotificationsContainer::videoRecordingEnded() { m_notifications->videoRecordingEnded(); } } + +void NotificationsContainer::autoFocusAcquired() { + QMutexLocker l(&m_mutex); + + if (m_notifications) { + m_notifications->autoFocusAcquired(); + } +} diff --git a/imports/notificationscontainer.h b/imports/notificationscontainer.h index b59038d..b6adda3 100644 --- a/imports/notificationscontainer.h +++ b/imports/notificationscontainer.h @@ -46,6 +46,7 @@ private slots: void imageCaptureEnded(); void videoRecordingStarted(); void videoRecordingEnded(); + void autoFocusAcquired(); private: QPointer m_dev; diff --git a/imports/sounds.cpp b/imports/sounds.cpp index 87d80cd..46b9984 100644 --- a/imports/sounds.cpp +++ b/imports/sounds.cpp @@ -24,10 +24,11 @@ #include #include -#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" @@ -88,6 +89,14 @@ void Sounds::videoRecordingEnded() { 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; } @@ -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->autoFocusAcquiredSound(), CAMERA_FOCUS_SOUND_ID); } void Sounds::cache(const QString& path, const char *id) { diff --git a/imports/sounds.h b/imports/sounds.h index 5f1c0eb..dfa56db 100644 --- a/imports/sounds.h +++ b/imports/sounds.h @@ -43,6 +43,7 @@ public: void imageCaptureEnded(); void videoRecordingStarted(); void videoRecordingEnded(); + void autoFocusAcquired(); bool isMuted() const; void setMuted(bool mute); diff --git a/lib/lib.pro b/lib/lib.pro index 17f6b05..b0531f5 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -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 -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 diff --git a/lib/qtcamautofocus_p.h b/lib/qtcamautofocus_p.h index deade4c..64aabb5 100644 --- a/lib/qtcamautofocus_p.h +++ b/lib/qtcamautofocus_p.h @@ -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; - if (gst_structure_get_int(s, "status", &st)) { if (*status != st) { *status = (QtCamAutoFocus::Status) st; diff --git a/lib/qtcamconfig.cpp b/lib/qtcamconfig.cpp index 31afe41..89ffbd3 100644 --- a/lib/qtcamconfig.cpp +++ b/lib/qtcamconfig.cpp @@ -207,3 +207,7 @@ QString QtCamConfig::videoRecordingStartedSound() const { QString QtCamConfig::videoRecordingEndedSound() const { return d_ptr->conf->value("sounds/videoRecordingEnded").toString(); } + +QString QtCamConfig::autoFocusAcquiredSound() const { + return d_ptr->conf->value("sounds/autoFocusAcquired").toString(); +} diff --git a/lib/qtcamconfig.h b/lib/qtcamconfig.h index ec9b8f6..650f479 100644 --- a/lib/qtcamconfig.h +++ b/lib/qtcamconfig.h @@ -74,6 +74,7 @@ public: QString imageCaptureEndedSound() const; QString videoRecordingStartedSound() const; QString videoRecordingEndedSound() const; + QString autoFocusAcquiredSound() const; private: QtCamConfigPrivate *d_ptr; diff --git a/lib/qtcamnotifications.cpp b/lib/qtcamnotifications.cpp index 5b50c0e..a147ade 100644 --- a/lib/qtcamnotifications.cpp +++ b/lib/qtcamnotifications.cpp @@ -19,23 +19,13 @@ */ #include "qtcamnotifications.h" -#include "qtcamgstreamermessagehandler.h" -#include "qtcamgstreamermessagelistener.h" +#include "qtcamnotifications_p.h" #include "qtcamdevice.h" -#include - -class QtCamNotificationsPrivate { -public: - QtCamDevice *dev; - QPointer imageStart; - QPointer imageEnd; - - QPointer videoDone; - QPointer listener; -}; 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(); @@ -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->af = new QtCamAutoFocus(dev, this); + 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->af, SIGNAL(statusChanged()), this, SLOT(autoFocusStatusChanged())); } QtCamNotifications::~QtCamNotifications() { @@ -69,5 +63,9 @@ QtCamNotifications::~QtCamNotifications() { delete d_ptr->imageStart.data(); delete d_ptr->imageEnd.data(); + delete d_ptr->af; + delete d_ptr; d_ptr = 0; } + +#include "moc_qtcamnotifications.cpp" diff --git a/lib/qtcamnotifications.h b/lib/qtcamnotifications.h index 395d004..784ab61 100644 --- a/lib/qtcamnotifications.h +++ b/lib/qtcamnotifications.h @@ -31,6 +31,8 @@ class QtCamDevice; class QtCamNotifications : public QObject { Q_OBJECT + friend class QtCamNotificationsPrivate; + public: QtCamNotifications(QtCamDevice *dev, QObject *parent = 0); ~QtCamNotifications(); @@ -44,7 +46,11 @@ signals: void videoRecordingStarted(); void videoRecordingEnded(); + void autoFocusAcquired(); + private: + Q_PRIVATE_SLOT(d_ptr, void autoFocusStatusChanged()); + QtCamNotificationsPrivate *d_ptr; }; diff --git a/lib/qtcamnotifications_p.h b/lib/qtcamnotifications_p.h new file mode 100644 index 0000000..c61c535 --- /dev/null +++ b/lib/qtcamnotifications_p.h @@ -0,0 +1,54 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012 Mohammed Sameer + * + * 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 +#include "qtcamautofocus.h" +#include "qtcamgstreamermessagehandler.h" +#include "qtcamgstreamermessagelistener.h" +#include "qtcamnotifications.h" + +class QtCamNotificationsPrivate : public QObject { + Q_OBJECT + +public: + QtCamDevice *dev; + QPointer imageStart; + QPointer imageEnd; + + QPointer videoDone; + QPointer listener; + QPointer af; + + QtCamNotifications *q_ptr; + +public slots: + void autoFocusStatusChanged() { + if (af->status() == QtCamAutoFocus::Success) { + emit q_ptr->autoFocusAcquired(); + } + } +}; + +#endif /* QT_CAM_NOTIFICATIONS_P_H */ -- 2.25.1