File indexing completed on 2026-07-12 11:20:43

0001 /*
0002     SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0003     SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KPLUGINMODEL_H
0009 #define KPLUGINMODEL_H
0010 
0011 #include "kcmutilscore_export.h"
0012 
0013 #include <QAbstractListModel>
0014 #include <QVector>
0015 
0016 #include <KPluginMetaData>
0017 #include <memory>
0018 
0019 class KConfigGroup;
0020 class KPluginModelPrivate;
0021 
0022 class KCMUTILSCORE_EXPORT KPluginModel : public QAbstractListModel
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     enum Roles {
0028         NameRole = Qt::DisplayRole,
0029         IconRole = Qt::DecorationRole,
0030         EnabledRole = Qt::CheckStateRole,
0031         DescriptionRole = Qt::UserRole + 1,
0032         IsChangeableRole,
0033         MetaDataRole,
0034         ConfigRole,
0035         IdRole,
0036         EnabledByDefaultRole,
0037     };
0038 
0039     explicit KPluginModel(QObject *parent = nullptr);
0040     ~KPluginModel() override;
0041 
0042     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0043     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0044     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0045     QHash<int, QByteArray> roleNames() const override;
0046 
0047     void addPlugins(const QVector<KPluginMetaData> &plugins, const QString &categoryLabel);
0048     void clear();
0049     void setConfig(const KConfigGroup &config);
0050     void save();
0051     void load();
0052     void defaults();
0053     bool isSaveNeeded();
0054 
0055     /**
0056      * Returns the KPluginMetaData object of the plugin's config module. If no plugin is found or the plugin does not have a config, the resulting
0057      * KPluginMetaData object will be invalid.
0058      * @since 5.94
0059      */
0060     KPluginMetaData findConfigForPluginId(const QString &pluginId) const;
0061 
0062     Q_SIGNAL void defaulted(bool isDefaulted);
0063     Q_SIGNAL void isSaveNeededChanged();
0064 
0065 private:
0066     const std::unique_ptr<KPluginModelPrivate> d;
0067 };
0068 #endif