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
15namespace Purpose
16{
17class Configuration;
18class AlternativesModelPrivate;
19
20/**
21 * @short Interface for client applications to share data
22 *
23 * Lists all the alternatives to share a specified type of data then provides
24 * a method to trigger a job.
25 */
26class PURPOSE_EXPORT AlternativesModel : public QAbstractListModel
27{
28 Q_OBJECT
29 /**
30 * Specifies the type of the plugin we want to list
31 *
32 * @sa inputData
33 */
34 Q_PROPERTY(QString pluginType READ pluginType WRITE setPluginType NOTIFY pluginTypeChanged)
35
36 /**
37 * Specifies the information that will be given to the plugin once it's started
38 *
39 * @note some plugins might be filtered out based on this setting
40 */
41 Q_PROPERTY(QJsonObject inputData READ inputData WRITE setInputData NOTIFY inputDataChanged)
42
43 /**
44 * Provides a list of plugin names to have filtered out
45 */
46 Q_PROPERTY(QStringList disabledPlugins READ disabledPlugins WRITE setDisabledPlugins NOTIFY disabledPluginsChanged)
47public:
48 enum Roles {
49 PluginIdRole = Qt::UserRole + 1,
50 IconNameRole,
51 ActionDisplayRole,
52 };
53
54 explicit AlternativesModel(QObject *parent = nullptr);
55 ~AlternativesModel() override;
56
57 QJsonObject inputData() const;
58 void setInputData(const QJsonObject &input);
59
60 QString pluginType() const;
61 void setPluginType(const QString &pluginType);
62
63 QStringList disabledPlugins() const;
64 void setDisabledPlugins(const QStringList &pluginIds);
65
66 /**
67 * This shouldn't require to have the job actually running on the same process as the app.
68 *
69 * @param row specifies the alternative to be used
70 * @param data specifies the data to have shared
71 *
72 * @returns the configuration instance that will offer the job.
73 */
74 Q_SCRIPTABLE Purpose::Configuration *configureJob(int row);
75
76 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
77 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
78 QHash<int, QByteArray> roleNames() const override;
79
80Q_SIGNALS:
81 void inputDataChanged();
82 void pluginTypeChanged();
83 void disabledPluginsChanged();
84
85private:
86 PURPOSE_NO_EXPORT void initializeModel();
87
88 AlternativesModelPrivate *const d_ptr;
89 Q_DECLARE_PRIVATE(AlternativesModel)
90};
91
92}
93
94#endif
95

source code of purpose/src/alternativesmodel.h