Skip to content

Commit b6d04fc

Browse files
luke-jrjonasschnelli
authored andcommitted
Qt: Get wallet name from WalletModel rather than passing it around
1 parent 12d8d26 commit b6d04fc

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,9 @@ void BitcoinApplication::initializeResult(bool success)
487487
for (CWalletRef pwallet : vpwallets) {
488488
WalletModel * const walletModel = new WalletModel(platformStyle, pwallet, optionsModel);
489489

490-
QString WalletName = QString::fromStdString(pwallet->GetName());
491-
if (WalletName.endsWith(".dat")) {
492-
WalletName.truncate(WalletName.size() - 4);
493-
}
494-
495-
window->addWallet(WalletName, walletModel);
490+
window->addWallet(walletModel);
496491
if (fFirstWallet) {
497-
window->setCurrentWallet(WalletName);
492+
window->setCurrentWallet(walletModel->getWalletName());
498493
fFirstWallet = false;
499494
}
500495

src/qt/bitcoingui.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,11 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
538538
}
539539

540540
#ifdef ENABLE_WALLET
541-
bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
541+
bool BitcoinGUI::addWallet(WalletModel *walletModel)
542542
{
543543
if(!walletFrame)
544544
return false;
545+
const QString name = walletModel->getWalletName();
545546
setWalletActionsEnabled(true);
546547
m_wallet_selector->addItem(name);
547548
if (m_wallet_selector->count() == 2) {
@@ -551,8 +552,8 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
551552
appToolBar->addWidget(m_wallet_selector_label);
552553
appToolBar->addWidget(m_wallet_selector);
553554
}
554-
rpcConsole->addWallet(name, walletModel);
555-
return walletFrame->addWallet(name, walletModel);
555+
rpcConsole->addWallet(walletModel);
556+
return walletFrame->addWallet(walletModel);
556557
}
557558

558559
bool BitcoinGUI::setCurrentWallet(const QString& name)

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class BitcoinGUI : public QMainWindow
6262
The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
6363
functionality.
6464
*/
65-
bool addWallet(const QString& name, WalletModel *walletModel);
65+
bool addWallet(WalletModel *walletModel);
6666
void removeAllWallets();
6767
#endif // ENABLE_WALLET
6868
bool enableWallet;

src/qt/rpcconsole.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,9 @@ void RPCConsole::setClientModel(ClientModel *model)
688688
}
689689

690690
#ifdef ENABLE_WALLET
691-
void RPCConsole::addWallet(const QString name, WalletModel * const walletModel)
691+
void RPCConsole::addWallet(WalletModel * const walletModel)
692692
{
693+
const QString name = walletModel->getWalletName();
693694
// use name for text and internal data object (to allow to move to a wallet id later)
694695
ui->WalletSelector->addItem(name, name);
695696
if (ui->WalletSelector->count() == 2 && !isVisible()) {

src/qt/rpcconsole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class RPCConsole: public QWidget
4343
}
4444

4545
void setClientModel(ClientModel *model);
46-
void addWallet(const QString name, WalletModel * const walletModel);
46+
void addWallet(WalletModel * const walletModel);
4747

4848
enum MessageClass {
4949
MC_ERROR,

src/qt/walletframe.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <qt/walletframe.h>
6+
#include <qt/walletmodel.h>
67

78
#include <qt/bitcoingui.h>
89
#include <qt/walletview.h>
@@ -39,10 +40,16 @@ void WalletFrame::setClientModel(ClientModel *_clientModel)
3940
this->clientModel = _clientModel;
4041
}
4142

42-
bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
43+
bool WalletFrame::addWallet(WalletModel *walletModel)
4344
{
44-
if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
45+
if (!gui || !clientModel || !walletModel) {
4546
return false;
47+
}
48+
49+
const QString name = walletModel->getWalletName();
50+
if (mapWalletViews.count(name) > 0) {
51+
return false;
52+
}
4653

4754
WalletView *walletView = new WalletView(platformStyle, this);
4855
walletView->setBitcoinGUI(gui);

src/qt/walletframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WalletFrame : public QFrame
3636

3737
void setClientModel(ClientModel *clientModel);
3838

39-
bool addWallet(const QString& name, WalletModel *walletModel);
39+
bool addWallet(WalletModel *walletModel);
4040
bool setCurrentWallet(const QString& name);
4141
bool removeWallet(const QString &name);
4242
void removeAllWallets();

0 commit comments

Comments
 (0)