not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / systemtray / core / job.cpp
blob3032326e81a3543e077da50e167612c388e381ef
1 /***************************************************************************
2 * Copyright (C) 2008 Rob Scheepmaker <r.scheepmaker@student.utwente.nl> *
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 as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
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 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 "job.h"
22 #include <QtCore/QTimer>
24 #include <KDebug>
26 namespace SystemTray
30 class Job::Private
32 public:
33 Private() :
34 percentage(0),
35 timerId(0),
36 killable(false),
37 suspendable(false),
38 shown(false)
42 QString applicationName;
43 QString applicationIconName;
44 QString message;
45 QString error;
46 QString speed;
48 QMap<QString, qlonglong> totalAmounts;
49 QMap<QString, qlonglong> processedAmounts;
51 QList<QPair<QString, QString> > labels;
53 State state;
54 uint percentage;
55 int timerId;
57 bool killable : 1;
58 bool suspendable : 1;
59 bool shown : 1;
62 Job::Job(QObject *parent)
63 : QObject(parent),
64 d(new Private)
66 //delay a little the job to avoid the user to be distracted with short ones
67 QTimer::singleShot(1500, this, SLOT(show()));
70 Job::~Job()
72 delete d;
75 void Job::destroy()
77 emit destroyed(this);
78 deleteLater();
81 QString Job::applicationName() const
83 return d->applicationName;
86 void Job::setApplicationName(const QString &applicationName)
88 if (d->applicationName != applicationName) {
89 d->applicationName = applicationName;
90 scheduleChangedSignal();
94 QString Job::applicationIconName() const
96 return d->applicationIconName;
99 void Job::setApplicationIconName(const QString &applicationIcon)
101 if (d->applicationIconName != applicationIcon) {
102 d->applicationIconName = applicationIcon;
103 scheduleChangedSignal();
107 QString Job::message() const
109 return d->message;
112 void Job::setMessage(const QString &message)
114 if (d->message != message) {
115 d->message = message;
116 scheduleChangedSignal();
120 QString Job::error() const
122 return d->error;
125 void Job::setError(const QString &error)
127 if (d->error != error) {
128 d->error = error;
129 scheduleChangedSignal();
133 QString Job::speed() const
135 return d->speed;
138 void Job::setSpeed(const QString &speed)
140 if (d->speed != speed) {
141 d->speed = speed;
142 scheduleChangedSignal();
146 QMap<QString, qlonglong> Job::totalAmounts() const
148 return d->totalAmounts;
151 void Job::setTotalAmounts(QMap<QString, qlonglong> amounts)
153 if (d->totalAmounts != amounts) {
154 d->totalAmounts = amounts;
155 scheduleChangedSignal();
159 QMap<QString, qlonglong> Job::processedAmounts() const
161 return d->processedAmounts;
164 void Job::setProcessedAmounts(QMap<QString, qlonglong> amounts)
166 d->processedAmounts = amounts;
167 scheduleChangedSignal();
170 Job::State Job::state() const
172 return d->state;
175 void Job::setState(State state)
177 if (d->state != state) {
178 d->state = state;
179 scheduleChangedSignal();
183 QList<QPair<QString, QString> > Job::labels() const
185 return d->labels;
188 void Job::setLabels(QList<QPair<QString, QString> > labels)
190 d->labels = labels;
191 scheduleChangedSignal();
194 uint Job::percentage() const
196 return d->percentage;
199 void Job::setPercentage(uint percentage)
201 if (d->percentage != percentage) {
202 d->percentage = percentage;
203 scheduleChangedSignal();
207 bool Job::isSuspendable() const
209 return d->suspendable;
212 void Job::setSuspendable(bool suspendable)
214 if (d->suspendable != suspendable) {
215 d->suspendable = suspendable;
216 scheduleChangedSignal();
220 bool Job::isKillable() const
222 return d->killable;
225 void Job::setKillable(bool killable)
227 if (d->killable != killable) {
228 d->killable = killable;
229 scheduleChangedSignal();
233 void Job::suspend()
235 kWarning() << "Suspend is not implemented in this job provider.";
238 void Job::resume()
240 kWarning() << "Resume is not implemented in this job provider.";
243 void Job::stop()
245 kWarning() << "Stop is not implemented in this job provider.";
248 void Job::show()
250 if (state() == Job::Running) {
251 d->shown = true;
252 emit ready(this);
256 void Job::scheduleChangedSignal()
258 if (d->shown && !d->timerId) {
259 d->timerId = startTimer(0);
263 void Job::timerEvent(QTimerEvent *)
265 killTimer(d->timerId);
266 d->timerId = 0;
267 emit changed(this);
272 #include "job.moc"