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

« back to all changes in this revision

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