Skip to content

Commit

Permalink
qt: Add privacy feature to Overview page
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#16432
Rebased-From: ea1fb69
  • Loading branch information
hebasto authored and luke-jr committed Apr 3, 2020
1 parent 62c81dc commit 2c05389
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 23 deletions.
14 changes: 14 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ void BitcoinGUI::createActions()
showHelpMessageAction->setMenuRole(QAction::NoRole);
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(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("Cloak values on Overview tab"));
m_mask_values_action->setCheckable(true);

connect(quitAction, &QAction::triggered, qApp, QApplication::quit);
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
Expand Down Expand Up @@ -409,6 +414,8 @@ void BitcoinGUI::createActions()
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
activity->create();
});

connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
}
#endif // ENABLE_WALLET

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

Expand Down Expand Up @@ -1390,6 +1399,11 @@ void BitcoinGUI::unsubscribeFromCoreSignals()
m_handler_question->disconnect();
}

bool BitcoinGUI::isPrivacyModeActivated() const
{
return m_mask_values_action && m_mask_values_action->isChecked();
}

UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
optionsModel(nullptr),
menu(nullptr)
Expand Down
4 changes: 4 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class BitcoinGUI : public QMainWindow
/** Disconnect core signals from GUI client */
void unsubscribeFromCoreSignals();

bool isPrivacyModeActivated() const;

protected:
void changeEvent(QEvent *e);
void closeEvent(QCloseEvent *event);
Expand Down Expand Up @@ -153,6 +155,7 @@ class BitcoinGUI : public QMainWindow
QAction* m_close_wallet_action{nullptr};
QAction* m_wallet_selector_label_action = nullptr;
QAction* m_wallet_selector_action = nullptr;
QAction* m_mask_values_action{nullptr};

QLabel *m_wallet_selector_label = nullptr;
QComboBox* m_wallet_selector = nullptr;
Expand Down Expand Up @@ -205,6 +208,7 @@ class BitcoinGUI : public QMainWindow
void receivedURI(const QString &uri);
/** Signal raised when RPC console shown */
void consoleShown(RPCConsole* console);
void setPrivacy(bool privacy);

public Q_SLOTS:
/** Set number of connections shown in the UI */
Expand Down
28 changes: 18 additions & 10 deletions src/qt/forms/overviewpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>596</width>
<height>342</height>
<width>798</width>
<height>318</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -118,6 +118,7 @@
<widget class="QLabel" name="labelWatchPending">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -129,7 +130,7 @@
<string>Unconfirmed transactions to watch-only addresses</string>
</property>
<property name="text">
<string notr="true">0.000 000 00 BTC</string>
<string notr="true">0.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand All @@ -143,6 +144,7 @@
<widget class="QLabel" name="labelUnconfirmed">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -154,7 +156,7 @@
<string>Total of transactions that have yet to be confirmed, and do not yet count toward the spendable balance</string>
</property>
<property name="text">
<string notr="true">0.000 000 00 BTC</string>
<string notr="true">0.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand All @@ -168,6 +170,7 @@
<widget class="QLabel" name="labelWatchImmature">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -179,7 +182,7 @@
<string>Mined balance in watch-only addresses that has not yet matured</string>
</property>
<property name="text">
<string notr="true">0.000 000 00 BTC</string>
<string notr="true">0.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -226,6 +229,7 @@
<widget class="QLabel" name="labelImmature">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -237,7 +241,7 @@
<string>Mined balance that has not yet matured</string>
</property>
<property name="text">
<string notr="true">0.000 000 00 BTC</string>
<string notr="true">0.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -271,6 +275,7 @@
<widget class="QLabel" name="labelTotal">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -282,7 +287,7 @@
<string>Your current total balance</string>
</property>
<property name="text">
<string notr="true">0.000000 00 BTC</string>
<string notr="true">21 000 000.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand All @@ -296,6 +301,7 @@
<widget class="QLabel" name="labelWatchTotal">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -307,7 +313,7 @@
<string>Current total balance in watch-only addresses</string>
</property>
<property name="text">
<string notr="true">0.000000 00 BTC</string>
<string notr="true">21 000 000.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -338,6 +344,7 @@
<widget class="QLabel" name="labelBalance">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -349,7 +356,7 @@
<string>Your current spendable balance</string>
</property>
<property name="text">
<string notr="true">0.000000 00 BTC</string>
<string notr="true">21 000 000.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand All @@ -363,6 +370,7 @@
<widget class="QLabel" name="labelWatchAvailable">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
Expand All @@ -374,7 +382,7 @@
<string>Your current balance in watch-only addresses</string>
</property>
<property name="text">
<string notr="true">0.000000 00 BTC</string>
<string notr="true">21 000 000.00000000 BTC</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down
43 changes: 31 additions & 12 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <qt/walletmodel.h>

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

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

void OverviewPage::setPrivacy(bool privacy)
{
m_privacy = privacy;
if (walletModel && walletModel->getOptionsModel()) {
if (m_balances.balance != -1) {
setBalance(m_balances);
}

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

const QString status_tip = m_privacy ? tr("PRIVACY mode is activated. To reveal cloaked values uncheck Menu->Settings->Mask values") : "";
setStatusTip(status_tip);
QStatusTipEvent event(status_tip);
QApplication::sendEvent(this, &event);
}

OverviewPage::~OverviewPage()
{
delete ui;
Expand All @@ -162,19 +181,19 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
int unit = walletModel->getOptionsModel()->getDisplayUnit();
m_balances = balances;
if (walletModel->wallet().privateKeysDisabled()) {
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
} else {
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.balance, false, BitcoinUnits::separatorAlways));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_balance, false, BitcoinUnits::separatorAlways));
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_balance, false, BitcoinUnits::separatorAlways));
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelWatchPending->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelWatchImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
ui->labelWatchTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, BitcoinUnits::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
2 changes: 2 additions & 0 deletions src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class OverviewPage : public QWidget

public Q_SLOTS:
void setBalance(const interfaces::WalletBalances& balances);
void setPrivacy(bool privacy);

Q_SIGNALS:
void transactionClicked(const QModelIndex &index);
Expand All @@ -49,6 +50,7 @@ public Q_SLOTS:
ClientModel *clientModel;
WalletModel *walletModel;
interfaces::WalletBalances m_balances;
bool m_privacy{false};

TxViewDelegate *txdelegate;
std::unique_ptr<TransactionFilterProxy> filter;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void TestGUI(interfaces::Node& node)
OverviewPage overviewPage(platformStyle.get());
overviewPage.setWalletModel(&walletModel);
QLabel* balanceLabel = overviewPage.findChild<QLabel*>("labelBalance");
QString balanceText = balanceLabel->text();
QString balanceText = balanceLabel->text().trimmed();
int unit = walletModel.getOptionsModel()->getDisplayUnit();
CAmount balance = walletModel.wallet().getBalance();
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
Expand Down
10 changes: 10 additions & 0 deletions src/qt/walletframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
} else {
walletView->gotoOverviewPage();
}
walletView->setPrivacy(gui->isPrivacyModeActivated());

walletStack->addWidget(walletView);
mapWalletViews[walletModel] = walletView;
Expand All @@ -74,6 +75,8 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
connect(walletView, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
connect(walletView, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);

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

return true;
}

Expand Down Expand Up @@ -121,6 +124,13 @@ void WalletFrame::showOutOfSyncWarning(bool fShow)
i.value()->showOutOfSyncWarning(fShow);
}

void WalletFrame::setPrivacy(const bool nv)
{
for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
i.value()->setPrivacy(nv);
}
}

void WalletFrame::gotoOverviewPage()
{
QMap<WalletModel*, WalletView*>::const_iterator i;
Expand Down
1 change: 1 addition & 0 deletions src/qt/walletframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class WalletFrame : public QFrame
WalletModel* currentWalletModel() const;

public Q_SLOTS:
void setPrivacy(bool);
/** Switch to overview (home) page */
void gotoOverviewPage();
/** Switch to history (transactions) page */
Expand Down
5 changes: 5 additions & 0 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int
Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, GUIUtil::HtmlEscape(walletModel->getWalletName()));
}

void WalletView::setPrivacy(const bool nv)
{
overviewPage->setPrivacy(nv);
}

void WalletView::gotoOverviewPage()
{
setCurrentWidget(overviewPage);
Expand Down
1 change: 1 addition & 0 deletions src/qt/walletview.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class WalletView : public QStackedWidget
const PlatformStyle *platformStyle;

public Q_SLOTS:
void setPrivacy(bool);
/** Switch to overview (home) page */
void gotoOverviewPage();
/** Switch to history (transactions) page */
Expand Down

0 comments on commit 2c05389

Please sign in to comment.