5b50c0efaf479ff40adeb6f827f89a5cd0dc5e1a
[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 "qtcamgstreamermessagehandler.h"
23 #include "qtcamgstreamermessagelistener.h"
24 #include "qtcamdevice.h"
25 #include <QPointer>
26
27 class QtCamNotificationsPrivate {
28 public:
29   QtCamDevice *dev;
30   QPointer<QtCamGStreamerMessageHandler> imageStart;
31   QPointer<QtCamGStreamerMessageHandler> imageEnd;
32
33   QPointer<QtCamGStreamerMessageHandler> videoDone;
34   QPointer<QtCamGStreamerMessageListener> listener;
35 };
36
37 QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
38   QObject(parent), d_ptr(new QtCamNotificationsPrivate) {
39   d_ptr->dev = dev;
40
41   d_ptr->listener = dev->listener();
42   d_ptr->imageStart = new QtCamGStreamerMessageHandler("photo-capture-start", this);
43   d_ptr->imageEnd = new QtCamGStreamerMessageHandler("photo-capture-end", this);
44   d_ptr->videoDone = new QtCamGStreamerMessageHandler("video-done", this);
45
46   if (d_ptr->listener) {
47     d_ptr->listener->addSyncHandler(d_ptr->imageStart);
48     d_ptr->listener->addHandler(d_ptr->imageEnd);
49     d_ptr->listener->addHandler(d_ptr->videoDone);
50   }
51
52   QObject::connect(d_ptr->imageStart, SIGNAL(messageSent(GstMessage *)),
53                    this, SIGNAL(imageCaptureStarted()), Qt::DirectConnection);
54
55   QObject::connect(d_ptr->imageEnd, SIGNAL(messageSent(GstMessage *)),
56                    this, SIGNAL(imageCaptureEnded()), Qt::DirectConnection);
57
58   QObject::connect(d_ptr->videoDone, SIGNAL(messageSent(GstMessage *)),
59                    this, SIGNAL(videoRecordingEnded()), Qt::DirectConnection);
60 }
61
62 QtCamNotifications::~QtCamNotifications() {
63   if (d_ptr->listener) {
64     d_ptr->listener->removeSyncHandler(d_ptr->imageStart);
65     d_ptr->listener->removeHandler(d_ptr->imageEnd);
66     d_ptr->listener->removeHandler(d_ptr->videoDone);
67   }
68
69   delete d_ptr->imageStart.data();
70   delete d_ptr->imageEnd.data();
71
72   delete d_ptr; d_ptr = 0;
73 }