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 2013/12/05 01:59:50 UTC

[5/8] git commit: add ubuntu platform

add ubuntu platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/commit/291b25f5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/291b25f5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/291b25f5

Branch: refs/heads/master
Commit: 291b25f5cce3493812d0fcd3742f7ec6dad57c79
Parents: 5f50ac7
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Mon Nov 18 15:08:23 2013 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Mon Nov 18 15:08:23 2013 +0400

----------------------------------------------------------------------
 plugin.xml                    |  18 +++-
 src/ubuntu/back.png           | Bin 0 -> 12428 bytes
 src/ubuntu/capture.cpp        | 167 +++++++++++++++++++++++++++++++++++++
 src/ubuntu/capture.h          |  84 +++++++++++++++++++
 src/ubuntu/microphone.png     | Bin 0 -> 10415 bytes
 src/ubuntu/record_off.png     | Bin 0 -> 10087 bytes
 src/ubuntu/record_on.png      | Bin 0 -> 4902 bytes
 src/ubuntu/shoot.png          | Bin 0 -> 14430 bytes
 src/ubuntu/toolbar-left.png   | Bin 0 -> 1212 bytes
 src/ubuntu/toolbar-middle.png | Bin 0 -> 4416 bytes
 src/ubuntu/toolbar-right.png  | Bin 0 -> 1161 bytes
 11 files changed, 268 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index cd22f66..38a306e 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -59,7 +59,23 @@ xmlns:android="http://schemas.android.com/apk/res/android"
         <source-file src="src/android/Capture.java" target-dir="src/org/apache/cordova/mediacapture" />
         <source-file src="src/android/FileHelper.java" target-dir="src/org/apache/cordova/mediacapture" />
     </platform>
-    
+
+    <!-- ubuntu -->
+    <platform name="ubuntu">
+        <header-file src="src/ubuntu/capture.h" />
+        <source-file src="src/ubuntu/capture.cpp" />
+
+        <resource-file src="src/ubuntu/back.png" />
+        <resource-file src="src/ubuntu/MediaCaptureWidget.qml" />
+        <resource-file src="src/ubuntu/shoot.png" />
+        <resource-file src="src/ubuntu/microphone.png" />
+        <resource-file src="src/ubuntu/record_on.png" />
+        <resource-file src="src/ubuntu/record_off.png" />
+        <resource-file src="src/ubuntu/toolbar-left.png" />
+        <resource-file src="src/ubuntu/toolbar-middle.png" />
+        <resource-file src="src/ubuntu/toolbar-right.png" />
+    </platform>
+
     <!-- ios -->
     <platform name="ios">    
         <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/back.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/back.png b/src/ubuntu/back.png
new file mode 100644
index 0000000..af78faa
Binary files /dev/null and b/src/ubuntu/back.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/capture.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/capture.cpp b/src/ubuntu/capture.cpp
new file mode 100644
index 0000000..cab4074
--- /dev/null
+++ b/src/ubuntu/capture.cpp
@@ -0,0 +1,167 @@
+/*
+ *
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Licensed 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.
+ *
+*/
+#include "capture.h"
+
+const char code[] = "\
+var component, object;                                                  \
+function createObject() {                                               \
+    component = Qt.createComponent(%1);                                 \
+    if (component.status == Component.Ready)                            \
+        finishCreation();                                               \
+    else                                                                \
+        component.statusChanged.connect(finishCreation);                \
+}                                                                       \
+function finishCreation() {                                             \
+    CordovaWrapper.captureObject = component.createObject(root,         \
+        {root: root, cordova: cordova, state: \"%2\"});                 \
+}                                                                       \
+createObject()";
+
+static QString formatFile(const QMimeDatabase &db, const QString &path) {
+    QFileInfo info(path);
+    QMimeType mime = db.mimeTypeForFile(info.fileName());
+
+    QVariantMap file;
+    file.insert("name", info.fileName());
+    file.insert("fullPath", info.absoluteFilePath());
+    file.insert("lastModifiedDate", info.lastModified().toMSecsSinceEpoch());
+    file.insert("size", info.size());
+    file.insert("type", mime.name());
+
+    return CordovaInternal::format(file);
+}
+
+MediaCapture::MediaCapture(Cordova *cordova): CPlugin(cordova), _scId(0), _ecId(0) {
+}
+
+void MediaCapture::captureAudio(int scId, int ecId, QVariantMap options) {
+    if (_scId || _ecId) {
+        this->callback(_ecId, QString("{code: %1}").arg(CAPTURE_APPLICATION_BUSY));
+        return;
+    }
+
+    QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidget.qml";
+
+    // TODO: relative url
+    QString qml = QString(code).arg(CordovaInternal::format(path)).arg("audio");
+    m_cordova->execQML(qml);
+
+    _scId = scId;
+    _ecId = ecId;
+}
+
+void MediaCapture::onAudioRecordError(QMediaRecorder::Error) {
+    if (!_ecId)
+        return;
+    this->callback(_ecId, QString("{code: %1}").arg(CAPTURE_INTERNAL_ERR));
+    _ecId = _scId = 0;
+
+    _recorder.clear();
+    _files.clear();
+
+    m_cordova->execQML("CordovaWrapper.captureObject.destroy()");
+}
+
+void MediaCapture::recordAudio() {
+    if (_recorder.data()) {
+        QUrl url = _recorder->outputLocation();
+
+        QString path = url.toString();
+        _recorder->stop();
+
+        _recorder.clear();
+
+        this->callback(_scId, QString("[%1]").arg(formatFile(_db, path)));
+        _ecId = _scId = 0;
+
+        m_cordova->execQML("CordovaWrapper.captureObject.destroy()");
+    } else {
+        _recorder = QSharedPointer<QAudioRecorder>(new QAudioRecorder);
+        QObject::connect(_recorder.data(), SIGNAL(error(QMediaRecorder::Error)), this, SLOT(onAudioRecordError(QMediaRecorder::Error)));
+
+        if (_options.find("mode")->toString() == "audio/amr") {
+            _recorder->setContainerFormat("amr");
+            _recorder->setOutputLocation(generateLocation("amr"));
+        } else {
+            _recorder->setContainerFormat("wav");
+            _recorder->setOutputLocation(generateLocation("wav"));
+        }
+        _recorder->record();
+    }
+}
+
+void MediaCapture::cancel() {
+    if (!_ecId)
+        return;
+
+    m_cordova->execQML("CordovaWrapper.captureObject.destroy()");
+
+    _recorder.clear();
+    this->callback(_ecId, QString("{code: %1}").arg(CAPTURE_NO_MEDIA_FILES));
+    _ecId = _scId = 0;
+
+    _recorder.clear();
+}
+
+void MediaCapture::captureVideo(int scId, int ecId, QVariantMap options) {
+    if (_scId || _ecId) {
+        this->callback(_ecId, QString("{code: %1}").arg(CAPTURE_APPLICATION_BUSY));
+        return;
+    }
+
+    QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidget.qml";
+
+    // TODO: relative url
+    QString qml = QString(code).arg(CordovaInternal::format(path)).arg("videoRecording");
+    m_cordova->execQML(qml);
+
+    _scId = scId;
+    _ecId = ecId;
+}
+
+void MediaCapture::onVideoRecordEnd(QString path) {
+    assert(path.startsWith("file:"));
+    path = path.mid(5);
+
+    this->callback(_scId, QString("[%1]").arg(formatFile(_db, path)));
+    _ecId = _scId = 0;
+
+    m_cordova->execQML("CordovaWrapper.captureObject.destroy()");
+}
+
+void MediaCapture::captureImage(int scId, int ecId, QVariantMap options) {
+    if (_scId || _ecId) {
+        this->callback(_ecId, QString("{code: %1}").arg(CAPTURE_APPLICATION_BUSY));
+        return;
+    }
+
+    QString path = m_cordova->get_app_dir() + "/../qml/MediaCaptureWidget.qml";
+
+    // TODO: relative url
+    QString qml = QString(code).arg(CordovaInternal::format(path)).arg("camera");
+    m_cordova->execQML(qml);
+
+    _scId = scId;
+    _ecId = ecId;
+}
+
+void MediaCapture::onImageSaved(const QString &path) {
+    this->callback(_scId, QString("[%1]").arg(formatFile(_db, path)));
+    _ecId = _scId = 0;
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/capture.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/capture.h b/src/ubuntu/capture.h
new file mode 100644
index 0000000..2c6caa4
--- /dev/null
+++ b/src/ubuntu/capture.h
@@ -0,0 +1,84 @@
+/*
+ *
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Licensed 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.
+ *
+*/
+#ifndef CAPTURE_H_ASCXZFG975
+#define CAPTURE_H_ASCXZFG975
+
+#include <cordova.h>
+#include <cplugin.h>
+#include <QtMultimedia>
+#include <QtCore>
+#include <QtQuick>
+
+class MediaCapture: public CPlugin {
+    Q_OBJECT
+public:
+    explicit MediaCapture(Cordova *cordova);
+
+    virtual const QString fullName() override {
+        return MediaCapture::fullID();
+    }
+
+    virtual const QString shortName() override {
+        return "Capture";
+    }
+
+    static const QString fullID() {
+        return "Capture";
+    }
+
+public slots:
+    void captureAudio(int scId, int ecId, QVariantMap options);
+    void captureImage(int scId, int ecId, QVariantMap options);
+    void captureVideo(int scId, int ecId, QVariantMap options);
+
+    void recordAudio();
+    void cancel();
+    void onVideoRecordEnd(QString path);
+    void onImageSaved(const 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 slots:
+    void onAudioRecordError(QMediaRecorder::Error);
+private:
+    QSharedPointer<QAudioRecorder> _recorder;
+
+    int _scId, _ecId;
+    QList<QString> _files;
+    QVariantMap _options;
+    QMimeDatabase _db;
+
+    enum CaptureError {
+        CAPTURE_INTERNAL_ERR = 0,
+        CAPTURE_APPLICATION_BUSY = 1,
+        CAPTURE_INVALID_ARGUMENT = 2,
+        CAPTURE_NO_MEDIA_FILES = 3,
+        CAPTURE_NOT_SUPPORTED = 20
+    };
+};
+
+#endif

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/microphone.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/microphone.png b/src/ubuntu/microphone.png
new file mode 100644
index 0000000..4f2a5cf
Binary files /dev/null and b/src/ubuntu/microphone.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/record_off.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/record_off.png b/src/ubuntu/record_off.png
new file mode 100644
index 0000000..adc822c
Binary files /dev/null and b/src/ubuntu/record_off.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/record_on.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/record_on.png b/src/ubuntu/record_on.png
new file mode 100644
index 0000000..985658a
Binary files /dev/null and b/src/ubuntu/record_on.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/shoot.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/shoot.png b/src/ubuntu/shoot.png
new file mode 100644
index 0000000..c093b63
Binary files /dev/null and b/src/ubuntu/shoot.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/toolbar-left.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/toolbar-left.png b/src/ubuntu/toolbar-left.png
new file mode 100644
index 0000000..720d7f6
Binary files /dev/null and b/src/ubuntu/toolbar-left.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/toolbar-middle.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/toolbar-middle.png b/src/ubuntu/toolbar-middle.png
new file mode 100644
index 0000000..77595bb
Binary files /dev/null and b/src/ubuntu/toolbar-middle.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/291b25f5/src/ubuntu/toolbar-right.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/toolbar-right.png b/src/ubuntu/toolbar-right.png
new file mode 100644
index 0000000..e4e6aa6
Binary files /dev/null and b/src/ubuntu/toolbar-right.png differ