~ubuntu-branches/ubuntu/saucy/kactivities/saucy-proposed

« back to all changes in this revision

Viewing changes to src/service/jobs/schedulers/Abstract.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Scott Kitterman
  • Date: 2012-11-20 13:47:27 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121120134727-vqzk04slqjoay3de
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Scott Kitterman ]
* Add new libkactivities-models1 library package (debian/control, .install,
  and .symbols)
* Add nepomuk-core-dev to build-depends
* Wildcard libkactivities6.install so that soversion changes don't cause
  build failures
* Update libkactivities6.symbols
* Update libkactivities-dev.install for new files for libkactivies-models
* Add new files to libkactivities-bin.install, including Activities kcm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2012 Ivan Cukic <ivan.cukic(at)kde.org>
 
3
 *
 
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
 
7
 *   Software Foundation
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "Abstract.h"
 
21
#include "Abstract_p.h"
 
22
 
 
23
#include <KDebug>
 
24
 
 
25
#include <utils/d_ptr_implementation.h>
 
26
 
 
27
namespace Jobs {
 
28
namespace Schedulers {
 
29
 
 
30
Abstract::Private::Private(Abstract * parent)
 
31
    : q(parent)
 
32
{
 
33
}
 
34
 
 
35
void Abstract::Private::jobFinished(KJob * job)
 
36
{
 
37
    kDebug() << "Job has finished with this result" << job->error();
 
38
    q->jobFinished(job->error());
 
39
}
 
40
 
 
41
bool Abstract::startJob(int index)
 
42
{
 
43
    d->lastJobStarted = index;
 
44
 
 
45
    // If the index is not valid
 
46
    if (index < 0 || d->jobs.size() <= index) {
 
47
        returnResult(0);
 
48
        return false;
 
49
    }
 
50
 
 
51
    JobFactory * factory = d->jobs[index];
 
52
 
 
53
    // If the job factory is null, exit
 
54
    if (!factory) {
 
55
        returnResult(0);
 
56
        return false;
 
57
    }
 
58
 
 
59
    // Starting the job
 
60
    KJob * job = d->jobs[index]->create(this);
 
61
 
 
62
    connect(job, SIGNAL(finished(KJob *)),
 
63
            d.get(), SLOT(jobFinished(KJob *)));
 
64
 
 
65
    job->start();
 
66
 
 
67
    return true;
 
68
}
 
69
 
 
70
Abstract::Abstract(QObject * parent)
 
71
    : Job(parent), d(this)
 
72
{
 
73
    d->lastJobStarted = -1;
 
74
 
 
75
    if (!parent) {
 
76
        connect(
 
77
            this, SIGNAL(finished(KJob *)),
 
78
            this, SLOT(deleteLater()),
 
79
            Qt::QueuedConnection
 
80
        );
 
81
    }
 
82
}
 
83
 
 
84
Abstract::~Abstract()
 
85
{
 
86
    qDeleteAll(d->jobs);
 
87
}
 
88
 
 
89
void Abstract::addJob(Job * other)
 
90
{
 
91
    d->jobs << JobFactory::wrap(other);
 
92
}
 
93
 
 
94
void Abstract::addJob(JobFactory * other)
 
95
{
 
96
    d->jobs << other;
 
97
}
 
98
 
 
99
void Abstract::start()
 
100
{
 
101
    if (d->jobs.size() == 0) {
 
102
        returnResult(0);
 
103
        return;
 
104
    }
 
105
 
 
106
    startJob(0);
 
107
}
 
108
 
 
109
int Abstract::lastJobStarted() const
 
110
{
 
111
    return d->lastJobStarted;
 
112
}
 
113
 
 
114
int Abstract::jobCount() const
 
115
{
 
116
    return d->jobs.size();
 
117
}
 
118
 
 
119
bool Abstract::hasJob(int index) const
 
120
{
 
121
    return (index >= 0 && index < d->jobs.size() && d->jobs[index] != nullptr);
 
122
}
 
123
 
 
124
void Abstract::returnResult(int result)
 
125
{
 
126
    kDebug() << "Returning" << result;
 
127
    setError(result);
 
128
    emitResult();
 
129
}
 
130
 
 
131
 
 
132
} // namespace Schedulers
 
133
} // namespace Jobs