File indexing completed on 2024-04-14 03:58:03

0001 /*
0002     SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef PURPOSE_CONFIGURATION_H
0008 #define PURPOSE_CONFIGURATION_H
0009 
0010 #include <QJsonArray>
0011 #include <QJsonObject>
0012 #include <QObject>
0013 #include <QUrl>
0014 #include <purpose/purpose_export.h>
0015 
0016 class QJsonObject;
0017 class KPluginMetaData;
0018 
0019 namespace Purpose
0020 {
0021 class ConfigurationPrivate;
0022 class Job;
0023 
0024 /**
0025  * @brief This class will be in charge of figuring out the job configuration
0026  *
0027  * Once it's figured out, it can proceed to create the job.
0028  *
0029  * The object will be destroyed as soon as the job finishes.
0030  */
0031 
0032 class PURPOSE_EXPORT Configuration : public QObject
0033 {
0034     Q_OBJECT
0035 
0036     /**
0037      * Tells whether there's still information to be provided, to be able to run
0038      * the job.
0039      *
0040      * @sa X-Purpose-MandatoryArguments and X-Purpose-AdditionalArguments
0041      */
0042     Q_PROPERTY(bool isReady READ isReady NOTIFY dataChanged)
0043 
0044     /**
0045      * Represents the data the job will have available to perform its task
0046      */
0047     Q_PROPERTY(QJsonObject data READ data WRITE setData NOTIFY dataChanged)
0048 
0049     /**
0050      * Specifies the arguments the config file and the job will be sharing
0051      */
0052     Q_PROPERTY(QJsonArray neededArguments READ neededArguments CONSTANT)
0053 
0054     /**
0055      * Specifies the qml source code to be used, to configure the current job.
0056      *
0057      * @sa JobController QtQuick component
0058      */
0059     Q_PROPERTY(QUrl configSourceCode READ configSourceCode CONSTANT)
0060 
0061     /**
0062      * @returns the plugin type name to display
0063      */
0064     Q_PROPERTY(QString pluginTypeName READ pluginTypeName CONSTANT)
0065 
0066     /**
0067      * @returns the plugin name to display
0068      */
0069     Q_PROPERTY(QString pluginName READ pluginName CONSTANT)
0070 public:
0071     Configuration(const QJsonObject &inputData,
0072                   const QString &pluginTypeName,
0073                   const QJsonObject &pluginType,
0074                   const KPluginMetaData &pluginInformation,
0075                   QObject *parent = nullptr);
0076     Configuration(const QJsonObject &inputData, const QString &pluginTypeName, const KPluginMetaData &pluginInformation, QObject *parent = nullptr);
0077     ~Configuration() override;
0078 
0079     void setData(const QJsonObject &data);
0080     QJsonObject data() const;
0081 
0082     bool isReady() const;
0083     QJsonArray neededArguments() const;
0084     QUrl configSourceCode() const;
0085 
0086     /**
0087      * @returns whether the job will be run in the same process.
0088      *
0089      * By default it will be true, unless the environment variable KDE_PURPOSE_LOCAL_JOBS is defined
0090      */
0091     bool useSeparateProcess() const;
0092 
0093     /**
0094      * @p separate will specify whether the process will be forced to execute
0095      * in-process or in a separate process.
0096      */
0097     void setUseSeparateProcess(bool separate);
0098 
0099     /**
0100      * @returns the configured job ready to be started.
0101      *
0102      * Before calling it, make sure that all information has been filled by
0103      * checking isReady().
0104      */
0105     Q_SCRIPTABLE Purpose::Job *createJob();
0106 
0107     QString pluginName() const;
0108 
0109     QString pluginTypeName() const;
0110 
0111 Q_SIGNALS:
0112     void dataChanged();
0113 
0114 private:
0115     Q_DECLARE_PRIVATE(Configuration)
0116     ConfigurationPrivate *const d_ptr;
0117 };
0118 
0119 }
0120 
0121 #endif // CONFIGURATION_H