File indexing completed on 2024-04-21 04:00:35

0001 /*
0002     SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
0003     SPDX-License-Identifier: LGPL-2.1-or-later
0004 */
0005 
0006 #ifndef JOBCONTROLLER_H
0007 #define JOBCONTROLLER_H
0008 
0009 #include <QObject>
0010 
0011 #include "alternativesmodel.h"
0012 #include "job.h"
0013 #include <purpose/purpose_export.h>
0014 
0015 namespace Purpose
0016 {
0017 class PURPOSE_EXPORT JobController : public QObject
0018 {
0019     Q_OBJECT
0020     Q_PROPERTY(AlternativesModel *model READ model WRITE setModel NOTIFY modelChanged)
0021     Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged)
0022     Q_PROPERTY(State state READ state NOTIFY stateChanged)
0023     Q_PROPERTY(Purpose::Configuration *configuration READ config NOTIFY configChanged)
0024     Q_PROPERTY(Purpose::Job *job READ job NOTIFY jobChanged)
0025 
0026 public:
0027     enum State {
0028         Inactive = 0,
0029         Configuring,
0030         Running,
0031         Finished,
0032         Cancelled,
0033         Error,
0034     };
0035     Q_ENUM(State)
0036 
0037     AlternativesModel *model() const;
0038     void setModel(AlternativesModel *model);
0039 
0040     int index() const;
0041     void setIndex(int index);
0042 
0043     State state() const;
0044 
0045     Configuration *config() const;
0046 
0047     Job *job() const;
0048 
0049     Q_INVOKABLE void configure();
0050     Q_INVOKABLE void startJob();
0051     Q_INVOKABLE void cancel();
0052 
0053 Q_SIGNALS:
0054     void modelChanged();
0055     void indexChanged();
0056     void stateChanged();
0057     void configChanged();
0058     void jobChanged();
0059 
0060 private:
0061     AlternativesModel *m_model = nullptr;
0062     int m_index = -1;
0063     Purpose::Configuration *m_configuration = nullptr;
0064     State m_state = Inactive;
0065     Job *m_job = nullptr;
0066 };
0067 
0068 }
0069 #endif