From a4e0908df2f908f2da1401a8f11e838d124f1291 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Thu, 7 Mar 2024 12:30:25 +0200 Subject: Disable 'clear cache' button until new cache settings are applied Check the cache validity and use it as the initial state for the button. After clearing the cache, regardless of success, the cache will become invalid so the button should stay disabled until new settings are applied and the cache is reinitialized. Also disable the button in case the selected cache path does not match the one currently applied in the settings. Task-number: QTIFW-3252 Change-Id: I1b403fbc8a6680dfd5222296479ab0821cdb4a37 Reviewed-by: Katja Marttila --- src/sdk/settingsdialog.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/sdk') diff --git a/src/sdk/settingsdialog.cpp b/src/sdk/settingsdialog.cpp index acd364b2f..0a16377b3 100644 --- a/src/sdk/settingsdialog.cpp +++ b/src/sdk/settingsdialog.cpp @@ -242,8 +242,19 @@ SettingsDialog::SettingsDialog(PackageManagerCore *core, QWidget *parent) connect(m_ui->m_clearPushButton, &QAbstractButton::clicked, this, &SettingsDialog::clearLocalCacheClicked); - connect(m_ui->m_clearPushButton, &QAbstractButton::clicked, - this, [&] { m_cacheCleared = true; }); + connect(m_ui->m_clearPushButton, &QAbstractButton::clicked, this, [&] { + // Disable the button as the new settings will only take effect after + // closing the dialog. + m_ui->m_clearPushButton->setEnabled(false); + m_cacheCleared = true; + }); + connect(m_ui->m_cachePathLineEdit, &QLineEdit::textChanged, this, [&] { + if (!m_cacheCleared) { + // Disable the button if the path is modified between applying settings + m_ui->m_clearPushButton->setEnabled( + settings.localCachePath() == m_ui->m_cachePathLineEdit->text()); + } + }); useTmpRepositoriesOnly(settings.hasReplacementRepos()); m_ui->m_useTmpRepositories->setChecked(settings.hasReplacementRepos()); @@ -256,8 +267,9 @@ SettingsDialog::SettingsDialog(PackageManagerCore *core, QWidget *parent) m_ui->m_repositories->setVisible(settings.repositorySettingsPageVisible()); } - m_ui->m_cachePathLineEdit->setText(settings.localCachePath()); - showClearCacheProgress(false); + m_ui->m_cachePathLineEdit->setText(settings.localCachePath()); + m_ui->m_clearPushButton->setEnabled(m_core->isValidCache()); + showClearCacheProgress(false); } void SettingsDialog::showClearCacheProgress(bool show) -- cgit v1.2.3