From 923b7558ee850db6928cbfb77a6fd6c5d8e9b67d Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Mon, 30 Sep 2024 15:31:33 +0500 Subject: [PATCH] UI: AboutPage: Simplify setupAutoUpdate() --- src/ui/form/home/pages/aboutpage.cpp | 45 ++++++++++++++-------------- src/ui/form/home/pages/aboutpage.h | 2 ++ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/ui/form/home/pages/aboutpage.cpp b/src/ui/form/home/pages/aboutpage.cpp index 038e0cd1..f30932f2 100644 --- a/src/ui/form/home/pages/aboutpage.cpp +++ b/src/ui/form/home/pages/aboutpage.cpp @@ -140,32 +140,33 @@ void AboutPage::setupNewVersionUpdate() void AboutPage::setupAutoUpdate() { - const auto refreshAutoUpdate = [&] { - auto manager = autoUpdateManager(); - - const bool hasUpdate = manager->hasUpdate(); - const bool isDownloaded = manager->isDownloaded(); - const bool isDownloading = manager->isDownloading(); - const bool isDownloadActive = (isDownloading || isDownloaded); - - if (!isDownloading || isDownloaded) { - m_progressBar->setValue( - isDownloaded ? m_progressBar->maximum() : m_progressBar->minimum()); - } - m_progressBar->setVisible(hasUpdate && isDownloadActive); - - m_btDownload->setVisible(hasUpdate && !isDownloadActive); - m_btInstall->setVisible(hasUpdate && isDownloaded); - - m_btInstall->setToolTip(isDownloaded ? manager->installerPath() : QString()); - }; - refreshAutoUpdate(); connect(autoUpdateManager(), &AutoUpdateManager::keepCurrentVersionChanged, this, - refreshAutoUpdate); - connect(autoUpdateManager(), &AutoUpdateManager::flagsChanged, this, refreshAutoUpdate); + &AboutPage::refreshAutoUpdate); + connect(autoUpdateManager(), &AutoUpdateManager::flagsChanged, this, + &AboutPage::refreshAutoUpdate); connect(autoUpdateManager(), &AutoUpdateManager::bytesReceivedChanged, m_progressBar, &QProgressBar::setValue); } + +void AboutPage::refreshAutoUpdate() +{ + auto manager = autoUpdateManager(); + + const bool hasUpdate = manager->hasUpdate(); + const bool isDownloaded = manager->isDownloaded(); + const bool isDownloading = manager->isDownloading(); + const bool isDownloadActive = (isDownloading || isDownloaded); + + if (!isDownloading || isDownloaded) { + m_progressBar->setValue(isDownloaded ? m_progressBar->maximum() : m_progressBar->minimum()); + } + m_progressBar->setVisible(hasUpdate && isDownloadActive); + + m_btDownload->setVisible(hasUpdate && !isDownloadActive); + m_btInstall->setVisible(hasUpdate && isDownloaded); + + m_btInstall->setToolTip(isDownloaded ? manager->installerPath() : QString()); +} diff --git a/src/ui/form/home/pages/aboutpage.h b/src/ui/form/home/pages/aboutpage.h index 33b76231..0e89a66f 100644 --- a/src/ui/form/home/pages/aboutpage.h +++ b/src/ui/form/home/pages/aboutpage.h @@ -24,6 +24,8 @@ private: void setupNewVersionUpdate(); void setupAutoUpdate(); + void refreshAutoUpdate(); + private: bool m_keepCurrentVersion = false; bool m_isNewVersion = false;