4f5ee5f91358c6ab97be8963031548ca4b6342e0
[harmattan/cameraplus] / imports / notificationscontainer.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 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 "notifications.h"
25
26 NotificationsContainer::NotificationsContainer(QObject *parent) :
27   QObject(parent), m_dev(0), m_notifications(0) {
28
29 }
30
31 NotificationsContainer::~NotificationsContainer() {
32   setDevice(0);
33
34   QMutexLocker locker(&m_mutex);
35   m_notifications = 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   }
46
47   m_dev = dev;
48
49   if (m_dev) {
50     QtCamNotifications *n = m_dev->notifications();
51     QObject::connect(n, SIGNAL(imageCaptureStarted()),
52                      this, SLOT(imageCaptureStarted()), Qt::DirectConnection);
53     QObject::connect(n, SIGNAL(imageCaptureEnded()),
54                      this, SLOT(imageCaptureEnded()), Qt::DirectConnection);
55     QObject::connect(n, SIGNAL(videoRecordingStarted()),
56                      this, SLOT(videoRecordingStarted()), Qt::DirectConnection);
57     QObject::connect(n, SIGNAL(videoRecordingEnded()),
58                      this, SLOT(videoRecordingEnded()), Qt::DirectConnection);
59   }
60 }
61
62 Notifications *NotificationsContainer::notifications() const {
63   return m_notifications;
64 }
65
66 bool NotificationsContainer::setNotifications(Notifications *notifications) {
67   QMutexLocker lock(&m_mutex);
68
69   if (m_notifications != notifications) {
70     m_notifications = notifications;
71     return true;
72   }
73
74   return false;
75 }
76
77 void NotificationsContainer::imageCaptureStarted() {
78   QMutexLocker l(&m_mutex);
79
80   if (m_notifications) {
81     m_notifications->imageCaptureStarted();
82   }
83 }
84
85 void NotificationsContainer::imageCaptureEnded() {
86   QMutexLocker l(&m_mutex);
87
88   if (m_notifications) {
89     m_notifications->imageCaptureEnded();
90   }
91 }
92
93 void NotificationsContainer::videoRecordingStarted() {
94   QMutexLocker l(&m_mutex);
95
96   if (m_notifications) {
97     m_notifications->videoRecordingStarted();
98   }
99 }
100
101 void NotificationsContainer::videoRecordingEnded() {
102   QMutexLocker l(&m_mutex);
103
104   if (m_notifications) {
105     m_notifications->videoRecordingEnded();
106   }
107 }