allow for lnf packages to override templates

Summary:
allow for lnf package to override templates, so that
for instance, "default panel" can be overriden, so in a
distribution adding a "default panel" would add what is the
"default panel" of that distribution.
switching lnf package would get back a normal panel

Reviewers: garg, ivan, #plasma

Reviewed By: ivan, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D2298
wilder-5.14
Marco Martin 10 years ago
parent dc8879e365
commit d204265370
  1. 26
      shell/scripting/scriptengine.cpp
  2. 29
      shell/shellcorona.cpp

@ -497,13 +497,29 @@ QScriptValue ScriptEngine::loadTemplate(QScriptContext *context, QScriptEngine *
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LayoutTemplate")); KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LayoutTemplate"));
KPluginInfo info(offers.first()); KPluginInfo info(offers.first());
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + info.pluginName() + "/metadata.desktop"); QString path;
if (path.isEmpty()) { {
// qDebug() << "script path is empty"; ScriptEngine *env = envFor(engine);
return false; ShellCorona *sc = qobject_cast<ShellCorona *>(env->m_corona);
if (sc) {
const QString overridePackagePath = sc->lookAndFeelPackage().path() + QStringLiteral("contents/layouts/") + info.pluginName();
path = overridePackagePath + QStringLiteral("/metadata.desktop");
if (QFile::exists(path)) {
package.setPath(overridePackagePath);
}
}
} }
package.setPath(info.pluginName()); if (!package.isValid()) {
path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + info.pluginName() + "/metadata.desktop");
if (path.isEmpty()) {
// qDebug() << "script path is empty";
return false;
}
package.setPath(info.pluginName());
}
const QString scriptFile = package.filePath("mainscript"); const QString scriptFile = package.filePath("mainscript");
if (scriptFile.isEmpty()) { if (scriptFile.isEmpty()) {

@ -1348,16 +1348,12 @@ void ShellCorona::populateAddPanelsMenu()
action->setData(plugin.pluginName()); action->setData(plugin.pluginName());
} else { } else {
//FIXME: proper names
KPluginInfo info(pair.second); KPluginInfo info(pair.second);
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + info.pluginName() + "/metadata.desktop"); package.setPath(info.pluginName());
if (!path.isEmpty()) { const QString scriptFile = package.filePath("mainscript");
package.setPath(info.pluginName()); if (!scriptFile.isEmpty()) {
const QString scriptFile = package.filePath("mainscript"); QAction *action = m_addPanelsMenu->addAction(info.name());
if (!scriptFile.isEmpty()) { action->setData(QStringLiteral("plasma-desktop-template:%1").arg(info.pluginName()));
QAction *action = m_addPanelsMenu->addAction(info.name());
action->setData(QStringLiteral("plasma-desktop-template:%1").arg(scriptFile));
}
} }
} }
} }
@ -1386,20 +1382,9 @@ void ShellCorona::addPanel(QAction *action)
[](const QString &msg) { [](const QString &msg) {
qDebug() << msg; qDebug() << msg;
}); });
const QString scriptFile = plugin.right(plugin.length() - qstrlen("plasma-desktop-template:")); const QString templateName = plugin.right(plugin.length() - qstrlen("plasma-desktop-template:"));
QFile file(scriptFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << i18n("Unable to load script file: %1", scriptFile);
return;
}
QString script = file.readAll();
if (script.isEmpty()) {
// qDebug() << "script is empty";
return;
}
scriptEngine.evaluateScript(script, scriptFile); scriptEngine.evaluateScript(QStringLiteral("loadTemplate(\"%1\")").arg(templateName));
} else if (!plugin.isEmpty()) { } else if (!plugin.isEmpty()) {
addPanel(plugin); addPanel(plugin);
} }

Loading…
Cancel
Save