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