You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2012/04/02 16:37:06 UTC
[2/2] qt commit: Merge Camera support patches for Symbian and
Harmattan, Fixed Symbian build issues
Merge Camera support patches for Symbian and Harmattan, Fixed Symbian build issues
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/commit/fee4e826
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/tree/fee4e826
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/diff/fee4e826
Branch: refs/remotes/origin/master
Commit: fee4e826de80b3707d76c6c6ca3667a065c1076e
Parents: 9f7439e
Author: Longwei Su <lo...@gmail.com>
Authored: Fri Mar 30 16:11:57 2012 -0400
Committer: Longwei Su <lo...@gmail.com>
Committed: Fri Mar 30 16:11:57 2012 -0400
----------------------------------------------------------------------
src/plugins/camera.cpp | 258 +++++++++++++++++++++++++++++++++++
src/plugins/camera.h | 74 ++++++++++
src/plugins/cameraresolution.h | 22 +++
www/js/camera.js | 52 +++++++
4 files changed, 406 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/fee4e826/src/plugins/camera.cpp
----------------------------------------------------------------------
diff --git a/src/plugins/camera.cpp b/src/plugins/camera.cpp
new file mode 100644
index 0000000..c567471
--- /dev/null
+++ b/src/plugins/camera.cpp
@@ -0,0 +1,258 @@
+#include "cameraresolution.h"
+#include "camera.h"
+
+
+#ifdef Q_OS_SYMBIAN
+# include <ecam.h>
+# include <NewFileServiceClient.h>
+# include <AiwServiceHandler.h>
+# include <AiwCommon.hrh>
+# include <AiwGenericParam.hrh>
+#elif defined MEEGO_EDITION_HARMATTAN
+# include <QDBusMessage>
+# include <QDBusConnection>
+#endif
+
+
+#include <QDebug>
+
+// This is returned as the path to the captured image on platforms other than Symbian
+#define DUMMY_IMAGE "dummy.jpg"
+
+// These define the (only) supported resolution on platforms other than Symbian
+#define DUMMY_WIDTH 1024
+#define DUMMY_HEIGHT 768
+
+
+
+Camera *Camera::m_camera = new Camera;
+
+Camera::Camera() : CPlugin(){
+ PluginRegistry::getRegistry()->registerPlugin( "com.cordova.Camera", this );
+}
+
+Camera::~Camera()
+{
+ qDeleteAll(m_supportedResolutionObjects);
+}
+
+void Camera::init(){
+ getSupportedResolutions();
+#ifdef MEEGO_EDITION_HARMATTAN
+ m_lastScId = 0;
+ m_lastEcId = 0;
+#endif
+}
+
+void Camera::getPicture( int scId, int ecId, QVariantMap p_options){
+ Q_UNUSED(p_options);
+
+ // Should we select the best resolution here?
+#ifdef MEEGO_EDITION_HARMATTAN
+ m_lastScId = scId;
+ m_lastEcId = ecId;
+ startCamera();
+#else
+ Q_UNUSED(ecId);
+
+ QString callbackArguments = newImageFile(m_supportedResolutions.at(0).width(),m_supportedResolutions.at(0).height());
+
+ this->callback( scId, callbackArguments );
+#endif
+}
+
+#ifdef MEEGO_EDITION_HARMATTAN
+void Camera::captureCanceled(const QString &mode)
+{
+ Q_UNUSED(mode);
+ qDebug() << Q_FUNC_INFO;
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ bus.disconnect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCanceled",
+ this, SLOT(captureCanceled(QString)));
+
+ bus.disconnect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCompleted",
+ this, SLOT(captureCompleted(QString,QString)));
+ if (m_lastEcId)
+ this->callback(m_lastEcId, "");
+}
+
+void Camera::captureCompleted(const QString &mode, const QString &fileName)
+{
+ Q_UNUSED(mode);
+ qDebug() << Q_FUNC_INFO;
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ bus.disconnect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCanceled",
+ this, SLOT(captureCanceled(QString)));
+
+ bus.disconnect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCompleted",
+ this, SLOT(captureCompleted(QString,QString)));
+ if (m_lastScId)
+ this->callback(m_lastScId, QString("\"%1\"").arg(fileName));
+}
+
+void Camera::startCamera()
+{
+ QDBusConnection bus = QDBusConnection::sessionBus();
+
+ bus.connect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCanceled",
+ this, SLOT(captureCanceled(QString)));
+
+ bus.connect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCompleted",
+ this, SLOT(captureCompleted(QString,QString)));
+
+ QDBusMessage message = QDBusMessage::createMethodCall(
+ "com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "showCamera");
+
+ QList<QVariant> args;
+ args << (uint)0 << "" << "still-capture" << true;
+ message.setArguments(args);
+
+ QDBusMessage reply = bus.call(message);
+ if (reply.type() == QDBusMessage::ErrorMessage) {
+ qDebug() << Q_FUNC_INFO << "reply.type == errormessage; name=" << reply.errorName() << "; message=" << reply.errorMessage();
+ bus.disconnect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCanceled",
+ this, SLOT(captureCanceled(QString)));
+
+ bus.disconnect("com.nokia.maemo.CameraService",
+ "/",
+ "com.nokia.maemo.meegotouch.CameraInterface",
+ "captureCompleted",
+ this, SLOT(captureCompleted(QString,QString)));
+ if (m_lastEcId)
+ this->callback(m_lastEcId, "");
+ }
+}
+#endif
+
+QString Camera::newImageFile(int width, int height)
+{
+ qDebug() << Q_FUNC_INFO;
+#ifdef MEEGO_EDITION_HARMATTAN
+ Q_UNUSED(width);
+ Q_UNUSED(height);
+#endif
+#ifdef Q_OS_SYMBIAN
+ QString filename;
+// TRAPD(err, filename = symbianCapture(width, height));
+ filename = symbianCapture(width, height);
+// if (err != KErrNone)
+// emit error(err);
+ qDebug() << "Error";
+ return filename;
+#else
+ return DUMMY_IMAGE;
+#endif
+}
+
+QUrl Camera::newImageUrl(int width, int height)
+{
+ QString filename = newImageFile(width, height);
+ if (filename.isEmpty())
+ return QUrl();
+ else
+ return QUrl::fromLocalFile(filename);
+}
+
+
+QList<QSize> Camera::supportedResolutions()
+{
+ if (m_supportedResolutions.isEmpty())
+ getSupportedResolutions();
+ return m_supportedResolutions;
+}
+
+void Camera::getSupportedResolutions()
+{
+#ifdef Q_OS_SYMBIAN
+ TRAPD(err, symbianEnumerateResolutions());
+#else
+ m_supportedResolutions.append(QSize(DUMMY_WIDTH, DUMMY_HEIGHT));
+ m_supportedResolutionObjects.append(new CameraResolution(DUMMY_WIDTH, DUMMY_HEIGHT));
+#endif
+}
+
+QList<QObject*> Camera::supportedResolutionObjects()
+{
+ if (m_supportedResolutionObjects.isEmpty())
+ getSupportedResolutions();
+ return m_supportedResolutionObjects;
+}
+
+#ifdef Q_OS_SYMBIAN
+QString Camera::symbianCapture(int width, int height)
+{
+ CNewFileServiceClient* fileClient = NewFileServiceFactory::NewClientL();
+ CleanupStack::PushL(fileClient);
+
+ CDesCArray* fileNames = new (ELeave) CDesCArrayFlat(1);
+ CleanupStack::PushL(fileNames);
+
+ CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
+
+ TSize resolution = TSize(width, height);
+ TPckgBuf<TSize> buffer( resolution );
+ TAiwVariant resolutionVariant( buffer );
+ TAiwGenericParam param( EGenericParamResolution, resolutionVariant );
+ paramList->AppendL( param );
+
+ const TUid KUidCamera = { 0x101F857A }; // Camera UID for S60 5th edition
+
+ TBool result = fileClient->NewFileL( KUidCamera, *fileNames, paramList,
+ ENewFileServiceImage, EFalse );
+
+ QString ret;
+
+ if (result) {
+ TPtrC fileName=fileNames->MdcaPoint(0);
+ ret = QString((QChar*) fileName.Ptr(), fileName.Length());
+ }
+ qDebug() << ret;
+ CleanupStack::PopAndDestroy(3);
+
+ return ret;
+}
+
+void Camera::symbianEnumerateResolutions()
+{
+ CCamera* camera = CCamera::NewL(*this, 0);
+ TCameraInfo info;
+ camera->CameraInfo(info);
+ int resolutionCount = info.iNumImageSizesSupported;
+ qDebug() << resolutionCount;
+ for (int i=0; i < resolutionCount; i++) {
+ TSize size;
+ camera->EnumerateCaptureSizes(size, i, CCamera::EFormatExif);
+ qDebug() << size.iWidth << size.iHeight;
+ m_supportedResolutions.append(QSize(size.iWidth, size.iHeight));
+ m_supportedResolutionObjects.append(new CameraResolution(size.iWidth, size.iHeight));
+ }
+ qDebug() << m_supportedResolutionObjects.length();
+ delete camera;
+
+}
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/fee4e826/src/plugins/camera.h
----------------------------------------------------------------------
diff --git a/src/plugins/camera.h b/src/plugins/camera.h
new file mode 100644
index 0000000..3e24961
--- /dev/null
+++ b/src/plugins/camera.h
@@ -0,0 +1,74 @@
+#ifndef CAMERA_H
+#define CAMERA_H
+
+#include "../cplugin.h"
+#include "../pluginregistry.h"
+
+#include <QObject>
+#include <QUrl>
+#include <QList>
+#include <QSize>
+#include <QVariantMap>
+
+#include <qplatformdefs.h>
+
+#ifdef Q_OS_SYMBIAN
+#include <ecam.h>
+#endif
+
+#ifdef QTM_NAMESPACE
+QTM_USE_NAMESPACE
+#endif
+
+class Camera : public CPlugin
+#ifdef Q_OS_SYMBIAN
+ , public MCameraObserver
+#endif
+{
+
+ Q_OBJECT
+public:
+ explicit Camera();
+ void init();
+ ~Camera();
+
+ QString newImageFile(int width, int height);
+ QUrl newImageUrl(int width, int height);
+ QList<QSize> supportedResolutions();
+
+
+signals:
+
+public slots:
+ void getPicture( int scId, int ecId, QVariantMap p_options);
+
+private slots:
+#ifdef MEEGO_EDITION_HARMATTAN
+ void captureCanceled(const QString &mode);
+ void captureCompleted(const QString &mode, const QString &fileName);
+#endif
+
+private:
+#ifdef Q_OS_SYMBIAN
+ QString symbianCapture(int width, int height);
+ void symbianEnumerateResolutions();
+ void FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError) {}
+ void ImageReady(CFbsBitmap* aBitmap,HBufC8* aData,TInt aError) {}
+ void ViewFinderFrameReady(CFbsBitmap& aFrame) {}
+ void PowerOnComplete(TInt aError) {};
+ void ReserveComplete(TInt aError) {};
+#elif defined MEEGO_EDITION_HARMATTAN
+ void startCamera();
+ int m_lastScId;
+ int m_lastEcId;
+#endif
+ void getSupportedResolutions();
+ QList<QObject*> supportedResolutionObjects();
+
+ QList<QSize> m_supportedResolutions;
+ QList<QObject*> m_supportedResolutionObjects;
+
+ static Camera *m_camera;
+};
+
+#endif // CAMERA_H
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/fee4e826/src/plugins/cameraresolution.h
----------------------------------------------------------------------
diff --git a/src/plugins/cameraresolution.h b/src/plugins/cameraresolution.h
new file mode 100644
index 0000000..ca70b29
--- /dev/null
+++ b/src/plugins/cameraresolution.h
@@ -0,0 +1,22 @@
+#ifndef CAMERARESOLUTION_H
+#define CAMERARESOLUTION_H
+
+#include <QObject>
+
+class CameraResolution : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int width READ width CONSTANT)
+ Q_PROPERTY(int height READ height CONSTANT)
+
+public:
+ CameraResolution(int width, int height) : m_width(width), m_height(height) {}
+ int width() { return m_width; }
+ int height() { return m_height; }
+
+ int m_width;
+ int m_height;
+};
+
+#endif // CAMERARESOLUTION_H
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/fee4e826/www/js/camera.js
----------------------------------------------------------------------
diff --git a/www/js/camera.js b/www/js/camera.js
new file mode 100644
index 0000000..7938c75
--- /dev/null
+++ b/www/js/camera.js
@@ -0,0 +1,52 @@
+function Camera(){
+}
+
+Camera.DestinationType = {
+ DATA_URL : 0, // Return image as base64 encoded string
+ FILE_URI : 1 // Return image file URI
+};
+
+Camera.PictureSourceType = {
+ PHOTOLIBRARY : 0,
+ CAMERA : 1,
+ SAVEDPHOTOALBUM : 2
+};
+
+
+Camera.EncodingType = {
+ JPEG : 0, // Return JPEG encoded image
+ PNG : 1 // Return PNG encoded image
+};
+
+
+
+function CameraOptions() {
+};
+
+/*
+CameraOptions.prototype.magneticHeading = 0;
+
+quality : 75,
+ destinationType : Camera.DestinationType.DATA_URL,
+ sourceType : Camera.PictureSourceType.CAMERA,
+ allowEdit : true,
+ encodingType: Camera.EncodingType.JPEG,
+ targetWidth: 100,
+ targetHeight: 100
+*/
+
+Camera.prototype.getPicture = function( successCallback, errorCallback, options ) {
+ // Check the callbacks
+ console.log("Camera.getPicture()")
+ if( typeof successCallback !== "function" ) return;
+ if( typeof errorCallback !== "function" ) errorCallback = function() {};
+ var cameraOptions = new CameraOptions();
+
+ // Call the native function
+ Cordova.exec( successCallback, errorCallback, "com.cordova.Camera", "getPicture", [ cameraOptions ] );
+};
+
+Cordova.addConstructor( "com.cordova.Camera", function () {
+ console.log("Camera.ctor()")
+ navigator.camera = new Camera();
+ } );