get completely rid of the packageaccessmanager

This commit is contained in:
Marco Martin 2013-10-24 13:27:02 +02:00
parent 6ff8554ae7
commit 990fd3b860
8 changed files with 2 additions and 236 deletions

View File

@ -6,10 +6,6 @@ set(plasmaquick_LIB_SRC
configview.cpp
packageurlinterceptor.cpp
private/configcategory_p.cpp
private/packageaccessmanager.cpp
private/packageaccessmanagerfactory.cpp
#private/containmentconfigview_p.cpp
#private/currentcontainmentactionsmodel_p.cpp
)
add_library(PlasmaQuick SHARED ${plasmaquick_LIB_SRC})

View File

@ -21,8 +21,6 @@
#include <packageurlinterceptor.h>
#include <QQmlNetworkAccessManagerFactory>
#include <qtest.h>
#include <QDebug>
@ -31,9 +29,7 @@ QTEST_MAIN(PackageUrlInterceptorTest)
void PackageUrlInterceptorTest::loadAccessManager()
{
const Plasma::Package &pkg = Plasma::Package();
QQmlNetworkAccessManagerFactory* pui = PackageUrlInterceptor::createPackageAccessManagerFactory(pkg);
QVERIFY(pui != 0);
delete pui;
//TODO: tests on path resolution
}
#include "moc_packageurlinterceptortest.cpp"

View File

@ -18,7 +18,6 @@
*/
#include "packageurlinterceptor.h"
#include "private/packageaccessmanagerfactory.h"
#include <QDebug>
#include <QQmlEngine>
@ -116,9 +115,6 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
return path;
}
QQmlNetworkAccessManagerFactory* PackageUrlInterceptor::createPackageAccessManagerFactory(const Plasma::Package& package)
{
return new PackageAccessManagerFactory(package);
}

View File

@ -21,7 +21,6 @@
#define PACKAGEURLINTERCEPTOR_H
#include <QQmlAbstractUrlInterceptor>
#include <QQmlNetworkAccessManagerFactory>
#include <plasmaquick/plasmaquick_export.h>
@ -38,8 +37,6 @@ public:
virtual QUrl intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type);
static QQmlNetworkAccessManagerFactory* createPackageAccessManagerFactory(const Plasma::Package &package);
static inline QByteArray prefixForType(QQmlAbstractUrlInterceptor::DataType type, const QString &fileName)
{
switch (type) {

View File

@ -1,82 +0,0 @@
/*
* Copyright 2010 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 "packageaccessmanager.h"
#include <QNetworkReply>
class ErrorReply : public QNetworkReply
{
public:
ErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &req)
: QNetworkReply()
{
setError(QNetworkReply::ContentOperationNotPermittedError, QStringLiteral("The plasmoid has not been authorized to load remote content"));
setOperation(op);
setRequest(req);
setUrl(req.url());
}
qint64 readData(char *data, qint64 maxSize)
{
Q_UNUSED(data);
Q_UNUSED(maxSize);
return 0;
}
void abort()
{
}
};
PackageAccessManager::PackageAccessManager(const Plasma::Package &package, QObject *parent)
: KIO::AccessManager(parent),
m_package(package)
{
}
PackageAccessManager::~PackageAccessManager()
{
}
QNetworkReply *PackageAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
{
QUrl reqUrl(req.url());
if (reqUrl.scheme() == QStringLiteral("plasmapackage")) {
QNetworkRequest request = req;
reqUrl.setScheme(QStringLiteral("file"));
reqUrl.setPath(m_package.filePath(0, reqUrl.path()));
request.setUrl(reqUrl);
return QNetworkAccessManager::createRequest(op, request, outgoingData);
} else if ((reqUrl.scheme() == QStringLiteral("http")) ||
((reqUrl.scheme() == QStringLiteral("file") || reqUrl.scheme() == QStringLiteral("desktop")))) {
return new ErrorReply(op, req);
} else {
#ifndef PLASMA_NO_KIO
return KIO::AccessManager::createRequest(op, req, outgoingData);
#else
return QNetworkAccessManager::createRequest(op, req, outgoingData);
#endif
}
}

View File

@ -1,56 +0,0 @@
/*
* Copyright 2010 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 PACKAGEACCESSMANAGER_H
#define PACKAGEACCESSMANAGER_H
#include <kdemacros.h>
#include <Plasma/Package>
#ifndef PLASMA_NO_KIO
#include <kio/accessmanager.h>
#else
#include <QtNetwork/QNetworkAccessManager>
#endif
namespace Plasma
{
class Package;
}
class PackageAccessManager :
#ifdef PLASMA_NO_KIO
public QNetworkAccessManager
#else
public KIO::AccessManager
#endif
{
public:
PackageAccessManager(const Plasma::Package &package, QObject *parent = 0);
~PackageAccessManager();
protected:
QNetworkReply *createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0);
private:
Plasma::Package m_package;
};
#endif

View File

@ -1,39 +0,0 @@
/*
* Copyright 2010 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 "packageaccessmanagerfactory.h"
#include "packageaccessmanager.h"
PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package &package)
: QQmlNetworkAccessManagerFactory(),
m_package(package)
{
}
PackageAccessManagerFactory::~PackageAccessManagerFactory()
{
}
QNetworkAccessManager *PackageAccessManagerFactory::create(QObject *parent)
{
return new PackageAccessManager(m_package, parent);
}

View File

@ -1,42 +0,0 @@
/*
* Copyright 2010 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 PACKAGEACCESSMANAGERFACTORY_H
#define PACKAGEACCESSMANAGERFACTORY_H
#include <QQmlNetworkAccessManagerFactory>
#include <plasmaquick/plasmaquick_export.h>
#include <Plasma/Package>
class AppletAuthorization;
class PackageAccessManagerFactory : public QQmlNetworkAccessManagerFactory
{
public:
PackageAccessManagerFactory(const Plasma::Package &package);
~PackageAccessManagerFactory();
QNetworkAccessManager *create(QObject *parent);
private:
Plasma::Package m_package;
};
#endif