From 2baef31dc4e458e8d1bbdccf620c83d890283b4a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 2 Sep 2013 20:25:04 +0200 Subject: [PATCH] use a QmlWallpaper package type for wallpapers --- CMakeLists.txt | 2 +- containmentconfigview.cpp | 3 +- main.cpp | 2 +- lookandfeelpackage.cpp => packages.cpp | 50 ++++++++++++++++++++++++-- lookandfeelpackage.h => packages.h | 11 ++++-- shellpluginloader.cpp | 8 +++-- 6 files changed, 65 insertions(+), 11 deletions(-) rename lookandfeelpackage.cpp => packages.cpp (73%) rename lookandfeelpackage.h => packages.h (88%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 646239c7f..d29c35e4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ add_executable(plasma-shell panelview.cpp shellpluginloader.cpp shellmanager.cpp - lookandfeelpackage.cpp + packages.cpp view.cpp panelconfigview.cpp ${scripting_SRC} diff --git a/containmentconfigview.cpp b/containmentconfigview.cpp index 235a33f8b..3427aff7a 100644 --- a/containmentconfigview.cpp +++ b/containmentconfigview.cpp @@ -52,8 +52,7 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow engine()->rootContext()->setContextProperty("configDialog", this); setCurrentWallpaper(cont->containment()->wallpaper()); - Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); - pkg.setDefaultPackageRoot("plasma/wallpapers"); + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/QmlWallpaper"); pkg.setPath(m_containment->wallpaper()); QFile file(pkg.filePath("config", "main.xml")); KConfigGroup cfg = m_containment->config(); diff --git a/main.cpp b/main.cpp index d8329b7d3..f094d555a 100644 --- a/main.cpp +++ b/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char** argv) QQmlDebuggingEnabler enabler; } - // Plasma::PluginLoader::setPluginLoader(new ShellPluginLoader); + Plasma::PluginLoader::setPluginLoader(new ShellPluginLoader); // DesktopCorona *corona = new DesktopCorona(); // corona->loadLayout(); // if (corona->containments().isEmpty()) { diff --git a/lookandfeelpackage.cpp b/packages.cpp similarity index 73% rename from lookandfeelpackage.cpp rename to packages.cpp index 3515bd732..29d12f7bc 100644 --- a/lookandfeelpackage.cpp +++ b/packages.cpp @@ -18,14 +18,17 @@ * Boston, MA 02110-1301, USA. * *******************************************************************************/ -#include "lookandfeelpackage.h" +#include "packages.h" + +#include #include +#include #include -void LookAndFeelPackageStructure::initPackage(Plasma::Package *package) +void LookAndFeelPackage::initPackage(Plasma::Package *package) { // http://community.kde.org/Plasma/lookAndFeelPackage# @@ -71,4 +74,47 @@ void LookAndFeelPackageStructure::initPackage(Plasma::Package *package) } +void QmlWallpaperPackage::initPackage(Plasma::Package *package) +{ + package->addFileDefinition("mainscript", "ui/main.qml", i18n("Main Script File")); + //FIXME: why setting it required doesn't work? + //package->setRequired("mainscript", true); + + + QStringList platform = KDeclarative::runtimePlatform(); + if (!platform.isEmpty()) { + QMutableStringListIterator it(platform); + while (it.hasNext()) { + it.next(); + it.setValue("platformcontents/" + it.value()); + } + + platform.append("contents"); + package->setContentsPrefixPaths(platform); + } + + package->setDefaultPackageRoot("plasma/wallpapers/"); + package->addDirectoryDefinition("images", "images", i18n("Images")); + package->addDirectoryDefinition("theme", "theme", i18n("Themed Images")); + QStringList mimetypes; + mimetypes << "image/svg+xml" << "image/png" << "image/jpeg"; + package->setMimeTypes("images", mimetypes); + package->setMimeTypes("theme", mimetypes); + + package->addDirectoryDefinition("config", "config", i18n("Configuration Definitions")); + mimetypes.clear(); + mimetypes << "text/xml"; + package->setMimeTypes("config", mimetypes); + + package->addDirectoryDefinition("ui", "ui", i18n("User Interface")); + + package->addDirectoryDefinition("data", "data", i18n("Data Files")); + + package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts")); + mimetypes.clear(); + mimetypes << "text/plain"; + package->setMimeTypes("scripts", mimetypes); + + package->addDirectoryDefinition("translations", "locale", i18n("Translations")); +} diff --git a/lookandfeelpackage.h b/packages.h similarity index 88% rename from lookandfeelpackage.h rename to packages.h index 6c62e33b5..999b4c925 100644 --- a/lookandfeelpackage.h +++ b/packages.h @@ -19,19 +19,24 @@ * Boston, MA 02110-1301, USA. * *******************************************************************************/ -#ifndef SHELLPACKAGE_H -#define SHELLPACKAGE_H +#ifndef SHELLPACKAGES_H +#define SHELLPACKAGES_H #include #include -class LookAndFeelPackageStructure : public Plasma::PackageStructure +class LookAndFeelPackage : public Plasma::PackageStructure { public: void initPackage(Plasma::Package *package); }; +class QmlWallpaperPackage : public Plasma::PackageStructure +{ +public: + void initPackage(Plasma::Package *package); +}; #endif // LOOKANDFEELPACKAGE_H diff --git a/shellpluginloader.cpp b/shellpluginloader.cpp index 9df6e0584..49420352c 100644 --- a/shellpluginloader.cpp +++ b/shellpluginloader.cpp @@ -18,8 +18,9 @@ */ #include "shellpluginloader.h" -#include "lookandfeelpackage.h" +#include "packages.h" +#include ShellPluginLoader::ShellPluginLoader() : Plasma::PluginLoader() @@ -35,7 +36,10 @@ Plasma::Package ShellPluginLoader::internalLoadPackage(const QString &packageFor Q_UNUSED(specialization) if (packageFormat.endsWith("/LookAndFeel")) { - Plasma::PackageStructure *structure = new LookAndFeelPackageStructure(); + Plasma::PackageStructure *structure = new LookAndFeelPackage(); + return Plasma::Package(structure); + } else if (packageFormat.endsWith("/QmlWallpaper")) { + Plasma::PackageStructure *structure = new QmlWallpaperPackage(); return Plasma::Package(structure); } else { return Plasma::Package();