File indexing completed on 2024-05-19 05:38:22

0001 /*
0002     SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0004     SPDX-FileCopyrightText: 2019 Cyril Rossi <cyril.rossi@enioka.com>
0005     SPDX-FileCopyrightText: 2021 Benjamin Port <benjamin.port@enioka.com>
0006     SPDX-FileCopyrightText: 2022 Dominic Hayes <ferenosdev@outlook.com>
0007     SPDX-FileCopyrightText: 2023 Ismael Asensio <isma.af@gmail.com>
0008 
0009     SPDX-License-Identifier: LGPL-2.0-only
0010 */
0011 
0012 #pragma once
0013 
0014 #include <KConfig>
0015 #include <KConfigGroup>
0016 #include <KPackage/Package>
0017 #include <KService>
0018 #include <QDir>
0019 #include <QObject>
0020 
0021 class LookAndFeelData;
0022 class LookAndFeelSettings;
0023 
0024 class LookAndFeelManager : public QObject
0025 {
0026     Q_OBJECT
0027 public:
0028     enum class Mode {
0029         Apply, // Apply the look and feel theme, i.e. change the active settings and set them up as new defaults. This is the default.
0030         Defaults // Only set up the options of the look and feel theme as new defaults without changing any active setting
0031     };
0032 
0033     enum ContentFlags {
0034         Empty = 0,
0035         // Appearance
0036         Colors = 1 << 0,
0037         WidgetStyle = 1 << 1,
0038         WindowDecoration = 1 << 2,
0039         Icons = 1 << 3,
0040         PlasmaTheme = 1 << 4,
0041         Cursors = 1 << 5,
0042         Fonts = 1 << 6,
0043         WindowSwitcher = 1 << 7,
0044         SplashScreen = 1 << 8,
0045         LockScreen = 1 << 9,
0046         Wallpaper = 1 << 10,
0047         BorderSize = 1 << 11,
0048         AppearanceSettings = (1 << 12) - 1, // All the contents within Appearance
0049         // Layout
0050         DesktopLayout = 1 << 16,
0051         TitlebarLayout = 1 << 17,
0052         WindowPlacement = 1 << 18,
0053         ShellPackage = 1 << 19,
0054         LayoutSettings = (1 << 20) - (1 << 16), // All the contents within Layout
0055         // Maybe unused or deprecated?
0056         RunCommand = 1 << 24,
0057         LogOutScript = 1 << 25,
0058         // General Flag combinations
0059         KWinSettings = WindowSwitcher | WindowDecoration | WindowPlacement | TitlebarLayout | BorderSize,
0060         AllSettings = (1 << 26) - 1,
0061     };
0062     Q_DECLARE_FLAGS(Contents, ContentFlags)
0063     Q_FLAG(Contents)
0064 
0065     LookAndFeelManager(QObject *parent = nullptr);
0066 
0067     void setMode(Mode mode);
0068     /**
0069      * Apply the theme represented by @p package, with @p previousPackage being the currently active package.
0070      * Effects depend upon the Mode of this object. If Mode is Defaults, @p previousPackage is ignored.
0071      * @p applyMask filters the package contents that will be applied.
0072      */
0073     void save(const KPackage::Package &package, const KPackage::Package &previousPackage, Contents applyMask = AllSettings);
0074     bool remove(const KPackage::Package &package, Contents contentsMask = Empty);
0075 
0076     Contents packageContents(const KPackage::Package &package) const;
0077 
0078     QString colorSchemeFile(const QString &schemeName) const;
0079 
0080     // Setters of the various theme pieces
0081     void setWidgetStyle(const QString &style);
0082     void setColors(const QString &scheme, const QString &colorFile);
0083     void setIcons(const QString &theme);
0084     void setPlasmaTheme(const QString &theme);
0085     void setCursorTheme(const QString theme);
0086     void setSplashScreen(const QString &theme);
0087     void setLatteLayout(const QString &filepath, const QString &name);
0088     void setLockScreen(const QString &theme);
0089     void setWindowSwitcher(const QString &theme);
0090     void setWindowDecoration(const QString &library, const QString &theme, bool noPlugin);
0091     void setTitlebarLayout(const QString &leftbtns, const QString &rightbtns);
0092     void setBorderSize(const QString &size);
0093     void setBorderlessMaximized(const QString &value);
0094     void setWindowPlacement(const QString &value);
0095     void setShellPackage(const QString &name);
0096 
0097     void setGeneralFont(const QString &font);
0098     void setFixedFont(const QString &font);
0099     void setSmallFont(const QString &font);
0100     void setSmallestReadableFont(const QString &font);
0101     void setToolbarFont(const QString &font);
0102     void setMenuFont(const QString &font);
0103     void setWindowTitleFont(const QString &font);
0104 
0105     LookAndFeelSettings *settings() const;
0106 
0107 Q_SIGNALS:
0108     void message();
0109     void iconsChanged();
0110     void colorsChanged();
0111     void styleChanged(const QString &newStyle);
0112     void cursorsChanged(const QString &newStyle);
0113     void fontsChanged();
0114     void refreshServices(const QStringList &toStop, const KService::List &toStart);
0115 
0116 private:
0117     void writeNewDefaults(const QString &filename,
0118                           const QString &group,
0119                           const QString &key,
0120                           const QString &value,
0121                           KConfig::WriteConfigFlags writeFlags = KConfig::Normal);
0122     void writeNewDefaults(KConfig &config,
0123                           KConfig &configDefault,
0124                           const QString &group,
0125                           const QString &key,
0126                           const QString &value,
0127                           KConfig::WriteConfigFlags writeFlags = KConfig::Normal);
0128     void
0129     writeNewDefaults(KConfigGroup &cg, KConfigGroup &cgd, const QString &key, const QString &value, KConfig::WriteConfigFlags writeFlags = KConfig::Normal);
0130     static KConfig configDefaults(const QString &filename);
0131 
0132     QStringList m_cursorSearchPaths;
0133     LookAndFeelData *const m_data;
0134     Mode m_mode = Mode::Apply;
0135     bool m_applyLatteLayout : 1;
0136     bool m_plasmashellChanged : 1;
0137     bool m_fontsChanged : 1;
0138 };
0139 
0140 Q_DECLARE_OPERATORS_FOR_FLAGS(LookAndFeelManager::Contents)