File indexing completed on 2024-04-14 03:58:03
0001 /* 0002 SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef PURPOSEALTERNATIVESMODEL_H 0008 #define PURPOSEALTERNATIVESMODEL_H 0009 0010 #include <QAbstractListModel> 0011 #include <QJsonObject> 0012 0013 #include <purpose/purpose_export.h> 0014 0015 namespace Purpose 0016 { 0017 class Configuration; 0018 class AlternativesModelPrivate; 0019 0020 /** 0021 * @short Interface for client applications to share data 0022 * 0023 * Lists all the alternatives to share a specified type of data then provides 0024 * a method to trigger a job. 0025 */ 0026 class PURPOSE_EXPORT AlternativesModel : public QAbstractListModel 0027 { 0028 Q_OBJECT 0029 /** 0030 * Specifies the type of the plugin we want to list 0031 * 0032 * @sa inputData 0033 */ 0034 Q_PROPERTY(QString pluginType READ pluginType WRITE setPluginType NOTIFY pluginTypeChanged) 0035 0036 /** 0037 * Specifies the information that will be given to the plugin once it's started 0038 * 0039 * @note some plugins might be filtered out based on this setting 0040 */ 0041 Q_PROPERTY(QJsonObject inputData READ inputData WRITE setInputData NOTIFY inputDataChanged) 0042 0043 /** 0044 * Provides a list of plugin names to have filtered out 0045 */ 0046 Q_PROPERTY(QStringList disabledPlugins READ disabledPlugins WRITE setDisabledPlugins NOTIFY disabledPluginsChanged) 0047 public: 0048 enum Roles { 0049 PluginIdRole = Qt::UserRole + 1, 0050 IconNameRole, 0051 ActionDisplayRole, 0052 }; 0053 0054 explicit AlternativesModel(QObject *parent = nullptr); 0055 ~AlternativesModel() override; 0056 0057 QJsonObject inputData() const; 0058 void setInputData(const QJsonObject &input); 0059 0060 QString pluginType() const; 0061 void setPluginType(const QString &pluginType); 0062 0063 QStringList disabledPlugins() const; 0064 void setDisabledPlugins(const QStringList &pluginIds); 0065 0066 /** 0067 * This shouldn't require to have the job actually running on the same process as the app. 0068 * 0069 * @param row specifies the alternative to be used 0070 * @param data specifies the data to have shared 0071 * 0072 * @returns the configuration instance that will offer the job. 0073 */ 0074 Q_SCRIPTABLE Purpose::Configuration *configureJob(int row); 0075 0076 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0077 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0078 QHash<int, QByteArray> roleNames() const override; 0079 0080 Q_SIGNALS: 0081 void inputDataChanged(); 0082 void pluginTypeChanged(); 0083 void disabledPluginsChanged(); 0084 0085 private: 0086 PURPOSE_NO_EXPORT void initializeModel(); 0087 0088 AlternativesModelPrivate *const d_ptr; 0089 Q_DECLARE_PRIVATE(AlternativesModel) 0090 }; 0091 0092 } 0093 0094 #endif