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:41:55 UTC

[GitHub] maverickmishra closed pull request #30: ubuntu: use content hub on device

maverickmishra closed pull request #30: ubuntu: use content hub on device
URL: https://github.com/apache/cordova-plugin-media-capture/pull/30
 
 
   

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 c374dd3..fcae253 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -105,6 +105,7 @@ xmlns:rim="http://www.blackberry.com/ns/widgets"
 
         <resource-file src="src/ubuntu/back.png" />
         <resource-file src="src/ubuntu/MediaCaptureWidget.qml" />
+        <resource-file src="src/ubuntu/MediaCaptureWidgetContentHub.qml" />
         <resource-file src="src/ubuntu/shoot.png" />
         <resource-file src="src/ubuntu/microphone.png" />
         <resource-file src="src/ubuntu/record_on.png" />
diff --git a/src/ubuntu/MediaCaptureWidget.qml b/src/ubuntu/MediaCaptureWidget.qml
index 98350fa..4f5f5a5 100644
--- a/src/ubuntu/MediaCaptureWidget.qml
+++ b/src/ubuntu/MediaCaptureWidget.qml
@@ -51,12 +51,12 @@ Rectangle {
         }
         videoRecorder {
             audioBitRate: 128000
-            mediaContainer: "mp4"
             outputLocation: ui.parent.plugin('Capture').generateLocation("mp4")
             onRecorderStateChanged: {
                if (videoRecorder.recorderState === CameraRecorder.StoppedState) {
                    ui.parent.exec("Capture", "onVideoRecordEnd", [camera.videoRecorder.outputLocation]);
                    shootButton.source = recordOffImagePath
+                   ui.destroy();
                }
             }
         }
@@ -101,6 +101,7 @@ Rectangle {
                     anchors.fill: parent
                     onClicked: {
                         root.exec("Capture", "cancel");
+                        ui.destroy();
                     }
                 }
             }
diff --git a/src/ubuntu/MediaCaptureWidgetContentHub.qml b/src/ubuntu/MediaCaptureWidgetContentHub.qml
new file mode 100644
index 0000000..f60384d
--- /dev/null
+++ b/src/ubuntu/MediaCaptureWidgetContentHub.qml
@@ -0,0 +1,104 @@
+/*
+ *
+ * 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.Videos
+        handler: ContentHandler.Source
+        visible: true
+        onPeerSelected: {
+            peer.selectionType = ContentTransfer.Single
+            peerPicker.visible = false
+            activeTransfer = peer.request(store)
+        }
+        onCancelPressed: {
+            ui.visible = false
+            root.exec("Capture", "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.Aborted) {
+                ui.visible = false
+                root.exec("Capture", "cancel");
+                return;
+            }
+            if (ui.activeTransfer.state === ContentTransfer.Charged) {
+                var capture = root.plugin('Capture');
+
+                if (ui.state == 'camera') {
+                    var path = capture.generateLocation("jpg");
+                    capture.renameFile(String(ui.activeTransfer.items[0].url).substr('file://'.length), path);
+                    capture.onImageSaved(path);
+                    ui.visible = false
+                    ui.activeTransfer.finalize();
+                } else {
+                    var path = capture.generateLocation("mp4");
+                    capture.copyFile(String(ui.activeTransfer.items[0].url).substr('file://'.length), path);
+                    capture.onVideoRecordEnd(path);
+                    ui.activeTransfer.finalize();
+                    ui.visible = false
+                }
+            }
+        }
+    }
+    states: [
+        State {
+            name: "videoRecording"
+            StateChangeScript {
+                script: {
+                    peerPicker.contentType = ContentType.Videos
+                }
+            }
+        },
+        State {
+            name: "camera"
+            StateChangeScript {
+                script: {
+                    peerPicker.contentType = ContentType.Pictures
+                }
+            }
+        }
+    ]
+}
diff --git a/src/ubuntu/capture.cpp b/src/ubuntu/capture.cpp
index aaf0910..4e1ce1e 100644
--- a/src/ubuntu/capture.cpp
+++ b/src/ubuntu/capture.cpp
@@ -109,8 +109,6 @@ void MediaCapture::cancel() {
     if (!_ecId)
         return;
 
-    m_cordova->execQML("CordovaWrapper.global.captureObject.destroy()");
-
     _recorder.clear();
     this->callback(_ecId, QString("{code: %1}").arg(CAPTURE_NO_MEDIA_FILES));
     _ecId = _scId = 0;
@@ -124,7 +122,11 @@ void MediaCapture::captureVideo(int scId, int ecId, const QVariantMap &) {
         return;
     }
 
+#ifdef Q_PROCESSOR_X86
     QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidget.qml";
+#else
+    QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidgetContentHub.qml";
+#endif
     QString qml = QString(code).arg(CordovaInternal::format(path)).arg("videoRecording");
     m_cordova->execQML(qml);
 
@@ -137,8 +139,6 @@ void MediaCapture::onVideoRecordEnd(const QString &uri) {
 
     this->callback(_scId, QString("[%1]").arg(formatFile(_db, path)));
     _ecId = _scId = 0;
-
-    m_cordova->execQML("CordovaWrapper.global.captureObject.destroy()");
 }
 
 void MediaCapture::captureImage(int scId, int ecId, const QVariantMap &) {
@@ -147,7 +147,11 @@ void MediaCapture::captureImage(int scId, int ecId, const QVariantMap &) {
         return;
     }
 
+#ifdef Q_PROCESSOR_X86
     QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidget.qml";
+#else
+    QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidgetContentHub.qml";
+#endif
     QString qml = QString(code).arg(CordovaInternal::format(path)).arg("camera");
     m_cordova->execQML(qml);
 
diff --git a/src/ubuntu/capture.h b/src/ubuntu/capture.h
index 4806771..2a09f71 100644
--- a/src/ubuntu/capture.h
+++ b/src/ubuntu/capture.h
@@ -62,6 +62,12 @@ public slots:
                 return path;
         }
     }
+    void renameFile(const QString &old, const QString &n) {
+        QFile::rename(old, n);
+    }
+    void copyFile(const QString &old, const QString &n) {
+        QFile::copy(old, n);
+    }
 private slots:
     void onAudioRecordError(QMediaRecorder::Error);
 private:


 

----------------------------------------------------------------
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