Create a QDeclarativeItem Viewfinder subclass
[harmattan/cameraplus] / declarative / notificationscontainer.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "notificationscontainer.h"
22 #include "qtcamdevice.h"
23 #include "qtcamnotifications.h"
24 #include "sounds.h"
25
26 NotificationsContainer::NotificationsContainer(QObject *parent) :
27   QObject(parent), m_dev(0), m_sounds(0) {
28
29 }
30
31 NotificationsContainer::~NotificationsContainer() {
32   setDevice(0);
33
34   QMutexLocker locker(&m_mutex);
35   m_sounds = 0;
36 }
37
38 void NotificationsContainer::setDevice(QtCamDevice *dev) {
39   if (m_dev) {
40     QtCamNotifications *n = m_dev->notifications();
41     QObject::disconnect(n, SIGNAL(imageCaptureStarted()), this, SLOT(imageCaptureStarted()));
42     QObject::disconnect(n, SIGNAL(imageCaptureEnded()), this, SLOT(imageCaptureEnded()));
43     QObject::disconnect(n, SIGNAL(videoRecordingStarted()), this, SLOT(videoRecordingStarted()));
44     QObject::disconnect(n, SIGNAL(videoRecordingEnded()), this, SLOT(videoRecordingEnded()));
45     QObject::disconnect(n, SIGNAL(autoFocusAcquired()), this, SLOT(autoFocusAcquired()));
46   }
47
48   m_dev = dev;
49
50   if (m_dev) {
51     QtCamNotifications *n = m_dev->notifications();
52     QObject::connect(n, SIGNAL(imageCaptureStarted()),
53                      this, SLOT(imageCaptureStarted()), Qt::DirectConnection);
54     QObject::connect(n, SIGNAL(imageCaptureEnded()),
55                      this, SLOT(imageCaptureEnded()), Qt::DirectConnection);
56     QObject::connect(n, SIGNAL(videoRecordingStarted()),
57                      this, SLOT(videoRecordingStarted()), Qt::DirectConnection);
58     QObject::connect(n, SIGNAL(videoRecordingEnded()),
59                      this, SLOT(videoRecordingEnded()), Qt::DirectConnection);
60     QObject::connect(n, SIGNAL(autoFocusAcquired()),
61                      this, SLOT(autoFocusAcquired()), Qt::DirectConnection);
62   }
63 }
64
65 Sounds *NotificationsContainer::sounds() const {
66   return m_sounds;
67 }
68
69 bool NotificationsContainer::setSounds(Sounds *sounds) {
70   QMutexLocker lock(&m_mutex);
71
72   if (m_sounds != sounds) {
73     m_sounds = sounds;
74     return true;
75   }
76
77   return false;
78 }
79
80 void NotificationsContainer::imageCaptureStarted() {
81   QMutexLocker l(&m_mutex);
82
83   if (m_sounds) {
84     m_sounds->playImageCaptureStartedSound();
85   }
86 }
87
88 void NotificationsContainer::imageCaptureEnded() {
89   QMutexLocker l(&m_mutex);
90
91   if (m_sounds) {
92     m_sounds->playImageCaptureEndedSound();
93   }
94 }
95
96 void NotificationsContainer::videoRecordingStarted() {
97   QMutexLocker l(&m_mutex);
98
99   if (m_sounds) {
100     m_sounds->playVideoRecordingStartedSound();
101   }
102 }
103
104 void NotificationsContainer::videoRecordingEnded() {
105   QMutexLocker l(&m_mutex);
106
107   if (m_sounds) {
108     m_sounds->playVideoRecordingEndedSound();
109   }
110 }
111
112 void NotificationsContainer::autoFocusAcquired() {
113   QMutexLocker l(&m_mutex);
114
115   if (m_sounds) {
116     m_sounds->playAutoFocusAcquiredSound();
117   }
118 }