silence dbus-send output
[harmattan/cameraplus] / lib / qtcamflash_p.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef QT_CAM_FLASH_P_H
24 #define QT_CAM_FLASH_P_H
25
26 #include <QObject>
27 #include "qtcamcapability_p.h"
28 #include "qtcamdevice.h"
29 #include "qtcamgstreamermessagelistener.h"
30 #include "qtcamgstreamermessagehandler.h"
31 #include <QDebug>
32
33 // subdevsrc ./gst-libs/gst/camera/gstcamerasrc2.h
34 #define FLASH_STATUS_READY        0
35 #define FLASH_STATUS_NOT_READY    1
36
37 class QtCamFlashPrivate : public QObject, public QtCamCapabilityPrivate {
38   Q_OBJECT
39
40 public:
41   QtCamFlashPrivate(QtCamDevice *dev, QObject *parent = 0) :
42     QObject(parent),
43     QtCamCapabilityPrivate(dev, QtCamCapability::Flash, "flash-mode"),
44     ready(true) {
45
46   }
47
48   ~QtCamFlashPrivate() {
49
50   }
51
52   void init() {
53     QtCamGStreamerMessageListener *listener = dev->listener();
54     if (!listener) {
55       qWarning() << "Failed to get device listener. flash ready status will not be available";
56       return;
57     }
58
59     QtCamGStreamerMessageHandler *handler = new QtCamGStreamerMessageHandler("flash-status", this);
60     QObject::connect(handler, SIGNAL(messageSent(GstMessage *)),
61                      this, SLOT(messageSent(GstMessage *)));
62     listener->addHandler(handler);
63   }
64
65   bool isReady() const {
66     return ready;
67   }
68
69 signals:
70   void flashReadyChanged();
71
72 private slots:
73   void messageSent(GstMessage *message) {
74     const GstStructure *s = gst_message_get_structure(message);
75     if (QLatin1String("flash-status") != QLatin1String(gst_structure_get_name(s))) {
76       return;
77     }
78
79     int status = FLASH_STATUS_NOT_READY;
80     if (!gst_structure_get_int(s, "status", &status)) {
81       return;
82     }
83
84     bool newStatus = (status == FLASH_STATUS_READY);
85
86     if (ready != newStatus) {
87       ready = newStatus;
88       emit flashReadyChanged();
89     }
90   }
91
92 private:
93   bool ready;
94 };
95
96 #endif /* QT_CAM_FLASH_P_H */