Permalink
Browse files

Merge multiwallet_gui-0.14

  • Loading branch information...
luke-jr committed Mar 7, 2017
2 parents f582ed6 + ff19674 commit c0f1fbe1bc6b4c4753082724c17d987b06be0172
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
@@ -27,6 +27,7 @@
#ifdef ENABLE_WALLET
#include "walletframe.h"
#include "walletmodel.h"
#include "walletview.h"
#endif // ENABLE_WALLET
#ifdef Q_OS_MAC
@@ -42,6 +43,7 @@
#include <QAction>
#include <QApplication>
#include <QComboBox>
#include <QDateTime>
#include <QDesktopWidget>
#include <QDragEnterEvent>
@@ -76,10 +78,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),
@@ -94,6 +92,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
progressBar(0),
progressDialog(0),
appMenuBar(0),
appToolBar(0),
overviewAction(0),
historyAction(0),
quitAction(0),
@@ -475,13 +474,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
}
}
@@ -561,6 +570,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);
}
@@ -1135,6 +1153,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
@@ -37,6 +37,7 @@ class CWallet;
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QProgressBar;
class QProgressDialog;
QT_END_NAMESPACE
@@ -50,7 +51,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);
@@ -67,7 +67,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;
@@ -94,6 +93,7 @@ class BitcoinGUI : public QMainWindow
QProgressDialog *progressDialog;
QMenuBar *appMenuBar;
QToolBar *appToolBar;
QAction *overviewAction;
QAction *historyAction;
QAction *quitAction;
@@ -118,6 +118,9 @@ class BitcoinGUI : public QMainWindow
QAction *showHelpMessageAction;
QAction *showMempoolStatsAction;
QLabel *WalletSelectorLabel;
QComboBox *WalletSelector;
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
Notificator *notificator;
@@ -180,6 +183,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
@@ -192,6 +202,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
@@ -18,6 +18,7 @@ class ClientModel;
class GuiNetWatch;
class PlatformStyle;
class RPCTimerInterface;
class WalletModel;
namespace Ui {
class RPCConsole;
@@ -37,12 +38,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,
@@ -121,7 +123,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 c0f1fbe

Please sign in to comment.