| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef PURPOSEALTERNATIVESMODEL_H |
| 8 | #define PURPOSEALTERNATIVESMODEL_H |
| 9 | |
| 10 | #include <QAbstractListModel> |
| 11 | #include <QJsonObject> |
| 12 | |
| 13 | #include <purpose/purpose_export.h> |
| 14 | |
| 15 | namespace Purpose |
| 16 | { |
| 17 | class Configuration; |
| 18 | class AlternativesModelPrivate; |
| 19 | |
| 20 | /*! |
| 21 | * \class Purpose::AlternativesModel |
| 22 | * \inheaderfile Purpose/AlternativesModel |
| 23 | * \inmodule Purpose |
| 24 | * |
| 25 | * \brief Interface for client applications to share data. |
| 26 | * |
| 27 | * Lists all the alternatives to share a specified type of data then provides |
| 28 | * a method to trigger a job. |
| 29 | */ |
| 30 | class PURPOSE_EXPORT AlternativesModel : public QAbstractListModel |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | /*! |
| 34 | * \property Purpose::AlternativesModel::pluginType |
| 35 | * |
| 36 | * \brief Specifies the type of the plugin we want to list. |
| 37 | * |
| 38 | * \sa inputData |
| 39 | */ |
| 40 | Q_PROPERTY(QString pluginType READ pluginType WRITE setPluginType NOTIFY pluginTypeChanged) |
| 41 | |
| 42 | /*! |
| 43 | * \property Purpose::AlternativesModel::inputData |
| 44 | * |
| 45 | * \brief Specifies the information that will be given to the plugin once it's started. |
| 46 | * |
| 47 | * \note some plugins might be filtered out based on this setting |
| 48 | */ |
| 49 | Q_PROPERTY(QJsonObject inputData READ inputData WRITE setInputData NOTIFY inputDataChanged) |
| 50 | |
| 51 | /*! |
| 52 | * \property Purpose::AlternativesModel::disabledPlugins |
| 53 | * |
| 54 | * \brief Provides a list of plugin names to have filtered out. |
| 55 | */ |
| 56 | Q_PROPERTY(QStringList disabledPlugins READ disabledPlugins WRITE setDisabledPlugins NOTIFY disabledPluginsChanged) |
| 57 | public: |
| 58 | /*! |
| 59 | * \value PluginIdRole |
| 60 | * \value IconNameRole |
| 61 | * \value ActionDisplayRole |
| 62 | */ |
| 63 | enum Roles { |
| 64 | PluginIdRole = Qt::UserRole + 1, |
| 65 | IconNameRole, |
| 66 | ActionDisplayRole, |
| 67 | }; |
| 68 | |
| 69 | /*! |
| 70 | * Constructs an alternatives model with the given \a parent. |
| 71 | */ |
| 72 | explicit AlternativesModel(QObject *parent = nullptr); |
| 73 | |
| 74 | ~AlternativesModel() override; |
| 75 | |
| 76 | QJsonObject inputData() const; |
| 77 | void setInputData(const QJsonObject &input); |
| 78 | |
| 79 | QString pluginType() const; |
| 80 | void setPluginType(const QString &pluginType); |
| 81 | |
| 82 | QStringList disabledPlugins() const; |
| 83 | void setDisabledPlugins(const QStringList &pluginIds); |
| 84 | |
| 85 | /*! |
| 86 | * This shouldn't require to have the job actually running on the same process as the app. |
| 87 | * |
| 88 | * \a row specifies the alternative to be used. |
| 89 | * |
| 90 | * Returns the configuration instance that will offer the job. |
| 91 | */ |
| 92 | Q_SCRIPTABLE Purpose::Configuration *configureJob(int row); |
| 93 | |
| 94 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 95 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 96 | QHash<int, QByteArray> roleNames() const override; |
| 97 | |
| 98 | Q_SIGNALS: |
| 99 | void inputDataChanged(); |
| 100 | void pluginTypeChanged(); |
| 101 | void disabledPluginsChanged(); |
| 102 | |
| 103 | private: |
| 104 | PURPOSE_NO_EXPORT void initializeModel(); |
| 105 | |
| 106 | AlternativesModelPrivate *const d_ptr; |
| 107 | Q_DECLARE_PRIVATE(AlternativesModel) |
| 108 | }; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | #endif |
| 113 | |