From e449f9a9e620fb909eb7b32d815b413d235f05ad Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 9 Sep 2016 10:43:54 +0000 Subject: [PATCH] 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(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 0bf1d5c55..92fb3f190 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 b1ec6540c..42581e7d1 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