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 #include "jobcontroller.h" 0007 0008 #include "configuration.h" 0009 0010 namespace Purpose 0011 { 0012 void JobController::configure() 0013 { 0014 Q_ASSERT(m_model); 0015 Q_ASSERT(m_index >= 0); 0016 0017 m_configuration = m_model->configureJob(m_index); 0018 m_configuration->setUseSeparateProcess(false); 0019 Q_EMIT configChanged(); 0020 0021 if (m_configuration->isReady()) { 0022 startJob(); 0023 } else { 0024 m_state = Configuring; 0025 Q_EMIT stateChanged(); 0026 } 0027 } 0028 0029 void JobController::startJob() 0030 { 0031 m_job = m_configuration->createJob(); 0032 Q_ASSERT(m_job); 0033 Q_EMIT jobChanged(); 0034 0035 connect(m_job, &KJob::result, this, [this](KJob *job) { 0036 if (job->error()) { 0037 m_state = Error; 0038 } else { 0039 m_state = Finished; 0040 } 0041 0042 Q_EMIT stateChanged(); 0043 }); 0044 0045 m_job->start(); 0046 0047 m_state = Running; 0048 Q_EMIT stateChanged(); 0049 } 0050 0051 void JobController::cancel() 0052 { 0053 m_state = Cancelled; 0054 Q_EMIT stateChanged(); 0055 } 0056 0057 AlternativesModel *JobController::model() const 0058 { 0059 return m_model; 0060 } 0061 0062 void JobController::setModel(AlternativesModel *model) 0063 { 0064 if (m_model != model) { 0065 m_model = model; 0066 Q_EMIT modelChanged(); 0067 } 0068 } 0069 0070 int JobController::index() const 0071 { 0072 return m_index; 0073 } 0074 0075 void JobController::setIndex(int index) 0076 { 0077 if (index != m_index) { 0078 m_index = index; 0079 Q_EMIT indexChanged(); 0080 } 0081 } 0082 0083 JobController::State JobController::state() const 0084 { 0085 return m_state; 0086 } 0087 0088 Configuration *JobController::config() const 0089 { 0090 return m_configuration; 0091 } 0092 0093 Job *JobController::job() const 0094 { 0095 return m_job; 0096 } 0097 0098 } 0099 0100 #include "moc_jobcontroller.cpp"