Added notification when focus gets acquired
[harmattan/cameraplus] / lib / qtcamnotifications.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 "qtcamnotifications.h"
22 #include "qtcamnotifications_p.h"
23 #include "qtcamdevice.h"
24
25 QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
26   QObject(parent), d_ptr(new QtCamNotificationsPrivate) {
27
28   d_ptr->q_ptr = this;
29   d_ptr->dev = dev;
30
31   d_ptr->listener = dev->listener();
32   d_ptr->imageStart = new QtCamGStreamerMessageHandler("photo-capture-start", this);
33   d_ptr->imageEnd = new QtCamGStreamerMessageHandler("photo-capture-end", this);
34   d_ptr->videoDone = new QtCamGStreamerMessageHandler("video-done", this);
35
36   d_ptr->af = new QtCamAutoFocus(dev, this);
37
38   if (d_ptr->listener) {
39     d_ptr->listener->addSyncHandler(d_ptr->imageStart);
40     d_ptr->listener->addHandler(d_ptr->imageEnd);
41     d_ptr->listener->addHandler(d_ptr->videoDone);
42   }
43
44   QObject::connect(d_ptr->imageStart, SIGNAL(messageSent(GstMessage *)),
45                    this, SIGNAL(imageCaptureStarted()), Qt::DirectConnection);
46
47   QObject::connect(d_ptr->imageEnd, SIGNAL(messageSent(GstMessage *)),
48                    this, SIGNAL(imageCaptureEnded()), Qt::DirectConnection);
49
50   QObject::connect(d_ptr->videoDone, SIGNAL(messageSent(GstMessage *)),
51                    this, SIGNAL(videoRecordingEnded()), Qt::DirectConnection);
52
53   QObject::connect(d_ptr->af, SIGNAL(statusChanged()), this, SLOT(autoFocusStatusChanged()));
54 }
55
56 QtCamNotifications::~QtCamNotifications() {
57   if (d_ptr->listener) {
58     d_ptr->listener->removeSyncHandler(d_ptr->imageStart);
59     d_ptr->listener->removeHandler(d_ptr->imageEnd);
60     d_ptr->listener->removeHandler(d_ptr->videoDone);
61   }
62
63   delete d_ptr->imageStart.data();
64   delete d_ptr->imageEnd.data();
65
66   delete d_ptr->af;
67
68   delete d_ptr; d_ptr = 0;
69 }
70
71 #include "moc_qtcamnotifications.cpp"