summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-06-11 20:09:00 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2020-06-11 20:09:00 +0200
commit93b1cea0d30e635cad7988dd65578bbbc1abecc7 (patch)
tree1577540aa8f66fc470ece5e6efc0f35da9a9ad2e /src
parent26c7cd4f22f82cceff147dbe9a47fdbb2ff06cb3 (diff)
Rollback to using QProcessEvents but use WaitForMoreEvents.
Diffstat (limited to 'src')
-rw-r--r--src/installationmanager.cpp50
-rw-r--r--src/installationmanager.h7
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, &currentProgress](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, &currentFileName](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: