| 3312 | } |
| 3313 | |
| 3314 | void ShowProgressDialog(QWidget *window, const QString &labelText, ProgressFinishedMethod finished, |
| 3315 | ProgressUpdateMethod update, ProgressCancelMethod cancel) |
| 3316 | { |
| 3317 | if(finished()) |
| 3318 | return; |
| 3319 | |
| 3320 | RDProgressDialog dialog(labelText, window); |
| 3321 | |
| 3322 | if(cancel) |
| 3323 | dialog.enableCancel(); |
| 3324 | |
| 3325 | // if we don't have an update function, set the progress display to be 'infinite spinner' |
| 3326 | dialog.setInfinite(!update); |
| 3327 | |
| 3328 | QSemaphore tickerSemaphore(1); |
| 3329 | |
| 3330 | // start a lambda thread to tick our functions and close the progress dialog when we're done. |
| 3331 | LambdaThread progressTickerThread([finished, update, &dialog, &tickerSemaphore]() { |
| 3332 | while(tickerSemaphore.available()) |
| 3333 | { |
| 3334 | QThread::msleep(30); |
| 3335 | |
| 3336 | if(update) |
| 3337 | GUIInvoke::call(&dialog, [update, &dialog]() { dialog.setPercentage(update()); }); |
| 3338 | |
| 3339 | GUIInvoke::call(&dialog, [finished, &tickerSemaphore]() { |
| 3340 | if(finished()) |
| 3341 | tickerSemaphore.tryAcquire(); |
| 3342 | }); |
| 3343 | } |
| 3344 | |
| 3345 | GUIInvoke::call(&dialog, [&dialog]() { dialog.closeAndReset(); }); |
| 3346 | }); |
| 3347 | progressTickerThread.setName(lit("Progress Dialog")); |
| 3348 | progressTickerThread.start(); |
| 3349 | |
| 3350 | // show the dialog |
| 3351 | RDDialog::show(&dialog); |
| 3352 | |
| 3353 | // signal the thread to exit if somehow we got here without it finishing, then wait for the thread |
| 3354 | // to clean itself up |
| 3355 | tickerSemaphore.tryAcquire(); |
| 3356 | progressTickerThread.wait(); |
| 3357 | |
| 3358 | if(cancel && dialog.wasCanceled()) |
| 3359 | cancel(); |
| 3360 | } |
| 3361 | |
| 3362 | void UpdateTransferProgress(qint64 xfer, qint64 total, QElapsedTimer *timer, |
| 3363 | QProgressBar *progressBar, QLabel *progressLabel, QString progressText) |
no test coverage detected