From 7f0a971b4a038b8567c8daf3f241617e0955f52c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 25 Apr 2017 14:37:26 +0200 Subject: [PATCH] Ref T41, adjusted info component to be used with dialog --- .../components/distributioninfocomponent.cpp | 17 +++++++++++++++-- .../components/distributioninfocomponent.h | 11 ++++++++++- .../distributorpreferencescomponent.h | 2 +- src/swiftlauncher/swiftlauncher.cpp | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/blackgui/components/distributioninfocomponent.cpp b/src/blackgui/components/distributioninfocomponent.cpp index cab488efe..afa61c03e 100644 --- a/src/blackgui/components/distributioninfocomponent.cpp +++ b/src/blackgui/components/distributioninfocomponent.cpp @@ -36,19 +36,29 @@ namespace BlackGui // use version signal as trigger for completion connect(sGui, &CGuiApplication::distributionInfoAvailable, this, &CDistributionInfoComponent::ps_loadedDistributionInfo); - QTimer::singleShot(10 * 1000, this, [ = ] + const int time = this->m_distributionInfo.get().isEmpty() ? 10 * 1000 : 500; + QTimer::singleShot(time, this, [ = ] { // use this as timeout failover with cached data if (m_distributionsLoaded) { return; } this->ps_loadedDistributionInfo(true); }); - connect(ui->pb_CheckForUpdates, &QPushButton::pressed, this, &CDistributionInfoComponent::ps_loadSetup); } CDistributionInfoComponent::~CDistributionInfoComponent() { } + bool CDistributionInfoComponent::isNewVersionAvailable() const + { + const QStringList channelPlatform = m_distributionSettings.get(); + Q_ASSERT_X(channelPlatform.size() == 2, Q_FUNC_INFO, "wrong setting"); + const QVersionNumber vCurrentChannelPlatform = m_distributionInfo.get().getQVersionForChannelAndPlatform(channelPlatform); + if (vCurrentChannelPlatform.isNull() || vCurrentChannelPlatform.segmentCount() < 4) return false; + const QVersionNumber vCurrent = CBuildConfig::getVersion(); + return (vCurrentChannelPlatform > vCurrent); + } + void CDistributionInfoComponent::ps_loadSetup() { if (!ui->le_LatestVersion->text().isEmpty()) @@ -98,6 +108,7 @@ namespace BlackGui const CDistributionList distributions(m_distributionInfo.get()); const QStringList channels = distributions.getChannels(); const QStringList settings = m_distributionSettings.get(); // channel / platform + Q_ASSERT_X(settings.size() == 2, Q_FUNC_INFO, "Settings"); // default value QString channel = ui->cb_Channels->currentText(); @@ -169,6 +180,8 @@ namespace BlackGui ui->lbl_NewVersionUrl->setText(hl.arg(urlStr, currentPlatform)); ui->lbl_NewVersionUrl->setToolTip("Download '" + latestVersionStr + "' " + m_currentDistribution.getFilename(currentPlatform)); } + + emit selectionChanged(); } } } // ns diff --git a/src/blackgui/components/distributioninfocomponent.h b/src/blackgui/components/distributioninfocomponent.h index 7be2fab38..0d4056a4c 100644 --- a/src/blackgui/components/distributioninfocomponent.h +++ b/src/blackgui/components/distributioninfocomponent.h @@ -37,12 +37,21 @@ namespace BlackGui virtual ~CDistributionInfoComponent(); //! Is there a new version available return version, else empty string - QString getNewVersionAvailable() const { return m_newVersionAvailable; } + QString getNewAvailableVersionForSelection() const { return m_newVersionAvailable; } + + //! Is there a new version available? + bool isNewVersionAvailable() const; + + //! Current distribution + BlackMisc::Db::CDistribution getCurrentDistribution() { return m_currentDistribution; } signals: //! Distribution info loaded void distributionInfoAvailable(bool success); + //! New platfrom or channel + void selectionChanged(); + private slots: //! Load latest version void ps_loadSetup(); diff --git a/src/blackgui/components/distributorpreferencescomponent.h b/src/blackgui/components/distributorpreferencescomponent.h index e9de6d2c7..e4aa3c6b6 100644 --- a/src/blackgui/components/distributorpreferencescomponent.h +++ b/src/blackgui/components/distributorpreferencescomponent.h @@ -42,7 +42,7 @@ namespace BlackGui explicit CDistributorPreferencesComponent(QWidget *parent = nullptr); //! Destructor - ~CDistributorPreferencesComponent(); + virtual ~CDistributorPreferencesComponent(); private slots: //! Changed preferences diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index 79a9d6860..54d016275 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -136,7 +136,7 @@ void CSwiftLauncher::ps_distributionInfoAvailable(bool success) { if (success) { - this->setHeaderInfo(ui->comp_DistributionInfo->getNewVersionAvailable()); + this->setHeaderInfo(ui->comp_DistributionInfo->getNewAvailableVersionForSelection()); } else {