File indexing completed on 2024-11-24 05:01:58
0001 /* 0002 SPDX-FileCopyrightText: 2007 Ivan Cukic <ivan.cukic+kde@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kcategorizeditemsviewmodels_p.h" 0010 #include <KConfigGroup> 0011 #include <KPluginMetaData> 0012 0013 class PlasmaAppletItemModel; 0014 0015 /** 0016 * Implementation of the KCategorizedItemsViewModels::AbstractItem 0017 */ 0018 class PlasmaAppletItem : public KCategorizedItemsViewModels::AbstractItem 0019 { 0020 public: 0021 explicit PlasmaAppletItem(const KPluginMetaData &info); 0022 0023 QString pluginName() const; 0024 QString name() const override; 0025 QString category() const; 0026 QString description() const override; 0027 QString license() const; 0028 QString website() const; 0029 QString version() const; 0030 QString author() const; 0031 QString email() const; 0032 QString apiVersion() const; 0033 QString unsupportedMessage() const; 0034 bool isSupported() const; 0035 QVariant data(int role = Qt::UserRole + 1) const override; 0036 0037 int running() const override; 0038 bool isLocal() const; 0039 bool matches(const QString &pattern) const override; 0040 QStringList keywords() const override; 0041 0042 // set how many instances of this applet are running 0043 void setRunning(int count) override; 0044 bool passesFiltering(const KCategorizedItemsViewModels::Filter &filter) const override; 0045 QMimeData *mimeData() const; 0046 QStringList mimeTypes() const; 0047 0048 private: 0049 KPluginMetaData m_info; 0050 QString m_screenshot; 0051 QString m_icon; 0052 int m_runningCount; 0053 bool m_local; 0054 }; 0055 0056 class PlasmaAppletItemModel : public QStandardItemModel 0057 { 0058 Q_OBJECT 0059 0060 public: 0061 enum Roles { 0062 NameRole = Qt::UserRole + 1, 0063 PluginNameRole = Qt::UserRole + 2, 0064 DescriptionRole = Qt::UserRole + 3, 0065 CategoryRole = Qt::UserRole + 4, 0066 LicenseRole = Qt::UserRole + 5, 0067 WebsiteRole = Qt::UserRole + 6, 0068 VersionRole = Qt::UserRole + 7, 0069 AuthorRole = Qt::UserRole + 8, 0070 EmailRole = Qt::UserRole + 9, 0071 RunningRole = Qt::UserRole + 10, 0072 LocalRole = Qt::UserRole + 11, 0073 ScreenshotRole = Qt::UserRole + 12, 0074 ApiVersionRole = Qt::UserRole + 13, 0075 IsSupportedRole = Qt::UserRole + 14, 0076 UnsupportedMessageRole = Qt::UserRole + 15 0077 }; 0078 0079 explicit PlasmaAppletItemModel(QObject *parent = nullptr); 0080 0081 QStringList mimeTypes() const override; 0082 0083 QMimeData *mimeData(const QModelIndexList &indexes) const override; 0084 0085 void setApplication(const QString &app); 0086 void setRunningApplets(const QHash<QString, int> &apps); 0087 void setRunningApplets(const QString &name, int count); 0088 0089 QString &Application(); 0090 0091 QStringList provides() const; 0092 void setProvides(const QStringList &provides); 0093 0094 QHash<int, QByteArray> roleNames() const override; 0095 0096 bool startupCompleted() const; 0097 void setStartupCompleted(bool complete); 0098 0099 Q_SIGNALS: 0100 void modelPopulated(); 0101 0102 private: 0103 QString m_application; 0104 QStringList m_provides; 0105 KConfigGroup m_configGroup; 0106 bool m_startupCompleted : 1; 0107 0108 private Q_SLOTS: 0109 void populateModel(); 0110 };