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 <qt/walletframe.h>
7 #include <qt/bitcoingui.h>
8 #include <qt/walletview.h>
13 #include <QHBoxLayout>
16 WalletFrame::WalletFrame(const PlatformStyle
*_platformStyle
, BitcoinGUI
*_gui
) :
19 platformStyle(_platformStyle
)
21 // Leave HBox hook for adding a list view later
22 QHBoxLayout
*walletFrameLayout
= new QHBoxLayout(this);
23 setContentsMargins(0,0,0,0);
24 walletStack
= new QStackedWidget(this);
25 walletFrameLayout
->setContentsMargins(0,0,0,0);
26 walletFrameLayout
->addWidget(walletStack
);
28 QLabel
*noWallet
= new QLabel(tr("No wallet has been loaded."));
29 noWallet
->setAlignment(Qt::AlignCenter
);
30 walletStack
->addWidget(noWallet
);
33 WalletFrame::~WalletFrame()
37 void WalletFrame::setClientModel(ClientModel
*_clientModel
)
39 this->clientModel
= _clientModel
;
42 bool WalletFrame::addWallet(const QString
& name
, WalletModel
*walletModel
)
44 if (!gui
|| !clientModel
|| !walletModel
|| mapWalletViews
.count(name
) > 0)
47 WalletView
*walletView
= new WalletView(platformStyle
, this);
48 walletView
->setBitcoinGUI(gui
);
49 walletView
->setClientModel(clientModel
);
50 walletView
->setWalletModel(walletModel
);
51 walletView
->showOutOfSyncWarning(bOutOfSync
);
53 /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
54 walletView
->gotoOverviewPage();
55 walletStack
->addWidget(walletView
);
56 mapWalletViews
[name
] = walletView
;
58 // Ensure a walletView is able to show the main window
59 connect(walletView
, SIGNAL(showNormalIfMinimized()), gui
, SLOT(showNormalIfMinimized()));
61 connect(walletView
, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
66 bool WalletFrame::setCurrentWallet(const QString
& name
)
68 if (mapWalletViews
.count(name
) == 0)
71 WalletView
*walletView
= mapWalletViews
.value(name
);
72 walletStack
->setCurrentWidget(walletView
);
74 walletView
->updateEncryptionStatus();
78 bool WalletFrame::removeWallet(const QString
&name
)
80 if (mapWalletViews
.count(name
) == 0)
83 WalletView
*walletView
= mapWalletViews
.take(name
);
84 walletStack
->removeWidget(walletView
);
88 void WalletFrame::removeAllWallets()
90 QMap
<QString
, WalletView
*>::const_iterator i
;
91 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
92 walletStack
->removeWidget(i
.value());
93 mapWalletViews
.clear();
96 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient
&recipient
)
98 WalletView
*walletView
= currentWalletView();
102 return walletView
->handlePaymentRequest(recipient
);
105 void WalletFrame::showOutOfSyncWarning(bool fShow
)
108 QMap
<QString
, WalletView
*>::const_iterator i
;
109 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
110 i
.value()->showOutOfSyncWarning(fShow
);
113 void WalletFrame::gotoOverviewPage()
115 QMap
<QString
, WalletView
*>::const_iterator i
;
116 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
117 i
.value()->gotoOverviewPage();
120 void WalletFrame::gotoHistoryPage()
122 QMap
<QString
, WalletView
*>::const_iterator i
;
123 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
124 i
.value()->gotoHistoryPage();
127 void WalletFrame::gotoReceiveCoinsPage()
129 QMap
<QString
, WalletView
*>::const_iterator i
;
130 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
131 i
.value()->gotoReceiveCoinsPage();
134 void WalletFrame::gotoSendCoinsPage(QString addr
)
136 QMap
<QString
, WalletView
*>::const_iterator i
;
137 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
138 i
.value()->gotoSendCoinsPage(addr
);
141 void WalletFrame::gotoSignMessageTab(QString addr
)
143 WalletView
*walletView
= currentWalletView();
145 walletView
->gotoSignMessageTab(addr
);
148 void WalletFrame::gotoVerifyMessageTab(QString addr
)
150 WalletView
*walletView
= currentWalletView();
152 walletView
->gotoVerifyMessageTab(addr
);
155 void WalletFrame::encryptWallet(bool status
)
157 WalletView
*walletView
= currentWalletView();
159 walletView
->encryptWallet(status
);
162 void WalletFrame::backupWallet()
164 WalletView
*walletView
= currentWalletView();
166 walletView
->backupWallet();
169 void WalletFrame::changePassphrase()
171 WalletView
*walletView
= currentWalletView();
173 walletView
->changePassphrase();
176 void WalletFrame::unlockWallet()
178 WalletView
*walletView
= currentWalletView();
180 walletView
->unlockWallet();
183 void WalletFrame::usedSendingAddresses()
185 WalletView
*walletView
= currentWalletView();
187 walletView
->usedSendingAddresses();
190 void WalletFrame::usedReceivingAddresses()
192 WalletView
*walletView
= currentWalletView();
194 walletView
->usedReceivingAddresses();
197 WalletView
*WalletFrame::currentWalletView()
199 return qobject_cast
<WalletView
*>(walletStack
->currentWidget());
202 void WalletFrame::outOfSyncWarningClicked()
204 Q_EMIT
requestedSyncWarningInfo();