Skip to content

Commit

Permalink
qt: Add privacy feature to Overview page
Browse files Browse the repository at this point in the history
Backport of the following Bitcoin upstream commits:

- bitcoin/bitcoin@8d75115
- bitcoin/bitcoin@73d8ef7

Note that connect statements in this commit using new Qt5 connect syntax,
so as "TODO" we might want to switch to the new syntax everywhere, like
this:

- bitcoin/bitcoin@f78558f
  • Loading branch information
DeckerSU committed Jan 27, 2022
1 parent 8306553 commit 72aa41e
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/qt/komodooceangui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ void KomodoOceanGUI::createActions()
showHelpMessageAction->setMenuRole(QAction::NoRole);
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Komodo command-line options").arg(tr(PACKAGE_NAME)));

m_mask_values_action = new QAction(tr("&Mask values"), this);
m_mask_values_action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_M));
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
m_mask_values_action->setCheckable(true);

connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
Expand All @@ -420,6 +425,7 @@ void KomodoOceanGUI::createActions()
connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses()));
connect(usedReceivingZAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingZAddresses()));
connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked()));
connect(m_mask_values_action, &QAction::toggled, this, &KomodoOceanGUI::setPrivacy);
}
#endif // ENABLE_WALLET

Expand Down Expand Up @@ -459,6 +465,8 @@ void KomodoOceanGUI::createMenuBar()
settings->addAction(encryptWalletAction);
settings->addAction(changePassphraseAction);
settings->addSeparator();
settings->addAction(m_mask_values_action);
settings->addSeparator();
}
settings->addAction(optionsAction);

Expand Down Expand Up @@ -1242,6 +1250,12 @@ void KomodoOceanGUI::toggleNetworkActive()
}
}

bool KomodoOceanGUI::isPrivacyModeActivated() const
{
assert(m_mask_values_action);
return m_mask_values_action->isChecked();
}

UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
optionsModel(0),
menu(0)
Expand Down
4 changes: 4 additions & 0 deletions src/qt/komodooceangui.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class KomodoOceanGUI : public QMainWindow
The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
*/
void setClientModel(ClientModel *clientModel);
bool isPrivacyModeActivated() const;

#ifdef ENABLE_WALLET
/** Set the wallet model.
Expand Down Expand Up @@ -114,6 +115,7 @@ class KomodoOceanGUI : public QMainWindow
QAction *openRPCConsoleAction;
QAction *openAction;
QAction *showHelpMessageAction;
QAction *m_mask_values_action;

QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
Expand Down Expand Up @@ -156,6 +158,8 @@ class KomodoOceanGUI : public QMainWindow
/** Signal raised when a URI was entered or dragged to the GUI */
void receivedURI(const QString &uri);

void setPrivacy(bool privacy);

public Q_SLOTS:
/** Set number of connections shown in the UI */
void setNumConnections(int count);
Expand Down
12 changes: 11 additions & 1 deletion src/qt/komodounits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ QString KomodoUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorS
qint64 remainder = n_abs % coin;
QString quotient_str = QString::number(quotient);
QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');

// Use SI-style thin space separators as these are locale independent and can't be
// confused with the decimal marker.
QChar thin_sp(THIN_SP_CP);
Expand Down Expand Up @@ -135,6 +134,17 @@ QString KomodoUnits::formatHtmlWithUnit(int unit, const CAmount& amount, bool pl
return QString("<span style='white-space: nowrap;'>%1</span>").arg(str);
}

QString KomodoUnits::formatWithPrivacy(int unit, const CAmount& amount, SeparatorStyle separators, bool privacy)
{
assert(amount >= 0);
QString value;
if (privacy) {
value = format(unit, 0, false, separators).replace('0', '#');
} else {
value = format(unit, amount, false, separators);
}
return value + QString(" ") + name(unit);
}

bool KomodoUnits::parse(int unit, const QString &value, CAmount *val_out)
{
Expand Down
2 changes: 2 additions & 0 deletions src/qt/komodounits.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class KomodoUnits: public QAbstractListModel
static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
//! Format as HTML string (with unit)
static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
//! Format as string (with unit) of fixed length to preserve privacy, if it is set.
static QString formatWithPrivacy(int unit, const CAmount& amount, SeparatorStyle separators, bool privacy);
//! Parse string to coin amount
static bool parse(int unit, const QString &value, CAmount *val_out);
//! Gets title for amount column including current display unit if optionsModel reference available */
Expand Down
42 changes: 31 additions & 11 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include "util.h" // for KOMODO_ASSETCHAIN_MAXLEN

#include <QAbstractItemDelegate>
#include <QApplication>
#include <QPainter>
#include <QStatusTipEvent>

#define DECORATION_SIZE 54
#define NUM_ITEMS 5
Expand Down Expand Up @@ -159,6 +161,24 @@ void OverviewPage::handleOutOfSyncWarningClicks()
Q_EMIT outOfSyncWarningClicked();
}

void OverviewPage::setPrivacy(bool privacy)
{
m_privacy = privacy;

if (currentBalance != -1) {
setBalance(currentBalance, currentUnconfirmedBalance, currentImmatureBalance,
currentWatchOnlyBalance, currentWatchUnconfBalance, currentWatchImmatureBalance,
currentPrivateBalance, currentInterestBalance);
}

ui->listTransactions->setVisible(!m_privacy);

const QString status_tip = m_privacy ? tr("Privacy mode activated for the Overview tab. To unmask the values, uncheck Settings->Mask values.") : "";
setStatusTip(status_tip);
QStatusTipEvent event(status_tip);
QApplication::sendEvent(this, &event);
}

OverviewPage::~OverviewPage()
{
delete ui;
Expand All @@ -175,17 +195,17 @@ void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmed
currentWatchImmatureBalance = watchImmatureBalance;
currentPrivateBalance = privateBalance;
currentInterestBalance = interestBalance;
ui->labelBalance->setText(KomodoUnits::formatWithUnit(unit, balance, false, KomodoUnits::separatorAlways));
ui->labelUnconfirmed->setText(KomodoUnits::formatWithUnit(unit, unconfirmedBalance, false, KomodoUnits::separatorAlways));
ui->labelImmature->setText(KomodoUnits::formatWithUnit(unit, immatureBalance, false, KomodoUnits::separatorAlways));
ui->labelTotal->setText(KomodoUnits::formatWithUnit(unit, balance + unconfirmedBalance + immatureBalance + privateBalance + interestBalance, false, KomodoUnits::separatorAlways));
ui->labelWatchAvailable->setText(KomodoUnits::formatWithUnit(unit, watchOnlyBalance, false, KomodoUnits::separatorAlways));
ui->labelWatchPending->setText(KomodoUnits::formatWithUnit(unit, watchUnconfBalance, false, KomodoUnits::separatorAlways));
ui->labelWatchImmature->setText(KomodoUnits::formatWithUnit(unit, watchImmatureBalance, false, KomodoUnits::separatorAlways));
ui->labelWatchTotal->setText(KomodoUnits::formatWithUnit(unit, watchOnlyBalance + watchUnconfBalance + watchImmatureBalance, false, KomodoUnits::separatorAlways));

ui->labelPrivateBalance->setText(KomodoUnits::formatWithUnit(unit, privateBalance, false, KomodoUnits::separatorAlways));
ui->labelInterestBalance->setText(KomodoUnits::formatWithUnit(unit, interestBalance, false, KomodoUnits::separatorAlways));
ui->labelBalance->setText(KomodoUnits::formatWithPrivacy(unit, balance, KomodoUnits::separatorAlways, m_privacy));
ui->labelUnconfirmed->setText(KomodoUnits::formatWithPrivacy(unit, unconfirmedBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelImmature->setText(KomodoUnits::formatWithPrivacy(unit, immatureBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelTotal->setText(KomodoUnits::formatWithPrivacy(unit, balance + unconfirmedBalance + immatureBalance + privateBalance + interestBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelWatchAvailable->setText(KomodoUnits::formatWithPrivacy(unit, watchOnlyBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelWatchPending->setText(KomodoUnits::formatWithPrivacy(unit, watchUnconfBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelWatchImmature->setText(KomodoUnits::formatWithPrivacy(unit, watchImmatureBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelWatchTotal->setText(KomodoUnits::formatWithPrivacy(unit, watchOnlyBalance + watchUnconfBalance + watchImmatureBalance, KomodoUnits::separatorAlways, m_privacy));

ui->labelPrivateBalance->setText(KomodoUnits::formatWithPrivacy(unit, privateBalance, KomodoUnits::separatorAlways, m_privacy));
ui->labelInterestBalance->setText(KomodoUnits::formatWithPrivacy(unit, interestBalance, KomodoUnits::separatorAlways, m_privacy));

// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
// for the non-mining users
Expand Down
3 changes: 3 additions & 0 deletions src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public Q_SLOTS:
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance,
const CAmount& privateBalance, const CAmount& interestBalance);
void setPrivacy(bool privacy);

Q_SIGNALS:
void transactionClicked(const QModelIndex &index);
Expand All @@ -62,6 +63,8 @@ public Q_SLOTS:
TxViewDelegate *txdelegate;
std::unique_ptr<TransactionFilterProxy> filter;

bool m_privacy{false};

private Q_SLOTS:
void updateDisplayUnit();
void handleTransactionClicked(const QModelIndex &index);
Expand Down
3 changes: 3 additions & 0 deletions src/qt/walletframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
walletView->setClientModel(clientModel);
walletView->setWalletModel(walletModel);
walletView->showOutOfSyncWarning(bOutOfSync);
walletView->setPrivacy(gui->isPrivacyModeActivated());

/* TODO we should goto the currently selected page once dynamically adding wallets is supported */
walletView->gotoOverviewPage();
Expand All @@ -60,6 +61,8 @@ bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)

connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));

connect(gui, &KomodoOceanGUI::setPrivacy, walletView, &WalletView::setPrivacy);

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
connect(zsendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
// Pass through messages from transactionView
connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));

connect(this, &WalletView::setPrivacy, overviewPage, &OverviewPage::setPrivacy);
}

WalletView::~WalletView()
Expand Down
2 changes: 2 additions & 0 deletions src/qt/walletview.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public Q_SLOTS:
void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label);
/** Notify that the out of sync warning icon has been pressed */
void outOfSyncWarningClicked();

void setPrivacy(bool privacy);
};

#endif // KOMODO_QT_WALLETVIEW_H

0 comments on commit 72aa41e

Please sign in to comment.