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

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 <KNSCore/Entry>
0017 #include <KSharedConfig>
0018 
0019 #include <QDir>
0020 #include <QStandardItemModel>
0021 
0022 #include <KPackage/Package>
0023 #include <KQuickManagedConfigModule>
0024 
0025 #include "lookandfeelmanager.h"
0026 #include "lookandfeelsettings.h"
0027 
0028 class QQuickItem;
0029 class LookAndFeelManager;
0030 
0031 class KCMLookandFeel : public KQuickManagedConfigModule
0032 {
0033     Q_OBJECT
0034     Q_PROPERTY(LookAndFeelSettings *lookAndFeelSettings READ lookAndFeelSettings CONSTANT)
0035     Q_PROPERTY(QStandardItemModel *lookAndFeelModel READ lookAndFeelModel CONSTANT)
0036 
0037     Q_PROPERTY(LookAndFeelManager::Contents themeContents READ themeContents NOTIFY themeContentsChanged)
0038     Q_PROPERTY(LookAndFeelManager::Contents selectedContents READ selectedContents WRITE setSelectedContents RESET resetSelectedContents NOTIFY
0039                    selectedContentsChanged)
0040 
0041 public:
0042     enum Roles {
0043         PluginNameRole = Qt::UserRole + 1,
0044         ScreenshotRole,
0045         FullScreenPreviewRole,
0046         DescriptionRole,
0047         ContentsRole,
0048         PackagePathRole, //< Package root path
0049         UninstallableRole, //< Package is installed in local directory
0050     };
0051     Q_ENUM(Roles)
0052 
0053     KCMLookandFeel(QObject *parent, const KPluginMetaData &data);
0054     ~KCMLookandFeel() override;
0055 
0056     LookAndFeelSettings *lookAndFeelSettings() const;
0057     QStandardItemModel *lookAndFeelModel() const;
0058 
0059     /**
0060      * Removes the given row from the LookandFeel items.
0061      * It calls \QStandardItemModel::removeRow and removes local files
0062      *
0063      * @param row the given row from LookandFeel items
0064      * @param removeDependencies whether the dependencies should also be removed
0065      * @return Returns true if the row is removed; otherwise returns false.
0066      */
0067     Q_INVOKABLE bool removeRow(int row, bool removeDependencies = false);
0068 
0069     Q_INVOKABLE int pluginIndex(const QString &pluginName) const;
0070     Q_INVOKABLE void knsEntryChanged(const KNSCore::Entry &entry);
0071     Q_INVOKABLE void reloadConfig()
0072     {
0073         KQuickManagedConfigModule::load();
0074     }
0075 
0076     LookAndFeelManager *lookAndFeel() const
0077     {
0078         return m_lnf;
0079     };
0080     void addKPackageToModel(const KPackage::Package &pkg);
0081 
0082     bool isSaveNeeded() const override;
0083 
0084     LookAndFeelManager::Contents themeContents() const;
0085 
0086     LookAndFeelManager::Contents selectedContents() const;
0087     void setSelectedContents(LookAndFeelManager::Contents items);
0088     void resetSelectedContents();
0089 
0090 public Q_SLOTS:
0091     void load() override;
0092     void save() override;
0093     void defaults() override;
0094 
0095 Q_SIGNALS:
0096     void showConfirmation();
0097     void themeContentsChanged();
0098     void selectedContentsChanged();
0099 
0100 private:
0101     // List only packages which provide at least one of the components
0102     QList<KPackage::Package> availablePackages(const QStringList &components);
0103     void loadModel();
0104     QDir cursorThemeDir(const QString &theme, const int depth);
0105     QStringList cursorSearchPaths();
0106     void cursorsChanged(const QString &name);
0107 
0108     LookAndFeelManager *const m_lnf;
0109 
0110     LookAndFeelManager::Contents m_themeContents;
0111     LookAndFeelManager::Contents m_selectedContents;
0112 
0113     QStandardItemModel *m_model;
0114     KPackage::Package m_package;
0115     QStringList m_cursorSearchPaths;
0116 };