File indexing completed on 2024-04-28 16:54:33
0001 /* 0002 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "job.h" 0008 #include "job_p.h" 0009 0010 #include <QDebug> 0011 0012 using namespace NotificationManager; 0013 0014 Job::Job(uint id, QObject *parent) 0015 : QObject(parent) 0016 , d(new JobPrivate(id, this)) 0017 { 0018 d->m_created = QDateTime::currentDateTimeUtc(); 0019 0020 // These properties are used in generating the pretty job text 0021 connect(d, &JobPrivate::infoMessageChanged, this, &Job::textChanged); 0022 connect(this, &Job::processedFilesChanged, this, &Job::textChanged); 0023 connect(this, &Job::processedItemsChanged, this, &Job::textChanged); 0024 connect(this, &Job::totalFilesChanged, this, &Job::textChanged); 0025 connect(this, &Job::totalItemsChanged, this, &Job::textChanged); 0026 connect(this, &Job::descriptionValue1Changed, this, &Job::textChanged); 0027 connect(this, &Job::descriptionValue2Changed, this, &Job::textChanged); 0028 connect(this, &Job::destUrlChanged, this, &Job::textChanged); 0029 connect(this, &Job::errorTextChanged, this, &Job::textChanged); 0030 } 0031 0032 Job::~Job() = default; 0033 0034 uint Job::id() const 0035 { 0036 return d->m_id; 0037 } 0038 0039 QDateTime Job::created() const 0040 { 0041 return d->m_created; 0042 } 0043 0044 QDateTime Job::updated() const 0045 { 0046 return d->m_updated; 0047 } 0048 0049 void Job::resetUpdated() 0050 { 0051 d->m_updated = QDateTime::currentDateTimeUtc(); 0052 Q_EMIT updatedChanged(); 0053 } 0054 0055 QString Job::summary() const 0056 { 0057 return d->m_summary; 0058 } 0059 0060 QString Job::text() const 0061 { 0062 return d->text(); 0063 } 0064 0065 QString Job::desktopEntry() const 0066 { 0067 return d->m_desktopEntry; 0068 } 0069 0070 void Job::setDesktopEntry(const QString &desktopEntry) 0071 { 0072 Q_ASSERT(d->m_desktopEntry.isNull()); 0073 d->m_desktopEntry = desktopEntry; 0074 } 0075 0076 QString Job::applicationName() const 0077 { 0078 return d->m_applicationName; 0079 } 0080 0081 void Job::setApplicationName(const QString &applicationName) 0082 { 0083 Q_ASSERT(d->m_applicationName.isNull()); 0084 d->m_applicationName = applicationName; 0085 } 0086 0087 QString Job::applicationIconName() const 0088 { 0089 return d->m_applicationIconName; 0090 } 0091 0092 void Job::setApplicationIconName(const QString &applicationIconName) 0093 { 0094 Q_ASSERT(d->m_applicationIconName.isNull()); 0095 d->m_applicationIconName = applicationIconName; 0096 } 0097 0098 Notifications::JobState Job::state() const 0099 { 0100 return d->m_state; 0101 } 0102 0103 void Job::setState(Notifications::JobState state) 0104 { 0105 if (d->m_state != state) { 0106 d->m_state = state; 0107 Q_EMIT stateChanged(state); 0108 } 0109 } 0110 0111 int Job::percentage() const 0112 { 0113 return d->m_percentage; 0114 } 0115 0116 int Job::error() const 0117 { 0118 return d->m_error; 0119 } 0120 0121 void Job::setError(int error) 0122 { 0123 if (d->m_error != error) { 0124 d->m_error = error; 0125 Q_EMIT errorChanged(error); 0126 } 0127 } 0128 0129 QString Job::errorText() const 0130 { 0131 return d->m_errorText; 0132 } 0133 0134 void Job::setErrorText(const QString &errorText) 0135 { 0136 if (d->m_errorText != errorText) { 0137 d->m_errorText = errorText; 0138 Q_EMIT errorTextChanged(errorText); 0139 } 0140 } 0141 0142 bool Job::suspendable() const 0143 { 0144 return d->m_suspendable; 0145 } 0146 0147 void Job::setSuspendable(bool suspendable) 0148 { 0149 // Cannot change after job started 0150 d->m_suspendable = suspendable; 0151 } 0152 0153 bool Job::killable() const 0154 { 0155 return d->m_killable; 0156 } 0157 0158 void Job::setKillable(bool killable) 0159 { 0160 // Cannot change after job started 0161 d->m_killable = killable; 0162 } 0163 0164 bool Job::transient() const 0165 { 0166 return d->m_transient; 0167 } 0168 0169 void Job::setTransient(bool transient) 0170 { 0171 d->m_transient = transient; 0172 } 0173 0174 QUrl Job::destUrl() const 0175 { 0176 return d->m_destUrl; 0177 } 0178 0179 qulonglong Job::speed() const 0180 { 0181 return d->m_speed; 0182 } 0183 0184 qulonglong Job::processedBytes() const 0185 { 0186 return d->m_processedBytes; 0187 } 0188 0189 qulonglong Job::processedFiles() const 0190 { 0191 return d->m_processedFiles; 0192 } 0193 0194 qulonglong Job::processedDirectories() const 0195 { 0196 return d->m_processedDirectories; 0197 } 0198 0199 qulonglong Job::processedItems() const 0200 { 0201 return d->m_processedItems; 0202 } 0203 0204 qulonglong Job::totalBytes() const 0205 { 0206 return d->m_totalBytes; 0207 } 0208 0209 qulonglong Job::totalFiles() const 0210 { 0211 return d->m_totalFiles; 0212 } 0213 0214 qulonglong Job::totalDirectories() const 0215 { 0216 return d->m_totalDirectories; 0217 } 0218 0219 qulonglong Job::totalItems() const 0220 { 0221 return d->m_totalItems; 0222 } 0223 0224 QString Job::descriptionLabel1() const 0225 { 0226 return d->m_descriptionLabel1; 0227 } 0228 0229 QString Job::descriptionValue1() const 0230 { 0231 return d->m_descriptionValue1; 0232 } 0233 0234 QString Job::descriptionLabel2() const 0235 { 0236 return d->m_descriptionLabel2; 0237 } 0238 0239 QString Job::descriptionValue2() const 0240 { 0241 return d->m_descriptionValue2; 0242 } 0243 0244 bool Job::hasDetails() const 0245 { 0246 return d->m_hasDetails; 0247 } 0248 0249 QUrl Job::descriptionUrl() const 0250 { 0251 return d->descriptionUrl(); 0252 } 0253 0254 bool Job::expired() const 0255 { 0256 return d->m_expired; 0257 } 0258 0259 void Job::setExpired(bool expired) 0260 { 0261 if (d->m_expired != expired) { 0262 d->m_expired = expired; 0263 Q_EMIT expiredChanged(); 0264 } 0265 } 0266 0267 bool Job::dismissed() const 0268 { 0269 return d->m_dismissed; 0270 } 0271 0272 void Job::setDismissed(bool dismissed) 0273 { 0274 if (d->m_dismissed != dismissed) { 0275 d->m_dismissed = dismissed; 0276 Q_EMIT dismissedChanged(); 0277 } 0278 } 0279 0280 void Job::suspend() 0281 { 0282 Q_EMIT d->suspendRequested(); 0283 } 0284 0285 void Job::resume() 0286 { 0287 Q_EMIT d->resumeRequested(); 0288 } 0289 0290 void Job::kill() 0291 { 0292 d->kill(); 0293 }