[scripting] Find scripts through KPackage

Another sycoca usage gone.
This commit is contained in:
Martin Gräßlin 2015-07-07 08:48:24 +02:00
parent 5b111cc467
commit b01b03aa84
3 changed files with 14 additions and 18 deletions

View file

@ -33,8 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../workspace.h" #include "../workspace.h"
// KDE // KDE
#include <KConfigGroup> #include <KConfigGroup>
#include <KPluginInfo> #include <KPackage/PackageLoader>
#include <KServiceTypeTrader>
// Qt // Qt
#include <QtDBus/QDBusConnection> #include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage> #include <QtDBus/QDBusMessage>
@ -661,30 +660,30 @@ LoadScriptList KWin::Scripting::queryScriptsToLoad()
s_started = true; s_started = true;
} }
QMap<QString,QString> pluginStates = KConfigGroup(_config, "Plugins").entryMap(); QMap<QString,QString> pluginStates = KConfigGroup(_config, "Plugins").entryMap();
KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("KWin/Script")); const QString scriptFolder = QStringLiteral(KWIN_NAME) + QStringLiteral("/scripts/");
const auto offers = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KWin/Script"), scriptFolder);
LoadScriptList scriptsToLoad; LoadScriptList scriptsToLoad;
foreach (const KService::Ptr & service, offers) { for (const KPluginMetaData &service: offers) {
KPluginInfo plugininfo(service); const QString value = pluginStates.value(service.pluginId() + QString::fromLatin1("Enabled"), QString());
const QString value = pluginStates.value(plugininfo.pluginName() + QString::fromLatin1("Enabled"), QString()); const bool enabled = value.isNull() ? service.isEnabledByDefault() : QVariant(value).toBool();
plugininfo.setPluginEnabled(value.isNull() ? plugininfo.isPluginEnabledByDefault() : QVariant(value).toBool()); const bool javaScript = service.value(QStringLiteral("X-Plasma-API")) == QStringLiteral("javascript");
const bool javaScript = service->property(QStringLiteral("X-Plasma-API")).toString() == QStringLiteral("javascript"); const bool declarativeScript = service.value(QStringLiteral("X-Plasma-API")) == QStringLiteral("declarativescript");
const bool declarativeScript = service->property(QStringLiteral("X-Plasma-API")).toString() == QStringLiteral("declarativescript");
if (!javaScript && !declarativeScript) { if (!javaScript && !declarativeScript) {
continue; continue;
} }
if (!plugininfo.isPluginEnabled()) { if (!enabled) {
if (isScriptLoaded(plugininfo.pluginName())) { if (isScriptLoaded(service.pluginId())) {
// unload the script // unload the script
unloadScript(plugininfo.pluginName()); unloadScript(service.pluginId());
} }
continue; continue;
} }
const QString pluginName = service->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString(); const QString pluginName = service.pluginId();
const QString scriptName = service->property(QStringLiteral("X-Plasma-MainScript")).toString(); const QString scriptName = service.value(QStringLiteral("X-Plasma-MainScript"));
const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME) + QStringLiteral("/scripts/") + pluginName + QStringLiteral("/contents/") + scriptName); const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, scriptFolder + pluginName + QStringLiteral("/contents/") + scriptName);
if (file.isNull()) { if (file.isNull()) {
qDebug() << "Could not find script file for " << pluginName; qDebug() << "Could not find script file for " << pluginName;
continue; continue;

View file

@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KWIN_SCRIPTING_H #define KWIN_SCRIPTING_H
#include <kwinglobals.h> #include <kwinglobals.h>
#include <kservice.h>
#include <QFile> #include <QFile>
#include <QHash> #include <QHash>

View file

@ -22,7 +22,6 @@ target_link_libraries( testTabBoxClientModel
Qt5::X11Extras Qt5::X11Extras
KF5::I18n KF5::I18n
KF5::Package KF5::Package
KF5::Service
KF5::WindowSystem KF5::WindowSystem
XCB::XCB XCB::XCB
) )
@ -51,7 +50,6 @@ target_link_libraries( testTabBoxHandler
Qt5::X11Extras Qt5::X11Extras
KF5::I18n KF5::I18n
KF5::Package KF5::Package
KF5::Service
KF5::WindowSystem KF5::WindowSystem
XCB::XCB XCB::XCB
) )