Changeset View
Changeset View
Standalone View
Standalone View
krusader/Archive/abstractthreadedjob.cpp
Show All 35 Lines | |||||
36 | 36 | | |||
37 | #include "krarchandler.h" | 37 | #include "krarchandler.h" | ||
38 | #include "../krglobal.h" | 38 | #include "../krglobal.h" | ||
39 | #include "../krservices.h" | 39 | #include "../krservices.h" | ||
40 | #include "../FileSystem/filesystemprovider.h" | 40 | #include "../FileSystem/filesystemprovider.h" | ||
41 | 41 | | |||
42 | extern KRarcHandler arcHandler; | 42 | extern KRarcHandler arcHandler; | ||
43 | 43 | | |||
44 | AbstractThreadedJob::AbstractThreadedJob() : KIO::Job(), _locker(), _waiter(), _stack(), _maxProgressValue(0), | 44 | AbstractThreadedJob::AbstractThreadedJob() : _maxProgressValue(0), | ||
45 | _currentProgress(0), _exiting(false), _jobThread(0) | 45 | _currentProgress(0), _exiting(false), _jobThread(nullptr) | ||
46 | { | 46 | { | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | void AbstractThreadedJob::startAbstractJobThread(AbstractJobThread * jobThread) | 49 | void AbstractThreadedJob::startAbstractJobThread(AbstractJobThread * jobThread) | ||
50 | { | 50 | { | ||
51 | _jobThread = jobThread; | 51 | _jobThread = jobThread; | ||
52 | _jobThread->setJob(this); | 52 | _jobThread->setJob(this); | ||
53 | _jobThread->moveToThread(_jobThread); | 53 | _jobThread->moveToThread(_jobThread); | ||
Show All 13 Lines | 60 | if (_jobThread) { | |||
67 | _jobThread->wait(); | 67 | _jobThread->wait(); | ||
68 | delete _jobThread; | 68 | delete _jobThread; | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | bool AbstractThreadedJob::event(QEvent *e) | 72 | bool AbstractThreadedJob::event(QEvent *e) | ||
73 | { | 73 | { | ||
74 | if (e->type() == QEvent::User) { | 74 | if (e->type() == QEvent::User) { | ||
75 | UserEvent *event = (UserEvent*) e; | 75 | auto *event = (UserEvent*) e; | ||
76 | switch (event->command()) { | 76 | switch (event->command()) { | ||
77 | case CMD_SUCCESS: { | 77 | case CMD_SUCCESS: { | ||
78 | emitResult(); | 78 | emitResult(); | ||
79 | } | 79 | } | ||
80 | break; | 80 | break; | ||
81 | case CMD_ERROR: { | 81 | case CMD_ERROR: { | ||
82 | int error = event->args()[ 0 ].value<int>(); | 82 | auto error = event->args()[ 0 ].value<int>(); | ||
83 | QString errorText = event->args()[ 1 ].value<QString>(); | 83 | QString errorText = event->args()[ 1 ].value<QString>(); | ||
84 | 84 | | |||
85 | setError(error); | 85 | setError(error); | ||
86 | setErrorText(errorText); | 86 | setErrorText(errorText); | ||
87 | emitResult(); | 87 | emitResult(); | ||
88 | } | 88 | } | ||
89 | break; | 89 | break; | ||
90 | case CMD_INFO: { | 90 | case CMD_INFO: { | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 133 | connect(job, SIGNAL(totalAmount(KJob*,KJob::Unit,qulonglong)), | |||
134 | this, SLOT(slotTotalAmount(KJob*,KJob::Unit,qulonglong))); | 134 | this, SLOT(slotTotalAmount(KJob*,KJob::Unit,qulonglong))); | ||
135 | connect(job, SIGNAL(speed(KJob*,ulong)), | 135 | connect(job, SIGNAL(speed(KJob*,ulong)), | ||
136 | this, SLOT(slotSpeed(KJob*,ulong))); | 136 | this, SLOT(slotSpeed(KJob*,ulong))); | ||
137 | connect(job, SIGNAL(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)), | 137 | connect(job, SIGNAL(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)), | ||
138 | this, SLOT(slotDescription(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>))); | 138 | this, SLOT(slotDescription(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>))); | ||
139 | } | 139 | } | ||
140 | break; | 140 | break; | ||
141 | case CMD_MAXPROGRESSVALUE: { | 141 | case CMD_MAXPROGRESSVALUE: { | ||
142 | qulonglong maxValue = event->args()[ 0 ].value<qulonglong>(); | 142 | auto maxValue = event->args()[ 0 ].value<qulonglong>(); | ||
143 | _maxProgressValue = maxValue; | 143 | _maxProgressValue = maxValue; | ||
144 | _currentProgress = 0; | 144 | _currentProgress = 0; | ||
145 | } | 145 | } | ||
146 | break; | 146 | break; | ||
147 | case CMD_ADD_PROGRESS: { | 147 | case CMD_ADD_PROGRESS: { | ||
148 | qulonglong progress = event->args()[ 0 ].value<qulonglong>(); | 148 | auto progress = event->args()[ 0 ].value<qulonglong>(); | ||
149 | _currentProgress += progress; | 149 | _currentProgress += progress; | ||
150 | if (_maxProgressValue != 0) { | 150 | if (_maxProgressValue != 0) { | ||
151 | setPercent(100 * _currentProgress / _maxProgressValue); | 151 | setPercent(100 * _currentProgress / _maxProgressValue); | ||
152 | 152 | | |||
153 | int elapsed = _time.isNull() ? 1 : _time.secsTo(QTime::currentTime()); | 153 | int elapsed = _time.isNull() ? 1 : _time.secsTo(QTime::currentTime()); | ||
154 | 154 | | |||
155 | if (elapsed != 0 && event->args().count() > 1) { | 155 | if (elapsed != 0 && event->args().count() > 1) { | ||
156 | _time = QTime::currentTime(); | 156 | _time = QTime::currentTime(); | ||
157 | QString progressString = (event->args()[ 1 ].value<QString>()); | 157 | QString progressString = (event->args()[ 1 ].value<QString>()); | ||
158 | emit description(this, _title, | 158 | emit description(this, _title, | ||
159 | qMakePair(progressString, QString("%1/%2").arg(_currentProgress).arg(_maxProgressValue)), | 159 | qMakePair(progressString, QString("%1/%2").arg(_currentProgress).arg(_maxProgressValue)), | ||
160 | qMakePair(QString(), QString()) | 160 | qMakePair(QString(), QString()) | ||
161 | ); | 161 | ); | ||
162 | } | 162 | } | ||
163 | } | 163 | } | ||
164 | } | 164 | } | ||
165 | break; | 165 | break; | ||
166 | case CMD_GET_PASSWORD: { | 166 | case CMD_GET_PASSWORD: { | ||
167 | QString path = event->args()[ 0 ].value<QString>(); | 167 | QString path = event->args()[ 0 ].value<QString>(); | ||
168 | QString password = KRarcHandler::getPassword(path); | 168 | QString password = KRarcHandler::getPassword(path); | ||
169 | 169 | | |||
170 | QList<QVariant> *resultResp = new QList<QVariant> (); | 170 | auto *resultResp = new QList<QVariant> (); | ||
171 | (*resultResp) << password; | 171 | (*resultResp) << password; | ||
172 | addEventResponse(resultResp); | 172 | addEventResponse(resultResp); | ||
173 | } | 173 | } | ||
174 | break; | 174 | break; | ||
175 | case CMD_MESSAGE: { | 175 | case CMD_MESSAGE: { | ||
176 | QString message = event->args()[ 0 ].value<QString>(); | 176 | QString message = event->args()[ 0 ].value<QString>(); | ||
177 | KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(uiDelegate()); | 177 | auto *ui = dynamic_cast<KIO::JobUiDelegate*>(uiDelegate()); | ||
178 | KMessageBox::information(ui ? ui->window() : 0, message); | 178 | KMessageBox::information(ui ? ui->window() : nullptr, message); | ||
179 | QList<QVariant> *resultResp = new QList<QVariant> (); | 179 | auto *resultResp = new QList<QVariant> (); | ||
180 | addEventResponse(resultResp); | 180 | addEventResponse(resultResp); | ||
181 | } | 181 | } | ||
182 | break; | 182 | break; | ||
183 | } | 183 | } | ||
184 | return true; | 184 | return true; | ||
185 | } else { | 185 | } else { | ||
186 | return KIO::Job::event(e); | 186 | return KIO::Job::event(e); | ||
187 | } | 187 | } | ||
188 | } | 188 | } | ||
189 | 189 | | |||
190 | void AbstractThreadedJob::addEventResponse(QList<QVariant> * obj) | 190 | void AbstractThreadedJob::addEventResponse(QList<QVariant> * obj) | ||
191 | { | 191 | { | ||
192 | _locker.lock(); | 192 | _locker.lock(); | ||
193 | _stack.push(obj); | 193 | _stack.push(obj); | ||
194 | _waiter.wakeOne(); | 194 | _waiter.wakeOne(); | ||
195 | _locker.unlock(); | 195 | _locker.unlock(); | ||
196 | } | 196 | } | ||
197 | 197 | | |||
198 | QList<QVariant> * AbstractThreadedJob::getEventResponse(UserEvent * event) | 198 | QList<QVariant> * AbstractThreadedJob::getEventResponse(UserEvent * event) | ||
199 | { | 199 | { | ||
200 | _locker.lock(); | 200 | _locker.lock(); | ||
201 | QApplication::postEvent(this, event); | 201 | QApplication::postEvent(this, event); | ||
202 | _waiter.wait(&_locker); | 202 | _waiter.wait(&_locker); | ||
203 | if (_exiting) | 203 | if (_exiting) | ||
204 | return 0; | 204 | return nullptr; | ||
205 | QList<QVariant> *resp = _stack.pop(); | 205 | QList<QVariant> *resp = _stack.pop(); | ||
206 | _locker.unlock(); | 206 | _locker.unlock(); | ||
207 | return resp; | 207 | return resp; | ||
208 | } | 208 | } | ||
209 | 209 | | |||
210 | void AbstractThreadedJob::sendEvent(UserEvent * event) | 210 | void AbstractThreadedJob::sendEvent(UserEvent * event) | ||
211 | { | 211 | { | ||
212 | QApplication::postEvent(this, event); | 212 | QApplication::postEvent(this, event); | ||
213 | } | 213 | } | ||
214 | 214 | | |||
215 | void AbstractThreadedJob::slotDownloadResult(KJob* job) | 215 | void AbstractThreadedJob::slotDownloadResult(KJob* job) | ||
216 | { | 216 | { | ||
217 | QList<QVariant> *resultResp = new QList<QVariant> (); | 217 | auto *resultResp = new QList<QVariant> (); | ||
218 | if (job) { | 218 | if (job) { | ||
219 | (*resultResp) << QVariant(job->error()); | 219 | (*resultResp) << QVariant(job->error()); | ||
220 | (*resultResp) << QVariant(job->errorText()); | 220 | (*resultResp) << QVariant(job->errorText()); | ||
221 | } else { | 221 | } else { | ||
222 | (*resultResp) << QVariant(KJob::UserDefinedError); | 222 | (*resultResp) << QVariant(KJob::UserDefinedError); | ||
223 | (*resultResp) << QVariant(QString(i18n("Internal error, undefined <job> in result signal"))); | 223 | (*resultResp) << QVariant(QString(i18n("Internal error, undefined <job> in result signal"))); | ||
224 | } | 224 | } | ||
225 | 225 | | |||
Show All 25 Lines | |||||
251 | } | 251 | } | ||
252 | 252 | | |||
253 | class AbstractJobObserver : public KRarcObserver | 253 | class AbstractJobObserver : public KRarcObserver | ||
254 | { | 254 | { | ||
255 | protected: | 255 | protected: | ||
256 | AbstractJobThread * _jobThread; | 256 | AbstractJobThread * _jobThread; | ||
257 | public: | 257 | public: | ||
258 | explicit AbstractJobObserver(AbstractJobThread * thread): _jobThread(thread) {} | 258 | explicit AbstractJobObserver(AbstractJobThread * thread): _jobThread(thread) {} | ||
259 | virtual ~AbstractJobObserver() {} | 259 | ~AbstractJobObserver() override = default; | ||
260 | 260 | | |||
261 | virtual void processEvents() Q_DECL_OVERRIDE { | 261 | void processEvents() Q_DECL_OVERRIDE { | ||
262 | usleep(1000); | 262 | usleep(1000); | ||
263 | qApp->processEvents(); | 263 | qApp->processEvents(); | ||
264 | } | 264 | } | ||
265 | 265 | | |||
266 | virtual void subJobStarted(const QString & jobTitle, int count) Q_DECL_OVERRIDE { | 266 | void subJobStarted(const QString & jobTitle, int count) Q_DECL_OVERRIDE { | ||
267 | _jobThread->sendReset(jobTitle); | 267 | _jobThread->sendReset(jobTitle); | ||
268 | _jobThread->sendMaxProgressValue(count); | 268 | _jobThread->sendMaxProgressValue(count); | ||
269 | } | 269 | } | ||
270 | 270 | | |||
271 | virtual void subJobStopped() Q_DECL_OVERRIDE { | 271 | void subJobStopped() Q_DECL_OVERRIDE { | ||
272 | } | 272 | } | ||
273 | 273 | | |||
274 | virtual bool wasCancelled() Q_DECL_OVERRIDE { | 274 | bool wasCancelled() Q_DECL_OVERRIDE { | ||
275 | return _jobThread->_exited; | 275 | return _jobThread->_exited; | ||
276 | } | 276 | } | ||
277 | 277 | | |||
278 | virtual void error(const QString & error) Q_DECL_OVERRIDE { | 278 | void error(const QString & error) Q_DECL_OVERRIDE { | ||
279 | _jobThread->sendError(KIO::ERR_NO_CONTENT, error); | 279 | _jobThread->sendError(KIO::ERR_NO_CONTENT, error); | ||
280 | } | 280 | } | ||
281 | 281 | | |||
282 | virtual void detailedError(const QString & error, const QString & details) Q_DECL_OVERRIDE { | 282 | void detailedError(const QString & error, const QString & details) Q_DECL_OVERRIDE { | ||
283 | _jobThread->sendError(KIO::ERR_NO_CONTENT, error + '\n' + details); | 283 | _jobThread->sendError(KIO::ERR_NO_CONTENT, error + '\n' + details); | ||
284 | } | 284 | } | ||
285 | 285 | | |||
286 | virtual void incrementProgress(int c) Q_DECL_OVERRIDE { | 286 | void incrementProgress(int c) Q_DECL_OVERRIDE { | ||
287 | _jobThread->sendAddProgress(c, _jobThread->_progressTitle); | 287 | _jobThread->sendAddProgress(c, _jobThread->_progressTitle); | ||
288 | } | 288 | } | ||
289 | }; | 289 | }; | ||
290 | 290 | | |||
291 | 291 | | |||
292 | AbstractJobThread::AbstractJobThread() : _job(0), _downloadTempDir(0), _observer(0), _tempFile(0), | 292 | AbstractJobThread::AbstractJobThread() : _job(nullptr), _downloadTempDir(nullptr), _observer(nullptr), _tempFile(nullptr), | ||
293 | _tempDir(0), _exited(false) | 293 | _tempDir(nullptr), _exited(false) | ||
294 | { | 294 | { | ||
295 | } | 295 | } | ||
296 | 296 | | |||
297 | AbstractJobThread::~AbstractJobThread() | 297 | AbstractJobThread::~AbstractJobThread() | ||
298 | { | 298 | { | ||
299 | if (_downloadTempDir) { | 299 | if (_downloadTempDir) { | ||
300 | delete _downloadTempDir; | 300 | delete _downloadTempDir; | ||
301 | _downloadTempDir = 0; | 301 | _downloadTempDir = nullptr; | ||
302 | } | 302 | } | ||
303 | if (_observer) { | 303 | if (_observer) { | ||
304 | delete _observer; | 304 | delete _observer; | ||
305 | _observer = 0; | 305 | _observer = nullptr; | ||
306 | } | 306 | } | ||
307 | if (_tempFile) { | 307 | if (_tempFile) { | ||
308 | delete _tempFile; | 308 | delete _tempFile; | ||
309 | _tempFile = 0; | 309 | _tempFile = nullptr; | ||
310 | } | 310 | } | ||
311 | } | 311 | } | ||
312 | 312 | | |||
313 | void AbstractJobThread::run() | 313 | void AbstractJobThread::run() | ||
314 | { | 314 | { | ||
315 | QTimer::singleShot(0, this, SLOT(slotStart())); | 315 | QTimer::singleShot(0, this, SLOT(slotStart())); | ||
316 | 316 | | |||
317 | QPointer<QEventLoop> threadLoop = new QEventLoop(this); | 317 | QPointer<QEventLoop> threadLoop = new QEventLoop(this); | ||
318 | _loop = threadLoop; | 318 | _loop = threadLoop; | ||
319 | threadLoop->exec(); | 319 | threadLoop->exec(); | ||
320 | 320 | | |||
321 | _loop = 0; | 321 | _loop = nullptr; | ||
322 | delete threadLoop; | 322 | delete threadLoop; | ||
323 | } | 323 | } | ||
324 | 324 | | |||
325 | void AbstractJobThread::terminate() | 325 | void AbstractJobThread::terminate() | ||
326 | { | 326 | { | ||
327 | if (_loop && !_exited) { | 327 | if (_loop && !_exited) { | ||
328 | _loop->quit(); | 328 | _loop->quit(); | ||
329 | _exited = true; | 329 | _exited = true; | ||
Show All 28 Lines | 354 | if (!baseUrl.isLocalFile()) { | |||
358 | QList<QUrl> urlList = remoteUrls(baseUrl, files); | 358 | QList<QUrl> urlList = remoteUrls(baseUrl, files); | ||
359 | 359 | | |||
360 | QUrl dest(_downloadTempDir->path()); | 360 | QUrl dest(_downloadTempDir->path()); | ||
361 | 361 | | |||
362 | QList<QVariant> args; | 362 | QList<QVariant> args; | ||
363 | args << KrServices::toStringList(urlList); | 363 | args << KrServices::toStringList(urlList); | ||
364 | args << dest; | 364 | args << dest; | ||
365 | 365 | | |||
366 | UserEvent * downloadEvent = new UserEvent(CMD_DOWNLOAD_FILES, args); | 366 | auto * downloadEvent = new UserEvent(CMD_DOWNLOAD_FILES, args); | ||
367 | QList<QVariant> * result = _job->getEventResponse(downloadEvent); | 367 | QList<QVariant> * result = _job->getEventResponse(downloadEvent); | ||
368 | if (result == 0) | 368 | if (result == nullptr) | ||
369 | return QUrl(); | 369 | return QUrl(); | ||
370 | 370 | | |||
371 | int errorCode = (*result)[ 0 ].value<int>(); | 371 | auto errorCode = (*result)[ 0 ].value<int>(); | ||
372 | QString errorText = (*result)[ 1 ].value<QString>(); | 372 | QString errorText = (*result)[ 1 ].value<QString>(); | ||
373 | 373 | | |||
374 | delete result; | 374 | delete result; | ||
375 | 375 | | |||
376 | if (errorCode) { | 376 | if (errorCode) { | ||
377 | sendError(errorCode, errorText); | 377 | sendError(errorCode, errorText); | ||
378 | return QUrl(); | 378 | return QUrl(); | ||
379 | } else { | 379 | } else { | ||
Show All 33 Lines | |||||
413 | } | 413 | } | ||
414 | 414 | | |||
415 | void AbstractJobThread::sendSuccess() | 415 | void AbstractJobThread::sendSuccess() | ||
416 | { | 416 | { | ||
417 | terminate(); | 417 | terminate(); | ||
418 | 418 | | |||
419 | QList<QVariant> args; | 419 | QList<QVariant> args; | ||
420 | 420 | | |||
421 | UserEvent * errorEvent = new UserEvent(CMD_SUCCESS, args); | 421 | auto * errorEvent = new UserEvent(CMD_SUCCESS, args); | ||
422 | _job->sendEvent(errorEvent); | 422 | _job->sendEvent(errorEvent); | ||
423 | } | 423 | } | ||
424 | 424 | | |||
425 | void AbstractJobThread::sendError(int errorCode, QString message) | 425 | void AbstractJobThread::sendError(int errorCode, const QString& message) | ||
426 | { | 426 | { | ||
427 | terminate(); | 427 | terminate(); | ||
428 | 428 | | |||
429 | QList<QVariant> args; | 429 | QList<QVariant> args; | ||
430 | args << errorCode; | 430 | args << errorCode; | ||
431 | args << message; | 431 | args << message; | ||
432 | 432 | | |||
433 | UserEvent * errorEvent = new UserEvent(CMD_ERROR, args); | 433 | auto * errorEvent = new UserEvent(CMD_ERROR, args); | ||
434 | _job->sendEvent(errorEvent); | 434 | _job->sendEvent(errorEvent); | ||
435 | } | 435 | } | ||
436 | 436 | | |||
437 | void AbstractJobThread::sendInfo(QString message, QString a1, QString a2, QString a3, QString a4) | 437 | void AbstractJobThread::sendInfo(const QString& message, const QString& a1, const QString& a2, const QString& a3, const QString& a4) | ||
438 | { | 438 | { | ||
439 | QList<QVariant> args; | 439 | QList<QVariant> args; | ||
440 | args << message; | 440 | args << message; | ||
441 | args << a1; | 441 | args << a1; | ||
442 | args << a2; | 442 | args << a2; | ||
443 | args << a3; | 443 | args << a3; | ||
444 | args << a4; | 444 | args << a4; | ||
445 | 445 | | |||
446 | UserEvent * infoEvent = new UserEvent(CMD_INFO, args); | 446 | auto * infoEvent = new UserEvent(CMD_INFO, args); | ||
447 | _job->sendEvent(infoEvent); | 447 | _job->sendEvent(infoEvent); | ||
448 | } | 448 | } | ||
449 | 449 | | |||
450 | void AbstractJobThread::sendReset(QString message, QString a1, QString a2, QString a3, QString a4) | 450 | void AbstractJobThread::sendReset(const QString& message, const QString& a1, const QString& a2, const QString& a3, const QString& a4) | ||
451 | { | 451 | { | ||
452 | QList<QVariant> args; | 452 | QList<QVariant> args; | ||
453 | args << message; | 453 | args << message; | ||
454 | args << a1; | 454 | args << a1; | ||
455 | args << a2; | 455 | args << a2; | ||
456 | args << a3; | 456 | args << a3; | ||
457 | args << a4; | 457 | args << a4; | ||
458 | 458 | | |||
459 | UserEvent * infoEvent = new UserEvent(CMD_RESET, args); | 459 | auto * infoEvent = new UserEvent(CMD_RESET, args); | ||
460 | _job->sendEvent(infoEvent); | 460 | _job->sendEvent(infoEvent); | ||
461 | } | 461 | } | ||
462 | 462 | | |||
463 | void AbstractJobThread::sendMaxProgressValue(qulonglong value) | 463 | void AbstractJobThread::sendMaxProgressValue(qulonglong value) | ||
464 | { | 464 | { | ||
465 | QList<QVariant> args; | 465 | QList<QVariant> args; | ||
466 | args << value; | 466 | args << value; | ||
467 | 467 | | |||
468 | UserEvent * infoEvent = new UserEvent(CMD_MAXPROGRESSVALUE, args); | 468 | auto * infoEvent = new UserEvent(CMD_MAXPROGRESSVALUE, args); | ||
469 | _job->sendEvent(infoEvent); | 469 | _job->sendEvent(infoEvent); | ||
470 | } | 470 | } | ||
471 | 471 | | |||
472 | void AbstractJobThread::sendAddProgress(qulonglong value, const QString &progress) | 472 | void AbstractJobThread::sendAddProgress(qulonglong value, const QString &progress) | ||
473 | { | 473 | { | ||
474 | QList<QVariant> args; | 474 | QList<QVariant> args; | ||
475 | args << value; | 475 | args << value; | ||
476 | 476 | | |||
477 | if (!progress.isNull()) | 477 | if (!progress.isNull()) | ||
478 | args << progress; | 478 | args << progress; | ||
479 | 479 | | |||
480 | UserEvent * infoEvent = new UserEvent(CMD_ADD_PROGRESS, args); | 480 | auto * infoEvent = new UserEvent(CMD_ADD_PROGRESS, args); | ||
481 | _job->sendEvent(infoEvent); | 481 | _job->sendEvent(infoEvent); | ||
482 | } | 482 | } | ||
483 | 483 | | |||
484 | void countFiles(const QString &path, unsigned long &totalFiles, bool &stop) | 484 | void countFiles(const QString &path, unsigned long &totalFiles, bool &stop) | ||
485 | { | 485 | { | ||
486 | const QDir dir(path); | 486 | const QDir dir(path); | ||
487 | if (!dir.exists()) { | 487 | if (!dir.exists()) { | ||
488 | totalFiles++; // assume it's a file | 488 | totalFiles++; // assume it's a file | ||
489 | return; | 489 | return; | ||
490 | } | 490 | } | ||
491 | 491 | | |||
492 | for (const QString name : dir.entryList()) { | 492 | for (const QString& name : dir.entryList()) { | ||
493 | if (stop) | 493 | if (stop) | ||
494 | return; | 494 | return; | ||
495 | 495 | | |||
496 | if (name == QStringLiteral(".") || name == QStringLiteral("..")) | 496 | if (name == QStringLiteral(".") || name == QStringLiteral("..")) | ||
497 | continue; | 497 | continue; | ||
498 | 498 | | |||
499 | countFiles(dir.absoluteFilePath(name), totalFiles, stop); | 499 | countFiles(dir.absoluteFilePath(name), totalFiles, stop); | ||
500 | } | 500 | } | ||
501 | } | 501 | } | ||
502 | 502 | | |||
503 | void AbstractJobThread::countLocalFiles(const QUrl &baseUrl, const QStringList &names, | 503 | void AbstractJobThread::countLocalFiles(const QUrl &baseUrl, const QStringList &names, | ||
504 | unsigned long &totalFiles) | 504 | unsigned long &totalFiles) | ||
505 | { | 505 | { | ||
506 | sendReset(i18n("Counting files")); | 506 | sendReset(i18n("Counting files")); | ||
507 | 507 | | |||
508 | FileSystem *calcSpaceFileSystem = FileSystemProvider::instance().getFilesystem(baseUrl); | 508 | FileSystem *calcSpaceFileSystem = FileSystemProvider::instance().getFilesystem(baseUrl); | ||
509 | calcSpaceFileSystem->scanDir(baseUrl); | 509 | calcSpaceFileSystem->scanDir(baseUrl); | ||
510 | for (const QString name : names) { | 510 | for (const QString& name : names) { | ||
511 | if (_exited) | 511 | if (_exited) | ||
512 | return; | 512 | return; | ||
513 | 513 | | |||
514 | const QString path = calcSpaceFileSystem->getUrl(name).toLocalFile(); | 514 | const QString path = calcSpaceFileSystem->getUrl(name).toLocalFile(); | ||
515 | if (!QFileInfo(path).exists()) | 515 | if (!QFileInfo(path).exists()) | ||
516 | return; | 516 | return; | ||
517 | 517 | | |||
518 | countFiles(path, totalFiles, _exited); | 518 | countFiles(path, totalFiles, _exited); | ||
519 | } | 519 | } | ||
520 | 520 | | |||
521 | delete calcSpaceFileSystem; | 521 | delete calcSpaceFileSystem; | ||
522 | } | 522 | } | ||
523 | 523 | | |||
524 | KRarcObserver * AbstractJobThread::observer() | 524 | KRarcObserver * AbstractJobThread::observer() | ||
525 | { | 525 | { | ||
526 | if (_observer) | 526 | if (_observer) | ||
527 | return _observer; | 527 | return _observer; | ||
528 | _observer = new AbstractJobObserver(this); | 528 | _observer = new AbstractJobObserver(this); | ||
529 | return _observer; | 529 | return _observer; | ||
530 | } | 530 | } | ||
531 | 531 | | |||
532 | bool AbstractJobThread::uploadTempFiles() | 532 | bool AbstractJobThread::uploadTempFiles() | ||
533 | { | 533 | { | ||
534 | if (_tempFile != 0 || _tempDir != 0) { | 534 | if (_tempFile != nullptr || _tempDir != nullptr) { | ||
535 | sendInfo(i18n("Uploading to remote destination")); | 535 | sendInfo(i18n("Uploading to remote destination")); | ||
536 | 536 | | |||
537 | if (_tempFile) { | 537 | if (_tempFile) { | ||
538 | QList<QUrl> urlList; | 538 | QList<QUrl> urlList; | ||
539 | urlList << QUrl::fromLocalFile(_tempFileName); | 539 | urlList << QUrl::fromLocalFile(_tempFileName); | ||
540 | 540 | | |||
541 | QList<QVariant> args; | 541 | QList<QVariant> args; | ||
542 | args << KrServices::toStringList(urlList); | 542 | args << KrServices::toStringList(urlList); | ||
543 | args << _tempFileTarget; | 543 | args << _tempFileTarget; | ||
544 | 544 | | |||
545 | UserEvent * uploadEvent = new UserEvent(CMD_UPLOAD_FILES, args); | 545 | auto * uploadEvent = new UserEvent(CMD_UPLOAD_FILES, args); | ||
546 | QList<QVariant> * result = _job->getEventResponse(uploadEvent); | 546 | QList<QVariant> * result = _job->getEventResponse(uploadEvent); | ||
547 | if (result == 0) | 547 | if (result == nullptr) | ||
548 | return false; | 548 | return false; | ||
549 | 549 | | |||
550 | int errorCode = (*result)[ 0 ].value<int>(); | 550 | auto errorCode = (*result)[ 0 ].value<int>(); | ||
551 | QString errorText = (*result)[ 1 ].value<QString>(); | 551 | QString errorText = (*result)[ 1 ].value<QString>(); | ||
552 | 552 | | |||
553 | delete result; | 553 | delete result; | ||
554 | 554 | | |||
555 | if (errorCode) { | 555 | if (errorCode) { | ||
556 | sendError(errorCode, errorText); | 556 | sendError(errorCode, errorText); | ||
557 | return false; | 557 | return false; | ||
558 | } | 558 | } | ||
Show All 10 Lines | 565 | foreach(const QString &name, list) { | |||
569 | url.setPath(url.path() + '/' + (name)); | 569 | url.setPath(url.path() + '/' + (name)); | ||
570 | urlList << url; | 570 | urlList << url; | ||
571 | } | 571 | } | ||
572 | 572 | | |||
573 | QList<QVariant> args; | 573 | QList<QVariant> args; | ||
574 | args << KrServices::toStringList(urlList); | 574 | args << KrServices::toStringList(urlList); | ||
575 | args << _tempDirTarget; | 575 | args << _tempDirTarget; | ||
576 | 576 | | |||
577 | UserEvent * uploadEvent = new UserEvent(CMD_UPLOAD_FILES, args); | 577 | auto * uploadEvent = new UserEvent(CMD_UPLOAD_FILES, args); | ||
578 | QList<QVariant> * result = _job->getEventResponse(uploadEvent); | 578 | QList<QVariant> * result = _job->getEventResponse(uploadEvent); | ||
579 | if (result == 0) | 579 | if (result == nullptr) | ||
580 | return false; | 580 | return false; | ||
581 | 581 | | |||
582 | int errorCode = (*result)[ 0 ].value<int>(); | 582 | auto errorCode = (*result)[ 0 ].value<int>(); | ||
583 | QString errorText = (*result)[ 1 ].value<QString>(); | 583 | QString errorText = (*result)[ 1 ].value<QString>(); | ||
584 | 584 | | |||
585 | delete result; | 585 | delete result; | ||
586 | 586 | | |||
587 | if (errorCode) { | 587 | if (errorCode) { | ||
588 | sendError(errorCode, errorText); | 588 | sendError(errorCode, errorText); | ||
589 | return false; | 589 | return false; | ||
590 | } | 590 | } | ||
591 | } | 591 | } | ||
592 | } | 592 | } | ||
593 | return true; | 593 | return true; | ||
594 | } | 594 | } | ||
595 | 595 | | |||
596 | QString AbstractJobThread::getPassword(const QString &path) | 596 | QString AbstractJobThread::getPassword(const QString &path) | ||
597 | { | 597 | { | ||
598 | QList<QVariant> args; | 598 | QList<QVariant> args; | ||
599 | args << path; | 599 | args << path; | ||
600 | 600 | | |||
601 | UserEvent * getPasswdEvent = new UserEvent(CMD_GET_PASSWORD, args); | 601 | auto * getPasswdEvent = new UserEvent(CMD_GET_PASSWORD, args); | ||
602 | QList<QVariant> * result = _job->getEventResponse(getPasswdEvent); | 602 | QList<QVariant> * result = _job->getEventResponse(getPasswdEvent); | ||
603 | if (result == 0) | 603 | if (result == nullptr) | ||
604 | return QString(); | 604 | return QString(); | ||
605 | 605 | | |||
606 | QString password = (*result)[ 0 ].value<QString>(); | 606 | QString password = (*result)[ 0 ].value<QString>(); | ||
607 | if (password.isNull()) | 607 | if (password.isNull()) | ||
608 | password = QString(""); | 608 | password = QString(""); | ||
609 | 609 | | |||
610 | delete result; | 610 | delete result; | ||
611 | return password; | 611 | return password; | ||
612 | } | 612 | } | ||
613 | 613 | | |||
614 | void AbstractJobThread::sendMessage(const QString &message) | 614 | void AbstractJobThread::sendMessage(const QString &message) | ||
615 | { | 615 | { | ||
616 | QList<QVariant> args; | 616 | QList<QVariant> args; | ||
617 | args << message; | 617 | args << message; | ||
618 | 618 | | |||
619 | UserEvent * getPasswdEvent = new UserEvent(CMD_MESSAGE, args); | 619 | auto * getPasswdEvent = new UserEvent(CMD_MESSAGE, args); | ||
620 | QList<QVariant> * result = _job->getEventResponse(getPasswdEvent); | 620 | QList<QVariant> * result = _job->getEventResponse(getPasswdEvent); | ||
621 | if (result == 0) | 621 | if (result == nullptr) | ||
622 | return; | 622 | return; | ||
623 | delete result; | 623 | delete result; | ||
624 | } | 624 | } | ||
625 | 625 | | |||
626 | //! Gets some archive information that is needed in several cases. | 626 | //! Gets some archive information that is needed in several cases. | ||
627 | /*! | 627 | /*! | ||
628 | \param path A path to the archive. | 628 | \param path A path to the archive. | ||
629 | \param type The type of the archive. | 629 | \param type The type of the archive. | ||
Show All 35 Lines |