diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-06-11 20:09:00 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-06-11 20:09:00 +0200 |
| commit | 93b1cea0d30e635cad7988dd65578bbbc1abecc7 (patch) | |
| tree | 1577540aa8f66fc470ece5e6efc0f35da9a9ad2e | |
| parent | 26c7cd4f22f82cceff147dbe9a47fdbb2ff06cb3 (diff) | |
Rollback to using QProcessEvents but use WaitForMoreEvents.
| -rw-r--r-- | src/installationmanager.cpp | 50 | ||||
| -rw-r--r-- | src/installationmanager.h | 7 |
2 files changed, 28 insertions, 29 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(); } diff --git a/src/installationmanager.h b/src/installationmanager.h index 3da74ec4..695f2ed6 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -223,12 +223,7 @@ signals: /** * @brief Progress update from the extraction. */ - void progressUpdate(int percentage); - - /** - * @brief File change update from the extraction. - */ - void progressFileChange(QString const& value); + void progressUpdate(); private: |
