From 930c8647e6b466c81891b19d0cd0a622a6f11f12 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 18 Sep 2013 12:10:03 +0200 Subject: [PATCH] add a dummy url interceptor will be used for device specific stuff --- src/scriptengines/qml/CMakeLists.txt | 1 + .../qml/declarative/packageurlinterceptor.cpp | 42 ++++++++++++ .../qml/declarative/packageurlinterceptor.h | 40 +++++++++++ .../qqmlabstracturlinterceptor_p.h | 66 +++++++++++++++++++ .../qml/plasmoid/appletinterface.cpp | 5 ++ 5 files changed, 154 insertions(+) create mode 100644 src/scriptengines/qml/declarative/packageurlinterceptor.cpp create mode 100644 src/scriptengines/qml/declarative/packageurlinterceptor.h create mode 100644 src/scriptengines/qml/declarative/qqmlabstracturlinterceptor_p.h diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index d21c5d2ea..7f00b99e6 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories(${KDE4_INCLUDE_DIR}/KDE ${PHONON_INCLUDES} ${CMAKE_CURRENT_S set(declarative_appletscript_SRCS declarative/packageaccessmanager.cpp declarative/packageaccessmanagerfactory.cpp + declarative/packageurlinterceptor.cpp plasmoid/appletinterface.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp diff --git a/src/scriptengines/qml/declarative/packageurlinterceptor.cpp b/src/scriptengines/qml/declarative/packageurlinterceptor.cpp new file mode 100644 index 000000000..61bb17621 --- /dev/null +++ b/src/scriptengines/qml/declarative/packageurlinterceptor.cpp @@ -0,0 +1,42 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "packageurlinterceptor.h" + +#include + +PackageUrlInterceptor::PackageUrlInterceptor(const Plasma::Package &p) + : QQmlAbstractUrlInterceptor(), + m_package(p) +{ +} + +PackageUrlInterceptor::~PackageUrlInterceptor() +{ +} + +QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type) +{ + //qDebug() << "Intercepted URL:" << path; + + return path; +} + + + diff --git a/src/scriptengines/qml/declarative/packageurlinterceptor.h b/src/scriptengines/qml/declarative/packageurlinterceptor.h new file mode 100644 index 000000000..0827de090 --- /dev/null +++ b/src/scriptengines/qml/declarative/packageurlinterceptor.h @@ -0,0 +1,40 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef PACKAGEURLINTERCEPTOR_H +#define PACKAGEURLINTERCEPTOR_H + +#include "qqmlabstracturlinterceptor_p.h" + +#include + +class PackageUrlInterceptor: public QQmlAbstractUrlInterceptor +{ +public: + PackageUrlInterceptor(const Plasma::Package &p); + virtual ~PackageUrlInterceptor(); + + virtual QUrl intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type); + +private: + Plasma::Package m_package; +}; + + +#endif diff --git a/src/scriptengines/qml/declarative/qqmlabstracturlinterceptor_p.h b/src/scriptengines/qml/declarative/qqmlabstracturlinterceptor_p.h new file mode 100644 index 000000000..01ef3e65e --- /dev/null +++ b/src/scriptengines/qml/declarative/qqmlabstracturlinterceptor_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//Private API for 5.1 (at least) +#ifndef QQMLABSTRACTURLINTERCEPTOR_H +#define QQMLABSTRACTURLINTERCEPTOR_H + +#include + +QT_BEGIN_NAMESPACE + +class QQmlAbstractUrlInterceptor +{ + Q_FLAGS(InterceptionPoint) +public: + enum DataType { //Matches QQmlDataBlob::Type + QmlFile = 0, + JavaScriptFile = 1, + QmldirFile = 2, + UrlString = 0x1000 + }; + + QQmlAbstractUrlInterceptor() {} + virtual ~QQmlAbstractUrlInterceptor() {} + virtual QUrl intercept(const QUrl &path, DataType type) = 0; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index ab7bf1b05..c30ec994f 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -49,6 +49,7 @@ #include #include #include "declarative/packageaccessmanagerfactory.h" +#include "declarative/packageurlinterceptor.h" Q_DECLARE_METATYPE(AppletInterface*) @@ -112,6 +113,10 @@ void AppletInterface::init() delete factory; engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(m_appletScriptEngine->package())); + //Hook generic url resolution to the applet package as well + //TODO: same thing will have to be done for every qqmlengine: PackageUrlInterceptor is material for plasmaquick? + engine->setUrlInterceptor(new PackageUrlInterceptor(m_appletScriptEngine->package())); + m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript())); if (!m_qmlObject->engine() || !m_qmlObject->engine()->rootContext() || !m_qmlObject->engine()->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) {