Applets
job.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "job.h"
00021
00022 #include <QtCore/QTimer>
00023
00024 #include <KDebug>
00025
00026 namespace SystemTray
00027 {
00028
00029
00030 class Job::Private
00031 {
00032 public:
00033 Private() :
00034 percentage(0),
00035 timerId(0),
00036 killable(false),
00037 suspendable(false),
00038 shown(false)
00039 {
00040 }
00041
00042 QString applicationName;
00043 QString applicationIconName;
00044 QString message;
00045 QString error;
00046 QString speed;
00047
00048 QMap<QString, qlonglong> totalAmounts;
00049 QMap<QString, qlonglong> processedAmounts;
00050
00051 QList<QPair<QString, QString> > labels;
00052
00053 State state;
00054 uint percentage;
00055 int timerId;
00056
00057 bool killable : 1;
00058 bool suspendable : 1;
00059 bool shown : 1;
00060 };
00061
00062 Job::Job(QObject *parent)
00063 : QObject(parent),
00064 d(new Private)
00065 {
00066
00067 QTimer::singleShot(1500, this, SLOT(show()));
00068 }
00069
00070 Job::~Job()
00071 {
00072 delete d;
00073 }
00074
00075 void Job::destroy()
00076 {
00077 emit destroyed(this);
00078 deleteLater();
00079 }
00080
00081 QString Job::applicationName() const
00082 {
00083 return d->applicationName;
00084 }
00085
00086 void Job::setApplicationName(const QString &applicationName)
00087 {
00088 if (d->applicationName != applicationName) {
00089 d->applicationName = applicationName;
00090 scheduleChangedSignal();
00091 }
00092 }
00093
00094 QString Job::applicationIconName() const
00095 {
00096 return d->applicationIconName;
00097 }
00098
00099 void Job::setApplicationIconName(const QString &applicationIcon)
00100 {
00101 if (d->applicationIconName != applicationIcon) {
00102 d->applicationIconName = applicationIcon;
00103 scheduleChangedSignal();
00104 }
00105 }
00106
00107 QString Job::message() const
00108 {
00109 return d->message;
00110 }
00111
00112 void Job::setMessage(const QString &message)
00113 {
00114 if (d->message != message) {
00115 d->message = message;
00116 scheduleChangedSignal();
00117 }
00118 }
00119
00120 QString Job::error() const
00121 {
00122 return d->error;
00123 }
00124
00125 void Job::setError(const QString &error)
00126 {
00127 if (d->error != error) {
00128 d->error = error;
00129 scheduleChangedSignal();
00130 }
00131 }
00132
00133 QString Job::speed() const
00134 {
00135 return d->speed;
00136 }
00137
00138 void Job::setSpeed(const QString &speed)
00139 {
00140 if (d->speed != speed) {
00141 d->speed = speed;
00142 scheduleChangedSignal();
00143 }
00144 }
00145
00146 QMap<QString, qlonglong> Job::totalAmounts() const
00147 {
00148 return d->totalAmounts;
00149 }
00150
00151 void Job::setTotalAmounts(QMap<QString, qlonglong> amounts)
00152 {
00153 if (d->totalAmounts != amounts) {
00154 d->totalAmounts = amounts;
00155 scheduleChangedSignal();
00156 }
00157 }
00158
00159 QMap<QString, qlonglong> Job::processedAmounts() const
00160 {
00161 return d->processedAmounts;
00162 }
00163
00164 void Job::setProcessedAmounts(QMap<QString, qlonglong> amounts)
00165 {
00166 d->processedAmounts = amounts;
00167 scheduleChangedSignal();
00168 }
00169
00170 Job::State Job::state() const
00171 {
00172 return d->state;
00173 }
00174
00175 void Job::setState(State state)
00176 {
00177 if (d->state != state) {
00178 d->state = state;
00179 scheduleChangedSignal();
00180 }
00181 }
00182
00183 QList<QPair<QString, QString> > Job::labels() const
00184 {
00185 return d->labels;
00186 }
00187
00188 void Job::setLabels(QList<QPair<QString, QString> > labels)
00189 {
00190 d->labels = labels;
00191 scheduleChangedSignal();
00192 }
00193
00194 uint Job::percentage() const
00195 {
00196 return d->percentage;
00197 }
00198
00199 void Job::setPercentage(uint percentage)
00200 {
00201 if (d->percentage != percentage) {
00202 d->percentage = percentage;
00203 scheduleChangedSignal();
00204 }
00205 }
00206
00207 bool Job::isSuspendable() const
00208 {
00209 return d->suspendable;
00210 }
00211
00212 void Job::setSuspendable(bool suspendable)
00213 {
00214 if (d->suspendable != suspendable) {
00215 d->suspendable = suspendable;
00216 scheduleChangedSignal();
00217 }
00218 }
00219
00220 bool Job::isKillable() const
00221 {
00222 return d->killable;
00223 }
00224
00225 void Job::setKillable(bool killable)
00226 {
00227 if (d->killable != killable) {
00228 d->killable = killable;
00229 scheduleChangedSignal();
00230 }
00231 }
00232
00233 void Job::suspend()
00234 {
00235 kWarning() << "Suspend is not implemented in this job provider.";
00236 }
00237
00238 void Job::resume()
00239 {
00240 kWarning() << "Resume is not implemented in this job provider.";
00241 }
00242
00243 void Job::stop()
00244 {
00245 kWarning() << "Stop is not implemented in this job provider.";
00246 }
00247
00248 void Job::show()
00249 {
00250 if (state() == Job::Running) {
00251 d->shown = true;
00252 emit ready(this);
00253 }
00254 }
00255
00256 void Job::scheduleChangedSignal()
00257 {
00258 if (d->shown && !d->timerId) {
00259 d->timerId = startTimer(0);
00260 }
00261 }
00262
00263 void Job::timerEvent(QTimerEvent *)
00264 {
00265 killTimer(d->timerId);
00266 d->timerId = 0;
00267 emit changed(this);
00268 }
00269
00270 }
00271
00272 #include "job.moc"