2009-09-02 04:27:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2009 Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-11-25 02:08:35 +01:00
|
|
|
#include "plasmoidservice_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
|
|
|
|
#include "authorizationmanager_p.h"
|
|
|
|
#include "dataengineconsumer_p.h"
|
|
|
|
#include "dataengine_p.h"
|
|
|
|
|
|
|
|
#include <plasma/applet.h>
|
2009-09-03 23:10:33 +02:00
|
|
|
#include <plasma/remote/authorizationmanager.h>
|
|
|
|
#include <plasma/remote/authorizationrule.h>
|
2009-09-02 04:27:16 +02:00
|
|
|
#include <plasma/service.h>
|
|
|
|
#include <plasma/servicejob.h>
|
|
|
|
|
2009-09-02 08:28:32 +02:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <ktemporaryfile.h>
|
|
|
|
#include <kzip.h>
|
2011-07-13 20:03:00 +02:00
|
|
|
#include <kservicetypetrader.h>
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
#include <QDir>
|
2009-09-02 04:27:16 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QHostInfo>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2011-05-31 00:28:06 +02:00
|
|
|
PlasmoidServiceJob::PlasmoidServiceJob(const QString &destination,
|
2009-09-02 04:27:16 +02:00
|
|
|
const QString &operation,
|
2011-05-26 19:01:44 +02:00
|
|
|
QHash<QString,QVariant>& parameters,
|
2009-09-02 04:27:16 +02:00
|
|
|
PlasmoidService *service)
|
|
|
|
: Plasma::ServiceJob(destination, operation, parameters,
|
|
|
|
static_cast<Plasma::Service*>(service)),
|
2011-05-31 00:28:06 +02:00
|
|
|
m_service(service)
|
2009-09-02 04:27:16 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmoidServiceJob::start()
|
|
|
|
{
|
|
|
|
if (operationName() == "GetPackage") {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-02 04:27:16 +02:00
|
|
|
kDebug() << "sending " << m_service->m_packagePath;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-13 20:03:00 +02:00
|
|
|
if (m_service->m_packagePath.isEmpty()) {
|
|
|
|
// just return the plugin name in this case
|
|
|
|
setResult(m_service->m_pluginName);
|
2009-09-02 04:27:16 +02:00
|
|
|
} else {
|
2011-07-13 20:03:00 +02:00
|
|
|
QFileInfo fileInfo(m_service->m_packagePath);
|
|
|
|
|
|
|
|
if (fileInfo.exists() && fileInfo.isAbsolute()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2011-07-13 20:03:00 +02:00
|
|
|
kDebug() << "file exists, let's try and read it";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-13 20:03:00 +02:00
|
|
|
QFile file(m_service->m_packagePath);
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
setResult(file.readAll());
|
|
|
|
} else {
|
|
|
|
setResult(QString());
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
} else if (operationName() == "GetMetaData") {
|
2011-05-31 00:28:06 +02:00
|
|
|
QFile file(m_service->m_metadata);
|
2009-09-02 04:27:16 +02:00
|
|
|
setResult(file.readAll());
|
|
|
|
} else if (operationName() == "DataEngine") {
|
|
|
|
DataEngine *engine = m_service->dataEngine(parameters()["EngineName"].toString());
|
|
|
|
QString serviceName = "plasma-dataengine-" + parameters()["EngineName"].toString();
|
|
|
|
engine->d->publish(NoAnnouncement, serviceName);
|
|
|
|
if (!AuthorizationManager::self()->d->matchingRule(serviceName, identity())) {
|
|
|
|
AuthorizationRule *rule = new AuthorizationRule(serviceName, identity().id());
|
|
|
|
rule->setPolicy(AuthorizationRule::Allow);
|
|
|
|
AuthorizationManager::self()->d->rules.append(rule);
|
|
|
|
}
|
|
|
|
setResult(serviceName);
|
|
|
|
}
|
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
setResult(false);
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
PlasmoidService::PlasmoidService(Applet *applet)
|
|
|
|
: Plasma::Service(applet),
|
|
|
|
m_pluginName(applet->pluginName())
|
2009-09-02 04:27:16 +02:00
|
|
|
{
|
|
|
|
setName("plasmoidservice");
|
2009-09-03 01:49:46 +02:00
|
|
|
|
2011-07-15 13:03:22 +02:00
|
|
|
if (applet->package().isValid()) {
|
|
|
|
const QString root = applet->package().path();
|
2011-07-13 20:03:00 +02:00
|
|
|
m_metadata = root + "metadata.desktop";
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
m_tempFile.open();
|
|
|
|
m_packagePath = m_tempFile.fileName();
|
|
|
|
m_tempFile.close();
|
2011-05-31 00:28:06 +02:00
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
// put everything into a zip archive
|
|
|
|
KZip creation(m_packagePath);
|
|
|
|
creation.setCompression(KZip::NoCompression);
|
|
|
|
if (creation.open(QIODevice::WriteOnly)) {
|
|
|
|
QDir dir(root);
|
|
|
|
foreach (const QString &entry, dir.entryList(QDir::Files)) {
|
|
|
|
creation.addLocalFile(root + entry, entry);
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
foreach (const QString &entry, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
|
|
|
creation.addLocalDirectory(root + entry, entry);
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2011-07-13 20:03:00 +02:00
|
|
|
creation.close();
|
|
|
|
} else {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2011-07-13 20:03:00 +02:00
|
|
|
kDebug() << "could not open archive";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-13 20:03:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2011-07-13 20:03:00 +02:00
|
|
|
kDebug() << "applet lacks a valid package";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-13 20:03:00 +02:00
|
|
|
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(applet->pluginName());
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
if (!offers.isEmpty()) {
|
|
|
|
m_metadata = offers.first()->entryPath();
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 19:01:44 +02:00
|
|
|
Plasma::ServiceJob* PlasmoidService::createJob(const QString& operation, QHash<QString,QVariant>& parameters)
|
2009-09-02 04:27:16 +02:00
|
|
|
{
|
2011-05-31 00:28:06 +02:00
|
|
|
return new PlasmoidServiceJob(destination(), operation, parameters, this);
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-25 02:08:35 +01:00
|
|
|
#include "plasmoidservice_p.moc"
|
2009-09-02 04:27:16 +02:00
|
|
|
|