Added QtCamFlash::ready to indicate readiness of flash
authorMohammed Sameer <msameer@foolab.org>
Thu, 20 Dec 2012 21:25:51 +0000 (23:25 +0200)
committerMohammed Sameer <msameer@foolab.org>
Thu, 20 Dec 2012 21:25:51 +0000 (23:25 +0200)
imports/flash.cpp
imports/flash.h
lib/lib.pro
lib/qtcamcapability_p.h
lib/qtcamflash.cpp
lib/qtcamflash.h
lib/qtcamflash_p.h [new file with mode: 0644]
qml/main.qml

index fa90764..d4a2894 100644 (file)
@@ -25,6 +25,7 @@ Flash::Flash(QtCamDevice *dev, QObject *parent) :
   m_flash(new QtCamFlash(dev, this)) {
 
   QObject::connect(m_flash, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+  QObject::connect(m_flash, SIGNAL(flashReadyChanged()), this, SIGNAL(readyChanged()));
 }
 
 Flash::~Flash() {
@@ -38,3 +39,7 @@ Flash::FlashMode Flash::value() {
 void Flash::setValue(const Flash::FlashMode& mode) {
   m_flash->setValue((QtCamFlash::FlashMode)mode);
 }
+
+bool Flash::isReady() const {
+  return m_flash->isReady();
+}
index 916a936..deb2df0 100644 (file)
@@ -32,6 +32,7 @@ class Flash : public QObject {
   Q_OBJECT
 
   Q_PROPERTY(FlashMode value READ value WRITE setValue NOTIFY valueChanged);
+  Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged);
   Q_ENUMS(FlashMode);
 
 public:
@@ -49,8 +50,11 @@ public:
   FlashMode value();
   void setValue(const FlashMode& mode);
 
+  bool isReady() const;
+
 signals:
   void valueChanged();
+  void readyChanged();
 
 private:
   QtCamFlash *m_flash;
index b0531f5..211f1b8 100644 (file)
@@ -30,7 +30,8 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi
            qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \
            qtcamvideomute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp
 
-HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h qtcamnotifications_p.h
+HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h \
+           qtcamnotifications_p.h qtcamflash_p.h
 
 LIBS += -lgstphotography-0.10
 
index 1ff58be..eb1558d 100644 (file)
@@ -24,6 +24,7 @@
 #define QT_CAM_CAPABILITY_P_H
 
 #include <gst/gst.h>
+#include "qtcamcapability.h"
 #include "qtcamdevice.h"
 #include "qtcamdevice_p.h"
 
index 24f1eb2..cc6e16a 100644 (file)
 
 #include "qtcamflash.h"
 #include "qtcamcapability_p.h"
+#include "qtcamflash_p.h"
 
 QtCamFlash::QtCamFlash(QtCamDevice *dev, QObject *parent) :
-  QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Flash, "flash-mode"), parent) {
+  QtCamCapability(new QtCamFlashPrivate(dev, parent), parent) {
 
+  QtCamFlashPrivate *pvt = dynamic_cast<QtCamFlashPrivate *>(d_ptr);
+
+  // We get a weird crash if we pass this as parent to QtCamFlashPrivate
+  pvt->setParent(this);
+
+  QObject::connect(pvt, SIGNAL(flashReadyChanged()), this, SIGNAL(flashReadyChanged()));
+
+  pvt->init();
 }
 
 QtCamFlash::~QtCamFlash() {
@@ -51,3 +60,7 @@ QtCamFlash::FlashMode QtCamFlash::value() {
 bool QtCamFlash::setValue(const QtCamFlash::FlashMode& mode) {
   return d_ptr->setIntValue(mode, false);
 }
+
+bool QtCamFlash::isReady() const {
+  return dynamic_cast<QtCamFlashPrivate *>(d_ptr)->isReady();
+}
index d97d994..543bc7f 100644 (file)
@@ -42,6 +42,12 @@ public:
 
   FlashMode value();
   bool setValue(const FlashMode& mode);
+
+  bool isReady() const;
+
+signals:
+  void flashReadyChanged();
+
 };
 
 #endif /* QT_CAM_FLASH_H */
diff --git a/lib/qtcamflash_p.h b/lib/qtcamflash_p.h
new file mode 100644 (file)
index 0000000..ba2cfae
--- /dev/null
@@ -0,0 +1,96 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 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_FLASH_P_H
+#define QT_CAM_FLASH_P_H
+
+#include <QObject>
+#include "qtcamcapability_p.h"
+#include "qtcamdevice.h"
+#include "qtcamgstreamermessagelistener.h"
+#include "qtcamgstreamermessagehandler.h"
+#include <QDebug>
+
+// subdevsrc ./gst-libs/gst/camera/gstcamerasrc2.h
+#define FLASH_STATUS_READY        0
+#define FLASH_STATUS_NOT_READY    1
+
+class QtCamFlashPrivate : public QObject, public QtCamCapabilityPrivate {
+  Q_OBJECT
+
+public:
+  QtCamFlashPrivate(QtCamDevice *dev, QObject *parent = 0) :
+    QObject(parent),
+    QtCamCapabilityPrivate(dev, QtCamCapability::Flash, "flash-mode"),
+    ready(true) {
+
+  }
+
+  ~QtCamFlashPrivate() {
+
+  }
+
+  void init() {
+    QtCamGStreamerMessageListener *listener = dev->listener();
+    if (!listener) {
+      qWarning() << "Failed to get device listener. flash ready status will not be available";
+      return;
+    }
+
+    QtCamGStreamerMessageHandler *handler = new QtCamGStreamerMessageHandler("flash-status", this);
+    QObject::connect(handler, SIGNAL(messageSent(GstMessage *)),
+                    this, SLOT(messageSent(GstMessage *)));
+    listener->addHandler(handler);
+  }
+
+  bool isReady() const {
+    return ready;
+  }
+
+signals:
+  void flashReadyChanged();
+
+private slots:
+  void messageSent(GstMessage *message) {
+    const GstStructure *s = gst_message_get_structure(message);
+    if (QLatin1String("flash-status") != QLatin1String(gst_structure_get_name(s))) {
+      return;
+    }
+
+    int status = FLASH_STATUS_NOT_READY;
+    if (!gst_structure_get_int(s, "status", &status)) {
+      return;
+    }
+
+    bool newStatus = (status == FLASH_STATUS_READY);
+
+    if (ready != newStatus) {
+      ready = newStatus;
+      emit flashReadyChanged();
+    }
+  }
+
+private:
+  bool ready;
+};
+
+#endif /* QT_CAM_FLASH_P_H */
index a2e0f74..e9ff6a1 100644 (file)
@@ -29,7 +29,7 @@ import QtMobility.systeminfo 1.2
 import QtMobility.location 1.2
 
 // TODO: postcapture
-// TODO: flash not ready
+// TODO: flash not ready (battery low or flash not ready message)
 // TODO: portrait/landscape
 // TODO: stop viewfinder in settings pages ?
 // TODO: grid lines, face tracking, ambr