From 3dba3c3ac1679cf0086ee7734eee12268004ace7 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 9 Sep 2016 09:25:13 +0000 Subject: Qt: Load all wallets into WalletModels --- src/qt/bitcoin.cpp | 31 +++++++++++++++++++++---------- src/qt/bitcoingui.cpp | 4 ---- src/qt/bitcoingui.h | 1 - 3 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index ab381bfb5d..424d82ae1f 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -251,7 +251,7 @@ private: QTimer *pollShutdownTimer; #ifdef ENABLE_WALLET PaymentServer* paymentServer; - WalletModel *walletModel; + std::vector m_wallet_models; #endif int returnValue; const PlatformStyle *platformStyle; @@ -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) { @@ -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; @@ -481,16 +483,25 @@ 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); + QString WalletName = QString::fromStdString(pwallet->GetName()); + if (WalletName.endsWith(".dat")) { + WalletName.truncate(WalletName.size() - 4); + } + + window->addWallet(WalletName, walletModel); + if (fFirstWallet) { + window->setCurrentWallet(WalletName); + fFirstWallet = false; + } connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)), paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray))); + + m_wallet_models.push_back(walletModel); } #endif diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 4e868b7c17..0bf1d5c55f 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -70,10 +70,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), diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index ddb7ecb76a..b1ec6540c0 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -46,7 +46,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); -- cgit v1.2.3 From e449f9a9e620fb909eb7b32d815b413d235f05ad Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 9 Sep 2016 10:43:54 +0000 Subject: Qt: Add a combobox to toolbar to select from multiple wallets --- src/qt/bitcoingui.cpp | 23 +++++++++++++++++++++++ src/qt/bitcoingui.h | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 0bf1d5c55f..92fb3f1904 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -459,6 +460,23 @@ 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_label = new QLabel(); + m_wallet_selector_label->setText(tr("Wallet:") + " "); + toolbar->addWidget(m_wallet_selector_label); + m_wallet_selector_label->setVisible(false); + m_wallet_selector = new QComboBox(); + toolbar->addWidget(m_wallet_selector); + m_wallet_selector->setVisible(false); + m_wallet_selector_label->setBuddy(m_wallet_selector); + + connect(m_wallet_selector, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setCurrentWallet(const QString&))); +#endif } } @@ -530,6 +548,11 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) if(!walletFrame) return false; setWalletActionsEnabled(true); + m_wallet_selector->addItem(name); + if (m_wallet_selector->count() == 2) { + m_wallet_selector->setVisible(true); + m_wallet_selector->setVisible(true); + } return walletFrame->addWallet(name, walletModel); } diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index b1ec6540c0..42581e7d16 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -33,6 +33,7 @@ class ModalOverlay; QT_BEGIN_NAMESPACE class QAction; +class QComboBox; class QProgressBar; class QProgressDialog; QT_END_NAMESPACE @@ -62,7 +63,6 @@ public: functionality. */ bool addWallet(const QString& name, WalletModel *walletModel); - bool setCurrentWallet(const QString& name); void removeAllWallets(); #endif // ENABLE_WALLET bool enableWallet; @@ -111,6 +111,9 @@ private: QAction *openAction; QAction *showHelpMessageAction; + QLabel *m_wallet_selector_label; + QComboBox *m_wallet_selector; + QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; Notificator *notificator; @@ -170,6 +173,9 @@ 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); + +private: /** Set the encryption status as shown in the UI. @param[in] status current encryption status @see WalletModel::EncryptionStatus -- cgit v1.2.3 From 85d5319716b7b31b27bc7950d756465ae472f11d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 24 Oct 2016 07:21:51 +0000 Subject: Qt: Ensure UI updates only come from the currently selected walletView --- src/qt/bitcoingui.cpp | 15 +++++++++++++++ src/qt/bitcoingui.h | 4 ++++ src/qt/walletframe.h | 1 + src/qt/walletmodel.cpp | 5 +++-- src/qt/walletmodel.h | 2 +- src/qt/walletview.cpp | 10 +++++----- src/qt/walletview.h | 5 +++-- 7 files changed, 32 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 92fb3f1904..b39aaef46c 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -21,6 +21,7 @@ #ifdef ENABLE_WALLET #include #include +#include #endif // ENABLE_WALLET #ifdef Q_OS_MAC @@ -1097,6 +1098,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) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 42581e7d16..597c583ef2 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -174,6 +174,9 @@ public Q_SLOTS: #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. @@ -188,6 +191,7 @@ private: */ void setHDStatus(int hdEnabled); +public Q_SLOTS: bool handlePaymentRequest(const SendCoinsRecipient& recipient); /** Show incoming transaction notification for new transactions. */ diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 42ce69fea1..ce37e456f1 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -59,6 +59,7 @@ private: const PlatformStyle *platformStyle; +public: WalletView *currentWalletView(); public Q_SLOTS: diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 34954a6bfa..df1a996af0 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -110,8 +110,9 @@ void WalletModel::updateStatus() { EncryptionStatus newEncryptionStatus = getEncryptionStatus(); - if(cachedEncryptionStatus != newEncryptionStatus) - Q_EMIT encryptionStatusChanged(newEncryptionStatus); + if(cachedEncryptionStatus != newEncryptionStatus) { + Q_EMIT encryptionStatusChanged(); + } } void WalletModel::pollBalanceChanged() diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 9e13de79be..b0045fa272 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -255,7 +255,7 @@ Q_SIGNALS: const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); // Encryption status of wallet changed - void encryptionStatusChanged(int status); + void encryptionStatusChanged(); // Signal emitted when wallet needs to be unlocked // It is valid behaviour for listeners to keep the wallet locked after this signal; diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 64497a3431..afc5fb2630 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -101,13 +101,13 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui) connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int))); // Pass through encryption status changed signals - connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int))); + connect(this, SIGNAL(encryptionStatusChanged()), gui, SLOT(updateWalletStatus())); // Pass through transaction notifications connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString))); // Connect HD enabled state signal - connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int))); + connect(this, SIGNAL(hdEnabledStatusChanged()), gui, SLOT(updateWalletStatus())); } } @@ -137,11 +137,11 @@ void WalletView::setWalletModel(WalletModel *_walletModel) connect(_walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Handle changes in encryption status - connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int))); + connect(_walletModel, SIGNAL(encryptionStatusChanged()), this, SIGNAL(encryptionStatusChanged())); updateEncryptionStatus(); // update HD status - Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled()); + Q_EMIT hdEnabledStatusChanged(); // Balloon pop-up for new transaction connect(_walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)), @@ -234,7 +234,7 @@ void WalletView::showOutOfSyncWarning(bool fShow) void WalletView::updateEncryptionStatus() { - Q_EMIT encryptionStatusChanged(walletModel->getEncryptionStatus()); + Q_EMIT encryptionStatusChanged(); } void WalletView::encryptWallet(bool status) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 30d68e4eff..739b3a0b6d 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -44,6 +44,7 @@ public: The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic. */ void setClientModel(ClientModel *clientModel); + WalletModel *getWalletModel() { return walletModel; } /** Set the wallet model. The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending functionality. @@ -119,9 +120,9 @@ Q_SIGNALS: /** Fired when a message should be reported to the user */ void message(const QString &title, const QString &message, unsigned int style); /** Encryption status of wallet changed */ - void encryptionStatusChanged(int status); + void encryptionStatusChanged(); /** HD-Enabled status of wallet changed (only possible during startup) */ - void hdEnabledStatusChanged(int hdEnabled); + void hdEnabledStatusChanged(); /** Notify that a new transaction appeared */ void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label); /** Notify that the out of sync warning icon has been pressed */ -- cgit v1.2.3 From d558f44c58b61671899d6ef897df271de3f4f20a Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 14 Dec 2017 03:13:34 +0000 Subject: Bugfix: RPC: Add missing UnregisterHTTPHandler for /wallet/ --- src/httprpc.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 5e9e419744..0abab55b5b 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -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(); -- cgit v1.2.3 From d49cc70e6d96b45a4c062cbe2fa49a8181c8560f Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 9 Sep 2016 20:55:59 +0000 Subject: Qt: Add wallet selector to debug console --- src/qt/bitcoingui.cpp | 1 + src/qt/forms/debugwindow.ui | 16 ++++++++++++++++ src/qt/rpcconsole.cpp | 40 ++++++++++++++++++++++++++++++---------- src/qt/rpcconsole.h | 10 ++++++---- src/qt/walletmodel.h | 2 ++ 5 files changed, 55 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index b39aaef46c..2530c9dc7c 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -554,6 +554,7 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) m_wallet_selector->setVisible(true); m_wallet_selector->setVisible(true); } + rpcConsole->addWallet(name, walletModel); return walletFrame->addWallet(name, walletModel); } diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index bba822882e..695ed61228 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -412,6 +412,22 @@ 4 + + + + Wallet: + + + + + + + + (none) + + + + diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 1aa4de03ca..5e72b7b62e 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -84,7 +85,7 @@ class RPCExecutor : public QObject Q_OBJECT public Q_SLOTS: - void request(const QString &command); + void request(const QString &command, const QString &walletID); Q_SIGNALS: void reply(int category, const QString &command); @@ -145,7 +146,7 @@ public: * @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data */ -bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut) +bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const std::string *walletID) { std::vector< std::vector > stack; stack.push_back(std::vector()); @@ -303,10 +304,8 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string & req.params = RPCConvertValues(stack.back()[0], std::vector(stack.back().begin() + 1, stack.back().end())); req.strMethod = stack.back()[0]; #ifdef ENABLE_WALLET - // TODO: Move this logic to WalletModel - if (!vpwallets.empty()) { - // in Qt, use always the wallet with index 0 when running with multiple wallets - QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(vpwallets[0]->GetName())); + if (walletID && !walletID->empty()) { + QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(*walletID)); req.URI = "/wallet/"+std::string(encodedName.constData(), encodedName.length()); } #endif @@ -385,7 +384,7 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string & } } -void RPCExecutor::request(const QString &command) +void RPCExecutor::request(const QString &command, const QString &walletID) { try { @@ -416,7 +415,8 @@ void RPCExecutor::request(const QString &command) " example: getblock(getblockhash(0),true)[tx][0]\n\n"))); return; } - if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand)) + std::string wallet_id = walletID.toStdString(); + if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand, nullptr, &wallet_id)) { Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \"")); return; @@ -687,6 +687,18 @@ void RPCConsole::setClientModel(ClientModel *model) } } +#ifdef ENABLE_WALLET +void RPCConsole::addWallet(const QString name, WalletModel * const walletModel) +{ + // use name for text and internal data object (to allow to move to a wallet id later) + ui->WalletSelector->addItem(name, name); + if (ui->WalletSelector->count() == 2 && !isVisible()) { + // First wallet added, set to default so long as the window isn't presently visible (and potentially in use) + ui->WalletSelector->setCurrentIndex(1); + } +} +#endif + static QString categoryClass(int category) { switch(category) @@ -874,8 +886,16 @@ void RPCConsole::on_lineEdit_returnPressed() cmdBeforeBrowsing = QString(); + QString walletID; +#ifdef ENABLE_WALLET + const int wallet_index = ui->WalletSelector->currentIndex(); + if (wallet_index > 0) { + walletID = (QString)ui->WalletSelector->itemData(wallet_index).value(); + } +#endif + message(CMD_REQUEST, QString::fromStdString(strFilteredCmd)); - Q_EMIT cmdRequest(cmd); + Q_EMIT cmdRequest(cmd, walletID); cmd = QString::fromStdString(strFilteredCmd); @@ -923,7 +943,7 @@ void RPCConsole::startExecutor() // Replies from executor object must go to this object connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString))); // Requests from this object must go to executor - connect(this, SIGNAL(cmdRequest(QString)), executor, SLOT(request(QString))); + connect(this, SIGNAL(cmdRequest(QString, QString)), executor, SLOT(request(QString, QString))); // On stopExecutor signal // - quit the Qt event loop in the execution thread diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index c41cbb0933..6299d80793 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -17,6 +17,7 @@ class ClientModel; class PlatformStyle; class RPCTimerInterface; +class WalletModel; namespace Ui { class RPCConsole; @@ -36,12 +37,13 @@ public: explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent); ~RPCConsole(); - static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr); - static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr) { - return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut); + static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr); + static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr) { + return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut, walletID); } void setClientModel(ClientModel *model); + void addWallet(const QString name, WalletModel * const walletModel); enum MessageClass { MC_ERROR, @@ -120,7 +122,7 @@ public Q_SLOTS: Q_SIGNALS: // For RPC command executor void stopExecutor(); - void cmdRequest(const QString &command); + void cmdRequest(const QString &command, const QString &walletID); private: void startExecutor(); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index b0045fa272..02f59d001d 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -131,6 +131,8 @@ public: TransactionTableModel *getTransactionTableModel(); RecentRequestsTableModel *getRecentRequestsTableModel(); + CWallet *getWallet() const { return wallet; }; + CAmount getBalance(const CCoinControl *coinControl = nullptr) const; CAmount getUnconfirmedBalance() const; CAmount getImmatureBalance() const; -- cgit v1.2.3 From d1ec34a761d1d99b84e792fb6a6e62dbd8b5bdde Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 29 Dec 2016 13:53:25 +0000 Subject: Qt: QComboBox::setVisible doesn't work in toolbars, so defer adding it at all until needed --- src/qt/bitcoingui.cpp | 17 +++++++---------- src/qt/bitcoingui.h | 1 + 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 2530c9dc7c..6791a4a164 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -86,6 +86,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * progressBar(0), progressDialog(0), appMenuBar(0), + appToolBar(0), overviewAction(0), historyAction(0), quitAction(0), @@ -453,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); @@ -467,15 +469,7 @@ void BitcoinGUI::createToolBars() spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); toolbar->addWidget(spacer); - m_wallet_selector_label = new QLabel(); - m_wallet_selector_label->setText(tr("Wallet:") + " "); - toolbar->addWidget(m_wallet_selector_label); - m_wallet_selector_label->setVisible(false); m_wallet_selector = new QComboBox(); - toolbar->addWidget(m_wallet_selector); - m_wallet_selector->setVisible(false); - m_wallet_selector_label->setBuddy(m_wallet_selector); - connect(m_wallet_selector, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setCurrentWallet(const QString&))); #endif } @@ -551,8 +545,11 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) setWalletActionsEnabled(true); m_wallet_selector->addItem(name); if (m_wallet_selector->count() == 2) { - m_wallet_selector->setVisible(true); - m_wallet_selector->setVisible(true); + 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(name, walletModel); return walletFrame->addWallet(name, walletModel); diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 597c583ef2..5037203306 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -89,6 +89,7 @@ private: QProgressDialog *progressDialog; QMenuBar *appMenuBar; + QToolBar *appToolBar; QAction *overviewAction; QAction *historyAction; QAction *quitAction; -- cgit v1.2.3 From 12d8d2681e34a191f5d82f15448f8c4c9a14f6d0 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 6 Mar 2018 12:26:40 +0800 Subject: Qt: When multiple wallets are used, include in notifications the name --- src/qt/bitcoingui.cpp | 9 ++++++--- src/qt/bitcoingui.h | 2 +- src/qt/walletmodel.cpp | 15 +++++++++++++++ src/qt/walletmodel.h | 3 +++ src/qt/walletview.cpp | 4 ++-- src/qt/walletview.h | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6791a4a164..249c27ad6a 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1000,12 +1000,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()) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 5037203306..9ba50a6eca 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -196,7 +196,7 @@ 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: diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index df1a996af0..a1294998e8 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -744,3 +744,18 @@ int WalletModel::getDefaultConfirmTarget() const { return nTxConfirmTarget; } + +QString WalletModel::getWalletName() const +{ + LOCK(wallet->cs_wallet); + QString walletName = QString::fromStdString(wallet->GetName()); + if (walletName.endsWith(".dat")) { + walletName.truncate(walletName.size() - 4); + } + return walletName; +} + +bool WalletModel::isMultiwallet() +{ + return gArgs.GetArgs("-wallet").size() > 1; +} diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 02f59d001d..08175abe85 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -222,6 +222,9 @@ public: int getDefaultConfirmTarget() const; + QString getWalletName() const; + + static bool isMultiwallet(); private: CWallet *wallet; bool fHaveWatchOnly; diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index afc5fb2630..cc4300a7a1 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -104,7 +104,7 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui) connect(this, SIGNAL(encryptionStatusChanged()), gui, SLOT(updateWalletStatus())); // Pass through transaction notifications - connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString))); + connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString,QString))); // Connect HD enabled state signal connect(this, SIGNAL(hdEnabledStatusChanged()), gui, SLOT(updateWalletStatus())); @@ -172,7 +172,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int QString address = ttm->data(index, TransactionTableModel::AddressRole).toString(); QString label = ttm->data(index, TransactionTableModel::LabelRole).toString(); - Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); + Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, walletModel->getWalletName()); } void WalletView::gotoOverviewPage() diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 739b3a0b6d..878a5966d6 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -124,7 +124,7 @@ Q_SIGNALS: /** HD-Enabled status of wallet changed (only possible during startup) */ void hdEnabledStatusChanged(); /** Notify that a new transaction appeared */ - 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); /** Notify that the out of sync warning icon has been pressed */ void outOfSyncWarningClicked(); }; -- cgit v1.2.3 From b6d04fc7cc5de3370d2d8255f2b3e43f6bf9c80d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 12 Oct 2017 07:22:48 +0000 Subject: Qt: Get wallet name from WalletModel rather than passing it around --- src/qt/bitcoin.cpp | 9 ++------- src/qt/bitcoingui.cpp | 7 ++++--- src/qt/bitcoingui.h | 2 +- src/qt/rpcconsole.cpp | 3 ++- src/qt/rpcconsole.h | 2 +- src/qt/walletframe.cpp | 11 +++++++++-- src/qt/walletframe.h | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 424d82ae1f..df1be35c8d 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -487,14 +487,9 @@ void BitcoinApplication::initializeResult(bool success) for (CWalletRef pwallet : vpwallets) { WalletModel * const walletModel = new WalletModel(platformStyle, pwallet, optionsModel); - QString WalletName = QString::fromStdString(pwallet->GetName()); - if (WalletName.endsWith(".dat")) { - WalletName.truncate(WalletName.size() - 4); - } - - window->addWallet(WalletName, walletModel); + window->addWallet(walletModel); if (fFirstWallet) { - window->setCurrentWallet(WalletName); + window->setCurrentWallet(walletModel->getWalletName()); fFirstWallet = false; } diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 249c27ad6a..e9090e6a26 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -538,10 +538,11 @@ 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); m_wallet_selector->addItem(name); if (m_wallet_selector->count() == 2) { @@ -551,8 +552,8 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) appToolBar->addWidget(m_wallet_selector_label); appToolBar->addWidget(m_wallet_selector); } - rpcConsole->addWallet(name, walletModel); - return walletFrame->addWallet(name, walletModel); + rpcConsole->addWallet(walletModel); + return walletFrame->addWallet(walletModel); } bool BitcoinGUI::setCurrentWallet(const QString& name) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 9ba50a6eca..b9e92f2d5b 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -62,7 +62,7 @@ public: 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 addWallet(WalletModel *walletModel); void removeAllWallets(); #endif // ENABLE_WALLET bool enableWallet; diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 5e72b7b62e..f1f9f6fc4c 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -688,8 +688,9 @@ void RPCConsole::setClientModel(ClientModel *model) } #ifdef ENABLE_WALLET -void RPCConsole::addWallet(const QString name, WalletModel * const walletModel) +void RPCConsole::addWallet(WalletModel * const walletModel) { + const QString name = walletModel->getWalletName(); // use name for text and internal data object (to allow to move to a wallet id later) ui->WalletSelector->addItem(name, name); if (ui->WalletSelector->count() == 2 && !isVisible()) { diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 6299d80793..5a22be3987 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -43,7 +43,7 @@ public: } void setClientModel(ClientModel *model); - void addWallet(const QString name, WalletModel * const walletModel); + void addWallet(WalletModel * const walletModel); enum MessageClass { MC_ERROR, diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index c0b9d04269..5b13353d7b 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include @@ -39,10 +40,16 @@ void WalletFrame::setClientModel(ClientModel *_clientModel) this->clientModel = _clientModel; } -bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel) +bool WalletFrame::addWallet(WalletModel *walletModel) { - if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0) + if (!gui || !clientModel || !walletModel) { return false; + } + + const QString name = walletModel->getWalletName(); + if (mapWalletViews.count(name) > 0) { + return false; + } WalletView *walletView = new WalletView(platformStyle, this); walletView->setBitcoinGUI(gui); diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index ce37e456f1..6eedcf370c 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -36,7 +36,7 @@ public: void setClientModel(ClientModel *clientModel); - bool addWallet(const QString& name, WalletModel *walletModel); + bool addWallet(WalletModel *walletModel); bool setCurrentWallet(const QString& name); bool removeWallet(const QString &name); void removeAllWallets(); -- cgit v1.2.3 From cfa4133ce53db2de8791ee7fa758d50a438083a6 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 14 Dec 2017 03:29:55 +0000 Subject: GUI: RPCConsole: Log wallet changes --- src/qt/rpcconsole.cpp | 9 +++++++++ src/qt/rpcconsole.h | 1 + 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index f1f9f6fc4c..29b8c4d03a 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -893,6 +893,15 @@ void RPCConsole::on_lineEdit_returnPressed() if (wallet_index > 0) { walletID = (QString)ui->WalletSelector->itemData(wallet_index).value(); } + + if (m_last_wallet_id != walletID) { + if (walletID.isEmpty()) { + message(CMD_REQUEST, tr("Executing command without any wallet")); + } else { + message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(walletID)); + } + m_last_wallet_id = walletID; + } #endif message(CMD_REQUEST, QString::fromStdString(strFilteredCmd)); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 5a22be3987..c97260b2c3 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -153,6 +153,7 @@ private: int consoleFontSize; QCompleter *autoCompleter; QThread thread; + QString m_last_wallet_id; /** Update UI with latest network info from model. */ void updateNetworkState(); -- cgit v1.2.3 From 4826ca4b8438b6dd97701bb921f9d5122d8f832a Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 6 Mar 2018 12:56:21 +0800 Subject: Qt: show wallet name in send confirmation dlg in case of multiwallet --- src/qt/sendcoinsdialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index ef36aab1a4..a1cb2eb2bb 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -277,8 +277,11 @@ void SendCoinsDialog::on_sendButton_clicked() QStringList formatted; for (const SendCoinsRecipient &rcp : currentTransaction.getRecipients()) { - // generate bold amount string + // generate bold amount string with wallet name in case of multiwallet QString amount = "" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); + if (model->isMultiwallet()) { + amount.append(" "+tr("from wallet %1").arg(GUIUtil::HtmlEscape(model->getWalletName()))+" "); + } amount.append(""); // generate monospace address string QString address = "" + rcp.address; -- cgit v1.2.3 From dc6f150f350f9c669d1c33e20afd0fdbb7fcf047 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 6 Mar 2018 13:17:36 +0800 Subject: Qt: show wallet name in request dlg in case of multiwallet --- src/qt/receivecoinsdialog.cpp | 4 ++-- src/qt/receiverequestdialog.cpp | 9 ++++++--- src/qt/receiverequestdialog.h | 6 ++---- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 7fd5285467..3436bbe312 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -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(); @@ -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(); diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp index d4cb0e5ba2..75146e2214 100644 --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -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(); @@ -143,11 +143,14 @@ void ReceiveRequestDialog::update() html += "" + GUIUtil::HtmlEscape(uri) + "
"; html += ""+tr("Address")+": " + GUIUtil::HtmlEscape(info.address) + "
"; if(info.amount) - html += ""+tr("Amount")+": " + BitcoinUnits::formatHtmlWithUnit(model->getDisplayUnit(), info.amount) + "
"; + html += ""+tr("Amount")+": " + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount) + "
"; if(!info.label.isEmpty()) html += ""+tr("Label")+": " + GUIUtil::HtmlEscape(info.label) + "
"; if(!info.message.isEmpty()) html += ""+tr("Message")+": " + GUIUtil::HtmlEscape(info.message) + "
"; + if(model->isMultiwallet()) { + html += ""+tr("Wallet")+": " + GUIUtil::HtmlEscape(model->getWalletName()) + "
"; + } ui->outUri->setText(html); #ifdef USE_QRCODE diff --git a/src/qt/receiverequestdialog.h b/src/qt/receiverequestdialog.h index 21bbf1edb7..23c5529535 100644 --- a/src/qt/receiverequestdialog.h +++ b/src/qt/receiverequestdialog.h @@ -12,8 +12,6 @@ #include #include -class OptionsModel; - namespace Ui { class ReceiveRequestDialog; } @@ -53,7 +51,7 @@ public: explicit ReceiveRequestDialog(QWidget *parent = 0); ~ReceiveRequestDialog(); - void setModel(OptionsModel *model); + void setModel(WalletModel *model); void setInfo(const SendCoinsRecipient &info); private Q_SLOTS: @@ -64,7 +62,7 @@ private Q_SLOTS: private: Ui::ReceiveRequestDialog *ui; - OptionsModel *model; + WalletModel *model; SendCoinsRecipient info; }; -- cgit v1.2.3 From 779c5f984064cfc48304b78da664de13fc3d9bb4 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sun, 18 Mar 2018 15:35:51 +0700 Subject: Qt: hide RPCConsole wallet selector when no wallets are present --- src/qt/rpcconsole.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 29b8c4d03a..c41e19f6f5 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -478,6 +478,10 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) : connect(ui->fontSmallerButton, SIGNAL(clicked()), this, SLOT(fontSmaller())); connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear())); + // disable the wallet selector by default + ui->WalletSelector->setVisible(false); + ui->WalletSelectorLabel->setVisible(false); + // set library version labels #ifdef ENABLE_WALLET ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0)); @@ -697,6 +701,10 @@ void RPCConsole::addWallet(WalletModel * const walletModel) // First wallet added, set to default so long as the window isn't presently visible (and potentially in use) ui->WalletSelector->setCurrentIndex(1); } + if (ui->WalletSelector->count() > 2) { + ui->WalletSelector->setVisible(true); + ui->WalletSelectorLabel->setVisible(true); + } } #endif -- cgit v1.2.3