Skip to content

Commit 3dba3c3

Browse files
luke-jrjonasschnelli
authored andcommitted
Qt: Load all wallets into WalletModels
1 parent ed6ae80 commit 3dba3c3

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/qt/bitcoin.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public Q_SLOTS:
251251
QTimer *pollShutdownTimer;
252252
#ifdef ENABLE_WALLET
253253
PaymentServer* paymentServer;
254-
WalletModel *walletModel;
254+
std::vector<WalletModel*> m_wallet_models;
255255
#endif
256256
int returnValue;
257257
const PlatformStyle *platformStyle;
@@ -333,7 +333,7 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
333333
pollShutdownTimer(0),
334334
#ifdef ENABLE_WALLET
335335
paymentServer(0),
336-
walletModel(0),
336+
m_wallet_models(),
337337
#endif
338338
returnValue(0)
339339
{
@@ -451,8 +451,10 @@ void BitcoinApplication::requestShutdown()
451451

452452
#ifdef ENABLE_WALLET
453453
window->removeAllWallets();
454-
delete walletModel;
455-
walletModel = 0;
454+
for (WalletModel *walletModel : m_wallet_models) {
455+
delete walletModel;
456+
}
457+
m_wallet_models.clear();
456458
#endif
457459
delete clientModel;
458460
clientModel = 0;
@@ -481,16 +483,25 @@ void BitcoinApplication::initializeResult(bool success)
481483
window->setClientModel(clientModel);
482484

483485
#ifdef ENABLE_WALLET
484-
// TODO: Expose secondary wallets
485-
if (!vpwallets.empty())
486-
{
487-
walletModel = new WalletModel(platformStyle, vpwallets[0], optionsModel);
486+
bool fFirstWallet = true;
487+
for (CWalletRef pwallet : vpwallets) {
488+
WalletModel * const walletModel = new WalletModel(platformStyle, pwallet, optionsModel);
488489

489-
window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel);
490-
window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET);
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);
496+
if (fFirstWallet) {
497+
window->setCurrentWallet(WalletName);
498+
fFirstWallet = false;
499+
}
491500

492501
connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
493502
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
503+
504+
m_wallet_models.push_back(walletModel);
494505
}
495506
#endif
496507

src/qt/bitcoingui.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
7070
#endif
7171
;
7272

73-
/** Display name for default wallet name. Uses tilde to avoid name
74-
* collisions in the future with additional wallets */
75-
const QString BitcoinGUI::DEFAULT_WALLET = "~Default";
76-
7773
BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
7874
QMainWindow(parent),
7975
enableWallet(false),

src/qt/bitcoingui.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class BitcoinGUI : public QMainWindow
4646
Q_OBJECT
4747

4848
public:
49-
static const QString DEFAULT_WALLET;
5049
static const std::string DEFAULT_UIPLATFORM;
5150

5251
explicit BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0);

0 commit comments

Comments
 (0)