File indexing completed on 2024-12-22 05:16:37

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Aaron Seigo <aseigo@kde.org>
0003     SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include <KPackage/PackageLoader>
0009 #include <KPackage/PackageStructure>
0010 
0011 #define DEFAULT_LOOKANDFEEL "org.kde.breeze.desktop"
0012 
0013 class LookAndFeelPackage : public KPackage::PackageStructure
0014 {
0015     Q_OBJECT
0016 public:
0017     using KPackage::PackageStructure::PackageStructure;
0018 
0019     void initPackage(KPackage::Package *package) override
0020     {
0021         // https://community.kde.org/Plasma/lookAndFeelPackage#
0022         package->setDefaultPackageRoot(QStringLiteral("plasma/look-and-feel/"));
0023 
0024         // Defaults
0025         package->removeDefinition("mainscript"); // This doesn't make sense, because we don't have one single entrypoint
0026         package->addFileDefinition("defaults", QStringLiteral("defaults"));
0027         package->addFileDefinition("layoutdefaults", QStringLiteral("layouts/defaults"));
0028         package->addDirectoryDefinition("plasmoidsetupscripts", QStringLiteral("plasmoidsetupscripts"));
0029         // Colors
0030         package->addFileDefinition("colors", QStringLiteral("colors"));
0031 
0032         // Directories
0033         package->addDirectoryDefinition("previews", QStringLiteral("previews"));
0034         package->addFileDefinition("preview", QStringLiteral("previews/preview.png"));
0035         package->addFileDefinition("fullscreenpreview", QStringLiteral("previews/fullscreenpreview.jpg"));
0036         package->addFileDefinition("loginmanagerpreview", QStringLiteral("previews/loginmanager.png"));
0037         package->addFileDefinition("lockscreenpreview", QStringLiteral("previews/lockscreen.png"));
0038         package->addFileDefinition("userswitcherpreview", QStringLiteral("previews/userswitcher.png"));
0039         package->addFileDefinition("splashpreview", QStringLiteral("previews/splash.png"));
0040         package->addFileDefinition("runcommandpreview", QStringLiteral("previews/runcommand.png"));
0041         package->addFileDefinition("windowdecorationpreview", QStringLiteral("previews/windowdecoration.png"));
0042         package->addFileDefinition("windowswitcherpreview", QStringLiteral("previews/windowswitcher.png"));
0043 
0044         package->addDirectoryDefinition("loginmanager", QStringLiteral("loginmanager"));
0045         package->addFileDefinition("loginmanagermainscript", QStringLiteral("loginmanager/LoginManager.qml"));
0046 
0047         package->addDirectoryDefinition("logout", QStringLiteral("logout"));
0048         package->addFileDefinition("logoutmainscript", QStringLiteral("logout/Logout.qml"));
0049 
0050         package->addDirectoryDefinition("lockscreen", QStringLiteral("lockscreen"));
0051         package->addFileDefinition("lockscreenmainscript", QStringLiteral("lockscreen/LockScreen.qml"));
0052 
0053         package->addDirectoryDefinition("userswitcher", QStringLiteral("userswitcher"));
0054         package->addFileDefinition("userswitchermainscript", QStringLiteral("userswitcher/UserSwitcher.qml"));
0055 
0056         package->addDirectoryDefinition("osd", QStringLiteral("osd"));
0057         package->addFileDefinition("osdmainscript", QStringLiteral("osd/Osd.qml"));
0058 
0059         package->addDirectoryDefinition("splash", QStringLiteral("splash"));
0060         package->addFileDefinition("splashmainscript", QStringLiteral("splash/Splash.qml"));
0061 
0062         package->addDirectoryDefinition("runcommand", QStringLiteral("runcommand"));
0063         package->addFileDefinition("runcommandmainscript", QStringLiteral("runcommand/RunCommand.qml"));
0064 
0065         package->addDirectoryDefinition("windowdecoration", QStringLiteral("windowdecoration"));
0066         package->addFileDefinition("windowdecorationmainscript", QStringLiteral("windowdecoration/WindowDecoration.qml"));
0067 
0068         package->addDirectoryDefinition("windowswitcher", QStringLiteral("windowswitcher"));
0069         package->addFileDefinition("windowswitchermainscript", QStringLiteral("windowswitcher/WindowSwitcher.qml"));
0070 
0071         package->addDirectoryDefinition("systemdialog", QStringLiteral("systemdialog"));
0072         package->addFileDefinition("systemdialogscript", QStringLiteral("systemdialog/SystemDialog.qml"));
0073 
0074         package->addDirectoryDefinition("layouts", QStringLiteral("layouts"));
0075 
0076         package->setPath(DEFAULT_LOOKANDFEEL);
0077     }
0078 
0079     void pathChanged(KPackage::Package *package) override
0080     {
0081         if (!package->metadata().isValid()) {
0082             return;
0083         }
0084 
0085         const QString pluginName = package->metadata().pluginId();
0086 
0087         if (!pluginName.isEmpty() && pluginName != DEFAULT_LOOKANDFEEL) {
0088             KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"), DEFAULT_LOOKANDFEEL);
0089             package->setFallbackPackage(pkg);
0090         } else if (package->fallbackPackage().isValid() && pluginName == DEFAULT_LOOKANDFEEL) {
0091             package->setFallbackPackage(KPackage::Package());
0092         }
0093     }
0094 };
0095 
0096 K_PLUGIN_CLASS_WITH_JSON(LookAndFeelPackage, "plasma-packagestructure-lookandfeel.json")
0097 
0098 #include "lookandfeel.moc"