Skip to content

Commit 25cf18f

Browse files
committed
Merge #12610: Multiwallet for the GUI
779c5f9 Qt: hide RPCConsole wallet selector when no wallets are present (Jonas Schnelli) dc6f150 Qt: show wallet name in request dlg in case of multiwallet (Jonas Schnelli) 4826ca4 Qt: show wallet name in send confirmation dlg in case of multiwallet (Jonas Schnelli) cfa4133 GUI: RPCConsole: Log wallet changes (Luke Dashjr) b6d04fc Qt: Get wallet name from WalletModel rather than passing it around (Luke Dashjr) 12d8d26 Qt: When multiple wallets are used, include in notifications the name (Jonas Schnelli) d1ec34a Qt: QComboBox::setVisible doesn't work in toolbars, so defer adding it at all until needed (Luke Dashjr) d49cc70 Qt: Add wallet selector to debug console (Jonas Schnelli) d558f44 Bugfix: RPC: Add missing UnregisterHTTPHandler for /wallet/ (Luke Dashjr) 85d5319 Qt: Ensure UI updates only come from the currently selected walletView (Luke Dashjr) e449f9a Qt: Add a combobox to toolbar to select from multiple wallets (Luke Dashjr) 3dba3c3 Qt: Load all wallets into WalletModels (Luke Dashjr) Pull request description: This is an overhaul of #11383 (plus some additions). It avoids unnecessary coupling of httpserver/jsonrpc and the wallet as well as it avoids pointer pure passing (and pointer deletion) of `CWallet` (plus other minor design changes). Additionally it adds the wallet name to the sendconfirmation and request dialog (in case multiwallet is active) Tree-SHA512: 3d06e18badbc5d1821e488bf1dae463bb0be544cf11b2b618e025812bfdd13c5f39604bb93b4c705313930e7dc4e66f4848b9469ba14871bade58e7a027246a1
2 parents 7466a26 + 779c5f9 commit 25cf18f

17 files changed

+209
-63
lines changed

src/httprpc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ void StopHTTPRPC()
252252
{
253253
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
254254
UnregisterHTTPHandler("/", true);
255+
#ifdef ENABLE_WALLET
256+
UnregisterHTTPHandler("/wallet/", false);
257+
#endif
255258
if (httpRPCTimerInterface) {
256259
RPCUnsetTimerInterface(httpRPCTimerInterface.get());
257260
httpRPCTimerInterface.reset();

src/qt/bitcoin.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public Q_SLOTS:
251251
QTimer *pollShutdownTimer;
252252
#ifdef ENABLE_WALLET
253253
PaymentServer* paymentServer;
254-
WalletModel *walletModel;
254+
std::vector<WalletModel*> m_wallet_models;
255255
#endif
256256
int returnValue;
257257
const PlatformStyle *platformStyle;
@@ -333,7 +333,7 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
333333
pollShutdownTimer(0),
334334
#ifdef ENABLE_WALLET
335335
paymentServer(0),
336-
walletModel(0),
336+
m_wallet_models(),
337337
#endif
338338
returnValue(0)
339339
{
@@ -451,8 +451,10 @@ void BitcoinApplication::requestShutdown()
451451

452452
#ifdef ENABLE_WALLET
453453
window->removeAllWallets();
454-
delete walletModel;
455-
walletModel = 0;
454+
for (WalletModel *walletModel : m_wallet_models) {
455+
delete walletModel;
456+
}
457+
m_wallet_models.clear();
456458
#endif
457459
delete clientModel;
458460
clientModel = 0;
@@ -481,16 +483,20 @@ void BitcoinApplication::initializeResult(bool success)
481483
window->setClientModel(clientModel);
482484

483485
#ifdef ENABLE_WALLET
484-
// TODO: Expose secondary wallets
485-
if (!vpwallets.empty())
486-
{
487-
walletModel = new WalletModel(platformStyle, vpwallets[0], optionsModel);
486+
bool fFirstWallet = true;
487+
for (CWalletRef pwallet : vpwallets) {
488+
WalletModel * const walletModel = new WalletModel(platformStyle, pwallet, optionsModel);
488489

489-
window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel);
490-
window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET);
490+
window->addWallet(walletModel);
491+
if (fFirstWallet) {
492+
window->setCurrentWallet(walletModel->getWalletName());
493+
fFirstWallet = false;
494+
}
491495

492496
connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
493497
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
498+
499+
m_wallet_models.push_back(walletModel);
494500
}
495501
#endif
496502

src/qt/bitcoingui.cpp

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifdef ENABLE_WALLET
2222
#include <qt/walletframe.h>
2323
#include <qt/walletmodel.h>
24+
#include <qt/walletview.h>
2425
#endif // ENABLE_WALLET
2526

2627
#ifdef Q_OS_MAC
@@ -36,6 +37,7 @@
3637

3738
#include <QAction>
3839
#include <QApplication>
40+
#include <QComboBox>
3941
#include <QDateTime>
4042
#include <QDesktopWidget>
4143
#include <QDragEnterEvent>
@@ -70,10 +72,6 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
7072
#endif
7173
;
7274

73-
/** Display name for default wallet name. Uses tilde to avoid name
74-
* collisions in the future with additional wallets */
75-
const QString BitcoinGUI::DEFAULT_WALLET = "~Default";
76-
7775
BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
7876
QMainWindow(parent),
7977
enableWallet(false),
@@ -88,6 +86,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
8886
progressBar(0),
8987
progressDialog(0),
9088
appMenuBar(0),
89+
appToolBar(0),
9190
overviewAction(0),
9291
historyAction(0),
9392
quitAction(0),
@@ -455,6 +454,7 @@ void BitcoinGUI::createToolBars()
455454
if(walletFrame)
456455
{
457456
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
457+
appToolBar = toolbar;
458458
toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
459459
toolbar->setMovable(false);
460460
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
@@ -463,6 +463,15 @@ void BitcoinGUI::createToolBars()
463463
toolbar->addAction(receiveCoinsAction);
464464
toolbar->addAction(historyAction);
465465
overviewAction->setChecked(true);
466+
467+
#ifdef ENABLE_WALLET
468+
QWidget *spacer = new QWidget();
469+
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
470+
toolbar->addWidget(spacer);
471+
472+
m_wallet_selector = new QComboBox();
473+
connect(m_wallet_selector, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setCurrentWallet(const QString&)));
474+
#endif
466475
}
467476
}
468477

@@ -529,12 +538,22 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
529538
}
530539

531540
#ifdef ENABLE_WALLET
532-
bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
541+
bool BitcoinGUI::addWallet(WalletModel *walletModel)
533542
{
534543
if(!walletFrame)
535544
return false;
545+
const QString name = walletModel->getWalletName();
536546
setWalletActionsEnabled(true);
537-
return walletFrame->addWallet(name, walletModel);
547+
m_wallet_selector->addItem(name);
548+
if (m_wallet_selector->count() == 2) {
549+
m_wallet_selector_label = new QLabel();
550+
m_wallet_selector_label->setText(tr("Wallet:") + " ");
551+
m_wallet_selector_label->setBuddy(m_wallet_selector);
552+
appToolBar->addWidget(m_wallet_selector_label);
553+
appToolBar->addWidget(m_wallet_selector);
554+
}
555+
rpcConsole->addWallet(walletModel);
556+
return walletFrame->addWallet(walletModel);
538557
}
539558

540559
bool BitcoinGUI::setCurrentWallet(const QString& name)
@@ -983,12 +1002,15 @@ void BitcoinGUI::showEvent(QShowEvent *event)
9831002
}
9841003

9851004
#ifdef ENABLE_WALLET
986-
void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label)
1005+
void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName)
9871006
{
9881007
// On new transaction, make an info balloon
9891008
QString msg = tr("Date: %1\n").arg(date) +
990-
tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true)) +
991-
tr("Type: %1\n").arg(type);
1009+
tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true));
1010+
if (WalletModel::isMultiwallet() && !walletName.isEmpty()) {
1011+
msg += tr("Wallet: %1\n").arg(walletName);
1012+
}
1013+
msg += tr("Type: %1\n").arg(type);
9921014
if (!label.isEmpty())
9931015
msg += tr("Label: %1\n").arg(label);
9941016
else if (!address.isEmpty())
@@ -1079,6 +1101,20 @@ void BitcoinGUI::setEncryptionStatus(int status)
10791101
break;
10801102
}
10811103
}
1104+
1105+
void BitcoinGUI::updateWalletStatus()
1106+
{
1107+
if (!walletFrame) {
1108+
return;
1109+
}
1110+
WalletView * const walletView = walletFrame->currentWalletView();
1111+
if (!walletView) {
1112+
return;
1113+
}
1114+
WalletModel * const walletModel = walletView->getWalletModel();
1115+
setEncryptionStatus(walletModel->getEncryptionStatus());
1116+
setHDStatus(walletModel->hdEnabled());
1117+
}
10821118
#endif // ENABLE_WALLET
10831119

10841120
void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)

src/qt/bitcoingui.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ModalOverlay;
3333

3434
QT_BEGIN_NAMESPACE
3535
class QAction;
36+
class QComboBox;
3637
class QProgressBar;
3738
class QProgressDialog;
3839
QT_END_NAMESPACE
@@ -46,7 +47,6 @@ class BitcoinGUI : public QMainWindow
4647
Q_OBJECT
4748

4849
public:
49-
static const QString DEFAULT_WALLET;
5050
static const std::string DEFAULT_UIPLATFORM;
5151

5252
explicit BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0);
@@ -62,8 +62,7 @@ class BitcoinGUI : public QMainWindow
6262
The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
6363
functionality.
6464
*/
65-
bool addWallet(const QString& name, WalletModel *walletModel);
66-
bool setCurrentWallet(const QString& name);
65+
bool addWallet(WalletModel *walletModel);
6766
void removeAllWallets();
6867
#endif // ENABLE_WALLET
6968
bool enableWallet;
@@ -90,6 +89,7 @@ class BitcoinGUI : public QMainWindow
9089
QProgressDialog *progressDialog;
9190

9291
QMenuBar *appMenuBar;
92+
QToolBar *appToolBar;
9393
QAction *overviewAction;
9494
QAction *historyAction;
9595
QAction *quitAction;
@@ -112,6 +112,9 @@ class BitcoinGUI : public QMainWindow
112112
QAction *openAction;
113113
QAction *showHelpMessageAction;
114114

115+
QLabel *m_wallet_selector_label;
116+
QComboBox *m_wallet_selector;
117+
115118
QSystemTrayIcon *trayIcon;
116119
QMenu *trayIconMenu;
117120
Notificator *notificator;
@@ -171,6 +174,12 @@ public Q_SLOTS:
171174
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
172175

173176
#ifdef ENABLE_WALLET
177+
bool setCurrentWallet(const QString& name);
178+
/** Set the UI status indicators based on the currently selected wallet.
179+
*/
180+
void updateWalletStatus();
181+
182+
private:
174183
/** Set the encryption status as shown in the UI.
175184
@param[in] status current encryption status
176185
@see WalletModel::EncryptionStatus
@@ -183,10 +192,11 @@ public Q_SLOTS:
183192
*/
184193
void setHDStatus(int hdEnabled);
185194

195+
public Q_SLOTS:
186196
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
187197

188198
/** Show incoming transaction notification for new transactions. */
189-
void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label);
199+
void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
190200
#endif // ENABLE_WALLET
191201

192202
private Q_SLOTS:

src/qt/forms/debugwindow.ui

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,22 @@
412412
<property name="spacing">
413413
<number>4</number>
414414
</property>
415+
<item>
416+
<widget class="QLabel" name="WalletSelectorLabel">
417+
<property name="text">
418+
<string>Wallet: </string>
419+
</property>
420+
</widget>
421+
</item>
422+
<item>
423+
<widget class="QComboBox" name="WalletSelector">
424+
<item>
425+
<property name="text">
426+
<string>(none)</string>
427+
</property>
428+
</item>
429+
</widget>
430+
</item>
415431
<item>
416432
<spacer name="horizontalSpacer">
417433
<property name="orientation">

src/qt/receivecoinsdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
153153
ui->reqAmount->value(), ui->reqMessage->text());
154154
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
155155
dialog->setAttribute(Qt::WA_DeleteOnClose);
156-
dialog->setModel(model->getOptionsModel());
156+
dialog->setModel(model);
157157
dialog->setInfo(info);
158158
dialog->show();
159159
clear();
@@ -166,7 +166,7 @@ void ReceiveCoinsDialog::on_recentRequestsView_doubleClicked(const QModelIndex &
166166
{
167167
const RecentRequestsTableModel *submodel = model->getRecentRequestsTableModel();
168168
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
169-
dialog->setModel(model->getOptionsModel());
169+
dialog->setModel(model);
170170
dialog->setInfo(submodel->entry(index.row()).recipient);
171171
dialog->setAttribute(Qt::WA_DeleteOnClose);
172172
dialog->show();

src/qt/receiverequestdialog.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ ReceiveRequestDialog::~ReceiveRequestDialog()
108108
delete ui;
109109
}
110110

111-
void ReceiveRequestDialog::setModel(OptionsModel *_model)
111+
void ReceiveRequestDialog::setModel(WalletModel *_model)
112112
{
113113
this->model = _model;
114114

115115
if (_model)
116-
connect(_model, SIGNAL(displayUnitChanged(int)), this, SLOT(update()));
116+
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(update()));
117117

118118
// update the display unit if necessary
119119
update();
@@ -143,11 +143,14 @@ void ReceiveRequestDialog::update()
143143
html += "<a href=\""+uri+"\">" + GUIUtil::HtmlEscape(uri) + "</a><br>";
144144
html += "<b>"+tr("Address")+"</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>";
145145
if(info.amount)
146-
html += "<b>"+tr("Amount")+"</b>: " + BitcoinUnits::formatHtmlWithUnit(model->getDisplayUnit(), info.amount) + "<br>";
146+
html += "<b>"+tr("Amount")+"</b>: " + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount) + "<br>";
147147
if(!info.label.isEmpty())
148148
html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
149149
if(!info.message.isEmpty())
150150
html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
151+
if(model->isMultiwallet()) {
152+
html += "<b>"+tr("Wallet")+"</b>: " + GUIUtil::HtmlEscape(model->getWalletName()) + "<br>";
153+
}
151154
ui->outUri->setText(html);
152155

153156
#ifdef USE_QRCODE

src/qt/receiverequestdialog.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <QLabel>
1313
#include <QPainter>
1414

15-
class OptionsModel;
16-
1715
namespace Ui {
1816
class ReceiveRequestDialog;
1917
}
@@ -53,7 +51,7 @@ class ReceiveRequestDialog : public QDialog
5351
explicit ReceiveRequestDialog(QWidget *parent = 0);
5452
~ReceiveRequestDialog();
5553

56-
void setModel(OptionsModel *model);
54+
void setModel(WalletModel *model);
5755
void setInfo(const SendCoinsRecipient &info);
5856

5957
private Q_SLOTS:
@@ -64,7 +62,7 @@ private Q_SLOTS:
6462

6563
private:
6664
Ui::ReceiveRequestDialog *ui;
67-
OptionsModel *model;
65+
WalletModel *model;
6866
SendCoinsRecipient info;
6967
};
7068

0 commit comments

Comments
 (0)