From a7336dc11900efbd885b36181dae5b7d3087f566 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 7 Sep 2009 22:36:04 +0000 Subject: [PATCH] * if no config group is provided, use the app global one (compat with krunner, allows comfortable usage with e.g. plasmoids) * allow setting the applet whitelist programmaticaly vs touching the config file directly svn path=/trunk/KDE/kdelibs/; revision=1021048 --- runnermanager.cpp | 57 +++++++++++++++++++++++++++++++++++++---------- runnermanager.h | 14 ++++++++++++ 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/runnermanager.cpp b/runnermanager.cpp index 02abeac29..ec3699de3 100644 --- a/runnermanager.cpp +++ b/runnermanager.cpp @@ -70,6 +70,7 @@ public: ~RunnerManagerPrivate() { + KConfigGroup config = configGroup(); context.save(config); } @@ -83,9 +84,9 @@ public: emit q->matchesChanged(context.matches()); } - void loadConfiguration(KConfigGroup &conf) + void loadConfiguration() { - config = conf; + KConfigGroup config = configGroup(); //The number of threads used scales with the number of processors. const int numProcs = @@ -105,14 +106,18 @@ public: context.restore(config); } + KConfigGroup configGroup() + { + return conf.isValid() ? conf : KConfigGroup(KGlobal::config(), "PlasmaRunnerManager"); + } + void loadRunners() { + KConfigGroup config = configGroup(); KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner"); bool loadAll = config.readEntry("loadAll", false); - //The plugin configuration is stored under the section Plugins - //and not PlasmaRunnerManager->Plugins - KConfigGroup conf(KGlobal::config(), "Plugins"); + KConfigGroup pluginConf(&config, "Plugins"); foreach (const KService::Ptr &service, offers) { //kDebug() << "Loading runner: " << service->name() << service->storageId(); @@ -125,7 +130,7 @@ public: KPluginInfo description(service); QString runnerName = description.pluginName(); - description.load(conf); + description.load(pluginConf); bool loaded = runners.contains(runnerName); bool selected = loadAll || description.isPluginEnabled(); @@ -240,7 +245,7 @@ public: QHash runners; QSet searchJobs; QSet oldSearchJobs; - KConfigGroup config; + KConfigGroup conf; bool loadAll : 1; bool prepped : 1; bool teardownRequested : 1; @@ -254,8 +259,7 @@ RunnerManager::RunnerManager(QObject *parent) : QObject(parent), d(new RunnerManagerPrivate(this)) { - KConfigGroup config(KGlobal::config(), "PlasmaRunnerManager"); - d->loadConfiguration(config); + d->loadConfiguration(); //ThreadWeaver::setDebugLevel(true, 4); } @@ -265,8 +269,8 @@ RunnerManager::RunnerManager(KConfigGroup &c, QObject *parent) { // Should this be really needed? Maybe d->loadConfiguration(c) would make // more sense. - KConfigGroup config(&c, "PlasmaRunnerManager"); - d->loadConfiguration(config); + d->conf = KConfigGroup(&c, "PlasmaRunnerManager"); + d->loadConfiguration(); //ThreadWeaver::setDebugLevel(true, 4); } @@ -281,10 +285,39 @@ RunnerManager::~RunnerManager() void RunnerManager::reloadConfiguration() { - d->loadConfiguration(d->config); + d->loadConfiguration(); d->loadRunners(); } +void RunnerManager::setAllowedRunners(const QStringList &runners) +{ + qDeleteAll(d->runners); + d->runners.clear(); + + KConfigGroup config = d->configGroup(); + KConfigGroup pluginConf(&config, "Plugins"); + pluginConf.deleteGroup(); + + foreach (const QString &runner, runners) { + pluginConf.writeEntry(runner, true); + } +} + +QStringList RunnerManager::allowedRunners() const +{ + KConfigGroup config = d->configGroup(); + KConfigGroup pluginConf(&config, "Plugins"); + + QStringList runners; + foreach (const QString &key, pluginConf.keyList()) { + if (pluginConf.readEntry(key, true)) { + runners << key; + } + } + + return runners; +} + AbstractRunner* RunnerManager::runner(const QString &name) const { if (d->runners.isEmpty()) { diff --git a/runnermanager.h b/runnermanager.h index f9fbdd050..352bf8a25 100644 --- a/runnermanager.h +++ b/runnermanager.h @@ -104,6 +104,20 @@ class PLASMA_EXPORT RunnerManager : public QObject */ void reloadConfiguration(); + /** + * Sets a whitelist for the plugins that can be loaded + * + * @arg plugins the plugin names of allowed runners + * @since 4.4 + */ + void setAllowedRunners(const QStringList &runners); + + /** + * @return the list of allowed plugins + * @since 4.4 + */ + QStringList allowedRunners() const; + public Q_SLOTS: /** * Call this method when the runners should be prepared for a query session.