21 #include "private/accessmanager_p.h"
26 #include "private/authorizationmanager_p.h"
28 #include "config-plasma.h"
30 #include <QtCore/QMap>
31 #include <QtCore/QTimer>
33 #include <dnssd/remoteservice.h>
34 #include <dnssd/servicebrowser.h>
37 #include <kstandarddirs.h>
38 #include <ktemporaryfile.h>
41 #include <QtJolie/Message>
46 class AccessManagerSingleton
52 K_GLOBAL_STATIC(AccessManagerSingleton, privateAccessManagerSelf)
56 return &privateAccessManagerSelf->
self;
59 AccessManager::AccessManager()
61 d(new AccessManagerPrivate(this))
63 KGlobal::dirs()->addResourceType(
"trustedkeys",
"config",
"trustedkeys/");
66 AccessManager::~AccessManager()
75 KUrl resolvedLocation;
76 if (location.protocol() ==
"plasma+zeroconf") {
77 if (d->zeroconfServices.contains(location.host())) {
78 resolvedLocation = d->services[location.host()].remoteLocation();
80 kDebug() <<
"There's no zeroconf service with this name.";
83 resolvedLocation = location;
88 QTimer::singleShot(0, job, SLOT(slotStart()));
94 return d->services.values();
100 list <<
"plasma" <<
"plasma+zeroconf";
104 AccessManagerPrivate::AccessManagerPrivate(
AccessManager *manager)
106 browser(new DNSSD::ServiceBrowser(
"_plasma._tcp"))
108 #ifdef ENABLE_REMOTE_WIDGETS
109 q->connect(browser, SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),
110 q, SLOT(slotAddService(DNSSD::RemoteService::Ptr)));
111 q->connect(browser, SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),
112 q, SLOT(slotRemoveService(DNSSD::RemoteService::Ptr)));
113 browser->startBrowse();
115 kWarning() <<
"libplasma is compiled without support for remote widgets. not monitoring remote widgets on the network";
119 AccessManagerPrivate::~AccessManagerPrivate()
124 void AccessManagerPrivate::slotJobFinished(
KJob *job)
126 emit q->finished(static_cast<AccessAppletJob*>(job));
129 void AccessManagerPrivate::slotAddService(DNSSD::RemoteService::Ptr service)
132 if (!service->resolve()) {
133 kDebug() <<
"Zeroconf service can't be resolved";
137 if (!services.contains(service->serviceName())) {
138 PackageMetadata metadata;
139 kDebug() <<
"textdata = " << service->textData();
140 kDebug() <<
"hostname: " << service->hostName();
141 QHostAddress address = DNSSD::ServiceBrowser::resolveHostName(service->hostName());
142 QString ip = address.toString();
143 kDebug() <<
"result for resolve = " << ip;
145 KUrl url(QString(
"plasma://%1:%2/%3").arg(ip)
146 .arg(service->port())
147 .arg(service->serviceName()));
149 if (!service->textData().isEmpty()) {
150 kDebug() <<
"service has got textdata";
151 QMap<QString, QByteArray> textData = service->textData();
152 metadata.setName(textData[
"name"]);
153 metadata.setDescription(textData[
"description"]);
154 metadata.setIcon(textData[
"icon"]);
155 metadata.setRemoteLocation(url.prettyUrl());
157 kDebug() <<
"no textdata?";
158 metadata.setName(service->serviceName());
159 metadata.setRemoteLocation(url.prettyUrl());
162 kDebug() <<
"location = " << metadata.remoteLocation();
163 kDebug() <<
"name = " << metadata.name();
164 kDebug() <<
"description = " << metadata.name();
166 services[service->serviceName()] = metadata;
167 zeroconfServices[service->serviceName()] = service;
168 emit q->remoteAppletAnnounced(metadata);
172 void AccessManagerPrivate::slotRemoveService(DNSSD::RemoteService::Ptr service)
175 emit q->remoteAppletUnannounced(services[service->serviceName()]);
176 services.remove(service->serviceName());
177 zeroconfServices.remove(service->serviceName());
182 #include "accessmanager.moc"
QList< PackageMetadata > remoteApplets() const
void finished(Plasma::AccessAppletJob *)
fires when an AccessAppletJob is finished.
static AuthorizationManager * self()
Singleton pattern accessor.
Allows access to remote Plasma::Applet classes.
static QStringList supportedProtocols()
static AccessManager * self()
Singleton pattern accessor.
This class is used for asynchronously accessing an applet published on a remote system.
AccessAppletJob * accessRemoteApplet(const KUrl &location) const
Access a native plasmoid hosted on another machine.