22 #include "private/authorizationmanager_p.h"
23 #include "private/service_p.h"
24 #include "private/serviceprovider_p.h"
26 #include "config-plasma.h"
29 #include <QGraphicsWidget>
34 #include <kservicetypetrader.h>
35 #include <ksharedconfig.h>
36 #include <kstandarddirs.h>
37 #include <dnssd/publicservice.h>
38 #include <dnssd/servicebrowser.h>
42 #include "private/configloader_p.h"
43 #include "private/remoteservice_p.h"
44 #include "private/remoteservicejob_p.h"
52 d(new ServicePrivate(this))
58 d(new ServicePrivate(this))
72 return load(name, args, parent);
82 return new RemoteService(parent, url);
85 void ServicePrivate::jobFinished(
KJob *job)
87 emit q->finished(static_cast<ServiceJob*>(job));
90 void ServicePrivate::associatedWidgetDestroyed(
QObject *obj)
92 associatedWidgets.remove(static_cast<QWidget*>(obj));
95 void ServicePrivate::associatedGraphicsWidgetDestroyed(
QObject *obj)
97 associatedGraphicsWidgets.remove(static_cast<QGraphicsObject*>(obj));
100 void ServicePrivate::publish(AnnouncementMethods methods,
const QString &name,
const PackageMetadata &metadata)
102 #ifdef ENABLE_REMOTE_WIDGETS
103 if (!serviceProvider) {
106 serviceProvider =
new ServiceProvider(name, q);
109 (DNSSD::ServiceBrowser::isAvailable() == DNSSD::ServiceBrowser::Working)) {
111 publicService =
new DNSSD::PublicService(name,
"_plasma._tcp", 4000);
113 QMap<QString, QByteArray> textData;
114 textData[
"name"] = name.toUtf8();
115 textData[
"plasmoidname"] = metadata.name().toUtf8();
116 textData[
"description"] = metadata.description().toUtf8();
117 textData[
"icon"] = metadata.icon().toUtf8();
118 publicService->setTextData(textData);
119 kDebug() <<
"about to publish";
121 publicService->publishAsync();
123 (DNSSD::ServiceBrowser::isAvailable() != DNSSD::ServiceBrowser::Working)) {
124 kDebug() <<
"sorry, but your zeroconf daemon doesn't seem to be running.";
127 kDebug() <<
"already published!";
130 kWarning() <<
"libplasma is compiled without support for remote widgets. not publishing.";
134 void ServicePrivate::unpublish()
136 delete serviceProvider;
139 delete publicService;
143 bool ServicePrivate::isPublished()
const
145 if (serviceProvider) {
152 KConfigGroup ServicePrivate::dummyGroup()
155 dummyConfig =
new KConfig(QString(), KConfig::SimpleConfig);
158 return KConfigGroup(dummyConfig,
"DummyGroup");
168 return d->destination;
174 kDebug() <<
"No valid operations scheme has been registered";
175 return QStringList();
178 return d->config->groupList();
184 kDebug() <<
"No valid operations scheme has been registered";
185 return d->dummyGroup();
188 d->config->writeConfig();
189 KConfigGroup params(d->config->config(), operationName);
198 QMap<QString, QVariant> params;
200 if (!d->config || !description.isValid()) {
204 const QString op = description.name();
205 foreach (
const QString &key, description.keyList()) {
206 KConfigSkeletonItem *item = d->config->findItem(op, key);
208 params.insert(key, description.readEntry(key, item->property()));
219 const QString op = description.isValid() ? description.name() : QString();
221 RemoteService *rs = qobject_cast<RemoteService *>(
this);
222 if (!op.isEmpty() && rs && !rs->isReady()) {
224 kDebug() <<
"Remote service is not ready; queueing operation";
225 QMap<QString, QVariant> params;
227 RemoteServiceJob *rsj = qobject_cast<RemoteServiceJob *>(job);
229 rsj->setDelayedDescription(description);
231 }
else if (!d->config) {
232 kDebug() <<
"No valid operations scheme has been registered";
233 }
else if (!op.isEmpty() && d->config->hasGroup(op)) {
234 if (d->disabledOperations.contains(op)) {
235 kDebug() <<
"Operation" << op <<
"is disabled";
241 kDebug() << op <<
"is not a valid group; valid groups are:" << d->config->groupList();
248 job->setParent(parent ? parent :
this);
250 QTimer::singleShot(0, job, SLOT(autoStart()));
261 d->associatedWidgets.insert(widget, operation);
262 connect(widget, SIGNAL(destroyed(
QObject*)),
this, SLOT(associatedWidgetDestroyed(
QObject*)));
264 widget->setEnabled(!d->disabledOperations.contains(operation));
273 disconnect(widget, SIGNAL(destroyed(
QObject*)),
274 this, SLOT(associatedWidgetDestroyed(
QObject*)));
275 d->associatedWidgets.remove(widget);
295 d->associatedGraphicsWidgets.insert(widget, operation);
296 connect(widget, SIGNAL(destroyed(
QObject*)),
297 this, SLOT(associatedGraphicsWidgetDestroyed(
QObject*)));
299 widget->setEnabled(!d->disabledOperations.contains(operation));
308 disconnect(widget, SIGNAL(destroyed(
QObject*)),
309 this, SLOT(associatedGraphicsWidgetDestroyed(
QObject*)));
310 d->associatedGraphicsWidgets.remove(widget);
326 delete d->dummyConfig;
336 if (!d->config || !d->config->hasGroup(operation)) {
341 d->disabledOperations.remove(operation);
343 d->disabledOperations.insert(operation);
347 QHashIterator<QWidget *, QString> it(d->associatedWidgets);
348 while (it.hasNext()) {
350 if (it.value() == operation) {
351 it.key()->setEnabled(enable);
357 QHashIterator<QGraphicsObject *, QString> it(d->associatedGraphicsWidgets);
358 while (it.hasNext()) {
360 if (it.value() == operation) {
361 it.key()->setEnabled(enable);
369 return d->config && d->config->hasGroup(operation) && !d->disabledOperations.contains(operation);
376 delete d->dummyConfig;
379 KSharedConfigPtr c = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
381 d->config->d->setWriteDefaults(
true);
386 QHashIterator<QWidget *, QString> it(d->associatedWidgets);
387 while (it.hasNext()) {
389 it.key()->setEnabled(d->config->hasGroup(it.value()));
394 QHashIterator<QGraphicsObject *, QString> it(d->associatedGraphicsWidgets);
395 while (it.hasNext()) {
397 it.key()->setEnabled(d->config->hasGroup(it.value()));
409 if (d->name.isEmpty()) {
410 kDebug() <<
"No name found";
414 const QString path = KStandardDirs::locate(
"data",
"plasma/services/" + d->name +
".operations");
416 if (path.isEmpty()) {
417 kDebug() <<
"Cannot find operations description:" << d->name <<
".operations";
427 #include "service.moc"