1
/***************************************************************************
2
* Copyright (C) 2008 Rob Scheepmaker <r.scheepmaker@student.utwente.nl> *
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
***************************************************************************/
22
#include <QtCore/QTimer>
23
#include <QtCore/QTime>
24
#include <QTextDocument>
25
#include <QFontMetrics>
26
#include <QApplication>
30
#include <KLocalizedString>
49
QString applicationName;
50
QString applicationIconName;
55
qlonglong numericSpeed;
58
QMap<QString, qlonglong> totalAmounts;
59
QMap<QString, qlonglong> processedAmounts;
61
QList<QPair<QString, QString> > labels;
76
Job::Job(QObject *parent)
80
//delay a little the job to avoid the user to be distracted with short ones
81
QTimer::singleShot(1500, this, SLOT(show()));
96
QString Job::applicationName() const
98
return d->applicationName;
101
void Job::setApplicationName(const QString &applicationName)
103
if (d->applicationName != applicationName) {
104
d->applicationName = applicationName;
105
scheduleChangedSignal();
109
QString Job::applicationIconName() const
111
return d->applicationIconName;
114
void Job::setApplicationIconName(const QString &applicationIcon)
116
if (d->applicationIconName != applicationIcon) {
117
d->applicationIconName = applicationIcon;
118
scheduleChangedSignal();
122
QString Job::message() const
127
void Job::setMessage(const QString &message)
129
if (d->message != message) {
130
d->message = message;
131
scheduleChangedSignal();
135
QString Job::error() const
140
void Job::setError(const QString &error)
142
if (d->error != error) {
144
scheduleChangedSignal();
148
QString Job::speed() const
153
void Job::setSpeed(const QString &speed)
155
if (d->speed != speed) {
157
scheduleChangedSignal();
161
qlonglong Job::numericSpeed() const
163
return d->numericSpeed;
166
void Job::setNumericSpeed(const qlonglong speed)
168
if (d->numericSpeed != speed) {
169
d->numericSpeed = speed;
170
scheduleChangedSignal();
174
QString Job::completedMessage() const
176
KUrl location(d->destination);
177
if (location.isValid()) {
178
if (totalAmounts().value("files") > 1) {
179
location.setFileName(QString());
182
QString destinationString;
183
if (location.isLocalFile()) {
184
destinationString = location.toLocalFile();
186
destinationString = location.prettyUrl();
189
//FIXME: this is visualization stuff, but putting html here is not so model as well
191
kDebug() << "href = " << location.url();
192
QString destinationLink = QString("<a href=\"%1\">%2</a>").arg(location.url())
193
.arg(Qt::escape(destinationString));
195
if (totalAmounts().value("files") > 1) {
196
return i18np("%1 file, to: %2", "%1 files, to: %2", totalAmounts().value("files"),
199
return destinationLink;
202
return QString("%1: %2").arg(labels().value(0).first).arg(labels().value(0).second);
206
KUrl Job::destination() const
208
return d->destination;
211
ulong Job::eta() const
216
void Job::setEta(ulong eta)
221
QMap<QString, qlonglong> Job::totalAmounts() const
223
return d->totalAmounts;
226
void Job::setTotalAmounts(QMap<QString, qlonglong> amounts)
228
d->totalAmounts = amounts;
229
scheduleChangedSignal();
232
QMap<QString, qlonglong> Job::processedAmounts() const
234
return d->processedAmounts;
237
void Job::setProcessedAmounts(QMap<QString, qlonglong> amounts)
239
d->processedAmounts = amounts;
240
scheduleChangedSignal();
243
Job::State Job::state() const
248
void Job::setState(State state)
250
if (d->state != state) {
253
if (state == Stopped) {
254
d->finalElapsed = d->elapsed.elapsed();
256
emit stateChanged(this);
260
QList<QPair<QString, QString> > Job::labels() const
265
void Job::setLabels(QList<QPair<QString, QString> > labels)
268
if (d->labels.count() > 1 && d->destination.isEmpty()) {
269
d->destination = d->labels.value(1).second;
271
scheduleChangedSignal();
274
uint Job::percentage() const
276
return d->percentage;
279
void Job::setPercentage(uint percentage)
281
if (d->percentage != percentage) {
282
d->percentage = percentage;
283
scheduleChangedSignal();
287
uint Job::elapsed() const
289
if (d->finalElapsed) {
290
return d->finalElapsed;
292
return d->elapsed.elapsed();
296
bool Job::isSuspendable() const
298
return d->suspendable;
301
void Job::setSuspendable(bool suspendable)
303
if (d->suspendable != suspendable) {
304
d->suspendable = suspendable;
305
scheduleChangedSignal();
309
bool Job::isKillable() const
314
void Job::setKillable(bool killable)
316
if (d->killable != killable) {
317
d->killable = killable;
318
scheduleChangedSignal();
324
kWarning() << "Suspend is not implemented in this job provider.";
329
kWarning() << "Resume is not implemented in this job provider.";
334
kWarning() << "Stop is not implemented in this job provider.";
339
if (state() == Job::Running && !d->shown) {
345
void Job::scheduleChangedSignal()
347
if (d->shown && !d->timerId) {
348
d->timerId = startTimer(0);
352
void Job::timerEvent(QTimerEvent *)
354
killTimer(d->timerId);