From af4103bac109787c6adc6bcbf793045adcce5a3f Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 14 Feb 2013 14:46:49 +0100 Subject: [PATCH] make GenericPackage the superclass for Plasmoid the hierarchy was a bit inverted; this allows GenericPackages to carry a few less Plasmoid-specific items without changing any other behaviour. uses of Plasma/Generic will need to bear in mind that they are not using Plasmoids. this opens doors to more appropriate and easier flexibility for other package types we ough to have, e.g. Wallpaper --- plasma/private/packages.cpp | 47 ++++++++----------------------------- plasma/private/packages_p.h | 17 +++++--------- 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/plasma/private/packages.cpp b/plasma/private/packages.cpp index 6634e2563..436a19ba4 100644 --- a/plasma/private/packages.cpp +++ b/plasma/private/packages.cpp @@ -39,16 +39,10 @@ namespace Plasma void ChangeableMainScriptPackage::initPackage(Package *package) { - package->addFileDefinition("mainscript", "code/main", i18n("Main Script File")); + package->addFileDefinition("mainscript", "ui/main.qml", i18n("Main Script File")); package->setRequired("mainscript", true); } -QString ChangeableMainScriptPackage::findMainScript(Package *package) const -{ - Q_UNUSED(package) - return QString(); -} - QString ChangeableMainScriptPackage::mainScriptConfigKey() const { return QLatin1String("X-Plasma-MainScript"); @@ -63,33 +57,13 @@ void ChangeableMainScriptPackage::pathChanged(Package *package) KDesktopFile config(package->path() + "/metadata.desktop"); KConfigGroup cg = config.desktopGroup(); QString mainScript = cg.readEntry(mainScriptConfigKey(), 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")); } } -QString PlasmoidPackage::findMainScript(Package *package) const -{ - const QString mainScript = package->path() + "/ui/main.qml"; - if (QFile::exists(mainScript)) { - return mainScript; - } - - return QString(); -} - -void PlasmoidPackage::initPackage(Package *package) +void GenericPackage::initPackage(Package *package) { ChangeableMainScriptPackage::initPackage(package); @@ -105,8 +79,7 @@ void PlasmoidPackage::initPackage(Package *package) package->setContentsPrefixPaths(platform); } - package->setServicePrefix("plasma-applet-"); - package->setDefaultPackageRoot("plasma/plasmoids"); + package->setDefaultPackageRoot("plasma/packages/"); package->addDirectoryDefinition("images", "images", i18n("Images")); QStringList mimetypes; @@ -119,7 +92,6 @@ void PlasmoidPackage::initPackage(Package *package) package->setMimeTypes("config", mimetypes); package->addDirectoryDefinition("ui", "ui", i18n("User Interface")); - package->setMimeTypes("ui", mimetypes); package->addDirectoryDefinition("data", "data", i18n("Data Files")); @@ -129,6 +101,13 @@ void PlasmoidPackage::initPackage(Package *package) package->setMimeTypes("scripts", mimetypes); package->addDirectoryDefinition("translations", "locale", i18n("Translations")); +} + +void PlasmoidPackage::initPackage(Package *package) +{ + GenericPackage::initPackage(package); + package->setServicePrefix("plasma-applet-"); + package->setDefaultPackageRoot("plasma/plasmoids/"); package->addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File")); package->addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file")); @@ -276,11 +255,5 @@ void ContainmentActionsPackage::initPackage(Package *package) package->setDefaultPackageRoot("plasma/containmentactions/"); } -void GenericPackage::initPackage(Package *package) -{ - PlasmoidPackage::initPackage(package); - package->setDefaultPackageRoot("plasma/packages/"); -} - } // namespace Plasma diff --git a/plasma/private/packages_p.h b/plasma/private/packages_p.h index 3e0514d73..a11fc7ecd 100644 --- a/plasma/private/packages_p.h +++ b/plasma/private/packages_p.h @@ -32,18 +32,20 @@ public: void initPackage(Package *package); protected: - virtual QString findMainScript(Package *package) const; virtual QString mainScriptConfigKey() const; void pathChanged(Package *package); }; -class PlasmoidPackage : public ChangeableMainScriptPackage +class GenericPackage : public ChangeableMainScriptPackage { public: void initPackage(Package *package); +}; -protected: - QString findMainScript(Package *package) const; +class PlasmoidPackage : public GenericPackage +{ +public: + void initPackage(Package *package); }; class ContainmentPackage : public PlasmoidPackage @@ -76,13 +78,6 @@ public: void initPackage(Package *package); }; -//FIXME: this should be aPlasmoidPackage or a base one? -class GenericPackage : public PlasmoidPackage -{ -public: - void initPackage(Package *package); -}; - } // namespace Plasma #endif // LIBS_PLASMA_PACKAGES_P_H