You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/12/14 19:14:41 UTC

[GitHub] surajpindoria closed pull request #62: ubuntu: use content hub on device

surajpindoria closed pull request #62: ubuntu: use content hub on device
URL: https://github.com/apache/cordova-plugin-camera/pull/62
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/plugin.xml b/plugin.xml
index 67fd4388..c1155851 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -104,6 +104,7 @@
          <config-file target="config.xml" parent="/*">
              <feature name="Camera">
                  <param policy_group="camera" policy_version="1" />
+                 <param policy_group="content_exchange" policy_version="1" />
              </feature>
          </config-file>
          <js-module src="www/CameraPopoverHandle.js" name="CameraPopoverHandle">
@@ -114,6 +115,7 @@
 
          <resource-file src="src/ubuntu/back.png" />
          <resource-file src="src/ubuntu/CaptureWidget.qml" />
+         <resource-file src="src/ubuntu/CameraWidgetContentHub.qml" />
          <resource-file src="src/ubuntu/shoot.png" />
          <resource-file src="src/ubuntu/toolbar-left.png" />
          <resource-file src="src/ubuntu/toolbar-middle.png" />
diff --git a/src/ubuntu/CameraWidgetContentHub.qml b/src/ubuntu/CameraWidgetContentHub.qml
new file mode 100644
index 00000000..4aae66ab
--- /dev/null
+++ b/src/ubuntu/CameraWidgetContentHub.qml
@@ -0,0 +1,71 @@
+/*
+ *
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+import QtQuick 2.0
+
+import Ubuntu.Components 0.1
+import Ubuntu.Content 0.1
+
+Rectangle {
+  id: ui
+  property list<ContentItem> importItems
+  property var activeTransfer
+  visible: true
+  anchors.fill: parent
+  ContentPeerPicker {
+      id: peerPicker
+      anchors.fill: parent
+      contentType: ContentType.Pictures
+      handler: ContentHandler.Source
+      visible: true
+      onPeerSelected: {
+          peer.selectionType = ContentTransfer.Single
+          peerPicker.visible = false
+          activeTransfer = peer.request(store)
+      }
+      onCancelPressed: {
+          root.exec("Camera", "cancel");
+      }
+  }
+  ContentStore {
+    id: store
+    scope: ContentScope.App
+  }
+  ContentTransferHint {
+      id: transferHint
+      anchors.fill: parent
+      activeTransfer: ui.activeTransfer
+  }
+  Connections {
+      target: ui.activeTransfer
+      onStateChanged: {
+          if (ui.activeTransfer.state === ContentTransfer.Charged) {
+              root.exec("Camera", "onImageSaved", [String(ui.activeTransfer.items[0].url).substr('file:/'.length)]);
+              ui.activeTransfer.finalize();
+              ui.visible = false
+          }
+          if (ui.activeTransfer.state === ContentTransfer.Finalized) {
+//              ui.destroy();
+          }
+      }
+  }
+}
diff --git a/src/ubuntu/camera.cpp b/src/ubuntu/camera.cpp
index c58af32f..100be483 100644
--- a/src/ubuntu/camera.cpp
+++ b/src/ubuntu/camera.cpp
@@ -22,12 +22,6 @@
 #include "camera.h"
 #include <cordova.h>
 
-#include <QCameraViewfinder>
-#include <QCameraImageCapture>
-#include <QGraphicsObject>
-#include <QCloseEvent>
-#include <QQuickItem>
-
 const char code[] = "\
 var component, object;                                                  \
 function createObject() {                                               \
@@ -50,7 +44,7 @@ Camera::Camera(Cordova *cordova):
     _lastEcId(0) {
 }
 
-bool Camera::preprocessImage(QString &path) {
+QString Camera::preprocessImage(const QString &path) {
     bool convertToPNG = (*_options.find("encodingType")).toInt() == Camera::PNG;
     int quality = (*_options.find("quality")).toInt();
     int width = (*_options.find("targetWidth")).toInt();
@@ -67,36 +61,35 @@ bool Camera::preprocessImage(QString &path) {
     QTemporaryFile newImage;
 
     const char *type;
+    QString newPath;
     if (convertToPNG) {
-        path = generateLocation("png");
+        newPath = generateLocation("png");
         type = "png";
     } else {
-        path = generateLocation("jpg");
+        newPath = generateLocation("jpg");
         type = "jpg";
     }
 
-    image.save(path, type, quality);
+    image.save(newPath, type, quality);
 
     oldImage.remove();
 
-    return true;
+    return newPath;
 }
 
-void Camera::onImageSaved(QString path) {
+void Camera::onImageSaved(const QString &path) {
     bool dataURL = _options.find("destinationType")->toInt() == Camera::DATA_URL;
 
     QString cbParams;
-    if (preprocessImage(path)) {
-        QString absolutePath = QFileInfo(path).absoluteFilePath();
-        if (dataURL) {
-            QFile image(absolutePath);
-            image.open(QIODevice::ReadOnly);
-            QByteArray content = image.readAll().toBase64();
-            cbParams = QString("\"%1\"").arg(content.data());
-            image.remove();
-        } else {
-            cbParams = CordovaInternal::format(QString("file://localhost") + absolutePath);
-        }
+    QString absolutePath = QFileInfo(preprocessImage(path)).absoluteFilePath();
+    if (dataURL) {
+        QFile image(absolutePath);
+        image.open(QIODevice::ReadOnly);
+        QByteArray content = image.readAll().toBase64();
+        cbParams = QString("\"%1\"").arg(content.data());
+        image.remove();
+    } else {
+        cbParams = CordovaInternal::format(QString("file://localhost") + absolutePath);
     }
 
     this->callback(_lastScId, cbParams);
@@ -125,7 +118,12 @@ void Camera::takePicture(int scId, int ecId, int quality, int destinationType, i
     _lastScId = scId;
     _lastEcId = ecId;
 
-    QString path = m_cordova->get_app_dir() + "/../qml/CaptureWidget.qml";
+    QString path;
+#ifdef Q_PROCESSOR_X86
+    path = m_cordova->get_app_dir() + "/../qml/CaptureWidget.qml";
+#else
+    path = m_cordova->get_app_dir() + "/../qml/CameraWidgetContentHub.qml";
+#endif
 
     // TODO: relative url
     QString qml = QString(code).arg(CordovaInternal::format(path));
diff --git a/src/ubuntu/camera.h b/src/ubuntu/camera.h
index 6d960385..4a7f4fd0 100644
--- a/src/ubuntu/camera.h
+++ b/src/ubuntu/camera.h
@@ -25,10 +25,9 @@
 #include <cplugin.h>
 
 #include <QtCore>
-#include <QQuickView>
-#include <QCamera>
-#include <QtMultimediaWidgets/QCameraViewfinder>
-#include <QCameraImageCapture>
+#include <QtGlobal>
+#include <QtQuick>
+#include <QtMultimedia>
 
 class Camera: public CPlugin {
     Q_OBJECT
@@ -52,7 +51,7 @@ public slots:
                      int/*mediaType*/, bool/*allowEdit*/, bool/*correctOrientation*/, bool/*saveToPhotoAlbum*/, const QVariantMap &popoverOptions, int cameraDirection);
     void cancel();
 
-    void onImageSaved(QString path);
+    void onImageSaved(const QString &path);
 
     QString generateLocation(const QString &extension) {
         int i = 1;
@@ -65,7 +64,7 @@ public slots:
         }
     }
 private:
-    bool preprocessImage(QString &path);
+    QString preprocessImage(const QString &path);
 
     int _lastScId;
     int _lastEcId;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org