Purpose

jobcontroller.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
3 SPDX-License-Identifier: LGPL-2.1-or-later
4*/
5
6#include "jobcontroller.h"
7
8#include "configuration.h"
9
10namespace Purpose
11{
12void JobController::configure()
13{
14 Q_ASSERT(m_model);
15 Q_ASSERT(m_index >= 0);
16
17 m_configuration = m_model->configureJob(m_index);
18 m_configuration->setUseSeparateProcess(false);
19 Q_EMIT configChanged();
20
21 if (m_configuration->isReady()) {
22 startJob();
23 } else {
24 m_state = Configuring;
25 Q_EMIT stateChanged();
26 }
27}
28
29void JobController::startJob()
30{
31 m_job = m_configuration->createJob();
32 Q_ASSERT(m_job);
33 Q_EMIT jobChanged();
34
35 connect(m_job, &KJob::result, this, [this](KJob *job) {
36 if (job->error()) {
37 m_state = Error;
38 } else {
39 m_state = Finished;
40 }
41
42 Q_EMIT stateChanged();
43 });
44
45 m_job->start();
46
47 m_state = Running;
48 Q_EMIT stateChanged();
49}
50
51void JobController::cancel()
52{
53 m_state = Cancelled;
54 Q_EMIT stateChanged();
55}
56
57AlternativesModel *JobController::model() const
58{
59 return m_model;
60}
61
62void JobController::setModel(AlternativesModel *model)
63{
64 if (m_model != model) {
65 m_model = model;
66 Q_EMIT modelChanged();
67 }
68}
69
70int JobController::index() const
71{
72 return m_index;
73}
74
75void JobController::setIndex(int index)
76{
77 if (index != m_index) {
78 m_index = index;
79 Q_EMIT indexChanged();
80 }
81}
82
83JobController::State JobController::state() const
84{
85 return m_state;
86}
87
88Configuration *JobController::config() const
89{
90 return m_configuration;
91}
92
93Job *JobController::job() const
94{
95 return m_job;
96}
97
98}
99
100#include "moc_jobcontroller.cpp"
int error() const
void result(KJob *job)
virtual Q_SCRIPTABLE void start()=0
Q_SCRIPTABLE Purpose::Configuration * configureJob(int row)
This shouldn't require to have the job actually running on the same process as the app.
bool isReady
Tells whether there's still information to be provided, to be able to run the job.
void setUseSeparateProcess(bool separate)
separate will specify whether the process will be forced to execute in-process or in a separate proce...
Q_SCRIPTABLE Purpose::Job * createJob()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:07:47 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.