Changeset View
Changeset View
Standalone View
Standalone View
shell/scripting/scriptengine_v1.cpp
Show First 20 Lines • Show All 479 Lines • ▼ Show 20 Line(s) | 474 | { | |||
---|---|---|---|---|---|
480 | } | 480 | } | ||
481 | 481 | | |||
482 | const QString layout = context->argument(0).toString(); | 482 | const QString layout = context->argument(0).toString(); | ||
483 | if (layout.isEmpty() || layout.contains(QStringLiteral("'"))) { | 483 | if (layout.isEmpty() || layout.contains(QStringLiteral("'"))) { | ||
484 | // qDebug() << "layout is empty"; | 484 | // qDebug() << "layout is empty"; | ||
485 | return false; | 485 | return false; | ||
486 | } | 486 | } | ||
487 | 487 | | |||
488 | const QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%2'").arg(layout); | 488 | auto filter = [&layout](const KPluginMetaData &md) -> bool | ||
489 | KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/LayoutTemplate"), constraint); | 489 | { | ||
490 | return md.pluginId() == layout && md.value(QStringLiteral("X-Plasma-ContainmentCategories")).contains(QStringLiteral("panel")); | ||||
davidedmundson: I'm a bit lost.
We have an argument to this method which is stored as local QString layout. | |||||
actual plugin name now checked (and the application name isn't something really used anymore) mart: actual plugin name now checked (and the application name isn't something really used anymore) | |||||
491 | }; | ||||
492 | QList<KPluginMetaData> offers = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/LayoutTemplate"), QString(), filter); | ||||
davidedmundson: if you do &layout
you'll save doing a copy every time | |||||
490 | 493 | | |||
491 | if (offers.isEmpty()) { | 494 | if (offers.isEmpty()) { | ||
492 | // qDebug() << "offers fail" << constraint; | 495 | // qDebug() << "offers fail" << constraint; | ||
493 | return false; | 496 | return false; | ||
494 | } | 497 | } | ||
495 | 498 | | |||
496 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LayoutTemplate")); | 499 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LayoutTemplate")); | ||
497 | KPluginInfo info(offers.first()); | 500 | KPluginMetaData pluginData(offers.first()); | ||
498 | 501 | | |||
499 | QString path; | 502 | QString path; | ||
500 | { | 503 | { | ||
501 | ScriptEngine *env = envFor(engine); | 504 | ScriptEngine *env = envFor(engine); | ||
502 | ShellCorona *sc = qobject_cast<ShellCorona *>(env->m_corona); | 505 | ShellCorona *sc = qobject_cast<ShellCorona *>(env->m_corona); | ||
503 | if (sc) { | 506 | if (sc) { | ||
504 | const QString overridePackagePath = sc->lookAndFeelPackage().path() + QStringLiteral("contents/layouts/") + info.pluginName(); | 507 | const QString overridePackagePath = sc->lookAndFeelPackage().path() + QStringLiteral("contents/layouts/") + pluginData.pluginId(); | ||
505 | 508 | | |||
506 | path = overridePackagePath + QStringLiteral("/metadata.desktop"); | 509 | path = overridePackagePath + QStringLiteral("/metadata.desktop"); | ||
507 | if (QFile::exists(path)) { | 510 | if (QFile::exists(path)) { | ||
508 | package.setPath(overridePackagePath); | 511 | package.setPath(overridePackagePath); | ||
509 | } | 512 | } | ||
510 | } | 513 | } | ||
511 | } | 514 | } | ||
512 | 515 | | |||
513 | if (!package.isValid()) { | 516 | if (!package.isValid()) { | ||
514 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + info.pluginName() + "/metadata.desktop"); | 517 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + pluginData.pluginId() + "/metadata.desktop"); | ||
515 | if (path.isEmpty()) { | 518 | if (path.isEmpty()) { | ||
516 | // qDebug() << "script path is empty"; | 519 | // qDebug() << "script path is empty"; | ||
517 | return false; | 520 | return false; | ||
518 | } | 521 | } | ||
519 | 522 | | |||
520 | package.setPath(info.pluginName()); | 523 | package.setPath(pluginData.pluginId()); | ||
521 | } | 524 | } | ||
522 | 525 | | |||
523 | const QString scriptFile = package.filePath("mainscript"); | 526 | const QString scriptFile = package.filePath("mainscript"); | ||
524 | if (scriptFile.isEmpty()) { | 527 | if (scriptFile.isEmpty()) { | ||
525 | // qDebug() << "scriptfile is empty"; | 528 | // qDebug() << "scriptfile is empty"; | ||
526 | return false; | 529 | return false; | ||
527 | } | 530 | } | ||
528 | 531 | | |||
529 | QFile file(scriptFile); | 532 | QFile file(scriptFile); | ||
530 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | 533 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
531 | qWarning() << i18n("Unable to load script file: %1", path); | 534 | qWarning() << i18n("Unable to load script file: %1", path); | ||
532 | return false; | 535 | return false; | ||
533 | } | 536 | } | ||
534 | 537 | | |||
535 | QString script = file.readAll(); | 538 | QString script = file.readAll(); | ||
536 | if (script.isEmpty()) { | 539 | if (script.isEmpty()) { | ||
537 | // qDebug() << "script is empty"; | 540 | // qDebug() << "script is empty"; | ||
538 | return false; | 541 | return false; | ||
539 | } | 542 | } | ||
540 | 543 | | |||
541 | ScriptEngine *env = envFor(engine); | 544 | ScriptEngine *env = envFor(engine); | ||
542 | env->globalObject().setProperty(QStringLiteral("templateName"), env->newVariant(info.name()), QScriptValue::ReadOnly | QScriptValue::Undeletable); | 545 | env->globalObject().setProperty(QStringLiteral("templateName"), env->newVariant(pluginData.name()), QScriptValue::ReadOnly | QScriptValue::Undeletable); | ||
543 | env->globalObject().setProperty(QStringLiteral("templateComment"), env->newVariant(info.comment()), QScriptValue::ReadOnly | QScriptValue::Undeletable); | 546 | env->globalObject().setProperty(QStringLiteral("templateComment"), env->newVariant(pluginData.description()), QScriptValue::ReadOnly | QScriptValue::Undeletable); | ||
544 | 547 | | |||
545 | QScriptValue rv = env->newObject(); | 548 | QScriptValue rv = env->newObject(); | ||
546 | QScriptContext *ctx = env->pushContext(); | 549 | QScriptContext *ctx = env->pushContext(); | ||
547 | ctx->setThisObject(rv); | 550 | ctx->setThisObject(rv); | ||
548 | 551 | | |||
549 | env->evaluateScript(script, path); | 552 | env->evaluateScript(script, path); | ||
550 | 553 | | |||
551 | env->popContext(); | 554 | env->popContext(); | ||
▲ Show 20 Lines • Show All 377 Lines • Show Last 20 Lines |
I'm a bit lost.
We have an argument to this method which is stored as local QString layout.
The old code found all Plasma/LayoutTemplates with that name.
As far as I can tell, this finds all LayoutTemplates which contain any panel?
(and if we're not using layout, why are we still checking it on line 483)