4cc43a9ce611b0d7018ef9abd6814883f11e43e1
[harmattan/cameraplus] / lib / qtcamcapability_p.h
1 // -*- c++ -*-
2
3 #ifndef QT_CAM_CAPABILITY_P_H
4 #define QT_CAM_CAPABILITY_P_H
5
6 #include <gst/gst.h>
7 #include "qtcamdevice.h"
8 #include "qtcamdevice_p.h"
9
10 class QtCamCapabilityPrivate {
11 public:
12   QtCamCapabilityPrivate(QtCamDevice *d, const QtCamCapability::Capability& c, const QString& p) :
13     dev(d),
14     cap(c),
15     prop(p),
16     bin(0),
17     src(0),
18     handler(0),
19     q_ptr(0) {
20
21   }
22
23   QtCamCapabilityPrivate(QtCamDevice *d, const QtCamCapability::Capability& c) :
24     dev(d),
25     cap(c),
26     bin(0),
27     src(0),
28     handler(0),
29     q_ptr(0) {
30
31   }
32
33   virtual ~QtCamCapabilityPrivate() {
34
35   }
36
37   void startMonitoring() {
38     if (src) {
39       QString p = QString("notify::%1").arg(prop);
40       handler = g_signal_connect(src, p.toAscii().data(), G_CALLBACK(camera_src_notify), this);
41     }
42   }
43
44   void stopMonitoring() {
45     if (src) {
46       g_signal_handler_disconnect(src, handler);
47     }
48   }
49
50   bool uintValue(unsigned int *val) {
51     if (!src) {
52       return false;
53     }
54
55     g_object_get(src, prop.toAscii().data(), val, NULL);
56
57     return true;
58   }
59
60   bool setUintValue(unsigned int val) {
61     if (!src) {
62       return false;
63     }
64
65     g_object_set(src, prop.toAscii().data(), val, NULL);
66
67     return true;
68   }
69
70   bool intValue(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 setIntValue(int val, bool force) {
81     if (!src) {
82       return false;
83     }
84
85     if (force) {
86       g_object_set(src, prop.toAscii().data(), val, NULL);
87       return true;
88     }
89
90     int old = 0;
91     g_object_get(src, prop.toAscii().data(), &old, NULL);
92
93     if (old != val) {
94       g_object_set(src, prop.toAscii().data(), val, NULL);
95     }
96
97     return true;
98   }
99
100   bool floatValue(qreal *val) {
101     if (!src) {
102       return false;
103     }
104
105     g_object_get(src, prop.toAscii().data(), val, NULL);
106
107     return true;
108   }
109
110   bool setFloatValue(qreal val) {
111     if (!src) {
112       return false;
113     }
114
115     g_object_set(src, prop.toAscii().data(), val, NULL);
116
117     return true;
118   }
119
120   static void camera_src_notify(GObject *gobject, GParamSpec *pspec, QtCamCapabilityPrivate *d) {
121     Q_UNUSED(gobject);
122     Q_UNUSED(pspec);
123
124     QMetaObject::invokeMethod(d->q_ptr, "valueChanged", Qt::QueuedConnection);
125   }
126
127   QtCamDevice *dev;
128   QtCamCapability::Capability cap;
129   QString prop;
130   GstElement *bin;
131   GstElement *src;
132   gulong handler;
133   QtCamCapability *q_ptr;
134 };
135
136 #endif /* QT_CAM_CAPABILITY_P_H */