Skip to content

Commit

Permalink
Allow updatedialog to be called from About Gridcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Feb 16, 2024
1 parent ba2fd60 commit 7d9e1f6
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 17 deletions.
33 changes: 22 additions & 11 deletions src/gridcoin/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -163,26 +164,35 @@ 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) {
client_message_out.append(_("WARNING: A mandatory release is available. Please upgrade as soon as possible.")
+ "\n");
}

std::string ChangeLog = GithubReleaseBody;

if (ui_dialog) {
uiInterface.UpdateMessageBox(client_message_out, static_cast<int>(upgrade_type), ChangeLog);
uiInterface.UpdateMessageBox(client_message_out, static_cast<int>(upgrade_type), change_log);
}

return true;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

//!
Expand Down
23 changes: 23 additions & 0 deletions src/qt/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "qt/decoration.h"
#include "ui_aboutdialog.h"
#include "clientmodel.h"
#include "updatedialog.h"

AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
Expand All @@ -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)
Expand All @@ -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<GRC::Upgrade::UpgradeType>(upgrade_type));
update_dialog.setDetails(QString().fromStdString(change_log));
update_dialog.setModal(false);

update_dialog.exec();
}
1 change: 1 addition & 0 deletions src/qt/aboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AboutDialog : public QDialog

private slots:
void on_buttonBox_accepted();
void handlePressVersionInfoButton();
};

#endif // BITCOIN_QT_ABOUTDIALOG_H
2 changes: 0 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions src/qt/forms/aboutdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,43 @@ This product includes software developed by the OpenSSL Project for use in the O
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="versionInfoButton">
<property name="text">
<string>Version Information</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
3 changes: 2 additions & 1 deletion src/qt/upgradeqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/diagnose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7d9e1f6

Please sign in to comment.