cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [1/2] git commit: add ubuntu platform
Date Tue, 03 Dec 2013 00:04:36 GMT
Updated Branches:
  refs/heads/dev 312113a52 -> c7a4d238d


add ubuntu platform


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

Branch: refs/heads/dev
Commit: bb8b9e51fb27b5e097c7c9769d6faa6c7ee10abc
Parents: c8b0f95
Author: Maxim Ermilov <ermilov.maxim@gmail.com>
Authored: Fri Oct 4 17:02:11 2013 +0400
Committer: Maxim Ermilov <ermilov.maxim@gmail.com>
Committed: Fri Oct 4 17:02:11 2013 +0400

----------------------------------------------------------------------
 plugin.xml                  |  7 ++++
 src/ubuntu/notification.cpp | 81 ++++++++++++++++++++++++++++++++++++++++
 src/ubuntu/notification.h   | 63 +++++++++++++++++++++++++++++++
 src/ubuntu/notification.qml | 44 ++++++++++++++++++++++
 www/notification.js         |  2 +-
 5 files changed, 196 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/bb8b9e51/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 2bdbb3f..bed074c 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -30,6 +30,13 @@
 
     </platform>
 
+    <!-- ubuntu -->
+    <platform name="ubuntu">
+        <header-file src="src/ubuntu/notification.h" />
+        <source-file src="src/ubuntu/notification.cpp" />
+        <resource-file src="src/ubuntu/notification.qml" />
+    </platform>
+
     <!-- ios -->
     <platform name="ios">
         <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/bb8b9e51/src/ubuntu/notification.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/notification.cpp b/src/ubuntu/notification.cpp
new file mode 100644
index 0000000..77c5e25
--- /dev/null
+++ b/src/ubuntu/notification.cpp
@@ -0,0 +1,81 @@
+/*
+ *
+ *  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 "notification.h"
+
+#include <QApplication>
+
+#include <QMediaPlayer>
+#include <QMessageBox>
+
+void Dialogs::beep(int scId, int ecId, int times) {
+    Q_UNUSED(scId)
+    Q_UNUSED(ecId)
+    Q_UNUSED(times)
+    QMediaPlayer* player = new QMediaPlayer;
+    player->setVolume(100);
+    player->setMedia(QUrl::fromLocalFile("/usr/share/sounds/ubuntu/stereo/bell.ogg"));
+    player->play();
+}
+
+void Dialogs::alert(int scId, int ecId, const QString &message, const QString &title,
const QString &buttonLabel) {
+    QStringList list;
+    list.append(buttonLabel);
+
+    confirm(scId, ecId, message, title, list);
+}
+
+void Dialogs::confirm(int scId, int ecId, const QString &message, const QString &title,
const QStringList &buttonLabels) {
+    Q_UNUSED(ecId);
+
+    //FIXME:
+    assert(!_alertCallback);
+    _alertCallback = scId;
+
+    QString s1, s2, s3;
+    if (buttonLabels.size() > 0)
+        s1 = buttonLabels[0];
+    if (buttonLabels.size() > 1)
+        s2 = buttonLabels[1];
+    if (buttonLabels.size() > 2)
+        s3 = buttonLabels[2];
+
+    QString path = m_cordova->get_app_dir() + "/../qml/notification.qml";
+    //FIXME:
+    QString qml = QString("PopupUtils.open(\"%1\", root, { root: root, cordova: cordova,
title: \"%2\", text: \"%3\", promptVisible: false, button1Text: \"%4\", button2Text: \"%5\",
button3Text: \"%6\" })")
+                      .arg(path).arg(title).arg(message).arg(s1).arg(s2).arg(s3);
+    m_cordova->execQML(qml);
+}
+
+void Dialogs::prompt(int scId, int ecId, const QString &message, const QString &title,
const QStringList &buttonLabels, const QString &defaultText) {
+    Q_UNUSED(ecId)
+
+    assert(!_alertCallback);
+    _alertCallback = scId;
+
+    QString s1, s2, s3;
+    if (buttonLabels.size() > 0)
+        s1 = buttonLabels[0];
+    if (buttonLabels.size() > 1)
+        s2 = buttonLabels[1];
+    if (buttonLabels.size() > 2)
+        s3 = buttonLabels[2];
+    QString path = m_cordova->get_app_dir() + "/../qml/notification.qml";
+    QString qml = QString("PopupUtils.open(\"%1\", root, { root: root, cordova: cordova,
title: \"%2\", text: \"%3\", promptVisible: true, defaultPromptText: \"%7\", button1Text:
\"%4\", button2Text: \"%5\", button3Text: \"%6\" })")
+                      .arg(path).arg(title).arg(message).arg(s1).arg(s2).arg(s3).arg(defaultText);
+
+    qDebug() << qml;
+    m_cordova->execQML(qml);
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/bb8b9e51/src/ubuntu/notification.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/notification.h b/src/ubuntu/notification.h
new file mode 100644
index 0000000..3173d99
--- /dev/null
+++ b/src/ubuntu/notification.h
@@ -0,0 +1,63 @@
+/*
+ *
+ *  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 NOTIFICATION_H
+#define NOTIFICATION_H
+
+#include <QtQuick>
+#include <cplugin.h>
+#include <cordova.h>
+
+class Dialogs: public CPlugin {
+    Q_OBJECT
+public:
+    explicit Dialogs(Cordova *cordova): CPlugin(cordova), _alertCallback(0) {
+    }
+
+    virtual const QString fullName() override {
+        return Dialogs::fullID();
+    }
+
+    virtual const QString shortName() override {
+        return "Notification";
+    }
+
+    static const QString fullID() {
+        return "Notification";
+    }
+public slots:
+    void beep(int scId, int ecId, int times);
+    void alert(int scId, int ecId, const QString &message, const QString &title,
const QString &buttonLabel);
+    void confirm(int scId, int ecId, const QString &message, const QString &title,
const QStringList &buttonLabels);
+    void prompt(int scId, int ecId, const QString &message, const QString &title,
const QStringList &buttonLabels, const QString &defaultText);
+
+    void notificationDialogButtonPressed(int buttonId, const QString &text) {
+        if (text.size()) {
+            QVariantMap res;
+            res.insert("buttonIndex", buttonId);
+            res.insert("input1", text);
+            this->cb(_alertCallback, res);
+        } else {
+            this->cb(_alertCallback, buttonId);
+        }
+        _alertCallback = 0;
+    }
+
+private:
+    QQmlComponent *_component;
+    int _alertCallback;
+};
+
+#endif

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/bb8b9e51/src/ubuntu/notification.qml
----------------------------------------------------------------------
diff --git a/src/ubuntu/notification.qml b/src/ubuntu/notification.qml
new file mode 100644
index 0000000..dc42b4b
--- /dev/null
+++ b/src/ubuntu/notification.qml
@@ -0,0 +1,44 @@
+import QtQuick 2.0
+import Ubuntu.Components.Popups 0.1
+import Ubuntu.Components 0.1
+
+Dialog {
+    id: dialogue
+    property string button1Text
+    property string button2Text
+    property string button3Text
+    property bool promptVisible
+    property string defaultPromptText
+    TextInput {// FIXME: swith to TextField(TextField should support visible property)
+        id: prompt
+        color: "white"
+        text: defaultPromptText
+        visible: promptVisible
+        focus: true
+    }
+    Button {
+        text: button1Text
+        color: "orange"
+        onClicked: {
+            root.exec("Notification", "notificationDialogButtonPressed", [1, prompt.text]);
+            PopupUtils.close(dialogue)
+        }
+    }
+    Button {
+        text: button2Text
+        visible: button2Text.length > 0
+        color: "orange"
+        onClicked: {
+            root.exec("Notification", "notificationDialogButtonPressed", [2, prompt.text]);
+            PopupUtils.close(dialogue)
+        }
+    }
+    Button {
+        text: button3Text
+        visible: button3Text.length > 0
+        onClicked: {
+            root.exec("Notification", "notificationDialogButtonPressed", [3, prompt.text]);
+            PopupUtils.close(dialogue)
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/bb8b9e51/www/notification.js
----------------------------------------------------------------------
diff --git a/www/notification.js b/www/notification.js
index c16c367..1c2c191 100644
--- a/www/notification.js
+++ b/www/notification.js
@@ -63,7 +63,7 @@ module.exports = {
         // Some platforms take an array of button label names.
         // Other platforms take a comma separated list.
         // For compatibility, we convert to the desired type based on the platform.
-        if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone")
{
+        if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone"
|| platform.id == "ubuntu") {
             if (typeof _buttonLabels === 'string') {
                 var buttonLabelString = _buttonLabels;
                 _buttonLabels = _buttonLabels.split(","); // not crazy about changing the
var type here


Mime
View raw message