You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/06/03 23:25:12 UTC

git commit: ubuntu: use application directory for images

Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master 6e93ebbf9 -> 8ff4d3f16


ubuntu: use application directory for images


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/8ff4d3f1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/8ff4d3f1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/8ff4d3f1

Branch: refs/heads/master
Commit: 8ff4d3f16e733715c2985e4539282cc14f491b03
Parents: 6e93ebb
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Fri May 2 21:08:27 2014 +0400
Committer: Steven Gill <st...@gmail.com>
Committed: Tue Jun 3 14:25:01 2014 -0700

----------------------------------------------------------------------
 src/ubuntu/CaptureWidget.qml |  3 +--
 src/ubuntu/camera.cpp        | 15 ++++++---------
 src/ubuntu/camera.h          | 10 ++++++++++
 3 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/8ff4d3f1/src/ubuntu/CaptureWidget.qml
----------------------------------------------------------------------
diff --git a/src/ubuntu/CaptureWidget.qml b/src/ubuntu/CaptureWidget.qml
index e3fe20e..0a332e2 100644
--- a/src/ubuntu/CaptureWidget.qml
+++ b/src/ubuntu/CaptureWidget.qml
@@ -40,7 +40,6 @@ Rectangle {
             console.log(errorString);
         }
         videoRecorder.audioBitRate: 128000
-        videoRecorder.mediaContainer: "mp4"
         imageCapture {
             onImageSaved: {
                 root.exec("Camera", "onImageSaved", [path]);
@@ -100,7 +99,7 @@ Rectangle {
                 MouseArea {
                     anchors.fill: parent
                     onClicked: {
-                        camera.imageCapture.capture();
+                        camera.imageCapture.captureToLocation(ui.parent.plugin('Camera').generateLocation("jpg"));
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/8ff4d3f1/src/ubuntu/camera.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/camera.cpp b/src/ubuntu/camera.cpp
index eada5dc..c58af32 100644
--- a/src/ubuntu/camera.cpp
+++ b/src/ubuntu/camera.cpp
@@ -38,7 +38,7 @@ function createObject() {                                               \
         component.statusChanged.connect(finishCreation);                \
 }                                                                       \
 function finishCreation() {                                             \
-    CordovaWrapper.object = component.createObject(root,                \
+    CordovaWrapper.global.cameraPluginWidget = component.createObject(root, \
         {root: root, cordova: cordova});                                \
 }                                                                       \
 createObject()";
@@ -68,18 +68,15 @@ bool Camera::preprocessImage(QString &path) {
 
     const char *type;
     if (convertToPNG) {
-        newImage.setFileTemplate("imgXXXXXX.png");
+        path = generateLocation("png");
         type = "png";
     } else {
-        newImage.setFileTemplate("imgXXXXXX.jpg");
+        path = generateLocation("jpg");
         type = "jpg";
     }
 
-    newImage.open();
-    newImage.setAutoRemove(false);
-    image.save(newImage.fileName(), type, quality);
+    image.save(path, type, quality);
 
-    path = newImage.fileName();
     oldImage.remove();
 
     return true;
@@ -98,7 +95,7 @@ void Camera::onImageSaved(QString path) {
             cbParams = QString("\"%1\"").arg(content.data());
             image.remove();
         } else {
-            cbParams = CordovaInternal::format(QUrl::fromLocalFile(absolutePath).toString());
+            cbParams = CordovaInternal::format(QString("file://localhost") + absolutePath);
         }
     }
 
@@ -136,7 +133,7 @@ void Camera::takePicture(int scId, int ecId, int quality, int destinationType, i
 }
 
 void Camera::cancel() {
-    m_cordova->execQML("CordovaWrapper.object.destroy()");
+    m_cordova->execQML("CordovaWrapper.global.cameraPluginWidget.destroy()");
     this->cb(_lastEcId, "canceled");
 
     _lastEcId = _lastScId = 0;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/8ff4d3f1/src/ubuntu/camera.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/camera.h b/src/ubuntu/camera.h
index aa06698..6d96038 100644
--- a/src/ubuntu/camera.h
+++ b/src/ubuntu/camera.h
@@ -54,6 +54,16 @@ public slots:
 
     void onImageSaved(QString path);
 
+    QString generateLocation(const QString &extension) {
+        int i = 1;
+        for (;;++i) {
+            QString path = QString("%1/.local/share/%2/persistent/%3.%4").arg(QDir::homePath())
+                .arg(QCoreApplication::applicationName()).arg(i).arg(extension);
+
+            if (!QFileInfo(path).exists())
+                return path;
+        }
+    }
 private:
     bool preprocessImage(QString &path);