You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/04/28 21:16:47 UTC

[2/4] git commit: add ubuntu platform

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/55b096ac
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/55b096ac
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/55b096ac

Branch: refs/heads/dev
Commit: 55b096ac100676dd819e741f0ba4936c0070a8a6
Parents: 64a72e5
Author: Maxim Ermilov <er...@gmail.com>
Authored: Fri Oct 4 17:02:11 2013 +0400
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Apr 28 12:15:40 2014 -0700

----------------------------------------------------------------------
 plugin.xml                  | 138 +++++++++++++++++++++++++++++++++++++++
 src/ubuntu/notification.cpp |  81 +++++++++++++++++++++++
 src/ubuntu/notification.h   |  63 ++++++++++++++++++
 src/ubuntu/notification.qml |  44 +++++++++++++
 www/notification.js         | 109 +++++++++++++++++++++++++++++++
 5 files changed, 435 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..8cf2f25
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+           id="org.apache.cordova.dialogs"
+      version="0.2.4-dev">
+
+    <name>Notification</name>
+    <description>Cordova Notification Plugin</description>
+    <license>Apache 2.0</license>
+    <keywords>cordova,notification</keywords>
+    <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git</repo>
+    <issue>https://issues.apache.org/jira/browse/CB/component/12320642</issue>
+
+    <js-module src="www/notification.js" name="notification">
+        <merges target="navigator.notification" />
+    </js-module>
+
+    <!-- firefoxos -->
+    <platform name="firefoxos">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Notification">
+                <param name="firefoxos-package" value="Notification" />
+            </feature>
+        </config-file>                                         
+        
+		<asset src="www/firefoxos/notification.css" target="css/notification.css" />
+		<asset src="www/firefoxos/danger-press.png" target="css/danger-press.png" />
+		<asset src="www/firefoxos/danger.png" target="css/danger.png" />
+		<asset src="www/firefoxos/default.png" target="css/default.png" />
+		<asset src="www/firefoxos/gradient.png" target="css/gradient.png" />
+		<asset src="www/firefoxos/pattern.png" target="css/pattern.png" />
+		<asset src="www/firefoxos/recommend.png" target="css/recommend.png" />
+        <js-module src="src/firefoxos/notification.js" name="dialogs-impl">
+          <runs />
+        </js-module>
+    </platform>
+
+    <!-- android -->
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Notification">
+                <param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/Notification.java" target-dir="src/org/apache/cordova/dialogs" />
+
+        <!-- android specific notification apis -->
+        <js-module src="www/android/notification.js" name="notification_android">
+            <merges target="navigator.notification" />
+        </js-module>
+
+    </platform>
+    
+     <!-- amazon-fireos -->
+    <platform name="amazon-fireos">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Notification">
+                <param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/Notification.java" target-dir="src/org/apache/cordova/dialogs" />
+
+        <!-- android specific notification apis -->
+        <js-module src="www/android/notification.js" name="notification_android">
+            <merges target="navigator.notification" />
+        </js-module>
+
+    </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="/*">
+            <feature name="Notification">
+                <param name="ios-package" value="CDVNotification"/>
+            </feature>
+        </config-file>
+        <header-file src="src/ios/CDVNotification.h" />
+	    <source-file src="src/ios/CDVNotification.m" />
+	    <resource-file src="src/ios/CDVNotification.bundle" />
+		<framework src="AudioToolbox.framework" weak="true" />
+    </platform>
+
+    <!-- blackberry10 -->
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="Notification" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="Notification" value="Notification"/>
+        </config-file>
+        <js-module src="www/blackberry10/beep.js" name="beep">
+            <clobbers target="window.navigator.notification.beep" />
+        </js-module>
+    </platform>
+
+    <!-- wp7 -->
+    <platform name="wp7">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Notification">
+                <param name="wp-package" value="Notification"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/wp/Notification.cs" />
+        <source-file src="src/wp/NotificationBox.xaml.cs" />
+        <source-file src="src/wp/NotificationBox.xaml" />
+        <source-file src="src/wp/notification-beep.wav" />
+    </platform>
+
+    <!-- wp8 -->
+    <platform name="wp8">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Notification">
+                <param name="wp-package" value="Notification"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/wp/Notification.cs" />
+        <source-file src="src/wp/NotificationBox.xaml.cs" />
+        <source-file src="src/wp/NotificationBox.xaml" />
+        <source-file src="src/wp/notification-beep.wav" />
+    </platform>
+
+    <!-- windows8 -->
+    <platform name="windows8">
+        <js-module src="src/windows8/NotificationProxy.js" name="NotificationProxy">
+            <merges target="" />
+        </js-module>
+    </platform>
+
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/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/55b096ac/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/55b096ac/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/55b096ac/www/notification.js
----------------------------------------------------------------------
diff --git a/www/notification.js b/www/notification.js
new file mode 100644
index 0000000..1c2c191
--- /dev/null
+++ b/www/notification.js
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var exec = require('cordova/exec');
+var platform = require('cordova/platform');
+
+/**
+ * Provides access to notifications on the device.
+ */
+
+module.exports = {
+
+    /**
+     * Open a native alert dialog, with a customizable title and button text.
+     *
+     * @param {String} message              Message to print in the body of the alert
+     * @param {Function} completeCallback   The callback that is called when user clicks on a button.
+     * @param {String} title                Title of the alert dialog (default: Alert)
+     * @param {String} buttonLabel          Label of the close button (default: OK)
+     */
+    alert: function(message, completeCallback, title, buttonLabel) {
+        var _title = (title || "Alert");
+        var _buttonLabel = (buttonLabel || "OK");
+        exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]);
+    },
+
+    /**
+     * Open a native confirm dialog, with a customizable title and button text.
+     * The result that the user selects is returned to the result callback.
+     *
+     * @param {String} message              Message to print in the body of the alert
+     * @param {Function} resultCallback     The callback that is called when user clicks on a button.
+     * @param {String} title                Title of the alert dialog (default: Confirm)
+     * @param {Array} buttonLabels          Array of the labels of the buttons (default: ['OK', 'Cancel'])
+     */
+    confirm: function(message, resultCallback, title, buttonLabels) {
+        var _title = (title || "Confirm");
+        var _buttonLabels = (buttonLabels || ["OK", "Cancel"]);
+
+        // Strings are deprecated!
+        if (typeof _buttonLabels === 'string') {
+            console.log("Notification.confirm(string, function, string, string) is deprecated.  Use Notification.confirm(string, function, string, array).");
+        }
+
+        // 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" || platform.id == "ubuntu") {
+            if (typeof _buttonLabels === 'string') {
+                var buttonLabelString = _buttonLabels;
+                _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here
+            }
+        } else {
+            if (Array.isArray(_buttonLabels)) {
+                var buttonLabelArray = _buttonLabels;
+                _buttonLabels = buttonLabelArray.toString();
+            }
+        }
+        exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]);
+    },
+
+    /**
+     * Open a native prompt dialog, with a customizable title and button text.
+     * The following results are returned to the result callback:
+     *  buttonIndex     Index number of the button selected.
+     *  input1          The text entered in the prompt dialog box.
+     *
+     * @param {String} message              Dialog message to display (default: "Prompt message")
+     * @param {Function} resultCallback     The callback that is called when user clicks on a button.
+     * @param {String} title                Title of the dialog (default: "Prompt")
+     * @param {Array} buttonLabels          Array of strings for the button labels (default: ["OK","Cancel"])
+     * @param {String} defaultText          Textbox input value (default: "Default text")
+     */
+    prompt: function(message, resultCallback, title, buttonLabels, defaultText) {
+        var _message = (message || "Prompt message");
+        var _title = (title || "Prompt");
+        var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
+        var _defaultText = (defaultText || "Default text");
+        exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]);
+    },
+
+    /**
+     * Causes the device to beep.
+     * On Android, the default notification ringtone is played "count" times.
+     *
+     * @param {Integer} count       The number of beeps.
+     */
+    beep: function(count) {
+        exec(null, null, "Notification", "beep", [count]);
+    }
+};