From 7d9e1f61a8e79720d7b1b5b05eb8e57394814ace Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Fri, 16 Feb 2024 12:37:24 -0500 Subject: [PATCH] Allow updatedialog to be called from About Gridcoin --- src/gridcoin/upgrade.cpp | 33 ++++++++++++++++++++++----------- src/gridcoin/upgrade.h | 2 +- src/qt/aboutdialog.cpp | 23 +++++++++++++++++++++++ src/qt/aboutdialog.h | 1 + src/qt/bitcoingui.cpp | 2 -- src/qt/forms/aboutdialog.ui | 37 +++++++++++++++++++++++++++++++++++++ src/qt/upgradeqt.cpp | 3 ++- src/wallet/diagnose.h | 5 +++-- 8 files changed, 89 insertions(+), 17 deletions(-) diff --git a/src/gridcoin/upgrade.cpp b/src/gridcoin/upgrade.cpp index 513efb4f42..4ff8cc415d 100644 --- a/src/gridcoin/upgrade.cpp +++ b/src/gridcoin/upgrade.cpp @@ -33,13 +33,14 @@ Upgrade::Upgrade() void Upgrade::ScheduledUpdateCheck() { std::string VersionResponse = ""; + std::string change_log {}; Upgrade::UpgradeType upgrade_type {Upgrade::UpgradeType::Unknown}; - CheckForLatestUpdate(VersionResponse, upgrade_type); + CheckForLatestUpdate(VersionResponse, change_log, upgrade_type); } -bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, Upgrade::UpgradeType& upgrade_type, +bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, std::string& change_log, Upgrade::UpgradeType& upgrade_type, bool ui_dialog, bool snapshotrequest) { // If testnet skip this || If the user changes this to disable while wallet running just drop out of here now. @@ -163,15 +164,26 @@ bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, Upgrade::Upg return false; } - if (!NewVersion) return false; - - // New version was found + // Populate client_message_out regardless of whether new version is found, because we are using this method for + // the version information button in the "About Gridcoin" dialog. client_message_out = _("Local version: ") + strprintf("%d.%d.%d.%d", CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD) + "\r\n"; client_message_out.append(_("GitHub version: ") + GithubReleaseData + "\r\n"); - client_message_out.append(_("This update is ") + GithubReleaseType + "\r\n\r\n"); - // For snapshot requests we will handle things differently after this point + if (NewVersion) { + client_message_out.append(_("This update is ") + GithubReleaseType + "\r\n\r\n"); + } else { + client_message_out.append(_("The latest release is ") + GithubReleaseType + "\r\n\r\n"); + client_message_out.append(_("WARNING: You are running a version that is higher than the latest release.") + "\n"); + } + + change_log = GithubReleaseBody; + + if (!NewVersion) return false; + + // For snapshot requests we will only return true if there is a new mandatory version AND the snapshotrequest boolean + // is set true. This is because the snapshot request context is looking for the presence of a new mandatory to block + // the snapshot download before upgrading to the new mandatory if there is one. if (snapshotrequest && NewMandatory) return true; if (NewMandatory) { @@ -179,10 +191,8 @@ bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, Upgrade::Upg + "\n"); } - std::string ChangeLog = GithubReleaseBody; - if (ui_dialog) { - uiInterface.UpdateMessageBox(client_message_out, static_cast(upgrade_type), ChangeLog); + uiInterface.UpdateMessageBox(client_message_out, static_cast(upgrade_type), change_log); } return true; @@ -197,9 +207,10 @@ void Upgrade::SnapshotMain() // Verify a mandatory release is not available before we continue to snapshot download. std::string VersionResponse = ""; + std::string change_log {}; Upgrade::UpgradeType upgrade_type {Upgrade::UpgradeType::Unknown}; - if (CheckForLatestUpdate(VersionResponse, upgrade_type, false, true)) + if (CheckForLatestUpdate(VersionResponse, change_log, upgrade_type, false, true)) { std::cout << this->ResetBlockchainMessages(UpdateAvailable) << std::endl; std::cout << this->ResetBlockchainMessages(GithubResponse) << std::endl; diff --git a/src/gridcoin/upgrade.h b/src/gridcoin/upgrade.h index 4486894748..76ba46608c 100644 --- a/src/gridcoin/upgrade.h +++ b/src/gridcoin/upgrade.h @@ -140,7 +140,7 @@ class Upgrade //! //! \brief Check for latest updates on GitHub. //! - static bool CheckForLatestUpdate(std::string& client_message_out, UpgradeType& upgrade_type, + static bool CheckForLatestUpdate(std::string& client_message_out, std::string& change_log, UpgradeType& upgrade_type, bool ui_dialog = true, bool snapshotrequest = false); //! diff --git a/src/qt/aboutdialog.cpp b/src/qt/aboutdialog.cpp index b8707c941c..d54311f332 100755 --- a/src/qt/aboutdialog.cpp +++ b/src/qt/aboutdialog.cpp @@ -2,6 +2,7 @@ #include "qt/decoration.h" #include "ui_aboutdialog.h" #include "clientmodel.h" +#include "updatedialog.h" AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), @@ -11,6 +12,8 @@ AboutDialog::AboutDialog(QWidget *parent) : ui->copyrightLabel->setText("Copyright 2009-2024 The Bitcoin/Peercoin/Black-Coin/Gridcoin developers"); resize(GRC::ScaleSize(this, width(), height())); + + connect(ui->versionInfoButton, &QAbstractButton::pressed, this, [this]() { handlePressVersionInfoButton(); }); } void AboutDialog::setModel(ClientModel *model) @@ -30,3 +33,23 @@ void AboutDialog::on_buttonBox_accepted() { close(); } + +void AboutDialog::handlePressVersionInfoButton() +{ + std::string client_message_out; + std::string change_log; + GRC::Upgrade::UpgradeType upgrade_type = GRC::Upgrade::UpgradeType::Unknown; + + + GRC::Upgrade::CheckForLatestUpdate(client_message_out, change_log, upgrade_type, false, false); + + UpdateDialog update_dialog; + + update_dialog.setWindowTitle("Gridcoin Version Information"); + update_dialog.setVersion(QString().fromStdString(client_message_out)); + update_dialog.setUpgradeType(static_cast(upgrade_type)); + update_dialog.setDetails(QString().fromStdString(change_log)); + update_dialog.setModal(false); + + update_dialog.exec(); +} diff --git a/src/qt/aboutdialog.h b/src/qt/aboutdialog.h index 1b1dba84d7..a517b262b0 100644 --- a/src/qt/aboutdialog.h +++ b/src/qt/aboutdialog.h @@ -23,6 +23,7 @@ class AboutDialog : public QDialog private slots: void on_buttonBox_accepted(); + void handlePressVersionInfoButton(); }; #endif // BITCOIN_QT_ABOUTDIALOG_H diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 09e3595340..37fa568a96 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1162,8 +1162,6 @@ void BitcoinGUI::error(const QString &title, const QString &message, bool modal) void BitcoinGUI::update(const QString &title, const QString& version, const int& upgrade_type, const QString &message) { - // Create our own message box; A dialog can go here in future for qt if we choose - updateMessageDialog.reset(new UpdateDialog); updateMessageDialog->setWindowTitle(title); diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui index c67bdbac35..e3952591f1 100644 --- a/src/qt/forms/aboutdialog.ui +++ b/src/qt/forms/aboutdialog.ui @@ -136,6 +136,43 @@ This product includes software developed by the OpenSSL Project for use in the O + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Version Information + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/qt/upgradeqt.cpp b/src/qt/upgradeqt.cpp index 06a9c490d6..9499d5a032 100644 --- a/src/qt/upgradeqt.cpp +++ b/src/qt/upgradeqt.cpp @@ -41,9 +41,10 @@ bool UpgradeQt::SnapshotMain(QApplication& SnapshotApp) // Verify a mandatory release is not available before we continue to snapshot download. std::string VersionResponse = ""; + std::string change_log; Upgrade::UpgradeType upgrade_type {Upgrade::UpgradeType::Unknown}; - if (UpgradeMain.CheckForLatestUpdate(VersionResponse, upgrade_type, false, true)) + if (UpgradeMain.CheckForLatestUpdate(VersionResponse, change_log, upgrade_type, false, true)) { ErrorMsg(UpgradeMain.ResetBlockchainMessages(Upgrade::UpdateAvailable), UpgradeMain.ResetBlockchainMessages(Upgrade::GithubResponse) + "\r\n" + VersionResponse); diff --git a/src/wallet/diagnose.h b/src/wallet/diagnose.h index d09856ca82..606b0205ec 100644 --- a/src/wallet/diagnose.h +++ b/src/wallet/diagnose.h @@ -403,15 +403,16 @@ class CheckClientVersion : public Diagnose m_results_tip_arg.clear(); std::string client_message; + std::string change_log; GRC::Upgrade::UpgradeType upgrade_type {GRC::Upgrade::UpgradeType::Unknown}; - if (g_UpdateChecker->CheckForLatestUpdate(client_message, upgrade_type, false) + if (g_UpdateChecker->CheckForLatestUpdate(client_message, change_log, upgrade_type, false) && client_message.find("mandatory") != std::string::npos) { m_results_tip = _("There is a new mandatory version available and you should upgrade as soon as possible to " "ensure your wallet remains in consensus with the network."); m_results = Diagnose::FAIL; - } else if (g_UpdateChecker->CheckForLatestUpdate(client_message, upgrade_type, false) + } else if (g_UpdateChecker->CheckForLatestUpdate(client_message, change_log, upgrade_type, false) && client_message.find("mandatory") == std::string::npos) { m_results_tip = _("There is a new leisure version available and you should upgrade as soon as practical."); m_results = Diagnose::WARNING;