UI: AboutPage: Simplify setupAutoUpdate()

This commit is contained in:
Nodir Temirkhodjaev 2024-09-30 15:31:33 +05:00
parent d8d2f6dc65
commit 923b7558ee
2 changed files with 25 additions and 22 deletions

View File

@ -140,7 +140,19 @@ void AboutPage::setupNewVersionUpdate()
void AboutPage::setupAutoUpdate() void AboutPage::setupAutoUpdate()
{ {
const auto refreshAutoUpdate = [&] { refreshAutoUpdate();
connect(autoUpdateManager(), &AutoUpdateManager::keepCurrentVersionChanged, this,
&AboutPage::refreshAutoUpdate);
connect(autoUpdateManager(), &AutoUpdateManager::flagsChanged, this,
&AboutPage::refreshAutoUpdate);
connect(autoUpdateManager(), &AutoUpdateManager::bytesReceivedChanged, m_progressBar,
&QProgressBar::setValue);
}
void AboutPage::refreshAutoUpdate()
{
auto manager = autoUpdateManager(); auto manager = autoUpdateManager();
const bool hasUpdate = manager->hasUpdate(); const bool hasUpdate = manager->hasUpdate();
@ -149,8 +161,7 @@ void AboutPage::setupAutoUpdate()
const bool isDownloadActive = (isDownloading || isDownloaded); const bool isDownloadActive = (isDownloading || isDownloaded);
if (!isDownloading || isDownloaded) { if (!isDownloading || isDownloaded) {
m_progressBar->setValue( m_progressBar->setValue(isDownloaded ? m_progressBar->maximum() : m_progressBar->minimum());
isDownloaded ? m_progressBar->maximum() : m_progressBar->minimum());
} }
m_progressBar->setVisible(hasUpdate && isDownloadActive); m_progressBar->setVisible(hasUpdate && isDownloadActive);
@ -158,14 +169,4 @@ void AboutPage::setupAutoUpdate()
m_btInstall->setVisible(hasUpdate && isDownloaded); m_btInstall->setVisible(hasUpdate && isDownloaded);
m_btInstall->setToolTip(isDownloaded ? manager->installerPath() : QString()); m_btInstall->setToolTip(isDownloaded ? manager->installerPath() : QString());
};
refreshAutoUpdate();
connect(autoUpdateManager(), &AutoUpdateManager::keepCurrentVersionChanged, this,
refreshAutoUpdate);
connect(autoUpdateManager(), &AutoUpdateManager::flagsChanged, this, refreshAutoUpdate);
connect(autoUpdateManager(), &AutoUpdateManager::bytesReceivedChanged, m_progressBar,
&QProgressBar::setValue);
} }

View File

@ -24,6 +24,8 @@ private:
void setupNewVersionUpdate(); void setupNewVersionUpdate();
void setupAutoUpdate(); void setupAutoUpdate();
void refreshAutoUpdate();
private: private:
bool m_keepCurrentVersion = false; bool m_keepCurrentVersion = false;
bool m_isNewVersion = false; bool m_isNewVersion = false;