From: Mohammed Sameer Date: Thu, 20 Dec 2012 21:25:51 +0000 (+0200) Subject: Added QtCamFlash::ready to indicate readiness of flash X-Git-Url: http://cgit.sxemacs.org/?a=commitdiff_plain;h=0d1afea1ec6bcc7c8f6e02eb04db94432462a9f3;p=harmattan%2Fcameraplus Added QtCamFlash::ready to indicate readiness of flash --- diff --git a/imports/flash.cpp b/imports/flash.cpp index fa90764..d4a2894 100644 --- a/imports/flash.cpp +++ b/imports/flash.cpp @@ -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(); +} diff --git a/imports/flash.h b/imports/flash.h index 916a936..deb2df0 100644 --- a/imports/flash.h +++ b/imports/flash.h @@ -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; diff --git a/lib/lib.pro b/lib/lib.pro index b0531f5..211f1b8 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -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 diff --git a/lib/qtcamcapability_p.h b/lib/qtcamcapability_p.h index 1ff58be..eb1558d 100644 --- a/lib/qtcamcapability_p.h +++ b/lib/qtcamcapability_p.h @@ -24,6 +24,7 @@ #define QT_CAM_CAPABILITY_P_H #include +#include "qtcamcapability.h" #include "qtcamdevice.h" #include "qtcamdevice_p.h" diff --git a/lib/qtcamflash.cpp b/lib/qtcamflash.cpp index 24f1eb2..cc6e16a 100644 --- a/lib/qtcamflash.cpp +++ b/lib/qtcamflash.cpp @@ -20,10 +20,19 @@ #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(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(d_ptr)->isReady(); +} diff --git a/lib/qtcamflash.h b/lib/qtcamflash.h index d97d994..543bc7f 100644 --- a/lib/qtcamflash.h +++ b/lib/qtcamflash.h @@ -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 index 0000000..ba2cfae --- /dev/null +++ b/lib/qtcamflash_p.h @@ -0,0 +1,96 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012 Mohammed Sameer + * + * 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 +#include "qtcamcapability_p.h" +#include "qtcamdevice.h" +#include "qtcamgstreamermessagelistener.h" +#include "qtcamgstreamermessagehandler.h" +#include + +// 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 */ diff --git a/qml/main.qml b/qml/main.qml index a2e0f74..e9ff6a1 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -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