diff options
Diffstat (limited to 'src/installationmanager.cpp')
| -rw-r--r-- | src/installationmanager.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index b1eaf1d3..8500fec0 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -180,37 +180,34 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool installationProgress->setAutoReset(false); // Connect signals emitted by the extraction callback to the progress dialog slots: - connect(this, &InstallationManager::progressUpdate, installationProgress, &QProgressDialog::setValue); - connect(this, &InstallationManager::progressFileChange, installationProgress, &QProgressDialog::setLabelText); + QEventLoop loop; + connect(this, &InstallationManager::progressUpdate, &loop, &QEventLoop::wakeUp, Qt::QueuedConnection); // Cancelling progress only cancel the extraction, we do not force exiting the event-loop: connect(installationProgress, &QProgressDialog::canceled, [this]() { m_ArchiveHandler->cancel(); }); - installationProgress->show(); + int currentProgress = 0; + QString currentFileName; // The callbacks: - auto progressCallback = [this](auto progressType, uint64_t current, uint64_t total) { + auto progressCallback = [this, ¤tProgress](auto progressType, uint64_t current, uint64_t total) { if (progressType == Archive::ProgressType::EXTRACTION) { - int progress = static_cast<int>(100 * current / total); - emit progressUpdate(progress); + currentProgress = static_cast<int>(100 * current / total); + emit progressUpdate(); } }; - Archive::FileChangeCallback fileChangeCallback = [this](auto changeType, std::wstring const& file) { + Archive::FileChangeCallback fileChangeCallback = [this, ¤tFileName](auto changeType, std::wstring const& file) { if (changeType == Archive::FileChangeType::EXTRACTION_START) { - emit progressFileChange(QString::fromStdWString(file)); + currentFileName = QString::fromStdWString(file); + emit progressUpdate(); } }; - // Future watcher to exit the loop: + // unpack only the files we need for the installer QFutureWatcher<bool> futureWatcher; - - QEventLoop loop(this); - connect( - &futureWatcher, &QFutureWatcher<bool>::finished, - &loop, &QEventLoop::quit, + connect(&futureWatcher, &QFutureWatcher<bool>::finished, + &loop, &QEventLoop::wakeUp, Qt::QueuedConnection); - - // unpack only the files we need for the installer futureWatcher.setFuture(QtConcurrent::run([&]() -> bool { return m_ArchiveHandler->extract( extractPath.toStdWString(), @@ -220,14 +217,21 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool ); })); - // Wait for future to complete: - loop.exec(); + installationProgress->setModal(true); + installationProgress->show(); + + do { + if (currentProgress != installationProgress->value()) { + installationProgress->setValue(currentProgress); + } + if (currentFileName != installationProgress->labelText()) { + installationProgress->setLabelText(currentFileName); + } + loop.processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); + } while (!futureWatcher.isFinished()); + + installationProgress->hide(); - // There might still be signal in the queue at this point but the progress dialog is - // going to be destroyed so we must disconnect the signals: - disconnect(this, &InstallationManager::progressUpdate, installationProgress, &QProgressDialog::setValue); - disconnect(this, &InstallationManager::progressFileChange, installationProgress, &QProgressDialog::setLabelText); - future = futureWatcher.future(); } |
