Added copyright headers and COPYING file.
[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   void startMonitoring() {
58     if (src) {
59       QString p = QString("notify::%1").arg(prop);
60       handler = g_signal_connect(src, p.toAscii().data(), G_CALLBACK(camera_src_notify), this);
61     }
62   }
63
64   void stopMonitoring() {
65     if (src) {
66       g_signal_handler_disconnect(src, handler);
67     }
68   }
69
70   bool uintValue(unsigned int *val) {
71     if (!src) {
72       return false;
73     }
74
75     g_object_get(src, prop.toAscii().data(), val, NULL);
76
77     return true;
78   }
79
80   bool setUintValue(unsigned int val) {
81     if (!src) {
82       return false;
83     }
84
85     g_object_set(src, prop.toAscii().data(), val, NULL);
86
87     return true;
88   }
89
90   bool intValue(int *val) {
91     if (!src) {
92       return false;
93     }
94
95     g_object_get(src, prop.toAscii().data(), val, NULL);
96
97     return true;
98   }
99
100   bool setIntValue(int val, bool force) {
101     if (!src) {
102       return false;
103     }
104
105     if (force) {
106       g_object_set(src, prop.toAscii().data(), val, NULL);
107       return true;
108     }
109
110     int old = 0;
111     g_object_get(src, prop.toAscii().data(), &old, NULL);
112
113     if (old != val) {
114       g_object_set(src, prop.toAscii().data(), val, NULL);
115     }
116
117     return true;
118   }
119
120   bool floatValue(qreal *val) {
121     if (!src) {
122       return false;
123     }
124
125     g_object_get(src, prop.toAscii().data(), val, NULL);
126
127     return true;
128   }
129
130   bool setFloatValue(qreal val) {
131     if (!src) {
132       return false;
133     }
134
135     g_object_set(src, prop.toAscii().data(), val, NULL);
136
137     return true;
138   }
139
140   static void camera_src_notify(GObject *gobject, GParamSpec *pspec, QtCamCapabilityPrivate *d) {
141     Q_UNUSED(gobject);
142     Q_UNUSED(pspec);
143
144     QMetaObject::invokeMethod(d->q_ptr, "valueChanged", Qt::QueuedConnection);
145   }
146
147   QtCamDevice *dev;
148   QtCamCapability::Capability cap;
149   QString prop;
150   GstElement *bin;
151   GstElement *src;
152   gulong handler;
153   QtCamCapability *q_ptr;
154 };
155
156 #endif /* QT_CAM_CAPABILITY_P_H */