1
/***************************************************************************
2
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18
***************************************************************************/
20
#include "core/operationrunner.h"
22
#include "core/operationstack.h"
24
#include "ops/operation.h"
26
#include "util/report.h"
33
/** Constructs an OperationRunner.
34
@param ostack the OperationStack to act on
36
OperationRunner::OperationRunner(OperationStack& ostack) :
38
m_OperationStack(ostack),
45
/** Runs the operations in the OperationStack. */
46
void OperationRunner::run()
54
for (int i = 0; i < numOperations(); i++)
56
suspendMutex().lock();
58
if (!status || isCancelling())
60
suspendMutex().unlock();
64
Operation* op = operationStack().operations()[i];
65
op->setStatus(Operation::StatusRunning);
67
emit opStarted(i + 1, op);
69
connect(op, SIGNAL(progressChanged(int)), this, SIGNAL(progressSub(int)));
71
status = op->execute(report());
74
disconnect(op, SIGNAL(progressChanged(int)), this, SIGNAL(progressSub(int)));
76
emit opFinished(i + 1, op);
78
suspendMutex().unlock();
80
/** @todo Sleep a little to give others a chance to suspend us.
81
ProgressDialog::slotButtonClicked() blocks if we don't sleep here... Why?
82
It should block until we unlock above, but it blocks until run() ends...
89
else if (isCancelling())
95
/** @return the number of Operations to run */
96
qint32 OperationRunner::numOperations() const
98
return operationStack().operations().size();
101
/** @return the number of Jobs to run */
102
qint32 OperationRunner::numJobs() const
106
foreach (const Operation* op, operationStack().operations())
107
result += op->jobs().size();
112
/** @param op the number of the Operation to get a description for
113
@return the Operation's description
115
QString OperationRunner::description(qint32 op) const
118
Q_ASSERT(op < operationStack().size());
120
return operationStack().operations()[op]->description();