add a dummy url interceptor

will be used for device specific stuff
This commit is contained in:
Marco Martin 2013-09-18 12:10:03 +02:00
parent 8f20c41931
commit 930c8647e6
5 changed files with 154 additions and 0 deletions

View File

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

View File

@ -0,0 +1,42 @@
/*
* Copyright 2013 Marco Martin <notmart@gmail.com>
*
* 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 <QDebug>
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;
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2013 Marco Martin <notmart@gmail.com>
*
* 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 <Plasma/Package>
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

View File

@ -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 <QtCore/qurl.h>
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

View File

@ -49,6 +49,7 @@
#include <kdeclarative/configpropertymap.h>
#include <kdeclarative/qmlobject.h>
#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()) {