setIntValue does not set the value if it's equal to the old one. Added a force flag...
[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 intValue(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 setIntValue(int val, bool force) {
61     if (!src) {
62       return false;
63     }
64
65     if (force) {
66       g_object_set(src, prop.toAscii().data(), val, NULL);
67       return true;
68     }
69
70     int old = 0;
71     g_object_get(src, prop.toAscii().data(), &old, NULL);
72
73     if (old != val) {
74       g_object_set(src, prop.toAscii().data(), val, NULL);
75     }
76
77     return true;
78   }
79
80   bool floatValue(qreal *val) {
81     if (!src) {
82       return false;
83     }
84
85     g_object_get(src, prop.toAscii().data(), val, NULL);
86
87     return true;
88   }
89
90   bool setFloatValue(qreal val) {
91     if (!src) {
92       return false;
93     }
94
95     g_object_set(src, prop.toAscii().data(), val, NULL);
96
97     return true;
98   }
99
100   static void camera_src_notify(GObject *gobject, GParamSpec *pspec, QtCamCapabilityPrivate *d) {
101     Q_UNUSED(gobject);
102     Q_UNUSED(pspec);
103
104     QMetaObject::invokeMethod(d->q_ptr, "valueChanged", Qt::QueuedConnection);
105   }
106
107   QtCamDevice *dev;
108   QtCamCapability::Capability cap;
109   QString prop;
110   GstElement *bin;
111   GstElement *src;
112   gulong handler;
113   QtCamCapability *q_ptr;
114 };
115
116 #endif /* QT_CAM_CAPABILITY_P_H */