Source /tmp/session_bus_address.user before invoking dbus-send in postinst script
[harmattan/cameraplus] / lib / qtcamnotifications.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 "qtcamnotifications.h"
22 #include "qtcamnotifications_p.h"
23 #include "qtcamdevice.h"
24 #include "qtcamdevice_p.h"
25 #include "qtcamimagemode.h"
26 #ifndef GST_USE_UNSTABLE_API
27 #define GST_USE_UNSTABLE_API
28 #endif /* GST_USE_UNSTABLE_API */
29 #include <gst/interfaces/photography.h>
30
31 QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
32   QObject(parent), d_ptr(new QtCamNotificationsPrivate) {
33
34   d_ptr->q_ptr = this;
35   d_ptr->dev = dev;
36
37   d_ptr->listener = dev->listener();
38   d_ptr->imageStart = new QtCamGStreamerMessageHandler("photo-capture-start", this);
39   d_ptr->imageEnd = new QtCamGStreamerMessageHandler("photo-capture-end", this);
40   d_ptr->videoDone = new QtCamGStreamerMessageHandler("video-done", this);
41   d_ptr->af = new QtCamGStreamerMessageHandler(GST_PHOTOGRAPHY_AUTOFOCUS_DONE, this);
42
43   if (d_ptr->listener) {
44     d_ptr->listener->addSyncHandler(d_ptr->imageStart);
45     d_ptr->listener->addHandler(d_ptr->imageEnd);
46     d_ptr->listener->addHandler(d_ptr->videoDone);
47     d_ptr->listener->addHandler(d_ptr->af);
48   }
49
50   QObject::connect(d_ptr->imageStart, SIGNAL(messageSent(GstMessage *)),
51                    this, SIGNAL(imageCaptureStarted()), Qt::DirectConnection);
52
53   QObject::connect(d_ptr->imageEnd, SIGNAL(messageSent(GstMessage *)),
54                    this, SIGNAL(imageCaptureEnded()), Qt::DirectConnection);
55
56   QObject::connect(d_ptr->videoDone, SIGNAL(messageSent(GstMessage *)),
57                    this, SIGNAL(videoRecordingEnded()), Qt::DirectConnection);
58
59   QObject::connect(d_ptr->af, SIGNAL(messageSent(GstMessage *)),
60                    this, SLOT(autoFocusStatusChanged(GstMessage *)));
61
62   QObject::connect(d_ptr->imageStart, SIGNAL(messageSent(GstMessage *)),
63                    d_ptr->dev->d_ptr->image, SIGNAL(captureStarted()), Qt::AutoConnection);
64   QObject::connect(d_ptr->imageEnd, SIGNAL(messageSent(GstMessage *)),
65                    d_ptr->dev->d_ptr->image, SIGNAL(captureEnded()), Qt::AutoConnection);
66 }
67
68 QtCamNotifications::~QtCamNotifications() {
69   if (d_ptr->listener) {
70     d_ptr->listener->removeSyncHandler(d_ptr->imageStart);
71     d_ptr->listener->removeHandler(d_ptr->imageEnd);
72     d_ptr->listener->removeHandler(d_ptr->videoDone);
73     d_ptr->listener->removeHandler(d_ptr->af);
74   }
75
76   delete d_ptr->imageStart.data();
77   delete d_ptr->imageEnd.data();
78   delete d_ptr->videoDone.data();
79   delete d_ptr->af.data();
80
81   delete d_ptr; d_ptr = 0;
82 }
83
84 #include "moc_qtcamnotifications.cpp"