Permalink
Browse files

Merge multiwallet_gui

  • Loading branch information...
2 parents b5e1306 + ac2f538 commit 83153e120449ce3c0126299d3ca5dcc4e7a3739e @luke-jr luke-jr committed Feb 18, 2017
View
@@ -242,7 +242,7 @@ public Q_SLOTS:
QTimer *pollShutdownTimer;
#ifdef ENABLE_WALLET
PaymentServer* paymentServer;
- WalletModel *walletModel;
+ std::vector<WalletModel*> walletModels;
#endif
int returnValue;
const PlatformStyle *platformStyle;
@@ -319,7 +319,7 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
pollShutdownTimer(0),
#ifdef ENABLE_WALLET
paymentServer(0),
- walletModel(0),
+ walletModels(),
#endif
returnValue(0)
{
@@ -438,8 +438,10 @@ void BitcoinApplication::requestShutdown()
#ifdef ENABLE_WALLET
window->removeAllWallets();
- delete walletModel;
- walletModel = 0;
+ for (WalletModel *walletModel : walletModels) {
+ delete walletModel;
+ }
+ walletModels.clear();
#endif
delete clientModel;
clientModel = 0;
@@ -468,16 +470,25 @@ void BitcoinApplication::initializeResult(int retval)
window->setClientModel(clientModel);
#ifdef ENABLE_WALLET
- // TODO: Expose secondary wallets
- if (!vpwallets.empty())
- {
- walletModel = new WalletModel(platformStyle, vpwallets[0], optionsModel);
+ bool fFirstWallet = true;
+ for (CWallet_ptr 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->strWalletFile);
+ 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)));
+
+ walletModels.push_back(walletModel);
}
#endif
View
@@ -26,6 +26,7 @@
#ifdef ENABLE_WALLET
#include "walletframe.h"
#include "walletmodel.h"
+#include "walletview.h"
#endif // ENABLE_WALLET
#ifdef Q_OS_MAC
@@ -41,6 +42,7 @@
#include <QAction>
#include <QApplication>
+#include <QComboBox>
#include <QDateTime>
#include <QDesktopWidget>
#include <QDragEnterEvent>
@@ -75,10 +77,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),
@@ -93,6 +91,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
progressBar(0),
progressDialog(0),
appMenuBar(0),
+ appToolBar(0),
overviewAction(0),
historyAction(0),
quitAction(0),
@@ -465,13 +464,23 @@ void BitcoinGUI::createToolBars()
if(walletFrame)
{
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
+ appToolBar = toolbar;
toolbar->setMovable(false);
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolbar->addAction(overviewAction);
toolbar->addAction(sendCoinsAction);
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);
+
+ WalletSelector = new QComboBox();
+ connect(WalletSelector, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setCurrentWallet(const QString&)));
+#endif
}
}
@@ -541,6 +550,15 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
if(!walletFrame)
return false;
setWalletActionsEnabled(true);
+ WalletSelector->addItem(name);
+ if (WalletSelector->count() == 2) {
+ WalletSelectorLabel = new QLabel();
+ WalletSelectorLabel->setText(tr("Wallet:") + " ");
+ WalletSelectorLabel->setBuddy(WalletSelector);
+ appToolBar->addWidget(WalletSelectorLabel);
+ appToolBar->addWidget(WalletSelector);
+ }
+ rpcConsole->addWallet(name, walletModel);
return walletFrame->addWallet(name, walletModel);
}
@@ -1100,6 +1118,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)
View
@@ -36,6 +36,7 @@ class CWallet;
QT_BEGIN_NAMESPACE
class QAction;
+class QComboBox;
class QProgressBar;
class QProgressDialog;
QT_END_NAMESPACE
@@ -49,7 +50,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);
@@ -66,7 +66,6 @@ class BitcoinGUI : public QMainWindow
functionality.
*/
bool addWallet(const QString& name, WalletModel *walletModel);
- bool setCurrentWallet(const QString& name);
void removeAllWallets();
#endif // ENABLE_WALLET
bool enableWallet;
@@ -93,6 +92,7 @@ class BitcoinGUI : public QMainWindow
QProgressDialog *progressDialog;
QMenuBar *appMenuBar;
+ QToolBar *appToolBar;
QAction *overviewAction;
QAction *historyAction;
QAction *quitAction;
@@ -116,6 +116,9 @@ class BitcoinGUI : public QMainWindow
QAction *showHelpMessageAction;
QAction *showMempoolStatsAction;
+ QLabel *WalletSelectorLabel;
+ QComboBox *WalletSelector;
+
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
Notificator *notificator;
@@ -176,6 +179,13 @@ public Q_SLOTS:
void message(const QString &title, const QString &message, unsigned int style, bool *ret = NULL);
#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
@@ -188,6 +198,7 @@ public Q_SLOTS:
*/
void setHDStatus(int hdEnabled);
+public Q_SLOTS:
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
/** Show incoming transaction notification for new transactions. */
@@ -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">
View
@@ -14,6 +14,7 @@
#include "guiutil.h"
#include "platformstyle.h"
#include "bantablemodel.h"
+#include "walletmodel.h"
#include "chainparams.h"
#include "netbase.h"
@@ -89,7 +90,7 @@ class RPCExecutor : public QObject
Q_OBJECT
public Q_SLOTS:
- void request(const QString &command);
+ void request(const QString &command, void *ppwallet);
Q_SIGNALS:
void reply(int category, const QString &command);
@@ -150,7 +151,7 @@ class QtRPCTimerInterface: public RPCTimerInterface
* @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, void * const ppwallet_v)
{
std::vector< std::vector<std::string> > stack;
stack.push_back(std::vector<std::string>());
@@ -304,8 +305,11 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
req.strMethod = stack.back()[0];
#ifdef ENABLE_WALLET
- // TODO: Some way to access secondary wallets
- req.wallet = vpwallets.empty() ? NULL : vpwallets[0];
+ CWallet_ptr * const ppwallet = (CWallet_ptr*)ppwallet_v;
+ if (ppwallet) {
+ req.wallet = *ppwallet;
+ delete ppwallet;
+ }
#endif
lastResult = tableRPC.execute(req);
}
@@ -382,13 +386,13 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
}
}
-void RPCExecutor::request(const QString &command)
+void RPCExecutor::request(const QString &command, void * const ppwallet_v)
{
try
{
std::string result;
std::string executableCommand = command.toStdString() + "\n";
- if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand))
+ if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand, NULL, ppwallet_v))
{
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
return;
@@ -517,6 +521,12 @@ void RPCConsole::WriteCommandHistory()
RPCConsole::~RPCConsole()
{
+#ifdef ENABLE_WALLET
+ for (int i = ui->WalletSelector->count(); --i >= 1; ) {
+ CWallet_ptr * const ppwallet = (CWallet_ptr*)ui->WalletSelector->itemData(i).value<void*>();
+ delete ppwallet;
+ }
+#endif
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
WriteCommandHistory();
@@ -703,6 +713,18 @@ void RPCConsole::setClientModel(ClientModel *model)
}
}
+#ifdef ENABLE_WALLET
+void RPCConsole::addWallet(const QString name, WalletModel * const walletModel)
+{
+ CWallet_ptr * const ppwallet = new CWallet_ptr(walletModel->getWallet());
+ ui->WalletSelector->addItem(name, QVariant::fromValue((void*)(ppwallet)));
+ 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)
@@ -883,8 +905,18 @@ void RPCConsole::on_lineEdit_returnPressed()
cmdBeforeBrowsing = QString();
+ void *ppwallet_v = NULL;
+#ifdef ENABLE_WALLET
+ const int wallet_index = ui->WalletSelector->currentIndex();
+ if (wallet_index > 0) {
+ CWallet_ptr *ppwallet = (CWallet_ptr*)ui->WalletSelector->itemData(wallet_index).value<void*>();
+ ppwallet = new CWallet_ptr(*ppwallet); // Refcount
+ ppwallet_v = (void*)ppwallet;
+ }
+#endif
+
message(CMD_REQUEST, cmd);
- Q_EMIT cmdRequest(cmd);
+ Q_EMIT cmdRequest(cmd, ppwallet_v);
cmd = QString::fromStdString(strFilteredCmd);
@@ -932,7 +964,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, void*)), executor, SLOT(request(QString, void*)));
// On stopExecutor signal
// - quit the Qt event loop in the execution thread
View
@@ -17,6 +17,7 @@
class ClientModel;
class PlatformStyle;
class RPCTimerInterface;
+class WalletModel;
namespace Ui {
class RPCConsole;
@@ -36,12 +37,13 @@ class RPCConsole: public QWidget
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
~RPCConsole();
- static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = NULL);
- static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = NULL) {
- return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut);
+ static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = NULL, void *wallet = NULL);
+ static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = NULL, void *wallet = NULL) {
+ return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut, wallet);
}
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, void *ppwallet);
private:
static QString FormatBytes(quint64 bytes);
Oops, something went wrong.

0 comments on commit 83153e1

Please sign in to comment.