1 // Copyright (c) 2011-2015 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.
4
5 #include "walletframe.h"
6
7 #include "bitcoingui.h"
8 #include "walletview.h"
9
10 #include <cstdio>
11
12 #include <QHBoxLayout>
13 #include <QLabel>
14
WalletFrame(const PlatformStyle * platformStyle,BitcoinGUI * _gui)15 WalletFrame::WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui) :
16 QFrame(_gui),
17 gui(_gui),
18 platformStyle(platformStyle)
19 {
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);
26
27 QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
28 noWallet->setAlignment(Qt::AlignCenter);
29 walletStack->addWidget(noWallet);
30 }
31
~WalletFrame()32 WalletFrame::~WalletFrame()
33 {
34 }
35
setClientModel(ClientModel * clientModel)36 void WalletFrame::setClientModel(ClientModel *clientModel)
37 {
38 this->clientModel = clientModel;
39 }
40
addWallet(const QString & name,WalletModel * walletModel)41 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
42 {
43 if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
44 return false;
45
46 WalletView *walletView = new WalletView(platformStyle, this);
47 walletView->setBitcoinGUI(gui);
48 walletView->setClientModel(clientModel);
49 walletView->setWalletModel(walletModel);
50 walletView->showOutOfSyncWarning(bOutOfSync);
51
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;
56
57 // Ensure a walletView is able to show the main window
58 connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
59
60 return true;
61 }
62
setCurrentWallet(const QString & name)63 bool WalletFrame::setCurrentWallet(const QString& name)
64 {
65 if (mapWalletViews.count(name) == 0)
66 return false;
67
68 WalletView *walletView = mapWalletViews.value(name);
69 walletStack->setCurrentWidget(walletView);
70 walletView->updateEncryptionStatus();
71 return true;
72 }
73
removeWallet(const QString & name)74 bool WalletFrame::removeWallet(const QString &name)
75 {
76 if (mapWalletViews.count(name) == 0)
77 return false;
78
79 WalletView *walletView = mapWalletViews.take(name);
80 walletStack->removeWidget(walletView);
81 return true;
82 }
83
removeAllWallets()84 void WalletFrame::removeAllWallets()
85 {
86 QMap<QString, WalletView*>::const_iterator i;
87 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
88 walletStack->removeWidget(i.value());
89 mapWalletViews.clear();
90 }
91
handlePaymentRequest(const SendCoinsRecipient & recipient)92 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
93 {
94 WalletView *walletView = currentWalletView();
95 if (!walletView)
96 return false;
97
98 return walletView->handlePaymentRequest(recipient);
99 }
100
showOutOfSyncWarning(bool fShow)101 void WalletFrame::showOutOfSyncWarning(bool fShow)
102 {
103 bOutOfSync = fShow;
104 QMap<QString, WalletView*>::const_iterator i;
105 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
106 i.value()->showOutOfSyncWarning(fShow);
107 }
108
gotoOverviewPage()109 void WalletFrame::gotoOverviewPage()
110 {
111 QMap<QString, WalletView*>::const_iterator i;
112 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
113 i.value()->gotoOverviewPage();
114 }
115
gotoHistoryPage()116 void WalletFrame::gotoHistoryPage()
117 {
118 QMap<QString, WalletView*>::const_iterator i;
119 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
120 i.value()->gotoHistoryPage();
121 }
122
gotoReceiveCoinsPage()123 void WalletFrame::gotoReceiveCoinsPage()
124 {
125 QMap<QString, WalletView*>::const_iterator i;
126 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
127 i.value()->gotoReceiveCoinsPage();
128 }
129
gotoSendCoinsPage(QString addr)130 void WalletFrame::gotoSendCoinsPage(QString addr)
131 {
132 QMap<QString, WalletView*>::const_iterator i;
133 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
134 i.value()->gotoSendCoinsPage(addr);
135 }
136
gotoSignMessageTab(QString addr)137 void WalletFrame::gotoSignMessageTab(QString addr)
138 {
139 WalletView *walletView = currentWalletView();
140 if (walletView)
141 walletView->gotoSignMessageTab(addr);
142 }
143
gotoVerifyMessageTab(QString addr)144 void WalletFrame::gotoVerifyMessageTab(QString addr)
145 {
146 WalletView *walletView = currentWalletView();
147 if (walletView)
148 walletView->gotoVerifyMessageTab(addr);
149 }
150
encryptWallet(bool status)151 void WalletFrame::encryptWallet(bool status)
152 {
153 WalletView *walletView = currentWalletView();
154 if (walletView)
155 walletView->encryptWallet(status);
156 }
157
backupWallet()158 void WalletFrame::backupWallet()
159 {
160 WalletView *walletView = currentWalletView();
161 if (walletView)
162 walletView->backupWallet();
163 }
164
changePassphrase()165 void WalletFrame::changePassphrase()
166 {
167 WalletView *walletView = currentWalletView();
168 if (walletView)
169 walletView->changePassphrase();
170 }
171
unlockWallet()172 void WalletFrame::unlockWallet()
173 {
174 WalletView *walletView = currentWalletView();
175 if (walletView)
176 walletView->unlockWallet();
177 }
178
usedSendingAddresses()179 void WalletFrame::usedSendingAddresses()
180 {
181 WalletView *walletView = currentWalletView();
182 if (walletView)
183 walletView->usedSendingAddresses();
184 }
185
usedReceivingAddresses()186 void WalletFrame::usedReceivingAddresses()
187 {
188 WalletView *walletView = currentWalletView();
189 if (walletView)
190 walletView->usedReceivingAddresses();
191 }
192
currentWalletView()193 WalletView *WalletFrame::currentWalletView()
194 {
195 return qobject_cast<WalletView*>(walletStack->currentWidget());
196 }
197
198