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 baa544b commit ba2fd60
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 40 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
50 changes: 30 additions & 20 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,18 @@ 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
// This will be confirmed below by also checking the second position version. If not incremented, then it will
// be set to unknown.
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,23 +146,24 @@ 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;
}
}
}
catch (std::exception& ex)
{
} catch (std::exception& ex) {
error("%s: Exception occurred checking client version against GitHub version (%s)",
__func__, ToString(ex.what()));

return false;
}

if (!NewVersion) return NewVersion;
if (!NewVersion) return false;

// New version was found
client_message_out = _("Local version: ") + strprintf("%d.%d.%d.%d", CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR,
Expand All @@ -164,19 +172,20 @@ bool Upgrade::CheckForLatestUpdate(std::string& client_message_out, bool ui_dial
client_message_out.append(_("This update is ") + GithubReleaseType + "\r\n\r\n");

// For snapshot requests we will handle things differently after this point
if (snapshotrequest && NewMandatory)
return NewVersion;
if (snapshotrequest && NewMandatory) return true;

if (NewMandatory)
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, ChangeLog);
if (ui_dialog) {
uiInterface.UpdateMessageBox(client_message_out, static_cast<int>(upgrade_type), ChangeLog);
}

return NewVersion;
return true;
}

void Upgrade::SnapshotMain()
Expand All @@ -188,8 +197,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
1 change: 1 addition & 0 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ add_library(gridcoinqt STATIC
transactionrecord.cpp
transactiontablemodel.cpp
transactionview.cpp
updatedialog.cpp
upgradeqt.cpp
voting/additionalfieldstableview.cpp
voting/additionalfieldstablemodel.cpp
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
98 changes: 98 additions & 0 deletions src/qt/forms/updatedialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?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="0">
<widget class="QLabel" name="infoIcon">
<property name="text">
<string>icon</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="versionData">
<property name="text">
<string>version</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="versionDetails">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="placeholderText">
<string>changelog</string>
</property>
</widget>
</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>
Loading

0 comments on commit ba2fd60

Please sign in to comment.