summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2024-03-07 12:30:25 +0200
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2024-03-14 13:22:43 +0200
commita4e0908df2f908f2da1401a8f11e838d124f1291 (patch)
tree6e0efc138b243b206b0fd244bf34dd28f375893a
parentce47a87dcfaaf59da8f6a927468b00dcb43d1ae4 (diff)
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 <katja.marttila@qt.io>
-rw-r--r--src/libs/installer/metadatajob.cpp5
-rw-r--r--src/libs/installer/metadatajob.h1
-rw-r--r--src/libs/installer/packagemanagercore.cpp8
-rw-r--r--src/libs/installer/packagemanagercore.h2
-rw-r--r--src/sdk/settingsdialog.cpp20
5 files changed, 32 insertions, 4 deletions
diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp
index 03ad84e20..641f2da62 100644
--- a/src/libs/installer/metadatajob.cpp
+++ b/src/libs/installer/metadatajob.cpp
@@ -212,6 +212,11 @@ bool MetadataJob::clearCache()
return false;
}
+bool MetadataJob::isValidCache() const
+{
+ return m_metaFromCache.isValid();
+}
+
// -- private slots
void MetadataJob::doStart()
diff --git a/src/libs/installer/metadatajob.h b/src/libs/installer/metadatajob.h
index c862215de..13ad3ea8c 100644
--- a/src/libs/installer/metadatajob.h
+++ b/src/libs/installer/metadatajob.h
@@ -74,6 +74,7 @@ public:
bool resetCache(bool init = false);
bool clearCache();
+ bool isValidCache() const;
private slots:
void doStart() override;
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index eb344ce16..4600a1373 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -589,6 +589,14 @@ bool PackageManagerCore::clearLocalCache(QString *error)
}
/*!
+ Returns \c true if the metadata cache is initialized and valid, \c false otherwise.
+*/
+bool PackageManagerCore::isValidCache() const
+{
+ return d->m_metadataJob.isValidCache();
+}
+
+/*!
\internal
*/
template <typename T>
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index d36e8e0f4..5d093f875 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -390,6 +390,8 @@ public:
bool resetLocalCache(bool init = false);
bool clearLocalCache(QString *error = nullptr);
+ bool isValidCache() const;
+
template <typename T>
bool loadComponentScripts(const T &components, const bool postScript = false);
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)