1
/***************************************************************************
2
* Copyright 2010 Artur Duque de Souza <asouza@kde.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, 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 General Public License *
15
* 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 . *
18
***************************************************************************/
22
#include <KServiceTypeTrader>
24
#include <Plasma/DataContainer>
26
#include "shareengine.h"
27
#include "shareservice.h"
30
ShareEngine::ShareEngine(QObject *parent, const QVariantList &args)
31
: Plasma::DataEngine(parent, args)
36
void ShareEngine::init()
38
connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)),
39
this, SLOT(updatePlugins(QStringList)));
40
updatePlugins(QStringList() << "services");
43
void ShareEngine::updatePlugins(const QStringList &changes)
45
if (!changes.contains("services")) {
51
KService::List services = KServiceTypeTrader::self()->query("Plasma/ShareProvider");
52
QMultiMap<int, KService::Ptr> sortedServices;
53
foreach (KService::Ptr service, services) {
54
sortedServices.insert(service->property("X-KDE-Priority").toInt(), service);
57
QMapIterator<int, KService::Ptr> it(sortedServices);
59
QHash<QString, QStringList> mimetypes;
60
while (it.hasPrevious()) {
62
KService::Ptr service = it.value();
63
const QString pluginName =
64
service->property("X-KDE-PluginInfo-Name", QVariant::String).toString();
66
const QStringList pluginMimeTypes =
67
service->property("X-KDE-PlasmaShareProvider-MimeType", QVariant::StringList).toStringList();
69
const QString storageId = service->storageId();
71
if (pluginName.isEmpty() || pluginMimeTypes.isEmpty()) {
75
// create the list of providers
76
Plasma::DataEngine::Data data;
77
data.insert("Name", service->name());
78
data.insert("Service Id", service->storageId());
79
data.insert("Mimetypes", pluginMimeTypes);
80
setData(pluginName, data);
82
// create the list of providers by type
83
foreach (const QString &pluginMimeType, pluginMimeTypes) {
84
mimetypes[pluginMimeType].append(pluginName);
89
QHashIterator<QString, QStringList> it2(mimetypes);
90
while (it2.hasNext()) {
92
setData("Mimetypes", it2.key(), it2.value());
96
Plasma::Service *ShareEngine::serviceForSource(const QString &source)
98
Plasma::DataContainer *data = containerForSource(source);
101
return Plasma::DataEngine::serviceForSource(source);
104
if (source.compare("mimetype", Qt::CaseInsensitive) == 0) {
105
return Plasma::DataEngine::serviceForSource(source);
108
const QString id = data->data().value("Service Id").toString();
110
return Plasma::DataEngine::serviceForSource(source);
113
ShareService *service = new ShareService(this);
114
service->setDestination(id);
118
#include "shareengine.moc"
120
K_EXPORT_PLASMA_DATAENGINE(share, ShareEngine)