Skip to content

Commit

Permalink
Qt: Get wallet name from WalletModel rather than passing it around
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#11383
Rebased-From: 6445a935e6daeadd38c3d8633083ca45fc2cfe1f
  • Loading branch information
luke-jr committed Nov 6, 2017
1 parent 51b4432 commit 42ca0f5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
9 changes: 2 additions & 7 deletions src/qt/bitcoin.cpp
Expand Up @@ -490,14 +490,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;
}

Expand Down
7 changes: 4 additions & 3 deletions src/qt/bitcoingui.cpp
Expand Up @@ -536,10 +536,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);
WalletSelector->addItem(name);
if (WalletSelector->count() == 2) {
Expand All @@ -549,8 +550,8 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
appToolBar->addWidget(WalletSelectorLabel);
appToolBar->addWidget(WalletSelector);
}
rpcConsole->addWallet(name, walletModel);
return walletFrame->addWallet(name, walletModel);
rpcConsole->addWallet(walletModel);
return walletFrame->addWallet(walletModel);
}

bool BitcoinGUI::setCurrentWallet(const QString& name)
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.h
Expand Up @@ -62,7 +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 addWallet(WalletModel *walletModel);
void removeAllWallets();
bool multiWallet() const;
#endif // ENABLE_WALLET
Expand Down
3 changes: 2 additions & 1 deletion src/qt/rpcconsole.cpp
Expand Up @@ -663,8 +663,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();
CWalletRef * const ppwallet = new CWalletRef(walletModel->getWallet());
ui->WalletSelector->addItem(name, QVariant::fromValue((void*)(ppwallet)));
if (ui->WalletSelector->count() == 2 && !isVisible()) {
Expand Down
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.h
Expand Up @@ -43,7 +43,7 @@ class RPCConsole: public QWidget
}

void setClientModel(ClientModel *model);
void addWallet(const QString name, WalletModel * const walletModel);
void addWallet(WalletModel * const walletModel);

enum MessageClass {
MC_ERROR,
Expand Down
11 changes: 9 additions & 2 deletions src/qt/walletframe.cpp
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "walletframe.h"
#include "walletmodel.h"

#include "bitcoingui.h"
#include "walletview.h"
Expand Down Expand Up @@ -38,10 +39,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);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletframe.h
Expand Up @@ -36,7 +36,7 @@ class WalletFrame : public QFrame

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();
Expand Down

0 comments on commit 42ca0f5

Please sign in to comment.