Query the minimum, maximum and default values if needed from the GParamSpec objects
authorMohammed Sameer <msameer@foolab.org>
Sun, 7 Oct 2012 23:16:46 +0000 (02:16 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sun, 7 Oct 2012 23:23:06 +0000 (02:23 +0300)
lib/qtcamaperture.cpp
lib/qtcamaperture.h
lib/qtcamcapability_p.h
lib/qtcamevcomp.cpp
lib/qtcamevcomp.h
lib/qtcamexposure.cpp
lib/qtcamexposure.h
lib/qtcamiso.cpp
lib/qtcamiso.h
lib/qtcamzoom.cpp

index 07d95f4..b6187d9 100644 (file)
 #include "qtcamaperture.h"
 #include "qtcamcapability_p.h"
 
 #include "qtcamaperture.h"
 #include "qtcamcapability_p.h"
 
-// TODO: hardcoded
-#define APERTURE_MIN 0
-#define APERTURE_MAX 255
-
 QtCamAperture::QtCamAperture(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Aperture, "aperture"),
                  parent) {
 QtCamAperture::QtCamAperture(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Aperture, "aperture"),
                  parent) {
@@ -36,11 +32,9 @@ QtCamAperture::~QtCamAperture() {
 }
 
 unsigned int QtCamAperture::value() {
 }
 
 unsigned int QtCamAperture::value() {
-  unsigned int val = 0;
+  unsigned int val = defaultValue();
 
 
-  if (!d_ptr->uintValue(&val)) {
-    return 0;
-  }
+  d_ptr->uintValue(&val);
 
   return val;
 }
 
   return val;
 }
@@ -50,9 +44,31 @@ bool QtCamAperture::setValue(unsigned int val) {
 }
 
 unsigned int QtCamAperture::minimumValue() {
 }
 
 unsigned int QtCamAperture::minimumValue() {
-  return APERTURE_MIN;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->minimum;
+  }
+
+  return 0;
 }
 
 unsigned int QtCamAperture::maximumValue() {
 }
 
 unsigned int QtCamAperture::maximumValue() {
-  return APERTURE_MAX;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->maximum;
+  }
+
+  return 0;
+}
+
+unsigned int QtCamAperture::defaultValue() {
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->default_value;
+  }
+
+  return 0;
 }
 }
index 812e7b5..ab5e9e6 100644 (file)
@@ -32,6 +32,8 @@ public:
   QtCamAperture(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamAperture();
 
   QtCamAperture(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamAperture();
 
+  unsigned int defaultValue();
+
   unsigned int value();
   bool setValue(unsigned int val);
 
   unsigned int value();
   bool setValue(unsigned int val);
 
index ada68aa..1ff58be 100644 (file)
@@ -54,6 +54,14 @@ public:
 
   }
 
 
   }
 
+  GParamSpec *paramSpec() {
+    if (!src || prop.isEmpty()) {
+      return 0;
+    }
+
+    return g_object_class_find_property(G_OBJECT_GET_CLASS(src), prop.toUtf8().constData());
+  }
+
   void startMonitoring() {
     if (src) {
       QString p = QString("notify::%1").arg(prop);
   void startMonitoring() {
     if (src) {
       QString p = QString("notify::%1").arg(prop);
index 42d36a4..fe23f95 100644 (file)
 
 #include "qtcamevcomp.h"
 #include "qtcamcapability_p.h"
 
 #include "qtcamevcomp.h"
 #include "qtcamcapability_p.h"
-
-// TODO: hardcoded
-#define EV_COMP_MIN -2.5
-#define EV_COMP_MAX +2.5
+#include <QDebug>
 
 QtCamEvComp::QtCamEvComp(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::EvComp, "ev-compensation"),
 
 QtCamEvComp::QtCamEvComp(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::EvComp, "ev-compensation"),
@@ -36,11 +33,9 @@ QtCamEvComp::~QtCamEvComp() {
 }
 
 qreal QtCamEvComp::value() {
 }
 
 qreal QtCamEvComp::value() {
-  qreal val = 0.0;
+  qreal val = defaultValue();
 
 
-  if (!d_ptr->floatValue(&val)) {
-    return 0.0;
-  }
+  d_ptr->floatValue(&val);
 
   return val;
 }
 
   return val;
 }
@@ -50,9 +45,31 @@ bool QtCamEvComp::setValue(qreal val) {
 }
 
 qreal QtCamEvComp::minimumValue() {
 }
 
 qreal QtCamEvComp::minimumValue() {
-  return EV_COMP_MIN;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_FLOAT(p)) {
+    return G_PARAM_SPEC_FLOAT(p)->minimum;
+  }
+
+  return 0;
 }
 
 qreal QtCamEvComp::maximumValue() {
 }
 
 qreal QtCamEvComp::maximumValue() {
-  return EV_COMP_MAX;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_FLOAT(p)) {
+    return G_PARAM_SPEC_FLOAT(p)->maximum;
+  }
+
+  return 0;
+}
+
+qreal QtCamEvComp::defaultValue() {
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_FLOAT(p)) {
+    return G_PARAM_SPEC_FLOAT(p)->default_value;
+  }
+
+  return 0;
 }
 }
index 1d82f1a..9a7f2b2 100644 (file)
@@ -32,6 +32,8 @@ public:
   QtCamEvComp(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamEvComp();
 
   QtCamEvComp(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamEvComp();
 
+  qreal defaultValue();
+
   qreal value();
   bool setValue(qreal val);
 
   qreal value();
   bool setValue(qreal val);
 
index c1cb612..efd1f6e 100644 (file)
 #include "qtcamexposure.h"
 #include "qtcamcapability_p.h"
 
 #include "qtcamexposure.h"
 #include "qtcamcapability_p.h"
 
-// TODO: hardcoded
-#define EXPOSURE_MIN 0
-#define EXPOSURE_MAX 4294967295u
-
 QtCamExposure::QtCamExposure(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Exposure, "exposure"),
                  parent) {
 QtCamExposure::QtCamExposure(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Exposure, "exposure"),
                  parent) {
@@ -36,11 +32,9 @@ QtCamExposure::~QtCamExposure() {
 }
 
 unsigned int QtCamExposure::value() {
 }
 
 unsigned int QtCamExposure::value() {
-  unsigned int val = 0;
+  unsigned int val = defaultValue();
 
 
-  if (!d_ptr->uintValue(&val)) {
-    return 0;
-  }
+  d_ptr->uintValue(&val);
 
   return val;
 }
 
   return val;
 }
@@ -50,9 +44,31 @@ bool QtCamExposure::setValue(unsigned int val) {
 }
 
 unsigned int QtCamExposure::minimumValue() {
 }
 
 unsigned int QtCamExposure::minimumValue() {
-  return EXPOSURE_MIN;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->minimum;
+  }
+
+  return 0;
 }
 
 unsigned int QtCamExposure::maximumValue() {
 }
 
 unsigned int QtCamExposure::maximumValue() {
-  return EXPOSURE_MAX;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->maximum;
+  }
+
+  return 0;
+}
+
+unsigned int QtCamExposure::defaultValue() {
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->default_value;
+  }
+
+  return 0;
 }
 }
index 74d92c2..f87a2ef 100644 (file)
@@ -32,6 +32,8 @@ public:
   QtCamExposure(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamExposure();
 
   QtCamExposure(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamExposure();
 
+  unsigned int defaultValue();
+
   unsigned int value();
   bool setValue(unsigned int val);
 
   unsigned int value();
   bool setValue(unsigned int val);
 
index b70c5e0..8646cce 100644 (file)
 #include "qtcamiso.h"
 #include "qtcamcapability_p.h"
 
 #include "qtcamiso.h"
 #include "qtcamcapability_p.h"
 
-// TODO: hardcoded
-#define ISO_MIN 0
-#define ISO_MAX 6400
-
 QtCamIso::QtCamIso(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::IsoSpeed, "iso-speed"),
                  parent) {
 QtCamIso::QtCamIso(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::IsoSpeed, "iso-speed"),
                  parent) {
@@ -36,11 +32,9 @@ QtCamIso::~QtCamIso() {
 }
 
 unsigned int QtCamIso::value() {
 }
 
 unsigned int QtCamIso::value() {
-  unsigned int val = 0;
+  unsigned int val = defaultValue();
 
 
-  if (!d_ptr->uintValue(&val)) {
-    return 0;
-  }
+  d_ptr->uintValue(&val);
 
   return val;
 }
 
   return val;
 }
@@ -50,9 +44,31 @@ bool QtCamIso::setValue(unsigned int val) {
 }
 
 unsigned int QtCamIso::minimumValue() {
 }
 
 unsigned int QtCamIso::minimumValue() {
-  return ISO_MIN;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->minimum;
+  }
+
+  return 0;
 }
 
 unsigned int QtCamIso::maximumValue() {
 }
 
 unsigned int QtCamIso::maximumValue() {
-  return ISO_MAX;
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->maximum;
+  }
+
+  return 0;
+}
+
+unsigned int QtCamIso::defaultValue() {
+  GParamSpec *p = d_ptr->paramSpec();
+
+  if (p && G_IS_PARAM_SPEC_UINT(p)) {
+    return G_PARAM_SPEC_UINT(p)->default_value;
+  }
+
+  return 0;
 }
 }
index c8d4d6d..88aa77a 100644 (file)
@@ -32,6 +32,8 @@ public:
   QtCamIso(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamIso();
 
   QtCamIso(QtCamDevice *dev, QObject *parent = 0);
   ~QtCamIso();
 
+  unsigned int defaultValue();
+
   unsigned int value();
   bool setValue(unsigned int val);
 
   unsigned int value();
   bool setValue(unsigned int val);
 
index 3411179..2908bc5 100644 (file)
@@ -119,7 +119,15 @@ bool QtCamZoom::setValue(qreal zoom) {
 }
 
 qreal QtCamZoom::minimumValue() {
 }
 
 qreal QtCamZoom::minimumValue() {
-  // TODO: hardcoded
+  if (!d_ptr->bin) {
+    return 1.0;
+  }
+
+  GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(d_ptr->bin), "max-zoom");
+  if (pspec && G_IS_PARAM_SPEC_FLOAT(pspec)) {
+    return G_PARAM_SPEC_FLOAT(pspec)->minimum;
+  }
+
   return 1.0;
 }
 
   return 1.0;
 }