Skip to content

Commit 1b1cdbb

Browse files
committed
Implement GUI overview screen value masking
1 parent c5c37ee commit 1b1cdbb

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed

src/qt/bitcoingui.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ void BitcoinGUI::createActions()
408408
resetblockchainAction = new QAction(tr("&Reset blockchain data"), this);
409409
resetblockchainAction->setToolTip(tr("Remove blockchain data and start chain from zero"));
410410

411+
m_mask_values_action = new QAction(tr("&Mask values"), this);
412+
m_mask_values_action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_M));
413+
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview screen"));
414+
m_mask_values_action->setCheckable(true);
415+
411416
connect(quitAction, &QAction::triggered, this, &BitcoinGUI::tryQuit);
412417
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
413418
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
@@ -554,6 +559,8 @@ void BitcoinGUI::createMenuBar()
554559
settings->addSeparator();
555560
settings->addAction(optionsAction);
556561
settings->addAction(openConfigAction);
562+
settings->addSeparator();
563+
settings->addAction(m_mask_values_action);
557564

558565
QMenu *community = appMenuBar->addMenu(tr("&Community"));
559566
community->addAction(bxAction);
@@ -758,6 +765,13 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
758765
// Report errors from network/worker thread
759766
connect(clientModel, &ClientModel::error, this, &BitcoinGUI::error);
760767

768+
// Ensure the checkbox for mask values action matches the retrieved state from the optionsModel.
769+
m_mask_values_action->setChecked(isPrivacyModeActivated());
770+
771+
// Connect the action to the setPrivacy function. (This has to be done after the setting of the
772+
// checkbox state instead of in the createActions above.
773+
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
774+
761775
rpcConsole->setClientModel(clientModel);
762776
addressBookPage->setOptionsModel(clientModel->getOptionsModel());
763777
receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
@@ -839,6 +853,13 @@ void BitcoinGUI::createTrayIcon()
839853
notificator = new Notificator(qApp->applicationName(), trayIcon, this);
840854
}
841855

856+
bool BitcoinGUI::isPrivacyModeActivated() const
857+
{
858+
if (!clientModel || !clientModel->getOptionsModel()) return false;
859+
860+
return clientModel->getOptionsModel()->getMaskValues();
861+
}
862+
842863
void BitcoinGUI::createTrayIconMenu()
843864
{
844865
#ifndef Q_OS_MAC
@@ -1278,6 +1299,15 @@ void BitcoinGUI::resetblockchainClicked()
12781299
}
12791300
}
12801301

1302+
void BitcoinGUI::setPrivacy()
1303+
{
1304+
if (!clientModel || !clientModel->getOptionsModel()) return;
1305+
1306+
bool privacy_mode(!clientModel->getOptionsModel()->getMaskValues());
1307+
1308+
clientModel->getOptionsModel()->setMaskValues(privacy_mode);
1309+
}
1310+
12811311
bool BitcoinGUI::tryQuit()
12821312
{
12831313
if(clientModel &&

src/qt/bitcoingui.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class BitcoinGUI : public QMainWindow
7272
*/
7373
void setVotingModel(VotingModel *votingModel);
7474

75+
/**
76+
* @brief Queries the state of privacy mode (mask values on overview screen).
77+
* @return boolean of the mask values state
78+
*/
79+
bool isPrivacyModeActivated() const;
80+
7581
protected:
7682
void changeEvent(QEvent *e);
7783
void closeEvent(QCloseEvent *event);
@@ -140,6 +146,7 @@ class BitcoinGUI : public QMainWindow
140146
QAction *openRPCConsoleAction;
141147
QAction *snapshotAction;
142148
QAction *resetblockchainAction;
149+
QAction *m_mask_values_action;
143150

144151
QSystemTrayIcon *trayIcon;
145152
QMenu *trayIconMenu;
@@ -244,6 +251,7 @@ private slots:
244251
void peersClicked();
245252
void snapshotClicked();
246253
void resetblockchainClicked();
254+
void setPrivacy();
247255
bool tryQuit();
248256

249257
#ifndef Q_OS_MAC

src/qt/overviewpage.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include "gridcoin/voting/fwd.h"
2020

2121
#include <QAbstractItemDelegate>
22+
#include <QApplication>
2223
#include <QPainter>
24+
#include <QStatusTipEvent>
2325

2426
#define DECORATION_SIZE 40
2527

@@ -262,12 +264,13 @@ void OverviewPage::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBa
262264
currentStake = stake;
263265
currentUnconfirmedBalance = unconfirmedBalance;
264266
currentImmatureBalance = immatureBalance;
265-
ui->headerBalanceLabel->setText(BitcoinUnits::formatOverviewRounded(balance));
266-
ui->balanceLabel->setText(BitcoinUnits::formatWithUnit(unit, balance));
267-
ui->stakeLabel->setText(BitcoinUnits::formatWithUnit(unit, stake));
268-
ui->unconfirmedLabel->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance));
269-
ui->immatureLabel->setText(BitcoinUnits::formatWithUnit(unit, immatureBalance));
270-
ui->totalLabel->setText(BitcoinUnits::formatWithUnit(unit, balance + stake + unconfirmedBalance + immatureBalance));
267+
ui->headerBalanceLabel->setText(BitcoinUnits::formatOverviewRounded(balance, m_privacy));
268+
ui->balanceLabel->setText(BitcoinUnits::formatWithPrivacy(unit, balance, m_privacy));
269+
ui->stakeLabel->setText(BitcoinUnits::formatWithPrivacy(unit, stake, m_privacy));
270+
ui->unconfirmedLabel->setText(BitcoinUnits::formatWithPrivacy(unit, unconfirmedBalance, m_privacy));
271+
ui->immatureLabel->setText(BitcoinUnits::formatWithPrivacy(unit, immatureBalance, m_privacy));
272+
ui->totalLabel->setText(BitcoinUnits::formatWithPrivacy(unit, balance + stake + unconfirmedBalance + immatureBalance,
273+
m_privacy));
271274

272275
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
273276
// for the non-mining users
@@ -297,6 +300,27 @@ void OverviewPage::setCurrentPollTitle(const QString& title)
297300
ui->currentPollsTitleLabel->setText(title);
298301
}
299302

303+
void OverviewPage::setPrivacy(bool privacy)
304+
{
305+
m_privacy = privacy;
306+
if (currentBalance != -1) {
307+
setBalance(currentBalance, currentStake, currentUnconfirmedBalance, currentImmatureBalance);
308+
}
309+
310+
ui->listTransactions->setVisible(!m_privacy);
311+
ui->coinWeightTextLabel->setVisible(!m_privacy);
312+
ui->coinWeightLabel->setVisible(!m_privacy);
313+
314+
const QString status_tip = m_privacy ? tr("Privacy mode activated for the Overview screen. To unmask the values, uncheck "
315+
"Settings->Mask values.") : "";
316+
317+
updateTransactions();
318+
319+
setStatusTip(status_tip);
320+
QStatusTipEvent event(status_tip);
321+
QApplication::sendEvent(this, &event);
322+
}
323+
300324
void OverviewPage::setResearcherModel(ResearcherModel *researcherModel)
301325
{
302326
this->researcherModel = researcherModel;
@@ -337,6 +361,12 @@ void OverviewPage::setWalletModel(WalletModel *model)
337361

338362
connect(model->getOptionsModel(), &OptionsModel::LimitTxnDisplayChanged, this, &OverviewPage::updateTransactions);
339363
connect(model, &WalletModel::transactionUpdated, this, &OverviewPage::updateTransactions);
364+
365+
// Set the privacy state for the overview screen from the optionsModel for init.
366+
setPrivacy(model->getOptionsModel()->getMaskValues());
367+
368+
// Connect the privacy mode setting to the options dialog.
369+
connect(walletModel->getOptionsModel(), &OptionsModel::MaskValuesChanged, this, & OverviewPage::setPrivacy);
340370
}
341371

342372
// update the display unit, to not use the default ("BTC")

src/qt/overviewpage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public slots:
3535
void setDifficulty(double difficulty, double net_weight);
3636
void setCoinWeight(double coin_weight);
3737
void setCurrentPollTitle(const QString& title);
38+
void setPrivacy(bool privacy);
3839

3940
signals:
4041
void transactionClicked(const QModelIndex &index);
@@ -55,6 +56,7 @@ public slots:
5556
qint64 currentUnconfirmedBalance;
5657
qint64 currentImmatureBalance;
5758
int scaledDecorationSize;
59+
bool m_privacy = false;
5860

5961
TxViewDelegate *txdelegate;
6062
std::unique_ptr<TransactionFilterProxy> filter;

0 commit comments

Comments
 (0)