2009-09-02 04:27:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 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 "getsource_p.h"
|
2009-09-03 01:49:46 +02:00
|
|
|
|
|
|
|
#include "authorizationmanager_p.h"
|
2009-11-25 02:08:35 +01:00
|
|
|
#include "dataengineservice_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "service_p.h"
|
2009-09-03 01:49:46 +02:00
|
|
|
|
2009-09-03 23:10:33 +02:00
|
|
|
#include "../remote/authorizationmanager.h"
|
|
|
|
#include "../remote/authorizationrule.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "../dataengine.h"
|
2009-09-03 01:49:46 +02:00
|
|
|
#include "../service.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-11-25 02:08:35 +01:00
|
|
|
GetSource::GetSource(DataEngine *engine, const QString& operation,
|
|
|
|
QMap<QString,QVariant>& parameters,
|
|
|
|
DataEngineService *service)
|
|
|
|
: ServiceJob(QString("publickey"), operation, parameters, service),
|
|
|
|
m_engine(engine),
|
|
|
|
m_service(service)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
void GetSource::start()
|
|
|
|
{
|
|
|
|
kDebug() << "Trying to perform the action" << operationName();
|
|
|
|
|
|
|
|
//TODO: check with capabilities before performing actions.
|
|
|
|
if (operationName() == "GetSource") {
|
|
|
|
QString source = parameters().value("SourceName").toString();
|
|
|
|
QString UUID = parameters().value("UUID").toString();
|
|
|
|
if (!m_service->m_peersAlreadyUpdated[source].contains(UUID)) {
|
|
|
|
m_service->m_peersAlreadyUpdated[source].append(UUID);
|
|
|
|
setResult(m_service->m_data[source]);
|
|
|
|
} else {
|
|
|
|
setResult(false); //no update needed
|
|
|
|
}
|
|
|
|
} else if (operationName() == "GetSourceNames") {
|
|
|
|
setResult(m_engine->sources());
|
|
|
|
} else if (operationName() == "ServiceForSource") {
|
|
|
|
QString source = parameters().value("SourceName").toString();
|
|
|
|
Service *service = m_engine->serviceForSource(source);
|
|
|
|
QString serviceName = "plasma-service-" + service->name();
|
|
|
|
|
|
|
|
kDebug() << "serviceForSource: getting source " << serviceName;
|
|
|
|
service->d->publish(Plasma::NoAnnouncement, serviceName);
|
|
|
|
if (!AuthorizationManager::self()->d->matchingRule(serviceName, identity())) {
|
|
|
|
AuthorizationRule *rule = new AuthorizationRule(serviceName, identity().id());
|
2009-09-04 02:08:26 +02:00
|
|
|
rule->setPolicy(AuthorizationRule::Allow);
|
2009-09-02 04:27:16 +02:00
|
|
|
AuthorizationManager::self()->d->rules.append(rule);
|
|
|
|
}
|
|
|
|
setResult(serviceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-25 02:08:35 +01:00
|
|
|
#include "getsource_p.moc"
|
2009-09-02 04:27:16 +02:00
|
|
|
|