From 2133884b4f0ab0f2be1c0640897dca2c54baa838 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 2 Jun 2023 03:48:22 +0300 Subject: [PATCH] plasma: drop support for registering operations from non-scheme files no setter for operation names and non-virtual description/parameters getters make this feature a no-no Signed-off-by: Ivailo Monev --- plasma/service.cpp | 118 +++++++++++++++++++++------------------------ plasma/service.h | 14 ------ 2 files changed, 54 insertions(+), 78 deletions(-) diff --git a/plasma/service.cpp b/plasma/service.cpp index 9b838746..60d5be6f 100644 --- a/plasma/service.cpp +++ b/plasma/service.cpp @@ -122,9 +122,9 @@ KConfigGroup Service::operationDescription(const QString &operationName) d->config->writeConfig(); KConfigGroup params(d->config->config(), operationName); - //kDebug() << "operation" << operationName - // << "requested, has keys" << params.keyList() << "from" - // << d->config->config()->name(); + kDebug() << "operation" << operationName + << "requested, has keys" << params.keyList() << "from" + << d->config->config()->name(); return params; } @@ -183,7 +183,10 @@ void Service::associateWidget(QWidget *widget, const QString &operation) disassociateWidget(widget); d->associatedWidgets.insert(widget, operation); - connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*))); + connect( + widget, SIGNAL(destroyed(QObject*)), + this, SLOT(associatedWidgetDestroyed(QObject*)) + ); widget->setEnabled(!d->disabledOperations.contains(operation)); } @@ -194,8 +197,10 @@ void Service::disassociateWidget(QWidget *widget) return; } - disconnect(widget, SIGNAL(destroyed(QObject*)), - this, SLOT(associatedWidgetDestroyed(QObject*))); + disconnect( + widget, SIGNAL(destroyed(QObject*)), + this, SLOT(associatedWidgetDestroyed(QObject*)) + ); d->associatedWidgets.remove(widget); } @@ -217,8 +222,10 @@ void Service::associateItem(QGraphicsObject *widget, const QString &operation) disassociateItem(widget); d->associatedGraphicsWidgets.insert(widget, operation); - connect(widget, SIGNAL(destroyed(QObject*)), - this, SLOT(associatedGraphicsWidgetDestroyed(QObject*))); + connect( + widget, SIGNAL(destroyed(QObject*)), + this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)) + ); widget->setEnabled(!d->disabledOperations.contains(operation)); } @@ -229,8 +236,10 @@ void Service::disassociateItem(QGraphicsObject *widget) return; } - disconnect(widget, SIGNAL(destroyed(QObject*)), - this, SLOT(associatedGraphicsWidgetDestroyed(QObject*))); + disconnect( + widget, SIGNAL(destroyed(QObject*)), + this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)) + ); d->associatedGraphicsWidgets.remove(widget); } @@ -250,7 +259,41 @@ void Service::setName(const QString &name) delete d->dummyConfig; d->dummyConfig = 0; - registerOperationsScheme(); + if (d->name.isEmpty()) { + kDebug() << "No name found"; + emit serviceReady(this); + return; + } + + const QString path = KStandardDirs::locate("data", "plasma/services/" + d->name + ".operations"); + if (path.isEmpty()) { + kDebug() << "Cannot find operations description:" << d->name << ".operations"; + emit serviceReady(this); + return; + } + + QFile xmlfile(path); + KSharedConfigPtr c = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); + d->config = new ConfigLoader(c, &xmlfile, this); + d->config->d->setWriteDefaults(true); + + emit operationsChanged(); + + { + QHashIterator it(d->associatedWidgets); + while (it.hasNext()) { + it.next(); + it.key()->setEnabled(d->config->hasGroup(it.value())); + } + } + + { + QHashIterator it(d->associatedGraphicsWidgets); + while (it.hasNext()) { + it.next(); + it.key()->setEnabled(d->config->hasGroup(it.value())); + } + } emit serviceReady(this); } @@ -293,59 +336,6 @@ bool Service::isOperationEnabled(const QString &operation) const return d->config && d->config->hasGroup(operation) && !d->disabledOperations.contains(operation); } -void Service::setOperationsScheme(QIODevice *xml) -{ - delete d->config; - - delete d->dummyConfig; - d->dummyConfig = 0; - - KSharedConfigPtr c = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); - d->config = new ConfigLoader(c, xml, this); - d->config->d->setWriteDefaults(true); - - emit operationsChanged(); - - { - QHashIterator it(d->associatedWidgets); - while (it.hasNext()) { - it.next(); - it.key()->setEnabled(d->config->hasGroup(it.value())); - } - } - - { - QHashIterator it(d->associatedGraphicsWidgets); - while (it.hasNext()) { - it.next(); - it.key()->setEnabled(d->config->hasGroup(it.value())); - } - } -} - -void Service::registerOperationsScheme() -{ - if (d->config) { - // we've already done our job. let's go home. - return; - } - - if (d->name.isEmpty()) { - kDebug() << "No name found"; - return; - } - - const QString path = KStandardDirs::locate("data", "plasma/services/" + d->name + ".operations"); - - if (path.isEmpty()) { - kDebug() << "Cannot find operations description:" << d->name << ".operations"; - return; - } - - QFile file(path); - setOperationsScheme(&file); -} - } // namespace Plasma #include "moc_service.cpp" diff --git a/plasma/service.h b/plasma/service.h index e94e8e05..b112ac58 100644 --- a/plasma/service.h +++ b/plasma/service.h @@ -278,20 +278,6 @@ protected: virtual ServiceJob *createJob(const QString &operation, const QMap ¶meters) = 0; - /** - * By default this is based on the file in plasma/services/name.operations, but can be - * reimplented to use a different mechanism. - * - * It should result in a call to setOperationsScheme(QIODevice *); - */ - virtual void registerOperationsScheme(); - - /** - * Sets the XML used to define the operation schema for - * this Service. - */ - void setOperationsScheme(QIODevice *xml); - /** * Sets the name of the Service; useful for Services not loaded from plugins, * which use the plugin name for this.