2
* Copyright (C) 2012 Ivan Cukic <ivan.cukic(at)kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2,
6
* or (at your option) any later version, as published by the Free
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
15
* License 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.
21
#include "Abstract_p.h"
25
#include <utils/d_ptr_implementation.h>
28
namespace Schedulers {
30
Abstract::Private::Private(Abstract * parent)
35
void Abstract::Private::jobFinished(KJob * job)
37
kDebug() << "Job has finished with this result" << job->error();
38
q->jobFinished(job->error());
41
bool Abstract::startJob(int index)
43
d->lastJobStarted = index;
45
// If the index is not valid
46
if (index < 0 || d->jobs.size() <= index) {
51
JobFactory * factory = d->jobs[index];
53
// If the job factory is null, exit
60
KJob * job = d->jobs[index]->create(this);
62
connect(job, SIGNAL(finished(KJob *)),
63
d.get(), SLOT(jobFinished(KJob *)));
70
Abstract::Abstract(QObject * parent)
71
: Job(parent), d(this)
73
d->lastJobStarted = -1;
77
this, SIGNAL(finished(KJob *)),
78
this, SLOT(deleteLater()),
89
void Abstract::addJob(Job * other)
91
d->jobs << JobFactory::wrap(other);
94
void Abstract::addJob(JobFactory * other)
99
void Abstract::start()
101
if (d->jobs.size() == 0) {
109
int Abstract::lastJobStarted() const
111
return d->lastJobStarted;
114
int Abstract::jobCount() const
116
return d->jobs.size();
119
bool Abstract::hasJob(int index) const
121
return (index >= 0 && index < d->jobs.size() && d->jobs[index] != nullptr);
124
void Abstract::returnResult(int result)
126
kDebug() << "Returning" << result;
132
} // namespace Schedulers