Skip to content

Commit

Permalink
Add system tray notification for new polls
Browse files Browse the repository at this point in the history
This adds a GUI hook that displays a system notification when a node
receives a new poll as well as an accompanying GUI option to disable
those notifications.
  • Loading branch information
cyrossignol committed Jun 9, 2021
1 parent 0d548a5 commit 74de3ed
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "clicklabel.h"
#include "univalue.h"
#include "upgradeqt.h"
#include "voting/votingmodel.h"

#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
Expand Down Expand Up @@ -807,6 +808,12 @@ void BitcoinGUI::setResearcherModel(ResearcherModel *researcherModel)
void BitcoinGUI::setVotingModel(VotingModel *votingModel)
{
votingPage->setVotingModel(votingModel);

if (!votingModel) {
return;
}

connect(votingModel, SIGNAL(newPollReceived()), this, SLOT(handleNewPoll()));
}

void BitcoinGUI::createTrayIcon()
Expand Down Expand Up @@ -1786,6 +1793,20 @@ void BitcoinGUI::updateBeaconIcon()
.arg(researcherModel->formatBeaconStatus()));
}

void BitcoinGUI::handleNewPoll()
{
if (!clientModel || !clientModel->getOptionsModel()) {
return;
}

if (!clientModel->getOptionsModel()->getDisablePollNotifications()) {
notificator->notify(
Notificator::Information,
tr("New Poll"),
tr("A new poll is available. Open Gridcoin to vote."));
}
}

// -----------------------------------------------------------------------------
// Class: ToolbarButtonIconFilter
// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private slots:
QString GetEstimatedStakingFrequency(unsigned int nEstimateTime);

void updateGlobalStatus();
void handleNewPoll();
};

//!
Expand Down
7 changes: 7 additions & 0 deletions src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="disablePollNotifications">
<property name="text">
<string>Disable Poll Notifications</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_Window">
<property name="orientation">
Expand Down
1 change: 1 addition & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void OptionsDialog::setMapper()

/* Window */
mapper->addMapping(ui->disableTransactionNotifications, OptionsModel::DisableTrxNotifications);
mapper->addMapping(ui->disablePollNotifications, OptionsModel::DisablePollNotifications);
#ifndef Q_OS_MAC
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
Expand Down
12 changes: 12 additions & 0 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void OptionsModel::Init()
fStartMin = settings.value("fStartMin", true).toBool();
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
fDisableTrxNotifications = settings.value("fDisableTrxNotifications", false).toBool();
fDisablePollNotifications = settings.value("fDisablePollNotifications", false).toBool();
bDisplayAddresses = settings.value("bDisplayAddresses", false).toBool();
fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool();
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
Expand Down Expand Up @@ -97,6 +98,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return QVariant(fMinimizeToTray);
case DisableTrxNotifications:
return QVariant(fDisableTrxNotifications);
case DisablePollNotifications:
return QVariant(fDisablePollNotifications);
case MapPortUPnP:
return settings.value("fUseUPnP", gArgs.GetBoolArg("-upnp", true));
case MinimizeOnClose:
Expand Down Expand Up @@ -178,6 +181,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
fDisableTrxNotifications = value.toBool();
settings.setValue("fDisableTrxNotifications", fDisableTrxNotifications);
break;
case DisablePollNotifications:
fDisablePollNotifications = value.toBool();
settings.setValue("fDisablePollNotifications", fDisablePollNotifications);
break;
case MapPortUPnP:
fUseUPnP = value.toBool();
settings.setValue("fUseUPnP", fUseUPnP);
Expand Down Expand Up @@ -338,6 +345,11 @@ bool OptionsModel::getDisableTrxNotifications()
return fDisableTrxNotifications;
}

bool OptionsModel::getDisablePollNotifications()
{
return fDisablePollNotifications;
}

bool OptionsModel::getMinimizeOnClose()
{
return fMinimizeOnClose;
Expand Down
3 changes: 3 additions & 0 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class OptionsModel : public QAbstractListModel
MinimizeToTray, // bool
StartMin, // bool
DisableTrxNotifications, // bool
DisablePollNotifications,// bool
MapPortUPnP, // bool
MinimizeOnClose, // bool
ProxyUse, // bool
Expand Down Expand Up @@ -54,6 +55,7 @@ class OptionsModel : public QAbstractListModel
bool getStartMin();
bool getMinimizeToTray();
bool getDisableTrxNotifications();
bool getDisablePollNotifications();
bool getMinimizeOnClose();
int getDisplayUnit();
bool getDisplayAddresses();
Expand All @@ -75,6 +77,7 @@ class OptionsModel : public QAbstractListModel
bool fStartAtStartup;
bool fStartMin;
bool fDisableTrxNotifications;
bool fDisablePollNotifications;
bool bDisplayAddresses;
bool fMinimizeOnClose;
bool fCoinControlFeatures;
Expand Down

0 comments on commit 74de3ed

Please sign in to comment.