1 | /* |
2 | SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-or-later |
5 | */ |
6 | |
7 | #ifndef PURPOSE_CONFIGURATION_H |
8 | #define PURPOSE_CONFIGURATION_H |
9 | |
10 | #include <QJsonArray> |
11 | #include <QJsonObject> |
12 | #include <QObject> |
13 | #include <QUrl> |
14 | #include <purpose/purpose_export.h> |
15 | |
16 | class QJsonObject; |
17 | class KPluginMetaData; |
18 | |
19 | namespace Purpose |
20 | { |
21 | class ConfigurationPrivate; |
22 | class Job; |
23 | |
24 | /*! |
25 | * \class Purpose::Configuration |
26 | * \inheaderfile Purpose/Configuration |
27 | * \inmodule Purpose |
28 | * |
29 | * \brief This class will be in charge of figuring out the job configuration. |
30 | * |
31 | * Once it's figured out, it can proceed to create the job. |
32 | * |
33 | * The object will be destroyed as soon as the job finishes. |
34 | */ |
35 | |
36 | class PURPOSE_EXPORT Configuration : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | /*! |
41 | * \property Purpose::Configuration::isReady |
42 | * |
43 | * Tells whether there's still information to be provided, to be able to run |
44 | * the job. |
45 | */ |
46 | Q_PROPERTY(bool isReady READ isReady NOTIFY dataChanged) |
47 | |
48 | /*! |
49 | * \property Purpose::Configuration::data |
50 | * |
51 | * Represents the data the job will have available to perform its task. |
52 | */ |
53 | Q_PROPERTY(QJsonObject data READ data WRITE setData NOTIFY dataChanged) |
54 | |
55 | /*! |
56 | * \property Purpose::Configuration::neededArguments |
57 | * |
58 | * Specifies the arguments the config file and the job will be sharing. |
59 | */ |
60 | Q_PROPERTY(QJsonArray neededArguments READ neededArguments CONSTANT) |
61 | |
62 | /*! |
63 | * \property Purpose::Configuration::configSourceCode |
64 | * |
65 | * Specifies the QML source code to be used, to configure the current job. |
66 | */ |
67 | Q_PROPERTY(QUrl configSourceCode READ configSourceCode CONSTANT) |
68 | |
69 | /*! |
70 | * \property Purpose::Configuration::pluginTypeName |
71 | * |
72 | * Returns the plugin type name to display. |
73 | */ |
74 | Q_PROPERTY(QString pluginTypeName READ pluginTypeName CONSTANT) |
75 | |
76 | /*! |
77 | * \property Purpose::Configuration::pluginName |
78 | * |
79 | * Returns the plugin name to display. |
80 | */ |
81 | Q_PROPERTY(QString pluginName READ pluginName CONSTANT) |
82 | public: |
83 | /*! |
84 | * \brief Constructs a new configuration. |
85 | */ |
86 | Configuration(const QJsonObject &inputData, |
87 | const QString &pluginTypeName, |
88 | const QJsonObject &pluginType, |
89 | const KPluginMetaData &pluginInformation, |
90 | QObject *parent = nullptr); |
91 | /*! |
92 | * \brief Constructs a new configuration. |
93 | */ |
94 | Configuration(const QJsonObject &inputData, const QString &pluginTypeName, const KPluginMetaData &pluginInformation, QObject *parent = nullptr); |
95 | /*! |
96 | * \brief Destroys the configuration. |
97 | */ |
98 | ~Configuration() override; |
99 | |
100 | void setData(const QJsonObject &data); |
101 | QJsonObject data() const; |
102 | |
103 | bool isReady() const; |
104 | QJsonArray neededArguments() const; |
105 | QUrl configSourceCode() const; |
106 | |
107 | /*! |
108 | * Returns whether the job will be run in the same process. |
109 | * |
110 | * By default it will be true, unless the environment variable \c KDE_PURPOSE_LOCAL_JOBS is defined. |
111 | */ |
112 | bool useSeparateProcess() const; |
113 | |
114 | /*! |
115 | * \a separate will specify whether the process will be forced to execute |
116 | * in-process or in a separate process. |
117 | */ |
118 | void setUseSeparateProcess(bool separate); |
119 | |
120 | /*! |
121 | * Returns the configured job ready to be started. |
122 | * |
123 | * Before calling it, make sure that all information has been filled by |
124 | * checking \l isReady(). |
125 | */ |
126 | Q_SCRIPTABLE Purpose::Job *createJob(); |
127 | |
128 | QString pluginName() const; |
129 | |
130 | QString pluginTypeName() const; |
131 | |
132 | Q_SIGNALS: |
133 | void dataChanged(); |
134 | |
135 | private: |
136 | Q_DECLARE_PRIVATE(Configuration) |
137 | ConfigurationPrivate *const d_ptr; |
138 | }; |
139 | |
140 | } |
141 | |
142 | #endif // CONFIGURATION_H |
143 | |