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))
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" void setName(const QString &name)
Sets the name of the Service; useful for Services not loaded from plugins, which use the plugin name ...
static PluginLoader * pluginLoader()
Return the active plugin loader.
Service(QObject *parent=0)
Default constructor.
This class provides jobs for use with Plasma::Service.
Q_INVOKABLE ServiceJob * startOperationCall(const KConfigGroup &description, QObject *parent=0)
Called to create a ServiceJob which is associated with a given operation and parameter set...
static Service * load(const QString &name, const QVariantList &args, QObject *parent=0)
Used to load a given service from a plugin.
void setOperationEnabled(const QString &operation, bool enable)
Enables a given service by name.
void setOperationsScheme(QIODevice *xml)
Sets the XML used to define the operation schema for this Service.
Q_INVOKABLE void disassociateWidget(QWidget *widget)
Disassociates a widget if it has been associated with an operation on this service.
void operationsChanged()
Emitted when the Service's operations change.
Q_INVOKABLE QStringList operationNames() const
static AuthorizationManager * self()
Singleton pattern accessor.
Namespace for everything in libplasma.
Q_INVOKABLE KConfigGroup operationDescription(const QString &operationName)
Retrieves the parameters for a given operation.
This class provides a generic API for write access to settings or services.
void finished(Plasma::ServiceJob *job)
Emitted when a job associated with this Service completes its task.
Q_INVOKABLE void setDestination(const QString &destination)
Sets the destination for this Service to operate on.
Q_INVOKABLE void associateWidget(QWidget *widget, const QString &operation)
Assoicates a widget with an operation, which allows the service to automatically manage, for example, the enabled state of a widget.
Q_INVOKABLE void associateItem(QGraphicsObject *item, const QString &operation)
Associates a graphics item with an operation, which allows the service to automatically manage...
Q_INVOKABLE QMap< QString, QVariant > parametersFromDescription(const KConfigGroup &description)
virtual ServiceJob * createJob(const QString &operation, QMap< QString, QVariant > ¶meters)=0
Called when a job should be created by the Service.
Q_INVOKABLE bool isOperationEnabled(const QString &operation) const
Query to find if an operation is enabled or not.
Q_INVOKABLE QString name() const
The name of this service.
Service * loadService(const QString &name, const QVariantList &args, QObject *parent=0)
Load a Service plugin.
Announcements via ZeroConf.
void serviceReady(Plasma::Service *service)
Emitted when this service is ready for use.
static Service * access(const KUrl &url, QObject *parent=0)
Used to access a service from an url.
virtual void registerOperationsScheme()
By default this is based on the file in plasma/services/name.operations, but can be reimplented to us...
Q_INVOKABLE QString destination() const
Q_INVOKABLE void disassociateItem(QGraphicsObject *widget)
Disassociates a graphics item if it has been associated with an operation on this service...