2
* Copyright 2010 Marco Martin <notmart@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "packageaccessmanager.h"
22
#include <QNetworkReply>
24
#include <Plasma/Package>
26
#include "plasmoid/appletauthorization.h"
28
class ErrorReply : public QNetworkReply
31
ErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &req)
34
setError(QNetworkReply::ContentOperationNotPermittedError, "The plasmoid has not been authorized to load remote content");
40
qint64 readData(char *data, qint64 maxSize)
50
PackageAccessManager::PackageAccessManager(const Plasma::Package *package, AppletAuthorization *auth, QObject *parent)
51
: KIO::AccessManager(parent),
57
PackageAccessManager::~PackageAccessManager()
62
QNetworkReply *PackageAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
64
QUrl reqUrl(req.url());
66
if (reqUrl.scheme() == "plasmapackage") {
67
QNetworkRequest request = req;
68
reqUrl.setScheme("file");
69
reqUrl.setPath(m_package->filePath(0, reqUrl.path()));
70
request.setUrl(reqUrl);
71
return QNetworkAccessManager::createRequest(op, request, outgoingData);
72
} else if ((reqUrl.scheme() == "http" && !m_auth->authorizeRequiredExtension("http")) ||
73
((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop") && !m_auth->authorizeRequiredExtension("localio")) ||
74
(!m_auth->authorizeRequiredExtension("networkio"))) {
75
return new ErrorReply(op, req);
77
return KIO::AccessManager::createRequest(op, req, outgoingData);