diff options
Diffstat (limited to 'src/sdk/tabcontroller.cpp')
-rw-r--r-- | src/sdk/tabcontroller.cpp | 87 |
1 files changed, 67 insertions, 20 deletions
diff --git a/src/sdk/tabcontroller.cpp b/src/sdk/tabcontroller.cpp index 5e2f1ed13..8c15243f8 100644 --- a/src/sdk/tabcontroller.cpp +++ b/src/sdk/tabcontroller.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -29,6 +29,7 @@ #include "installerbasecommons.h" #include "settingsdialog.h" +#include "aboutapplicationdialog.h" #include "globals.h" #include <packagemanagercore.h> @@ -36,6 +37,8 @@ #include <productkeycheck.h> #include <QtCore/QTimer> +#include <QtWidgets/QMessageBox> +#include <QtConcurrent> using namespace QInstaller; @@ -118,6 +121,8 @@ int TabController::init() connect(d->m_gui, &QWizard::currentIdChanged, this, &TabController::onCurrentIdChanged); connect(d->m_gui, &PackageManagerGui::settingsButtonClicked, this, &TabController::onSettingsButtonClicked); + connect(d->m_gui, &PackageManagerGui::aboutApplicationClicked, + this, &TabController::onAboutApplicationClicked); } IntroductionPage *page = @@ -125,7 +130,7 @@ int TabController::init() if (page) { page->setMessage(QString()); page->setErrorMessage(QString()); - page->onCoreNetworkSettingsChanged(); + page->resetFetchedState(); } d->m_gui->restart(); @@ -151,6 +156,8 @@ void TabController::restartWizard() d->m_core->settings().setDefaultRepositories(d->m_settings.defaultRepositories()); d->m_core->settings().setTemporaryRepositories(d->m_settings.temporaryRepositories(), d->m_settings.hasReplacementRepos()); + d->m_core->settings().setLocalCachePath(d->m_settings.localCachePath()); + d->m_core->networkSettingsChanged(); } @@ -166,25 +173,11 @@ void TabController::restartWizard() void TabController::onSettingsButtonClicked() { SettingsDialog dialog(d->m_core); - // set custom stylesheet - const QString styleSheetFile = d->m_core->settings().styleSheet(); - if (!styleSheetFile.isEmpty()) { - QFile sheet(styleSheetFile); - if (sheet.exists()) { - if (sheet.open(QIODevice::ReadOnly)) { - dialog.setStyleSheet(QString::fromLatin1(sheet.readAll())); - } else { - qCWarning(QInstaller::lcDeveloperBuild) << "The specified style sheet file " - "can not be opened."; - } - } else { - qCWarning(QInstaller::lcDeveloperBuild) << "A style sheet file is specified, " - "but it does not exist."; - } - } - + dialog.adjustSize(); connect(&dialog, &SettingsDialog::networkSettingsChanged, this, &TabController::onNetworkSettingsChanged); + connect(&dialog, &SettingsDialog::clearLocalCacheClicked, + this, &TabController::onClearCacheClicked); dialog.exec(); if (d->m_networkSettingsChanged) { @@ -199,11 +192,65 @@ void TabController::onSettingsButtonClicked() } } +void TabController::onAboutApplicationClicked() +{ + AboutApplicationDialog dialog(d->m_core); + dialog.exec(); +} + +void TabController::onClearCacheClicked() +{ + SettingsDialog *settingsDialog = static_cast<SettingsDialog *>(sender()); + settingsDialog->setEnabled(false); + settingsDialog->showClearCacheProgress(true); + + QString errorMessage; + bool success = true; + + // Clearing might take some time, run in a separate thread + QEventLoop loop; + QFutureWatcher<bool> futureWatcher; + + connect(&futureWatcher, &QFutureWatcher<bool>::finished, this, [&]() { + success = futureWatcher.future().result(); + if (loop.isRunning()) + loop.quit(); + }); + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + futureWatcher.setFuture(QtConcurrent::run(&PackageManagerCore::clearLocalCache, + d->m_core, &errorMessage)); +#else + futureWatcher.setFuture(QtConcurrent::run(d->m_core, + &PackageManagerCore::clearLocalCache, &errorMessage)); +#endif + + if (!futureWatcher.isFinished()) + loop.exec(); + + settingsDialog->setEnabled(true); + settingsDialog->showClearCacheProgress(false); + + QMessageBox msgBox(settingsDialog); + msgBox.setWindowModality(Qt::WindowModal); + msgBox.setStandardButtons(QMessageBox::Close); + + msgBox.setIcon(success + ? QMessageBox::Information + : QMessageBox::Critical); + + msgBox.setText(success + ? tr("Cache cleared successfully!") + : errorMessage); + + msgBox.exec(); +} + void TabController::onCurrentIdChanged(int newId) { if (d->m_gui) { if (PackageManagerPage *page = qobject_cast<PackageManagerPage *>(d->m_gui->page(newId))) - d->m_gui->showSettingsButton(page->settingsButtonRequested()); + d->m_gui->requestSettingsButtonByInstaller(page->settingsButtonRequested()); } } |