Hide focus reticle if we cannot focus while a particular scene mode is active
[harmattan/cameraplus] / lib / qtcamcapability_p.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 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_CAPABILITY_P_H
24 #define QT_CAM_CAPABILITY_P_H
25
26 #include <gst/gst.h>
27 #include "qtcamdevice.h"
28 #include "qtcamdevice_p.h"
29
30 class QtCamCapabilityPrivate {
31 public:
32   QtCamCapabilityPrivate(QtCamDevice *d, const QtCamCapability::Capability& c, const QString& p) :
33     dev(d),
34     cap(c),
35     prop(p),
36     bin(0),
37     src(0),
38     handler(0),
39     q_ptr(0) {
40
41   }
42
43   QtCamCapabilityPrivate(QtCamDevice *d, const QtCamCapability::Capability& c) :
44     dev(d),
45     cap(c),
46     bin(0),
47     src(0),
48     handler(0),
49     q_ptr(0) {
50
51   }
52
53   virtual ~QtCamCapabilityPrivate() {
54
55   }
56
57   GParamSpec *paramSpec() {
58     if (!src || prop.isEmpty()) {
59       return 0;
60     }
61
62     return g_object_class_find_property(G_OBJECT_GET_CLASS(src), prop.toUtf8().constData());
63   }
64
65   void startMonitoring() {
66     if (src) {
67       QString p = QString("notify::%1").arg(prop);
68       handler = g_signal_connect(src, p.toAscii().data(), G_CALLBACK(camera_src_notify), this);
69     }
70   }
71
72   void stopMonitoring() {
73     if (src) {
74       g_signal_handler_disconnect(src, handler);
75     }
76   }
77
78   bool uintValue(unsigned int *val) {
79     if (!src) {
80       return false;
81     }
82
83     g_object_get(src, prop.toAscii().data(), val, NULL);
84
85     return true;
86   }
87
88   bool setUintValue(unsigned int val) {
89     if (!src) {
90       return false;
91     }
92
93     g_object_set(src, prop.toAscii().data(), val, NULL);
94
95     return true;
96   }
97
98   bool intValue(int *val) {
99     if (!src) {
100       return false;
101     }
102
103     g_object_get(src, prop.toAscii().data(), val, NULL);
104
105     return true;
106   }
107
108   bool setIntValue(int val, bool force) {
109     if (!src) {
110       return false;
111     }
112
113     if (force) {
114       g_object_set(src, prop.toAscii().data(), val, NULL);
115       return true;
116     }
117
118     int old = 0;
119     g_object_get(src, prop.toAscii().data(), &old, NULL);
120
121     if (old != val) {
122       g_object_set(src, prop.toAscii().data(), val, NULL);
123     }
124
125     return true;
126   }
127
128   bool floatValue(qreal *val) {
129     if (!src) {
130       return false;
131     }
132
133     g_object_get(src, prop.toAscii().data(), val, NULL);
134
135     return true;
136   }
137
138   bool setFloatValue(qreal val) {
139     if (!src) {
140       return false;
141     }
142
143     g_object_set(src, prop.toAscii().data(), val, NULL);
144
145     return true;
146   }
147
148   static void camera_src_notify(GObject *gobject, GParamSpec *pspec, QtCamCapabilityPrivate *d) {
149     Q_UNUSED(gobject);
150     Q_UNUSED(pspec);
151
152     QMetaObject::invokeMethod(d->q_ptr, "valueChanged", Qt::QueuedConnection);
153   }
154
155   QtCamDevice *dev;
156   QtCamCapability::Capability cap;
157   QString prop;
158   GstElement *bin;
159   GstElement *src;
160   gulong handler;
161   QtCamCapability *q_ptr;
162 };
163
164 #endif /* QT_CAM_CAPABILITY_P_H */