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"));
KPluginInfo info(offers.first());
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + info.pluginName() + "/metadata.desktop");
if (path.isEmpty()) {
// qDebug() << "script path is empty";
return false;
QString path;
{
ScriptEngine *env = envFor(engine);
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");
if (scriptFile.isEmpty()) {

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

Loading…
Cancel
Save