Skip to content

Commit

Permalink
Implement custom upgrade notification dialog box
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Feb 11, 2024
1 parent 9ff5510 commit 75b775c
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ QT_FORMS_UI = \
qt/forms/sendcoinsentry.ui \
qt/forms/signverifymessagedialog.ui \
qt/forms/transactiondescdialog.ui \
qt/forms/updatedialog.ui \
qt/forms/voting/additionalfieldstableview.ui \
qt/forms/voting/pollcard.ui \
qt/forms/voting/pollcardview.ui \
Expand Down Expand Up @@ -171,6 +172,7 @@ QT_MOC_CPP = \
qt/moc_transactionfilterproxy.cpp \
qt/moc_transactiontablemodel.cpp \
qt/moc_transactionview.cpp \
qt/moc_updatedialog.cpp \
qt/moc_walletmodel.cpp \
qt/researcher/moc_projecttablemodel.cpp \
qt/researcher/moc_researchermodel.cpp \
Expand Down Expand Up @@ -298,6 +300,7 @@ GRIDCOINRESEARCH_QT_H = \
qt/transactionrecord.h \
qt/transactiontablemodel.h \
qt/transactionview.h \
qt/updatedialog.h \
qt/upgradeqt.h \
qt/voting/additionalfieldstableview.h \
qt/voting/additionalfieldstablemodel.h \
Expand Down Expand Up @@ -388,6 +391,7 @@ GRIDCOINRESEARCH_QT_CPP = \
qt/transactiontablemodel.cpp \
qt/transactionview.cpp \
qt/upgradeqt.cpp \
qt/updatedialog.cpp \
qt/voting/additionalfieldstableview.cpp \
qt/voting/additionalfieldstablemodel.cpp \
qt/voting/poll_types.cpp \
Expand Down
30 changes: 19 additions & 11 deletions src/gridcoin/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ void Upgrade::ScheduledUpdateCheck()
{
std::string VersionResponse = "";

CheckForLatestUpdate(VersionResponse);
Upgrade::UpgradeType upgrade_type {Upgrade::UpgradeType::Unknown};

CheckForLatestUpdate(VersionResponse, upgrade_type);
}

bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, bool ui_dialog, bool snapshotrequest)
bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, 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.
// (Need a way to remove items from scheduler.)
Expand Down Expand Up @@ -95,14 +98,16 @@ bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, bool ui_dial
}

GithubReleaseTypeData = ToLower(GithubReleaseTypeData);
if (GithubReleaseTypeData.find("leisure") != std::string::npos)
if (GithubReleaseTypeData.find("leisure") != std::string::npos) {
GithubReleaseType = _("leisure");

else if (GithubReleaseTypeData.find("mandatory") != std::string::npos)
upgrade_type = Upgrade::UpgradeType::Leisure;
} else if (GithubReleaseTypeData.find("mandatory") != std::string::npos) {
GithubReleaseType = _("mandatory");

else
upgrade_type = Upgrade::UpgradeType::Mandatory;
} else {
GithubReleaseType = _("unknown");
upgrade_type = Upgrade::UpgradeType::Unknown;
}

// Parse version data
std::vector<std::string> GithubVersion;
Expand Down Expand Up @@ -139,10 +144,12 @@ bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, bool ui_dial
if (github_version > LocalVersion[x])
{
NewVersion = true;
if (x < 2)
{
if (x < 2 && upgrade_type == Upgrade::UpgradeType::Mandatory) {
NewMandatory = true;
} else {
upgrade_type = Upgrade::UpgradeType::Unknown;
}

break;
}
}
Expand Down Expand Up @@ -174,7 +181,7 @@ bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, bool ui_dial
std::string ChangeLog = GithubReleaseBody;

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

return NewVersion;
}
Expand All @@ -188,8 +195,9 @@ void Upgrade::SnapshotMain()

// Verify a mandatory release is not available before we continue to snapshot download.
std::string VersionResponse = "";
Upgrade::UpgradeType upgrade_type {Upgrade::UpgradeType::Unknown};

if (CheckForLatestUpdate(VersionResponse, false, true))
if (CheckForLatestUpdate(VersionResponse, upgrade_type, false, true))
{
std::cout << this->ResetBlockchainMessages(UpdateAvailable) << std::endl;
std::cout << this->ResetBlockchainMessages(GithubResponse) << std::endl;
Expand Down
10 changes: 9 additions & 1 deletion src/gridcoin/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class Upgrade
GithubResponse
};

enum UpgradeType {
Unknown,
Leisure,
Mandatory,
Testnet
};

//!
//! \brief Scheduler call to CheckForLatestUpdate
//!
Expand All @@ -133,7 +140,8 @@ class Upgrade
//!
//! \brief Check for latest updates on GitHub.
//!
static bool CheckForLatestUpdate(std::string& client_message_out, bool ui_dialog = true, bool snapshotrequest = false);
static bool CheckForLatestUpdate(std::string& client_message_out, UpgradeType& upgrade_type,
bool ui_dialog = true, bool snapshotrequest = false);

//!
//! \brief Function that will be threaded to download snapshot
Expand Down
2 changes: 1 addition & 1 deletion src/node/ui_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ADD_SIGNALS_IMPL_WRAPPER(UpdateMessageBox);
ADD_SIGNALS_IMPL_WRAPPER(RwSettingsUpdated);

void CClientUIInterface::ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style); }
void CClientUIInterface::UpdateMessageBox(const std::string& version, const std::string& message) { return g_ui_signals.UpdateMessageBox(version, message); }
void CClientUIInterface::UpdateMessageBox(const std::string& version, const int& update_type, const std::string& message) { return g_ui_signals.UpdateMessageBox(version, update_type, message); }
bool CClientUIInterface::ThreadSafeAskFee(int64_t nFeeRequired, const std::string& strCaption) { return g_ui_signals.ThreadSafeAskFee(nFeeRequired, strCaption).value_or(false); }
bool CClientUIInterface::ThreadSafeAskQuestion(std::string caption, std::string body) { return g_ui_signals.ThreadSafeAskQuestion(caption, body).value_or(false); }
void CClientUIInterface::ThreadSafeHandleURI(const std::string& strURI) { return g_ui_signals.ThreadSafeHandleURI(strURI); }
Expand Down
2 changes: 1 addition & 1 deletion src/node/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CClientUIInterface
ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, void, const std::string& message, const std::string& caption, int style);

/** Update notification message box. */
ADD_SIGNALS_DECL_WRAPPER(UpdateMessageBox, void, const std::string& version, const std::string& message);
ADD_SIGNALS_DECL_WRAPPER(UpdateMessageBox, void, const std::string& version, const int& update_type, const std::string& message);

/** Ask the user whether they want to pay a fee or not. */
ADD_SIGNALS_DECL_WRAPPER(ThreadSafeAskFee, bool, int64_t nFeeRequired, const std::string& strCaption);
Expand Down
2 changes: 1 addition & 1 deletion src/noui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static bool noui_ThreadSafeAskFee(int64_t nFeeRequired, const std::string& strCa
return true;
}

static int noui_UpdateMessageBox(const std::string& version, const std::string& message)
static int noui_UpdateMessageBox(const std::string& version, const int& upgrade_type, const std::string& message)
{
std::string caption = _("Gridcoin Update Available");

Expand Down
6 changes: 3 additions & 3 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,16 @@ static void InitMessage(const std::string &message)
}
}

static void UpdateMessageBox(const std::string& version, const std::string& message)
static void UpdateMessageBox(const std::string& version, const int& update_version, const std::string& message)
{
std::string caption = _("Gridcoin Update Available");

if (guiref)
{
std::string guiaddition = version + _("Click \"Show Details\" to view changes in latest update.");
QMetaObject::invokeMethod(guiref, "update", Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdString(caption)),
Q_ARG(QString, QString::fromStdString(guiaddition)),
Q_ARG(QString, QString::fromStdString(version)),
Q_ARG(int, update_version),
Q_ARG(QString, QString::fromStdString(message)));
}

Expand Down
17 changes: 9 additions & 8 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "upgradeqt.h"
#include "voting/votingmodel.h"
#include "voting/polltablemodel.h"
#include "updatedialog.h"

#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
Expand Down Expand Up @@ -1159,22 +1160,22 @@ void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
}
}

void BitcoinGUI::update(const QString &title, const QString& version, const QString &message)
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 QMessageBox);
updateMessageDialog.reset(new UpdateDialog);

updateMessageDialog->setWindowTitle(title);
updateMessageDialog->setText(version);
updateMessageDialog->setDetailedText(message);
updateMessageDialog->setIcon(QMessageBox::Information);
updateMessageDialog->setStandardButtons(QMessageBox::Ok);
updateMessageDialog->setVersion(version);
updateMessageDialog->setUpgradeType(static_cast<GRC::Upgrade::UpgradeType>(upgrade_type));
updateMessageDialog->setDetails(message);
updateMessageDialog->setModal(false);
connect(updateMessageDialog.get(), &QMessageBox::finished, [this](int) { updateMessageDialog.reset(); });

connect(updateMessageDialog.get(), &QDialog::finished, this, [this]() { updateMessageDialog.reset(); });

// Due to slight delay in gui load this could appear behind the gui ui
// The only other option available would make the message box stay on top of all applications

QTimer::singleShot(5000, updateMessageDialog.get(), [this]() { updateMessageDialog->show(); });
}

Expand Down
5 changes: 3 additions & 2 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Notificator;
class RPCConsole;
class DiagnosticsDialog;
class ClickLabel;
class UpdateDialog;

QT_BEGIN_NAMESPACE
class QLabel;
Expand Down Expand Up @@ -110,7 +111,7 @@ class BitcoinGUI : public QMainWindow
TransactionView *transactionView;
VotingPage *votingPage;
SignVerifyMessageDialog *signVerifyMessageDialog;
std::unique_ptr<QMessageBox> updateMessageDialog;
std::unique_ptr<UpdateDialog> updateMessageDialog;

QLabel *statusbarAlertsLabel;
QLabel *labelEncryptionIcon;
Expand Down Expand Up @@ -205,7 +206,7 @@ public slots:
void setEncryptionStatus(int status);

/** Notify the user if there is an update available */
void update(const QString& title, const QString& version, const QString& message);
void update(const QString& title, const QString& version, const int& upgrade_type, const QString& message);

/** Notify the user of an error in the network or transaction handling code. */
void error(const QString &title, const QString &message, bool modal);
Expand Down
85 changes: 85 additions & 0 deletions src/qt/forms/updatedialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpdateDialog</class>
<widget class="QDialog" name="UpdateDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>609</width>
<height>430</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="1">
<widget class="QLabel" name="versionData">
<property name="text">
<string>version</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="infoIcon">
<property name="text">
<string>icon</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="versionDetails"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UpdateDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UpdateDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
55 changes: 55 additions & 0 deletions src/qt/updatedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2014-2024 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "updatedialog.h"
#include "qicon.h"
#include "qstyle.h"
#include "qt/decoration.h"

#include "ui_updatedialog.h"

UpdateDialog::UpdateDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::UpdateDialog)
{
ui->setupUi(this);

resize(GRC::ScaleSize(this, width(), height()));
}

UpdateDialog::~UpdateDialog()
{
delete ui;
}

void UpdateDialog::setVersion(QString version)
{
ui->versionData->setText(version);
}

void UpdateDialog::setDetails(QString message)
{
ui->versionDetails->setText(message);
}

void UpdateDialog::setUpgradeType(GRC::Upgrade::UpgradeType upgrade_type)
{
QIcon info_icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
QIcon warning_icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
QIcon unkown_icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion);

switch (upgrade_type) {
case GRC::Upgrade::UpgradeType::Mandatory:
ui->infoIcon->setPixmap(GRC::ScaleIcon(this, warning_icon, 48));
break;
case GRC::Upgrade::UpgradeType::Leisure:
[[fallthrough]];
case GRC::Upgrade::UpgradeType::Testnet:
ui->infoIcon->setPixmap(GRC::ScaleIcon(this, info_icon, 48));
break;
case GRC::Upgrade::Unknown:
ui->infoIcon->setPixmap(GRC::ScaleIcon(this, unkown_icon, 48));
break;
}
}
Loading

0 comments on commit 75b775c

Please sign in to comment.