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.
5 #include "walletframe.h"
7 #include "bitcoingui.h"
8 #include "walletview.h"
12 #include <QHBoxLayout>
15 WalletFrame::WalletFrame(BitcoinGUI *_gui) :
19 // Leave HBox hook for adding a list view later
20 QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
21 setContentsMargins(0,0,0,0);
22 walletStack = new QStackedWidget(this);
23 walletFrameLayout->setContentsMargins(0,0,0,0);
24 walletFrameLayout->addWidget(walletStack);
26 QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
27 noWallet->setAlignment(Qt::AlignCenter);
28 walletStack->addWidget(noWallet);
31 WalletFrame::~WalletFrame()
35 void WalletFrame::setClientModel(ClientModel *clientModel)
37 this->clientModel = clientModel;
40 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
42 if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
45 WalletView *walletView = new WalletView(this);
46 walletView->setBitcoinGUI(gui);
47 walletView->setClientModel(clientModel);
48 walletView->setWalletModel(walletModel);
49 walletView->showOutOfSyncWarning(bOutOfSync);
51 /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
52 walletView->gotoOverviewPage();
53 walletStack->addWidget(walletView);
54 mapWalletViews[name] = walletView;
56 // Ensure a walletView is able to show the main window
57 connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
62 bool WalletFrame::setCurrentWallet(const QString& name)
64 if (mapWalletViews.count(name) == 0)
67 WalletView *walletView = mapWalletViews.value(name);
68 walletStack->setCurrentWidget(walletView);
69 walletView->updateEncryptionStatus();
73 bool WalletFrame::removeWallet(const QString &name)
75 if (mapWalletViews.count(name) == 0)
78 WalletView *walletView = mapWalletViews.take(name);
79 walletStack->removeWidget(walletView);
83 void WalletFrame::removeAllWallets()
85 QMap<QString, WalletView*>::const_iterator i;
86 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
87 walletStack->removeWidget(i.value());
88 mapWalletViews.clear();
91 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
93 WalletView *walletView = currentWalletView();
97 return walletView->handlePaymentRequest(recipient);
100 void WalletFrame::showOutOfSyncWarning(bool fShow)
103 QMap<QString, WalletView*>::const_iterator i;
104 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
105 i.value()->showOutOfSyncWarning(fShow);
108 void WalletFrame::gotoOverviewPage()
110 QMap<QString, WalletView*>::const_iterator i;
111 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
112 i.value()->gotoOverviewPage();
115 void WalletFrame::gotoHistoryPage()
117 QMap<QString, WalletView*>::const_iterator i;
118 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
119 i.value()->gotoHistoryPage();
122 void WalletFrame::gotoReceiveCoinsPage()
124 QMap<QString, WalletView*>::const_iterator i;
125 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
126 i.value()->gotoReceiveCoinsPage();
129 void WalletFrame::gotoSendCoinsPage(QString addr)
131 QMap<QString, WalletView*>::const_iterator i;
132 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
133 i.value()->gotoSendCoinsPage(addr);
136 void WalletFrame::gotoSignMessageTab(QString addr)
138 WalletView *walletView = currentWalletView();
140 walletView->gotoSignMessageTab(addr);
143 void WalletFrame::gotoVerifyMessageTab(QString addr)
145 WalletView *walletView = currentWalletView();
147 walletView->gotoVerifyMessageTab(addr);
150 void WalletFrame::encryptWallet(bool status)
152 WalletView *walletView = currentWalletView();
154 walletView->encryptWallet(status);
157 void WalletFrame::backupWallet()
159 WalletView *walletView = currentWalletView();
161 walletView->backupWallet();
164 void WalletFrame::changePassphrase()
166 WalletView *walletView = currentWalletView();
168 walletView->changePassphrase();
171 void WalletFrame::unlockWallet()
173 WalletView *walletView = currentWalletView();
175 walletView->unlockWallet();
178 void WalletFrame::usedSendingAddresses()
180 WalletView *walletView = currentWalletView();
182 walletView->usedSendingAddresses();
185 void WalletFrame::usedReceivingAddresses()
187 WalletView *walletView = currentWalletView();
189 walletView->usedReceivingAddresses();
192 WalletView *WalletFrame::currentWalletView()
194 return qobject_cast<WalletView*>(walletStack->currentWidget());