Added ubuntu support

This commit is contained in:
Steven Gill 2013-12-02 16:28:32 -08:00
commit d2b644e5d5
5 changed files with 244 additions and 0 deletions

View File

@ -30,6 +30,7 @@
<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>
<<<<<<< HEAD
<!-- amazon-fireos -->
<platform name="amazon-fireos">
@ -43,6 +44,13 @@
<source-file src="src/amazon/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">

View File

@ -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])
}
}
}
}

BIN
src/ubuntu/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 B

106
src/ubuntu/inappbrowser.cpp Normal file
View File

@ -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);
}
}

61
src/ubuntu/inappbrowser.h Normal file
View File

@ -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