From fee7b3297451bca45dd356e39126822461129396 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 30 Nov 2011 12:54:40 +0100 Subject: [PATCH] allow ui/main.qml to be the default for plasmoids, and code/main.js for plasmoids, dataengines, runners --- private/packages.cpp | 47 ++++++++++++++++++++++++++++++++++---------- private/packages_p.h | 9 ++++++++- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/private/packages.cpp b/private/packages.cpp index 9e8cbde90..1762cdd74 100644 --- a/private/packages.cpp +++ b/private/packages.cpp @@ -36,19 +36,52 @@ namespace Plasma { +void ChangeableMainScriptPackage::initPackage(Package *package) +{ + package->addFileDefinition("mainscript", "code/main", i18n("Main Script File")); + package->setRequired("mainscript", true); +} + +QString ChangeableMainScriptPackage::findMainScript(Package *package) +{ + Q_UNUSED(package) + return QString(); +} + void ChangeableMainScriptPackage::pathChanged(Package *package) { KDesktopFile config(package->path() + "/metadata.desktop"); KConfigGroup cg = config.desktopGroup(); QString mainScript = cg.readEntry("X-Plasma-MainScript", QString()); + if (mainScript.isEmpty()) { + mainScript = findMainScript(package); + + if (mainScript.isEmpty()) { + mainScript = package->path() + "/code/main.js"; + if (!QFile::exists(mainScript)) { + mainScript.clear(); + } + } + } + if (!mainScript.isEmpty()) { package->addFileDefinition("mainscript", mainScript, i18n("Main Script File")); - package->setRequired("mainscript", true); } } +QString PlasmoidPackage::findMainScript(Package *package) +{ + const QString mainScript = package->path() + "/ui/main.qml"; + if (QFile::exists(mainScript)) { + return mainScript; + } + + return QString(); +} + void PlasmoidPackage::initPackage(Package *package) { + ChangeableMainScriptPackage::initPackage(package); QString pathsString(getenv("PLASMA_CUSTOM_PREFIX_PATHS")); if (!pathsString.isEmpty()) { QStringList prefixPaths(pathsString.split(":")); @@ -84,14 +117,13 @@ void PlasmoidPackage::initPackage(Package *package) package->addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File")); package->addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file")); - package->addFileDefinition("mainscript", "code/main", i18n("Main Script File")); package->addFileDefinition("defaultconfig", "config/default-configrc", i18n("Default configuration")); package->addDirectoryDefinition("animations", "animations", i18n("Animation scripts")); - package->setRequired("mainscript", true); } void DataEnginePackage::initPackage(Package *package) { + ChangeableMainScriptPackage::initPackage(package); package->setServicePrefix("plasma-dataengine-"); package->setDefaultPackageRoot("plasma/dataengines/"); @@ -106,13 +138,11 @@ void DataEnginePackage::initPackage(Package *package) package->setMimeTypes("services", mimetypes); package->addDirectoryDefinition("translations", "locale", i18n("Translations")); - - package->addFileDefinition("mainscript", "code/main", i18n("Main Script File")); - package->setRequired("mainscript", true); } void RunnerPackage::initPackage(Package *package) { + ChangeableMainScriptPackage::initPackage(package); package->setServicePrefix("plasma-runner-"); package->setDefaultPackageRoot("plasma/runners/"); @@ -124,9 +154,6 @@ void RunnerPackage::initPackage(Package *package) package->setMimeTypes("scripts", mimetypes); package->addDirectoryDefinition("translations", "locale", i18n("Translations")); - - package->addFileDefinition("mainscript", "code/main", i18n("Main Script File")); - package->setRequired("mainscript", true); } void ThemePackage::initPackage(Package *package) @@ -331,8 +358,8 @@ float WallpaperPackage::distance(const QSize& size, const QSize& desired, void ContainmentActionsPackage::initPackage(Package *package) { + ChangeableMainScriptPackage::initPackage(package); package->setDefaultPackageRoot("plasma/containmentactions/"); - package->addFileDefinition("mainscript", "code/main", i18n("Main Script File")); } void GenericPackage::initPackage(Package *package) diff --git a/private/packages_p.h b/private/packages_p.h index 74f5c928b..0a65b16d7 100644 --- a/private/packages_p.h +++ b/private/packages_p.h @@ -29,7 +29,11 @@ namespace Plasma class ChangeableMainScriptPackage : public PackageStructure { +public: + void initPackage(Package *package); + protected: + virtual QString findMainScript(Package *package); void pathChanged(Package *package); }; @@ -37,6 +41,9 @@ class PlasmoidPackage : public ChangeableMainScriptPackage { public: void initPackage(Package *package); + +protected: + QString findMainScript(Package *package); }; class DataEnginePackage : public ChangeableMainScriptPackage @@ -82,7 +89,7 @@ private: Wallpaper::ResizeMethod m_resizeMethod; }; -class ContainmentActionsPackage : public PackageStructure +class ContainmentActionsPackage : public ChangeableMainScriptPackage { public: void initPackage(Package *package);