Skip to content

Commit

Permalink
Merge pull request dashpay#5796 from knst/bp-v21-qt-1
Browse files Browse the repository at this point in the history
backport: bitcoin#15202, bitcoin#15768, bitcoin#16432, bitcoin#17597 (Qt dash core wallet improvements)
  • Loading branch information
PastaPastaPasta authored Jan 7, 2024
2 parents 0e314fe + 2cda5f5 commit 8be260a
Show file tree
Hide file tree
Showing 29 changed files with 448 additions and 146 deletions.
2 changes: 2 additions & 0 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ AddressBookPage::AddressBookPage(Mode _mode, Tabs _tab, QWidget* parent) :
GUIUtil::updateFonts();

GUIUtil::disableMacFocusRect(this);

GUIUtil::handleCloseWindowShortcut(this);
}

AddressBookPage::~AddressBookPage()
Expand Down
2 changes: 2 additions & 0 deletions src/qt/askpassphrasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent, SecureStri
connect(ui->passEdit1, &QLineEdit::textChanged, this, &AskPassphraseDialog::textChanged);
connect(ui->passEdit2, &QLineEdit::textChanged, this, &AskPassphraseDialog::textChanged);
connect(ui->passEdit3, &QLineEdit::textChanged, this, &AskPassphraseDialog::textChanged);

GUIUtil::handleCloseWindowShortcut(this);
}

AskPassphraseDialog::~AskPassphraseDialog()
Expand Down
25 changes: 25 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle,
});
timerCustomCss->start(200);
}

GUIUtil::handleCloseWindowShortcut(this);
}

BitcoinGUI::~BitcoinGUI()
Expand Down Expand Up @@ -445,6 +447,9 @@ void BitcoinGUI::createActions()
m_create_wallet_action->setEnabled(false);
m_create_wallet_action->setStatusTip(tr("Create a new wallet"));

m_close_all_wallets_action = new QAction(tr("Close All Wallets..."), this);
m_close_all_wallets_action->setStatusTip(tr("Close all wallets"));

showHelpMessageAction = new QAction(tr("&Command-line options"), this);
showHelpMessageAction->setMenuRole(QAction::NoRole);
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Dash command-line options").arg(PACKAGE_NAME));
Expand All @@ -453,6 +458,11 @@ void BitcoinGUI::createActions()
showCoinJoinHelpAction->setMenuRole(QAction::NoRole);
showCoinJoinHelpAction->setStatusTip(tr("Show the %1 basic information").arg(strCoinJoinName));

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, &QAction::triggered, qApp, QApplication::quit);
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
Expand Down Expand Up @@ -532,6 +542,11 @@ void BitcoinGUI::createActions()
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
activity->create();
});
connect(m_close_all_wallets_action, &QAction::triggered, [this] {
m_wallet_controller->closeAllWallets(this);
});

connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
}
#endif // ENABLE_WALLET
}
Expand All @@ -553,6 +568,7 @@ void BitcoinGUI::createMenuBar()
file->addAction(m_create_wallet_action);
file->addAction(m_open_wallet_action);
file->addAction(m_close_wallet_action);
file->addAction(m_close_all_wallets_action);
file->addSeparator();
file->addAction(openAction);
file->addAction(backupWalletAction);
Expand All @@ -576,6 +592,8 @@ void BitcoinGUI::createMenuBar()
settings->addAction(unlockWalletAction);
settings->addAction(lockWalletAction);
settings->addSeparator();
settings->addAction(m_mask_values_action);
settings->addSeparator();
}
settings->addAction(optionsAction);

Expand Down Expand Up @@ -972,6 +990,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
usedReceivingAddressesAction->setEnabled(enabled);
openAction->setEnabled(enabled);
m_close_wallet_action->setEnabled(enabled);
m_close_all_wallets_action->setEnabled(enabled);
}

void BitcoinGUI::createTrayIcon()
Expand Down Expand Up @@ -1999,6 +2018,12 @@ void BitcoinGUI::handleRestart(QStringList args)
Q_EMIT requestedRestart(args);
}

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

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

bool isPrivacyModeActivated() const;

protected:
void changeEvent(QEvent *e) override;
void closeEvent(QCloseEvent *event) override;
Expand Down Expand Up @@ -171,7 +173,9 @@ class BitcoinGUI : public QMainWindow
QMenu* m_open_wallet_menu{nullptr};
QAction* m_close_wallet_action{nullptr};
QAction* showCoinJoinHelpAction = nullptr;
QAction* m_close_all_wallets_action{nullptr};
QAction* m_wallet_selector_action = nullptr;
QAction* m_mask_values_action{nullptr};

QComboBox* m_wallet_selector = nullptr;

Expand Down Expand Up @@ -252,6 +256,7 @@ class BitcoinGUI : public QMainWindow
void consoleShown(RPCConsole* console);
/** Restart handling */
void requestedRestart(QStringList args);
void setPrivacy(bool privacy);

public Q_SLOTS:
/** Set number of connections shown in the UI */
Expand Down
25 changes: 22 additions & 3 deletions src/qt/bitcoinunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <QSettings>
#include <QStringList>

#include <cassert>

BitcoinUnits::BitcoinUnits(QObject *parent):
QAbstractListModel(parent),
unitlist(availableUnits())
Expand Down Expand Up @@ -115,7 +117,7 @@ int BitcoinUnits::decimals(int unit)
}
}

QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators)
QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators, bool justify)
{
// Note: not using straight sprintf here because we do NOT want
// localized number formatting.
Expand All @@ -127,6 +129,7 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
qint64 n_abs = (n > 0 ? n : -n);
qint64 quotient = n_abs / coin;
QString quotient_str = QString::number(quotient);
if (justify) quotient_str = quotient_str.rightJustified(16 - num_decimals, ' ');

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

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

QString BitcoinUnits::floorWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators)
{
QSettings settings;
Expand All @@ -182,9 +197,13 @@ QString BitcoinUnits::floorWithUnit(int unit, const CAmount& amount, bool plussi
return result + QString(" ") + name(unit);
}

QString BitcoinUnits::floorHtmlWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators)
QString BitcoinUnits::floorHtmlWithPrivacy(int unit, const CAmount& amount, SeparatorStyle separators, bool privacy)
{
QString str(floorWithUnit(unit, amount, plussign, separators));
assert(amount >= 0);
QString str = privacy
? floorWithUnit(unit, 0, false, separators).replace('0', '#')
: floorWithUnit(unit, amount, false, separators);

str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML));
return QString("<span style='white-space: nowrap;'>%1</span>").arg(str);
}
Expand Down
6 changes: 4 additions & 2 deletions src/qt/bitcoinunits.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ class BitcoinUnits: public QAbstractListModel
//! Number of decimals left
static int decimals(int unit);
//! Format as string
static QString format(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
static QString format(int unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = separatorStandard, bool justify = false);
static QString simpleFormat(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
//! Format as string (with unit)
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);
//! Format as string (with unit) but floor value up to "digits" settings
static QString floorWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
static QString floorHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
static QString floorHtmlWithPrivacy(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
2 changes: 2 additions & 0 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ CoinControlDialog::CoinControlDialog(CCoinControl& coin_control, WalletModel* _m
updateLabelLocked();
CoinControlDialog::updateLabels(m_coin_control, _model, this);
}

GUIUtil::handleCloseWindowShortcut(this);
}

CoinControlDialog::~CoinControlDialog()
Expand Down
2 changes: 2 additions & 0 deletions src/qt/editaddressdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper);
connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);
mapper->setItemDelegate(delegate);

GUIUtil::handleCloseWindowShortcut(this);
}

EditAddressDialog::~EditAddressDialog()
Expand Down
20 changes: 10 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>960</width>
<height>585</height>
<width>798</width>
<height>318</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -116,7 +116,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 @@ -135,7 +135,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 @@ -154,7 +154,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 @@ -206,7 +206,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 @@ -245,7 +245,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 @@ -264,7 +264,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 @@ -300,7 +300,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 @@ -319,7 +319,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
Loading

0 comments on commit 8be260a

Please sign in to comment.