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:14 UTC

[02/11] git commit: add ubuntu platform

add ubuntu platform


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

Branch: refs/heads/master
Commit: a8f79e1fd6f86bfdda2eccc6a40835feda5b65ee
Parents: a001cff
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Wed Oct 16 21:13:03 2013 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Wed Oct 16 21:13:03 2013 +0400

----------------------------------------------------------------------
 plugin.xml                  |  10 +++-
 src/ubuntu/InAppBrowser.qml |  69 +++++++++++++++++++++++++
 src/ubuntu/close.png        | Bin 0 -> 461 bytes
 src/ubuntu/inappbrowser.cpp | 106 +++++++++++++++++++++++++++++++++++++++
 src/ubuntu/inappbrowser.h   |  61 ++++++++++++++++++++++
 5 files changed, 245 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/a8f79e1f/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 21990af..5febd9d 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -24,7 +24,15 @@
         <source-file src="src/android/InAppBrowser.java" target-dir="src/org/apache/cordova/inappbrowser" />
         <source-file src="src/android/InAppChromeClient.java" target-dir="src/org/apache/cordova/inappbrowser" />
     </platform>
-    
+
+    <!-- ubuntu -->
+    <platform name="ubuntu">
+        <header-file src="src/ubuntu/inappbrowser.h" />
+        <source-file src="src/ubuntu/inappbrowser.cpp" />
+        <resource-file src="src/ubuntu/InAppBrowser.qml" />
+        <resource-file src="src/ubuntu/close.png" />
+    </platform>
+
     <!-- ios -->
     <platform name="ios">    
         <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/a8f79e1f/src/ubuntu/InAppBrowser.qml
----------------------------------------------------------------------
diff --git a/src/ubuntu/InAppBrowser.qml b/src/ubuntu/InAppBrowser.qml
new file mode 100644
index 0000000..03448f6
--- /dev/null
+++ b/src/ubuntu/InAppBrowser.qml
@@ -0,0 +1,69 @@
+/*
+ *
+ * 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 QtWebKit 3.0
+import Ubuntu.Components.Popups 0.1
+import Ubuntu.Components 0.1
+
+Rectangle {
+    anchors.fill: parent
+    id: inappbrowser
+    property string url1
+    Rectangle {
+        border.color: "black"
+        width: parent.width
+        height: urlEntry.height
+        color: "gray"
+        TextInput {
+            id: urlEntry
+            width: parent.width - closeButton.width
+            text: url1
+            activeFocusOnPress: false
+        }
+        Image {
+            id: closeButton
+            width: height
+            x: parent.width - width
+            height: parent.height
+            source: "close.png"
+            MouseArea {
+                anchors.fill: parent
+                onClicked: {
+                    root.exec("InAppBrowser", "close", [0, 0])
+                }
+            }
+        }
+    }
+
+    WebView {
+        width: parent.width
+        y: urlEntry.height
+        height: parent.height - y
+        url: url1
+        onLoadingChanged: {
+            if (loadRequest.status) {
+                root.exec("InAppBrowser", "loadFinished", [loadRequest.status])
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/a8f79e1f/src/ubuntu/close.png
----------------------------------------------------------------------
diff --git a/src/ubuntu/close.png b/src/ubuntu/close.png
new file mode 100644
index 0000000..56373d1
Binary files /dev/null and b/src/ubuntu/close.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/a8f79e1f/src/ubuntu/inappbrowser.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/inappbrowser.cpp b/src/ubuntu/inappbrowser.cpp
new file mode 100644
index 0000000..d172bab
--- /dev/null
+++ b/src/ubuntu/inappbrowser.cpp
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+#include <QQuickView>
+#include <QQuickItem>
+
+#include "inappbrowser.h"
+#include <cordova.h>
+
+Inappbrowser::Inappbrowser(Cordova *cordova): CPlugin(cordova), _eventCb(0) {
+}
+
+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.object = component.createObject(root,                \
+        {root: root, cordova: cordova, url1: %2});                      \
+}                                                                       \
+createObject()";
+
+const char EXIT_EVENT[] = "'exit'";
+const char LOADSTART_EVENT[] = "'loadstart'";
+const char LOADSTOP_EVENT[] = "'loadstop'";
+const char LOADERROR_EVENT[] = "'loaderror'";
+
+void Inappbrowser::open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures) {
+    assert(_eventCb == 0);
+
+    _eventCb = cb;
+
+    QString path = m_cordova->get_app_dir() + "/../qml/InAppBrowser.qml";
+
+    // TODO: relative url
+    QString qml = QString(code)
+      .arg(CordovaInternal::format(path)).arg(CordovaInternal::format(url));
+    m_cordova->execQML(qml);
+}
+
+void Inappbrowser::show(int, int) {
+    m_cordova->execQML("CordovaWrapper.object.visible = true");
+}
+
+void Inappbrowser::close(int, int) {
+    m_cordova->execQML("CordovaWrapper.object.destroy()");
+    this->callbackWithoutRemove(_eventCb, EXIT_EVENT);
+    _eventCb = 0;
+}
+
+void Inappbrowser::injectStyleFile(int cb, int, const QString&, bool) {
+    // TODO:
+    qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+}
+
+void Inappbrowser::injectStyleCode(int cb, int, const QString&, bool) {
+    // TODO:
+    qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+}
+
+void Inappbrowser::injectScriptFile(int cb, int, const QString&, bool) {
+    // TODO:
+    qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+}
+
+void Inappbrowser::injectScriptCode(int cb, int, const QString&, bool) {
+    // TODO:
+    qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+}
+
+void Inappbrowser::loadFinished(int status) {
+    if (status == 2) {
+        this->callbackWithoutRemove(_eventCb, LOADERROR_EVENT);
+    }
+    if (status == 0) {
+        this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
+    }
+    if (status == 3) {
+        this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/a8f79e1f/src/ubuntu/inappbrowser.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/inappbrowser.h b/src/ubuntu/inappbrowser.h
new file mode 100644
index 0000000..7a4a68a
--- /dev/null
+++ b/src/ubuntu/inappbrowser.h
@@ -0,0 +1,61 @@
+/*
+ *
+ * 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.
+ *
+*/
+#ifndef INAPPBROWSER_H
+#define INAPPBROWSER_H
+
+#include <QtCore>
+#include <cplugin.h>
+
+class Inappbrowser: public CPlugin {
+    Q_OBJECT
+public:
+    Inappbrowser(Cordova *cordova);
+
+    virtual const QString fullName() override {
+        return Inappbrowser::fullID();
+    }
+
+    virtual const QString shortName() override {
+        return "InAppBrowser";
+    }
+
+    static const QString fullID() {
+        return "InAppBrowser";
+    }
+
+public slots:
+    void open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures);
+    void show(int, int);
+    void close(int, int);
+    void injectStyleFile(int cb, int, const QString&, bool);
+    void injectStyleCode(int cb, int, const QString&, bool);
+    void injectScriptFile(int cb, int, const QString&, bool);
+    void injectScriptCode(int cb, int, const QString&, bool);
+
+    void loadFinished(int status);
+
+private:
+    int _eventCb;
+};
+
+#endif