diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index df2f678b7..0de82fe11 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -595,6 +595,18 @@ namespace BlackCore return m_setupReader && m_startSetupReader; } + QString CApplication::getLastSuccesfulSetupUrl() const + { + if (!this->hasSetupReader()) { return ""; } + return m_setupReader->getLastSuccessfulSetupUrl(); + } + + QString CApplication::getLastSuccesfulDistributionUrl() const + { + if (!this->hasSetupReader()) { return ""; } + return m_setupReader->getLastSuccessfulDistributionUrl(); + } + void CApplication::exit(int retcode) { if (instance()) diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 2724dd496..b34c22d19 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -162,6 +162,14 @@ namespace BlackCore //! Setup reader? bool hasSetupReader() const; + //! Last setup URL (successfully read) + //! \threadsafe + QString getLastSuccesfulSetupUrl() const; + + //! Last distribution URL (successfully read) + //! \threadsafe + QString getLastSuccesfulDistributionUrl() const; + //! Setup already synchronized bool isSetupAvailable() const; diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index fbe384dd0..a2bcaf2cf 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -200,8 +200,7 @@ namespace BlackCore if (this->m_shutdown) { return CStatusMessage(this, CStatusMessage::SeverityError, "shutdown"); } if (!sApp->isNetworkAccessible()) { - const CStatusMessage m(this, CStatusMessage::SeverityError, - "No network, cancelled reading of setup"); + const CStatusMessage m(this, CStatusMessage::SeverityError, "No network, cancelled reading of setup"); CStatusMessageList msgs(m); msgs.push_back(this->manageSetupAvailability(false, false)); this->setLastSetupReadErrorMessages(msgs); @@ -230,7 +229,7 @@ namespace BlackCore const CUrl url(this->m_distributionUrls.obtainNextWorkingUrl()); if (url.isEmpty()) { - CLogMessage(this).warning("Cannot read update info, URLs: %1, failed URLs: %2") + CLogMessage(this).warning("Cannot read update info, URLs: '%1', failed URLs: '%2'") << this->m_distributionUrls << this->m_distributionUrls.getFailedUrls(); this->manageDistributionsInfoAvailability(false); @@ -329,7 +328,7 @@ namespace BlackCore if (sameVersionLoaded) { this->m_distributionUrls = currentSetup.getDistributionUrls(); // defaults - CLogMessage(this).info("Same setup version loaded from %1 as already in data cache %2") << urlString << m_setup.getFilename(); + CLogMessage(this).info("Same setup version loaded from '%1' as already in data cache '%2'") << urlString << m_setup.getFilename(); CLogMessage::preformatted(this->manageSetupAvailability(true)); return; // success } @@ -342,7 +341,12 @@ namespace BlackCore { // no issue with cache this->m_distributionUrls = loadedSetup.getDistributionUrls(); + CLogMessage(this).info("Loaded setup from '%1'") << urlString; CLogMessage(this).info("Setup: Updated data cache in '%1'") << this->m_setup.getFilename(); + { + QWriteLocker l(&m_lockSetup); + m_lastSuccessfulSetupUrl = urlString; + } } CLogMessage::preformatted(this->manageSetupAvailability(true)); return; @@ -366,7 +370,7 @@ namespace BlackCore // network error, log as warning as we will read again if possible // however, store as error because this will be a possible root cause if nothing else is nwReply->abort(); - const CStatusMessage msg = CStatusMessage(this).error("Reading setup failed %1 %2 (can possibly be fixed by reading from another server afterwards)") << replyMessage << urlString; + const CStatusMessage msg = CStatusMessage(this).error("Reading setup failed '%1' '%2' (can possibly be fixed by reading from another server afterwards)") << replyMessage << urlString; CLogMessage::preformatted(msg); this->setLastSetupReadErrorMessages(msg); } @@ -427,6 +431,11 @@ namespace BlackCore } else { + { + QWriteLocker l(&m_lockDistribution); + m_lastSuccessfulDistributionUrl = urlString; + } + CLogMessage(this).info("Distribution info loaded from '%1") << urlString; CLogMessage(this).info("Distribution info: Updated data cache in '%1'") << m_distributions.getFilename(); this->manageDistributionsInfoAvailability(true); } // cache @@ -441,8 +450,7 @@ namespace BlackCore const CStatusMessage msg = ex.toStatusMessage(this, errorMsg); CLogMessage::preformatted(msg); - // in dev. I get notified, in productive code I try next URL - // by falling thru + // in dev. I get notified, in productive code I try next URL by falling thru BLACK_VERIFY_X(false, Q_FUNC_INFO, errorMsg.toLocal8Bit().constData()); } } // json empty @@ -487,11 +495,23 @@ namespace BlackCore return m_setup.get(); } + QString CSetupReader::getLastSuccessfulSetupUrl() const + { + QReadLocker l(&m_lockSetup); + return m_lastSuccessfulSetupUrl; + } + CDistributionList CSetupReader::getDistributionInfo() const { return m_distributions.get(); } + QString CSetupReader::getLastSuccessfulDistributionUrl() const + { + QReadLocker l(&m_lockDistribution); + return m_lastSuccessfulDistributionUrl; + } + CStatusMessageList CSetupReader::getLastSetupReadErrorMessages() const { QReadLocker l(&m_lockSetup); diff --git a/src/blackcore/setupreader.h b/src/blackcore/setupreader.h index 6c349de5d..93be3d644 100644 --- a/src/blackcore/setupreader.h +++ b/src/blackcore/setupreader.h @@ -64,10 +64,18 @@ namespace BlackCore //! \threadsafe BlackCore::Data::CGlobalSetup getSetup() const; + //! Last distribution URL successfully read + //! \threadsafe + QString getLastSuccessfulSetupUrl() const; + //! Distributions info (channel, version, platforms, download URLs) //! \threadsafe BlackMisc::Db::CDistributionList getDistributionInfo() const; + //! Last distribution URL successfully read + //! \threadsafe + QString getLastSuccessfulDistributionUrl() const; + //! Last setup parsing error messages (if any) BlackMisc::CStatusMessageList getLastSetupReadErrorMessages() const; @@ -138,6 +146,9 @@ namespace BlackCore QCommandLineOption m_cmdBootstrapUrl; //!< bootstrap URL QCommandLineOption m_cmdBootstrapMode; //!< bootstrap mode mutable QReadWriteLock m_lockSetup; //!< lock for setup + mutable QReadWriteLock m_lockDistribution; //!< lock for distribution + QString m_lastSuccessfulSetupUrl; //!< last successful read setup URL + QString m_lastSuccessfulDistributionUrl; //!< last successful read distribution URL BlackMisc::CStatusMessageList m_setupReadErrorMsgs; //!< last parsing error messages BlackMisc::CData m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup BlackMisc::CData m_distributions {this}; //!< data cache distributions diff --git a/src/blackgui/components/distributioninfocomponent.cpp b/src/blackgui/components/distributioninfocomponent.cpp index 7bb38c416..1ff8381ad 100644 --- a/src/blackgui/components/distributioninfocomponent.cpp +++ b/src/blackgui/components/distributioninfocomponent.cpp @@ -38,9 +38,9 @@ namespace BlackGui connect(sGui, &CGuiApplication::distributionInfoAvailable, this, &CDistributionInfoComponent::ps_loadedDistributionInfo); QTimer::singleShot(10 * 1000, this, [ = ] { - // use has time out failover with cache data + // use this as timeout failover with cached data if (m_distributionsLoaded) { return; } - this->ps_loadedDistributionInfo(true); // failover + this->ps_loadedDistributionInfo(true); }); connect(ui->pb_CheckForUpdates, &QPushButton::pressed, this, &CDistributionInfoComponent::ps_loadSetup); @@ -61,6 +61,7 @@ namespace BlackGui void CDistributionInfoComponent::ps_loadedDistributionInfo(bool success) { + ui->pb_CheckForUpdates->setToolTip(""); if (!success) { CLogMessage(this).warning("Loading setup or distribution information failed"); @@ -69,6 +70,7 @@ namespace BlackGui m_distributionsLoaded = true; this->ps_channelChanged(); + ui->pb_CheckForUpdates->setToolTip(sApp->getLastSuccesfulDistributionUrl()); // emit only after all has been set emit this->distributionInfoAvailable(success);