From a8f79e1fd6f86bfdda2eccc6a40835feda5b65ee Mon Sep 17 00:00:00 2001 From: Maxim Ermilov Date: Wed, 16 Oct 2013 21:13:03 +0400 Subject: [PATCH] add ubuntu platform --- 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(-) create mode 100644 src/ubuntu/InAppBrowser.qml create mode 100644 src/ubuntu/close.png create mode 100644 src/ubuntu/inappbrowser.cpp create mode 100644 src/ubuntu/inappbrowser.h diff --git a/plugin.xml b/plugin.xml index 21990af..5febd9d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,7 +24,15 @@ - + + + + + + + + + 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]) + } + } + } +} diff --git a/src/ubuntu/close.png b/src/ubuntu/close.png new file mode 100644 index 0000000000000000000000000000000000000000..56373d1fab22ebf492ea9e145d866e444e0ed46e GIT binary patch literal 461 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-s-T^)#uK)l42QrBS0s;aC1_l8E z0SO5S1qB5Q7A!b$;J}3o7e0LW05pe>cjHx{L3|}ae!&d<^7{Vq`Stzt*Pp-t-e~@; zDh38dWltB!kcwMpFFQ_ZG7xaM=)%##mnhP5=l_zl6%X`Z$W>*pUvuvFQ>BBoKYv`f z_WP{rmaG5wy-MyWe?Q~H_Lt}W?BjUdq#g~d~TfSj$?1SDzA4I05U;D24E?e@`w(nif{~GTp%dgmd;CAbm zvc~P)FW)}8G{5R+ui32lEr&iHJ$wAOX!$>d6;Ec*IPz@f#eVJL+gvu%HEWLUJ{ezP(7s~RXqJYD@<);T3K0RZo?&l3Ou literal 0 HcmV?d00001 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 +#include + +#include "inappbrowser.h" +#include + +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); + } +} 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 +#include + +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