Skip to content

Commit a108921

Browse files
Merge #6681: backport: bitcoin-core/gui#557, #552, #556, #590, #581, #608, #673, #676, #681, #690, #697, #717, #757, #751, #773, #801 (qt backports: part 4)
a41f4e7 merge bitcoin-core/gui#801: Fix nullptr clientModel access during shutdown (Kittywhiskers Van Gogh) 56fc672 merge bitcoin-core/gui#773: Check for private keys disabled before attempting unlock (Kittywhiskers Van Gogh) ae0ca10 merge bitcoin-core/gui#751: macOS, do not process actions during shutdown (Kittywhiskers Van Gogh) 107a180 merge bitcoin-core/gui#757: Add wallet name to address book page title (Kittywhiskers Van Gogh) 9385d44 merge bitcoin-core/gui#717: Use the stored CSubNet entry when unbanning (Kittywhiskers Van Gogh) fd651ee merge bitcoin-core/gui#697: Remove reindex special case from the progress bar label (Kittywhiskers Van Gogh) 8bdcd12 merge bitcoin-core/gui#690: Catch invalid networks combination crash (Kittywhiskers Van Gogh) 6cc422d merge bitcoin-core/gui#681: Fix Transaction Relay tooltip text in Peers details window (Kittywhiskers Van Gogh) 5c894e1 merge bitcoin-core/gui#676: Update peers window "Transaction Relay" label and tooltip (Kittywhiskers Van Gogh) 13990d8 merge bitcoin-core/gui#673: Use fallback value for Version and User Agent during peer connection (Kittywhiskers Van Gogh) 320f0e6 merge bitcoin-core/gui#608: Make `WalletModel::sendCoins()` return `void` (Kittywhiskers Van Gogh) bb5b44e merge bitcoin-core/gui#581: Revamp `ClientModel` code to handle core signals (Kittywhiskers Van Gogh) a334b68 merge bitcoin-core/gui#590: Declare `WalletModel` member functions with `const` (Kittywhiskers Van Gogh) 212e54d merge bitcoin-core/gui#556: Make BitcoinUnits::Unit a scoped enum (Kittywhiskers Van Gogh) 27951a3 merge bitcoin-core/gui#552: Refactor `TransactionDesc::FormatTxStatus` and `TransactionStatus` (Kittywhiskers Van Gogh) 054ffdb merge bitcoin-core/gui#557: revert bitcoin-core/gui#296 (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Even though "DiplayBitcoinUnit" has been Dashified, the associated value is not (see below, from `~/.config/Dash/Dash-Qt-testnet.conf`) as renaming "BitcoinUnit" would cause significant conflicts when backporting, so it has retained its upstream name. ``` DisplayDashUnit=@variant(\0\0\0\x7f\0\0\0\x13\x42itcoinUnits::Unit\0\0) ``` * [bitcoin-core/gui#581](bitcoin-core/gui#581) affects three Dash-specific signal handlers, `m_handler_notify_additional_data_sync_progess_changed`, `m_handler_notify_chainlock` and `m_handler_notify_masternodelist_changed` and their refactoring needs to be specially reviewed. ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code **(note: N/A)** - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: light ACK a41f4e7 Tree-SHA512: 85e683beb2548e8d47a5c52b1ff802711b53c4432435f52c146ef6774edac6604fbc08365554ce23084bfb26f6ab9358df6ccae3d869c625510098cb3efc1471
2 parents f7f4ef3 + a41f4e7 commit a108921

39 files changed

+414
-489
lines changed

src/interfaces/node.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,8 @@ class Node
235235
//! Is masternode.
236236
virtual bool isMasternode() = 0;
237237

238-
//! Get reindex.
239-
virtual bool getReindex() = 0;
240-
241-
//! Get importing.
242-
virtual bool getImporting() = 0;
238+
//! Is loading blocks.
239+
virtual bool isLoadingBlocks() = 0;
243240

244241
//! Set network active.
245242
virtual void setNetworkActive(bool active) = 0;

src/node/interfaces.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ class NodeImpl : public Node
468468
{
469469
return m_context->mn_activeman != nullptr;
470470
}
471-
bool getReindex() override { return ::fReindex; }
472-
bool getImporting() override { return ::fImporting; }
471+
bool isLoadingBlocks() override { return ::fReindex || ::fImporting; }
473472
void setNetworkActive(bool active) override
474473
{
475474
if (m_context->connman) {

src/qt/addressbookpage.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ AddressBookPage::AddressBookPage(Mode _mode, Tabs _tab, QWidget* parent) :
7171
ui->showAddressQRCode->setEnabled(false);
7272
#endif
7373

74-
switch(mode)
75-
{
76-
case ForSelection:
74+
if (mode == ForSelection) {
7775
switch(tab)
7876
{
7977
case SendingTab: setWindowTitle(tr("Choose the address to send coins to")); break;
@@ -84,14 +82,6 @@ AddressBookPage::AddressBookPage(Mode _mode, Tabs _tab, QWidget* parent) :
8482
ui->tableView->setFocus();
8583
ui->closeButton->setText(tr("C&hoose"));
8684
ui->exportButton->hide();
87-
break;
88-
case ForEditing:
89-
switch(tab)
90-
{
91-
case SendingTab: setWindowTitle(tr("Sending addresses")); break;
92-
case ReceivingTab: setWindowTitle(tr("Receiving addresses")); break;
93-
}
94-
break;
9585
}
9686
switch(tab)
9787
{
@@ -162,6 +152,7 @@ void AddressBookPage::setModel(AddressTableModel *_model)
162152
connect(_model, &AddressTableModel::rowsInserted, this, &AddressBookPage::selectNewAddress);
163153

164154
selectionChanged();
155+
this->updateWindowsTitleWithWalletName();
165156
}
166157

167158
void AddressBookPage::on_copyAddress_clicked()
@@ -347,3 +338,16 @@ void AddressBookPage::selectNewAddress(const QModelIndex &parent, int begin, int
347338
newAddressToSelect.clear();
348339
}
349340
}
341+
342+
void AddressBookPage::updateWindowsTitleWithWalletName()
343+
{
344+
const QString walletName = this->model->GetWalletDisplayName();
345+
346+
if (mode == ForEditing) {
347+
switch(tab)
348+
{
349+
case SendingTab: setWindowTitle(tr("Sending addresses - %1").arg(walletName)); break;
350+
case ReceivingTab: setWindowTitle(tr("Receiving addresses - %1").arg(walletName)); break;
351+
}
352+
}
353+
}

src/qt/addressbookpage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public Q_SLOTS:
5555
AddressBookSortFilterProxyModel *proxyModel;
5656
QMenu *contextMenu;
5757
QString newAddressToSelect;
58+
void updateWindowsTitleWithWalletName();
5859

5960
private Q_SLOTS:
6061
/** Delete currently selected address entry */

src/qt/addresstablemodel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,5 @@ void AddressTableModel::emitDataChanged(int idx)
448448
{
449449
Q_EMIT dataChanged(index(idx, 0, QModelIndex()), index(idx, columns.length()-1, QModelIndex()));
450450
}
451+
452+
QString AddressTableModel::GetWalletDisplayName() const { return walletModel->getDisplayName(); };

src/qt/addresstablemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class AddressTableModel : public QAbstractTableModel
8080

8181
EditStatus getEditStatus() const { return editStatus; }
8282

83+
QString GetWalletDisplayName() const;
84+
8385
private:
8486
WalletModel* const walletModel;
8587
AddressTablePriv *priv = nullptr;

src/qt/bantablemodel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BanTablePriv
4343
/** Order (ascending or descending) to sort nodes by */
4444
Qt::SortOrder sortOrder;
4545

46-
/** Pull a full list of banned nodes from CNode into our cache */
46+
/** Pull a full list of banned nodes from interfaces::Node into our cache */
4747
void refreshBanlist(interfaces::Node& node)
4848
{
4949
banmap_t banMap;
@@ -181,3 +181,9 @@ bool BanTableModel::shouldShow()
181181
{
182182
return priv->size() > 0;
183183
}
184+
185+
bool BanTableModel::unban(const QModelIndex& index)
186+
{
187+
CCombinedBan* ban{static_cast<CCombinedBan*>(index.internalPointer())};
188+
return ban != nullptr && m_node.unban(ban->subnet);
189+
}

src/qt/bantablemodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BannedNodeLessThan
3737
};
3838

3939
/**
40-
Qt model providing information about connected peers, similar to the
40+
Qt model providing information about banned peers, similar to the
4141
"getpeerinfo" RPC call. Used by the rpc console UI.
4242
*/
4343
class BanTableModel : public QAbstractTableModel
@@ -68,6 +68,8 @@ class BanTableModel : public QAbstractTableModel
6868

6969
bool shouldShow();
7070

71+
bool unban(const QModelIndex& index);
72+
7173
public Q_SLOTS:
7274
void refresh();
7375

src/qt/bitcoin.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static void RegisterMetaTypes()
9797
qRegisterMetaType<std::function<void()>>("std::function<void()>");
9898
qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon");
9999
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
100+
101+
qRegisterMetaTypeStreamOperators<BitcoinUnit>("BitcoinUnit");
100102
}
101103

102104
static QString GetLangTerritory()
@@ -346,6 +348,11 @@ void BitcoinApplication::requestShutdown()
346348
// Request node shutdown, which can interrupt long operations, like
347349
// rescanning a wallet.
348350
node().startShutdown();
351+
// Prior to unsetting the client model, stop listening backend signals
352+
if (clientModel) {
353+
clientModel->stop();
354+
}
355+
349356
// Unsetting the client model can cause the current thread to wait for node
350357
// to complete an operation, like wait for a RPC execution to complete.
351358
window->setClientModel(nullptr);
@@ -564,29 +571,30 @@ int GuiMain(int argc, char* argv[])
564571
// Gracefully exit if the user cancels
565572
if (!Intro::showIfNeeded(did_show_intro, prune_MiB)) return EXIT_SUCCESS;
566573

567-
/// 6. Determine availability of data directory and parse dash.conf
568-
/// - Do not call gArgs.GetDataDirNet() before this step finishes
574+
/// 6a. Determine availability of data directory
569575
if (!CheckDataDirOption()) {
570576
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
571577
QMessageBox::critical(nullptr, PACKAGE_NAME,
572578
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
573579
return EXIT_FAILURE;
574580
}
575-
if (!gArgs.ReadConfigFiles(error, true)) {
576-
InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
577-
QMessageBox::critical(nullptr, PACKAGE_NAME,
578-
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
579-
return EXIT_FAILURE;
580-
}
581+
try {
582+
/// 6b. Parse dash.conf
583+
/// - Do not call gArgs.GetDataDirNet() before this step finishes
584+
if (!gArgs.ReadConfigFiles(error, true)) {
585+
InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
586+
QMessageBox::critical(nullptr, PACKAGE_NAME,
587+
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
588+
return EXIT_FAILURE;
589+
}
581590

582-
/// 7. Determine network (and switch to network specific options)
583-
// - Do not call Params() before this step
584-
// - Do this after parsing the configuration file, as the network can be switched there
585-
// - QSettings() will use the new application name after this, resulting in network-specific settings
586-
// - Needs to be done before createOptionsModel
591+
/// 7. Determine network (and switch to network specific options)
592+
// - Do not call Params() before this step
593+
// - Do this after parsing the configuration file, as the network can be switched there
594+
// - QSettings() will use the new application name after this, resulting in network-specific settings
595+
// - Needs to be done before createOptionsModel
587596

588-
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
589-
try {
597+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
590598
SelectParams(gArgs.GetChainName());
591599
} catch(std::exception &e) {
592600
InitError(Untranslated(strprintf("%s\n", e.what())));

src/qt/bitcoinamountfield.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
#include <QHBoxLayout>
1313
#include <QKeyEvent>
1414
#include <QLineEdit>
15+
#include <QVariant>
16+
17+
#include <cassert>
1518

1619
/**
1720
* Parse a string into a number of base monetary units and
1821
* return validity.
1922
* @note Must return 0 if !valid.
2023
*/
21-
static CAmount parse(const QString &text, int nUnit, bool *valid_out= nullptr)
24+
static CAmount parse(const QString &text, BitcoinUnit nUnit, bool *valid_out= nullptr)
2225
{
2326
CAmount val = 0;
2427
bool valid = BitcoinUnits::parse(nUnit, text, &val);
@@ -37,11 +40,12 @@ static CAmount parse(const QString &text, int nUnit, bool *valid_out= nullptr)
3740
class AmountValidator : public QValidator
3841
{
3942
Q_OBJECT
40-
int currentUnit;
43+
BitcoinUnit currentUnit;
44+
4145
public:
4246
explicit AmountValidator(QObject *parent) :
4347
QValidator(parent),
44-
currentUnit(BitcoinUnits::DASH) {}
48+
currentUnit(BitcoinUnit::DASH) {}
4549

4650
State validate(QString &input, int &pos) const override
4751
{
@@ -53,7 +57,7 @@ class AmountValidator : public QValidator
5357
return valid ? QValidator::Intermediate : QValidator::Invalid;
5458
}
5559

56-
void updateUnit(int nUnit)
60+
void updateUnit(BitcoinUnit nUnit)
5761
{
5862
currentUnit = nUnit;
5963
}
@@ -69,7 +73,7 @@ class AmountLineEdit: public QLineEdit
6973
public:
7074
explicit AmountLineEdit(QWidget *parent):
7175
QLineEdit(parent),
72-
currentUnit(BitcoinUnits::DASH)
76+
currentUnit(BitcoinUnit::DASH)
7377
{
7478
setAlignment(Qt::AlignLeft);
7579
amountValidator = new AmountValidator(this);
@@ -122,7 +126,7 @@ class AmountLineEdit: public QLineEdit
122126
m_max_amount = value;
123127
}
124128

125-
void setDisplayUnit(int unit)
129+
void setDisplayUnit(BitcoinUnit unit)
126130
{
127131
bool valid = false;
128132
CAmount val = value(&valid);
@@ -142,14 +146,14 @@ class AmountLineEdit: public QLineEdit
142146
ensurePolished();
143147
const QFontMetrics fm(fontMetrics());
144148
int h = 0;
145-
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnits::DASH, BitcoinUnits::maxMoney(), false, BitcoinUnits::SeparatorStyle::ALWAYS));
149+
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnit::DASH, BitcoinUnits::maxMoney(), false, BitcoinUnits::SeparatorStyle::ALWAYS));
146150
w += 2; // cursor blinking space
147151
w += GUIUtil::dashThemeActive() ? 24 : 0; // counteract padding from css
148152
return QSize(w, h);
149153
}
150154

151155
private:
152-
int currentUnit{BitcoinUnits::DASH};
156+
BitcoinUnit currentUnit{BitcoinUnit::DASH};
153157
bool m_allow_empty{true};
154158
CAmount m_min_amount{CAmount(0)};
155159
CAmount m_max_amount{BitcoinUnits::maxMoney()};
@@ -287,14 +291,13 @@ void BitcoinAmountField::unitChanged(int idx)
287291
amount->setToolTip(units->data(idx, Qt::ToolTipRole).toString());
288292

289293
// Determine new unit ID
290-
int newUnit = units->data(idx, BitcoinUnits::UnitRole).toInt();
291-
292-
amount->setPlaceholderText(tr("Amount in %1").arg(units->data(idx,Qt::DisplayRole).toString()));
293-
294-
amount->setDisplayUnit(newUnit);
294+
QVariant new_unit = units->data(idx, BitcoinUnits::UnitRole);
295+
assert(new_unit.isValid());
296+
amount->setPlaceholderText(tr("Amount in %1").arg(units->data(idx, Qt::DisplayRole).toString()));
297+
amount->setDisplayUnit(new_unit.value<BitcoinUnit>());
295298
}
296299

297-
void BitcoinAmountField::setDisplayUnit(int newUnit)
300+
void BitcoinAmountField::setDisplayUnit(BitcoinUnit new_unit)
298301
{
299-
unitChanged(newUnit);
302+
unitChanged(QVariant::fromValue(new_unit).toInt());
300303
}

0 commit comments

Comments
 (0)