Added QtCamQuirks to libQtCamera and Quirks to libdeclarativeQtCamera
authorMohammed Sameer <msameer@foolab.org>
Tue, 13 Aug 2013 21:42:49 +0000 (00:42 +0300)
committerMohammed Sameer <msameer@foolab.org>
Thu, 15 Aug 2013 22:53:35 +0000 (01:53 +0300)
This allows us to specify any device specific quirks to workaround from the UI side.
Also added N9 quirks

13 files changed:
data/n9/qtcamera.ini
declarative/camera.cpp
declarative/camera.h
declarative/cameraconfig.cpp
declarative/declarative.pro
declarative/plugin.cpp
declarative/quirks.cpp [new file with mode: 0644]
declarative/quirks.h [new file with mode: 0644]
lib/lib.pro
lib/qtcamconfig.cpp
lib/qtcamconfig.h
lib/qtcamquirks.cpp [new file with mode: 0644]
lib/qtcamquirks.h [new file with mode: 0644]

index 65fc889..c912b67 100644 (file)
@@ -201,3 +201,9 @@ message=regions-of-interest
 
 [%General]
 preview-supported=true
+
+[quirks-0]
+quirks = NoSceneModeChangeDuringRecording
+
+[quirks-1]
+quirks = NoNightSceneMode, NoFlash, NoVideoTorch, NoAutoFocus, NoSceneModeChangeDuringRecording
\ No newline at end of file
index 2ce7aed..3429832 100644 (file)
@@ -51,6 +51,7 @@
 #include "videomute.h"
 #include "videotorch.h"
 #include "cameraconfig.h"
+#include "quirks.h"
 
 Camera::Camera(QObject *parent) :
   QObject(parent),
@@ -74,7 +75,8 @@ Camera::Camera(QObject *parent) :
   m_roi(0),
   m_videoMute(0),
   m_videoTorch(0),
-  m_config(new CameraConfig(this)) {
+  m_config(new CameraConfig(this)),
+  m_quirks(0) {
 
   m_config->componentComplete();
 }
@@ -106,6 +108,7 @@ Camera::~Camera() {
   delete m_roi;
   delete m_videoMute;
   delete m_videoTorch;
+  delete m_quirks;
 }
 
 int Camera::deviceCount() const {
@@ -333,6 +336,10 @@ void Camera::resetCapabilities() {
   delete m_videoTorch;
   m_videoTorch = new VideoTorch(dev, this);
   emit videoTorchChanged();
+
+  delete m_quirks;
+  m_quirks = new Quirks(dev->config()->quirks(dev->id()), this);
+  emit quirksChanged();
 }
 
 Zoom *Camera::zoom() const {
@@ -402,3 +409,7 @@ VideoTorch *Camera::videoTorch() const {
 CameraConfig *Camera::cameraConfig() const {
   return m_config;
 }
+
+Quirks *Camera::quirks() const {
+  return m_quirks;
+}
index b533991..76ad878 100644 (file)
@@ -48,6 +48,7 @@ class Roi;
 class VideoMute;
 class VideoTorch;
 class CameraConfig;
+class Quirks;
 
 class Camera : public QObject {
   Q_OBJECT
@@ -79,6 +80,8 @@ class Camera : public QObject {
   Q_PROPERTY(VideoMute *videoMute READ videoMute NOTIFY videoMuteChanged);
   Q_PROPERTY(VideoTorch *videoTorch READ videoTorch NOTIFY videoTorchChanged);
 
+  Q_PROPERTY(Quirks *quirks READ quirks NOTIFY quirksChanged);
+
   // TODO: We need a setter here too.
   Q_PROPERTY(CameraConfig *cameraConfig READ cameraConfig CONSTANT);
 
@@ -136,6 +139,8 @@ public:
   VideoMute *videoMute() const;
   VideoTorch *videoTorch() const;
 
+  Quirks *quirks() const;
+
   CameraConfig *cameraConfig() const;
 
 signals:
@@ -169,6 +174,7 @@ signals:
   void videoMuteChanged();
   void videoTorchChanged();
   void renderingEnabledChanged();
+  void quirksChanged();
 
 private:
   bool applyMode();
@@ -201,6 +207,7 @@ private:
   VideoMute *m_videoMute;
   VideoTorch *m_videoTorch;
   CameraConfig *m_config;
+  Quirks *m_quirks;
 };
 
 #endif /* CAMERA_H */
index 1c1678a..169c34c 100644 (file)
@@ -28,6 +28,8 @@
 #include <QQmlInfo>
 #endif
 
+// TODO: share that with qtcamera. We now have 2 instances of QtCamConfig
+
 CameraConfig::CameraConfig(QObject *parent) :
   QObject(parent),
   m_config(0) {
index c7249f2..c83ecb5 100644 (file)
@@ -22,7 +22,7 @@ HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \
            imageresolutionmodel.h videosettings.h videoresolutionmodel.h \
            notificationscontainer.h sounds.h focus.h autofocus.h \
            roi.h cameraconfig.h videoplayer.h viewfinder.h capability.h \
-           imageresolution.h videoresolution.h
+           imageresolution.h videoresolution.h quirks.h
 
 SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp videomode.cpp \
            zoom.cpp flash.cpp scene.cpp evcomp.cpp videotorch.cpp whitebalance.cpp \
@@ -31,7 +31,7 @@ SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp vide
            imageresolutionmodel.cpp videosettings.cpp videoresolutionmodel.cpp \
            notificationscontainer.cpp sounds.cpp focus.cpp autofocus.cpp \
            roi.cpp cameraconfig.cpp videoplayer.cpp viewfinder.cpp capability.cpp \
-           imageresolution.cpp videoresolution.cpp
+           imageresolution.cpp videoresolution.cpp quirks.cpp
 
 PLUGIN_IMPORT_PATH = QtCamera
 target.path = $$[QT_INSTALL_IMPORTS]/$$PLUGIN_IMPORT_PATH
index b510a73..263328f 100644 (file)
@@ -51,6 +51,7 @@
 #include "capability.h"
 #include "imageresolution.h"
 #include "videoresolution.h"
+#include "quirks.h"
 #if defined(QT4)
 #include <QDeclarativeEngine>
 #elif defined(QT5)
@@ -127,6 +128,9 @@ void Plugin::registerTypes(const char *uri) {
 
   qmlRegisterType<ImageResolution>(uri, MAJOR, MINOR, "ImageResolution");
   qmlRegisterType<VideoResolution>(uri, MAJOR, MINOR, "VideoResolution");
+
+  qmlRegisterUncreatableType<Quirks>(uri, MAJOR, MINOR, "Quirks",
+                         "Quirks can be obtained from Camera");
 }
 
 #if defined(QT4)
diff --git a/declarative/quirks.cpp b/declarative/quirks.cpp
new file mode 100644 (file)
index 0000000..4c352f7
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "quirks.h"
+
+Quirks::Quirks(QtCamQuirks *quirks, QObject *parent) :
+  QObject(parent),
+  m_quirks(quirks) {
+
+}
+
+Quirks::~Quirks() {
+  delete m_quirks;
+  m_quirks = 0;
+}
+
+bool Quirks::hasQuirk(const QuirkType& type) {
+  return m_quirks->quirks().testFlag(QtCamQuirks::QuirkType(type));
+}
diff --git a/declarative/quirks.h b/declarative/quirks.h
new file mode 100644 (file)
index 0000000..2b1c641
--- /dev/null
@@ -0,0 +1,53 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef QUIRKS_H
+#define QUIRKS_H
+
+#include <QObject>
+#include "qtcamquirks.h"
+
+class Quirks : public QObject {
+  Q_OBJECT
+
+  Q_ENUMS(QuirkType);
+
+public:
+  Quirks(QtCamQuirks *quirks, QObject *parent = 0);
+  ~Quirks();
+
+  typedef enum {
+    NoNightSceneMode = QtCamQuirks::NoNightSceneMode,
+    NoFlash = QtCamQuirks::NoFlash,
+    NoVideoTorch = QtCamQuirks::NoVideoTorch,
+    NoAutoFocus = QtCamQuirks::NoAutoFocus,
+    NoSceneModeChangeDuringRecording = QtCamQuirks::NoSceneModeChangeDuringRecording,
+    NoRedEyeFlash = QtCamQuirks::NoRedEyeFlash,
+  } QuirkType;
+
+  Q_INVOKABLE bool hasQuirk(const QuirkType& type);
+
+private:
+  QtCamQuirks *m_quirks;
+};
+
+#endif /* QUIRKS_H */
index 3e27453..fd6b936 100644 (file)
@@ -23,7 +23,7 @@ HEADERS += qtcamconfig.h qtcamera.h qtcamscanner.h qtcamdevice.h qtcamviewfinder
            qtcamwhitebalance.h qtcamcolortone.h qtcamflickerreduction.h \
            qtcamnoisereduction.h qtcamiso.h qtcamaperture.h qtcamexposure.h \
            qtcamvideomute.h qtcamnotifications.h qtcamfocus.h qtcamautofocus.h \
-           qtcamanalysisbin.h qtcampropertysetter.h qtcamroi.h
+           qtcamanalysisbin.h qtcampropertysetter.h qtcamroi.h qtcamquirks.h
 
 SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamviewfinder.cpp \
            qtcammode.cpp qtcamgstreamermessagehandler.cpp qtcamgstreamermessagelistener.cpp \
@@ -33,7 +33,7 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi
            qtcamwhitebalance.cpp qtcamcolortone.cpp qtcamflickerreduction.cpp \
            qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \
            qtcamvideomute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp \
-           qtcamanalysisbin.cpp qtcampropertysetter.cpp qtcamroi.cpp
+           qtcamanalysisbin.cpp qtcampropertysetter.cpp qtcamroi.cpp qtcamquirks.cpp
 
 HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h \
            qtcamnotifications_p.h qtcamflash_p.h qtcamroi_p.h
index 1b2a1b8..41da44c 100644 (file)
  */
 
 #include "qtcamconfig.h"
+#include "qtcamimagesettings.h"
+#include "qtcamvideosettings.h"
+#include "qtcamquirks.h"
 #include <QSettings>
 #include <QStringList>
 #include <QDebug>
+#include <QMetaEnum>
 
 #define CONFIGURATION_FILE                    DATA_DIR"/qtcamera.ini"
 
@@ -168,6 +172,39 @@ QtCamVideoSettings *QtCamConfig::videoSettings(const QVariant& id) {
   return new QtCamVideoSettings(id.toString(), suffix, profileName, profilePath, resolutions);
 }
 
+QtCamQuirks *QtCamConfig::quirks(const QVariant& id) {
+  QString group = QString("quirks-%1").arg(id.toString());
+  d_ptr->conf->beginGroup(group);
+  QStringList quirks = d_ptr->conf->value("quirks").toStringList();
+  d_ptr->conf->endGroup();
+
+  QMetaObject m = QtCamQuirks::staticMetaObject;
+  int index = m.indexOfEnumerator("QuirkType");
+  if (index == -1) {
+    qCritical() << "Failed to obtain QuirkType index";
+    return 0;
+  }
+
+  QMetaEnum e = m.enumerator(index);
+
+  int value = 0;
+
+  foreach (const QString& quirk, quirks) {
+    int val = e.keyToValue(quirk.toLatin1().constData());
+
+    if (val == -1) {
+      qWarning() << "Unknown quirk" << quirk;
+    }
+    else {
+      value |= val;
+    }
+  }
+
+  QtCamQuirks::QuirkTypes types = (QtCamQuirks::QuirkTypes)value;
+
+  return new QtCamQuirks(types);
+}
+
 QString QtCamConfig::imageEncodingProfileName() const {
   return d_ptr->conf->value("image/profile-name").toString();
 }
index cd7a493..bd1469c 100644 (file)
 #define QT_CAM_CONFIG_H
 
 #include <QObject>
-#include "qtcamimagesettings.h"
-#include "qtcamvideosettings.h"
 #include <QStringList>
 
+class QtCamImageSettings;
+class QtCamVideoSettings;
+class QtCamQuirks;
+
 #define SCANNER_TYPE_V4L2                     "v4l2"
 #define SCANNER_TYPE_ENUM                     "enum"
 
@@ -63,6 +65,7 @@ public:
 
   QtCamImageSettings *imageSettings(const QVariant& id);
   QtCamVideoSettings *videoSettings(const QVariant& id);
+  QtCamQuirks *quirks(const QVariant& id);
 
   QString imageEncodingProfileName() const;
   QString imageEncodingProfilePath() const;
diff --git a/lib/qtcamquirks.cpp b/lib/qtcamquirks.cpp
new file mode 100644 (file)
index 0000000..93c79cb
--- /dev/null
@@ -0,0 +1,44 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "qtcamquirks.h"
+#include "qtcamconfig.h" // For DATA_DIR
+
+#define CONFIGURATION_FILE                    DATA_DIR"/qtcamera.ini"
+
+class QtCamQuirksPrivate {
+public:
+  QtCamQuirks::QuirkTypes types;
+};
+
+QtCamQuirks::QtCamQuirks(const QuirkTypes& types, QObject *parent) :
+  QObject(parent),
+  d_ptr(new QtCamQuirksPrivate) {
+
+  d_ptr->types = types;
+}
+
+QtCamQuirks::~QtCamQuirks() {
+  delete d_ptr; d_ptr = 0;
+}
+
+QtCamQuirks::QuirkTypes QtCamQuirks::quirks() const {
+  return d_ptr->types;
+}
diff --git a/lib/qtcamquirks.h b/lib/qtcamquirks.h
new file mode 100644 (file)
index 0000000..c22ff10
--- /dev/null
@@ -0,0 +1,59 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef QT_CAM_QUIRKS_H
+#define QT_CAM_QUIRKS_H
+
+#include <QObject>
+
+class QtCamQuirksPrivate;
+class QtCamDevice;
+
+class QtCamQuirks : public QObject {
+  Q_OBJECT
+
+  Q_ENUMS(QuirkType);
+
+public:
+  typedef enum {
+    NoNightSceneMode = 0x1,
+    NoFlash = 0x2,
+    NoVideoTorch = 0x4,
+    NoAutoFocus = 0x8,
+    NoSceneModeChangeDuringRecording = 0x10,
+    NoRedEyeFlash = 0x20,
+  } QuirkType;
+
+  Q_DECLARE_FLAGS(QuirkTypes, QuirkType);
+
+  QtCamQuirks(const QuirkTypes& types, QObject *parent = 0);
+  ~QtCamQuirks();
+
+  QuirkTypes quirks() const;
+
+private:
+  QtCamQuirksPrivate *d_ptr;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QtCamQuirks::QuirkTypes);
+
+#endif /* QT_CAM_QUIRKS_H */