Skip to content

Commit

Permalink
Merge #12610: Multiwallet for the GUI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonasschnelli committed Mar 26, 2018
2 parents 7466a26 + 779c5f9 commit 25cf18f
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 63 deletions.
3 changes: 3 additions & 0 deletions src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ void StopHTTPRPC()
{
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
UnregisterHTTPHandler("/", true);
#ifdef ENABLE_WALLET
UnregisterHTTPHandler("/wallet/", false);
#endif
if (httpRPCTimerInterface) {
RPCUnsetTimerInterface(httpRPCTimerInterface.get());
httpRPCTimerInterface.reset();
Expand Down
26 changes: 16 additions & 10 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public Q_SLOTS:
QTimer *pollShutdownTimer;
#ifdef ENABLE_WALLET
PaymentServer* paymentServer;
WalletModel *walletModel;
std::vector<WalletModel*> m_wallet_models;
#endif
int returnValue;
const PlatformStyle *platformStyle;
Expand Down Expand Up @@ -333,7 +333,7 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
pollShutdownTimer(0),
#ifdef ENABLE_WALLET
paymentServer(0),
walletModel(0),
m_wallet_models(),
#endif
returnValue(0)
{
Expand Down Expand Up @@ -451,8 +451,10 @@ void BitcoinApplication::requestShutdown()

#ifdef ENABLE_WALLET
window->removeAllWallets();
delete walletModel;
walletModel = 0;
for (WalletModel *walletModel : m_wallet_models) {
delete walletModel;
}
m_wallet_models.clear();
#endif
delete clientModel;
clientModel = 0;
Expand Down Expand Up @@ -481,16 +483,20 @@ void BitcoinApplication::initializeResult(bool success)
window->setClientModel(clientModel);

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

window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel);
window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET);
window->addWallet(walletModel);
if (fFirstWallet) {
window->setCurrentWallet(walletModel->getWalletName());
fFirstWallet = false;
}

connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));

m_wallet_models.push_back(walletModel);
}
#endif

Expand Down
54 changes: 45 additions & 9 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifdef ENABLE_WALLET
#include <qt/walletframe.h>
#include <qt/walletmodel.h>
#include <qt/walletview.h>
#endif // ENABLE_WALLET

#ifdef Q_OS_MAC
Expand All @@ -36,6 +37,7 @@

#include <QAction>
#include <QApplication>
#include <QComboBox>
#include <QDateTime>
#include <QDesktopWidget>
#include <QDragEnterEvent>
Expand Down Expand Up @@ -70,10 +72,6 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#endif
;

/** Display name for default wallet name. Uses tilde to avoid name
* collisions in the future with additional wallets */
const QString BitcoinGUI::DEFAULT_WALLET = "~Default";

BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
QMainWindow(parent),
enableWallet(false),
Expand All @@ -88,6 +86,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
progressBar(0),
progressDialog(0),
appMenuBar(0),
appToolBar(0),
overviewAction(0),
historyAction(0),
quitAction(0),
Expand Down Expand Up @@ -455,6 +454,7 @@ void BitcoinGUI::createToolBars()
if(walletFrame)
{
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
appToolBar = toolbar;
toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
toolbar->setMovable(false);
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
Expand All @@ -463,6 +463,15 @@ void BitcoinGUI::createToolBars()
toolbar->addAction(receiveCoinsAction);
toolbar->addAction(historyAction);
overviewAction->setChecked(true);

#ifdef ENABLE_WALLET
QWidget *spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
toolbar->addWidget(spacer);

m_wallet_selector = new QComboBox();
connect(m_wallet_selector, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setCurrentWallet(const QString&)));
#endif
}
}

Expand Down Expand Up @@ -529,12 +538,22 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
}

#ifdef ENABLE_WALLET
bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
bool BitcoinGUI::addWallet(WalletModel *walletModel)
{
if(!walletFrame)
return false;
const QString name = walletModel->getWalletName();
setWalletActionsEnabled(true);
return walletFrame->addWallet(name, walletModel);
m_wallet_selector->addItem(name);
if (m_wallet_selector->count() == 2) {
m_wallet_selector_label = new QLabel();
m_wallet_selector_label->setText(tr("Wallet:") + " ");
m_wallet_selector_label->setBuddy(m_wallet_selector);
appToolBar->addWidget(m_wallet_selector_label);
appToolBar->addWidget(m_wallet_selector);
}
rpcConsole->addWallet(walletModel);
return walletFrame->addWallet(walletModel);
}

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

#ifdef ENABLE_WALLET
void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label)
void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName)
{
// On new transaction, make an info balloon
QString msg = tr("Date: %1\n").arg(date) +
tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true)) +
tr("Type: %1\n").arg(type);
tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true));
if (WalletModel::isMultiwallet() && !walletName.isEmpty()) {
msg += tr("Wallet: %1\n").arg(walletName);
}
msg += tr("Type: %1\n").arg(type);
if (!label.isEmpty())
msg += tr("Label: %1\n").arg(label);
else if (!address.isEmpty())
Expand Down Expand Up @@ -1079,6 +1101,20 @@ void BitcoinGUI::setEncryptionStatus(int status)
break;
}
}

void BitcoinGUI::updateWalletStatus()
{
if (!walletFrame) {
return;
}
WalletView * const walletView = walletFrame->currentWalletView();
if (!walletView) {
return;
}
WalletModel * const walletModel = walletView->getWalletModel();
setEncryptionStatus(walletModel->getEncryptionStatus());
setHDStatus(walletModel->hdEnabled());
}
#endif // ENABLE_WALLET

void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
Expand Down
18 changes: 14 additions & 4 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ModalOverlay;

QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QProgressBar;
class QProgressDialog;
QT_END_NAMESPACE
Expand All @@ -46,7 +47,6 @@ class BitcoinGUI : public QMainWindow
Q_OBJECT

public:
static const QString DEFAULT_WALLET;
static const std::string DEFAULT_UIPLATFORM;

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

QMenuBar *appMenuBar;
QToolBar *appToolBar;
QAction *overviewAction;
QAction *historyAction;
QAction *quitAction;
Expand All @@ -112,6 +112,9 @@ class BitcoinGUI : public QMainWindow
QAction *openAction;
QAction *showHelpMessageAction;

QLabel *m_wallet_selector_label;
QComboBox *m_wallet_selector;

QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
Notificator *notificator;
Expand Down Expand Up @@ -171,6 +174,12 @@ public Q_SLOTS:
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);

#ifdef ENABLE_WALLET
bool setCurrentWallet(const QString& name);
/** Set the UI status indicators based on the currently selected wallet.
*/
void updateWalletStatus();

private:
/** Set the encryption status as shown in the UI.
@param[in] status current encryption status
@see WalletModel::EncryptionStatus
Expand All @@ -183,10 +192,11 @@ public Q_SLOTS:
*/
void setHDStatus(int hdEnabled);

public Q_SLOTS:
bool handlePaymentRequest(const SendCoinsRecipient& recipient);

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

private Q_SLOTS:
Expand Down
16 changes: 16 additions & 0 deletions src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@
<property name="spacing">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="WalletSelectorLabel">
<property name="text">
<string>Wallet: </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="WalletSelector">
<item>
<property name="text">
<string>(none)</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
4 changes: 2 additions & 2 deletions src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
ui->reqAmount->value(), ui->reqMessage->text());
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModel(model->getOptionsModel());
dialog->setModel(model);
dialog->setInfo(info);
dialog->show();
clear();
Expand All @@ -166,7 +166,7 @@ void ReceiveCoinsDialog::on_recentRequestsView_doubleClicked(const QModelIndex &
{
const RecentRequestsTableModel *submodel = model->getRecentRequestsTableModel();
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setModel(model->getOptionsModel());
dialog->setModel(model);
dialog->setInfo(submodel->entry(index.row()).recipient);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
Expand Down
9 changes: 6 additions & 3 deletions src/qt/receiverequestdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ ReceiveRequestDialog::~ReceiveRequestDialog()
delete ui;
}

void ReceiveRequestDialog::setModel(OptionsModel *_model)
void ReceiveRequestDialog::setModel(WalletModel *_model)
{
this->model = _model;

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

// update the display unit if necessary
update();
Expand Down Expand Up @@ -143,11 +143,14 @@ void ReceiveRequestDialog::update()
html += "<a href=\""+uri+"\">" + GUIUtil::HtmlEscape(uri) + "</a><br>";
html += "<b>"+tr("Address")+"</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>";
if(info.amount)
html += "<b>"+tr("Amount")+"</b>: " + BitcoinUnits::formatHtmlWithUnit(model->getDisplayUnit(), info.amount) + "<br>";
html += "<b>"+tr("Amount")+"</b>: " + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount) + "<br>";
if(!info.label.isEmpty())
html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
if(!info.message.isEmpty())
html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
if(model->isMultiwallet()) {
html += "<b>"+tr("Wallet")+"</b>: " + GUIUtil::HtmlEscape(model->getWalletName()) + "<br>";
}
ui->outUri->setText(html);

#ifdef USE_QRCODE
Expand Down
6 changes: 2 additions & 4 deletions src/qt/receiverequestdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <QLabel>
#include <QPainter>

class OptionsModel;

namespace Ui {
class ReceiveRequestDialog;
}
Expand Down Expand Up @@ -53,7 +51,7 @@ class ReceiveRequestDialog : public QDialog
explicit ReceiveRequestDialog(QWidget *parent = 0);
~ReceiveRequestDialog();

void setModel(OptionsModel *model);
void setModel(WalletModel *model);
void setInfo(const SendCoinsRecipient &info);

private Q_SLOTS:
Expand All @@ -64,7 +62,7 @@ private Q_SLOTS:

private:
Ui::ReceiveRequestDialog *ui;
OptionsModel *model;
WalletModel *model;
SendCoinsRecipient info;
};

Expand Down
Loading

0 comments on commit 25cf18f

Please sign in to comment.