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