1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "walletframe.h"
7 #include "bitcoingui.h"
8 #include "walletview.h"
12 #include <QHBoxLayout>
15 WalletFrame::WalletFrame(const PlatformStyle
*_platformStyle
, BitcoinGUI
*_gui
) :
18 platformStyle(_platformStyle
)
20 // Leave HBox hook for adding a list view later
21 QHBoxLayout
*walletFrameLayout
= new QHBoxLayout(this);
22 setContentsMargins(0,0,0,0);
23 walletStack
= new QStackedWidget(this);
24 walletFrameLayout
->setContentsMargins(0,0,0,0);
25 walletFrameLayout
->addWidget(walletStack
);
27 QLabel
*noWallet
= new QLabel(tr("No wallet has been loaded."));
28 noWallet
->setAlignment(Qt::AlignCenter
);
29 walletStack
->addWidget(noWallet
);
32 WalletFrame::~WalletFrame()
36 void WalletFrame::setClientModel(ClientModel
*_clientModel
)
38 this->clientModel
= _clientModel
;
41 bool WalletFrame::addWallet(const QString
& name
, WalletModel
*walletModel
)
43 if (!gui
|| !clientModel
|| !walletModel
|| mapWalletViews
.count(name
) > 0)
46 WalletView
*walletView
= new WalletView(platformStyle
, this);
47 walletView
->setBitcoinGUI(gui
);
48 walletView
->setClientModel(clientModel
);
49 walletView
->setWalletModel(walletModel
);
50 walletView
->showOutOfSyncWarning(bOutOfSync
);
52 /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
53 walletView
->gotoOverviewPage();
54 walletStack
->addWidget(walletView
);
55 mapWalletViews
[name
] = walletView
;
57 // Ensure a walletView is able to show the main window
58 connect(walletView
, SIGNAL(showNormalIfMinimized()), gui
, SLOT(showNormalIfMinimized()));
60 connect(walletView
, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
65 bool WalletFrame::setCurrentWallet(const QString
& name
)
67 if (mapWalletViews
.count(name
) == 0)
70 WalletView
*walletView
= mapWalletViews
.value(name
);
71 walletStack
->setCurrentWidget(walletView
);
72 walletView
->updateEncryptionStatus();
76 bool WalletFrame::removeWallet(const QString
&name
)
78 if (mapWalletViews
.count(name
) == 0)
81 WalletView
*walletView
= mapWalletViews
.take(name
);
82 walletStack
->removeWidget(walletView
);
86 void WalletFrame::removeAllWallets()
88 QMap
<QString
, WalletView
*>::const_iterator i
;
89 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
90 walletStack
->removeWidget(i
.value());
91 mapWalletViews
.clear();
94 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient
&recipient
)
96 WalletView
*walletView
= currentWalletView();
100 return walletView
->handlePaymentRequest(recipient
);
103 void WalletFrame::showOutOfSyncWarning(bool fShow
)
106 QMap
<QString
, WalletView
*>::const_iterator i
;
107 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
108 i
.value()->showOutOfSyncWarning(fShow
);
111 void WalletFrame::gotoOverviewPage()
113 QMap
<QString
, WalletView
*>::const_iterator i
;
114 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
115 i
.value()->gotoOverviewPage();
118 void WalletFrame::gotoHistoryPage()
120 QMap
<QString
, WalletView
*>::const_iterator i
;
121 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
122 i
.value()->gotoHistoryPage();
125 void WalletFrame::gotoReceiveCoinsPage()
127 QMap
<QString
, WalletView
*>::const_iterator i
;
128 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
129 i
.value()->gotoReceiveCoinsPage();
132 void WalletFrame::gotoSendCoinsPage(QString addr
)
134 QMap
<QString
, WalletView
*>::const_iterator i
;
135 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
136 i
.value()->gotoSendCoinsPage(addr
);
139 void WalletFrame::gotoSignMessageTab(QString addr
)
141 WalletView
*walletView
= currentWalletView();
143 walletView
->gotoSignMessageTab(addr
);
146 void WalletFrame::gotoVerifyMessageTab(QString addr
)
148 WalletView
*walletView
= currentWalletView();
150 walletView
->gotoVerifyMessageTab(addr
);
153 void WalletFrame::encryptWallet(bool status
)
155 WalletView
*walletView
= currentWalletView();
157 walletView
->encryptWallet(status
);
160 void WalletFrame::backupWallet()
162 WalletView
*walletView
= currentWalletView();
164 walletView
->backupWallet();
167 void WalletFrame::changePassphrase()
169 WalletView
*walletView
= currentWalletView();
171 walletView
->changePassphrase();
174 void WalletFrame::unlockWallet()
176 WalletView
*walletView
= currentWalletView();
178 walletView
->unlockWallet();
181 void WalletFrame::usedSendingAddresses()
183 WalletView
*walletView
= currentWalletView();
185 walletView
->usedSendingAddresses();
188 void WalletFrame::usedReceivingAddresses()
190 WalletView
*walletView
= currentWalletView();
192 walletView
->usedReceivingAddresses();
195 WalletView
*WalletFrame::currentWalletView()
197 return qobject_cast
<WalletView
*>(walletStack
->currentWidget());
200 void WalletFrame::outOfSyncWarningClicked()
202 Q_EMIT
requestedSyncWarningInfo();