4 * W.J. van der Laan 2011-2012
5 * The Bitcoin Developers 2011-2013
7 #include "walletframe.h"
8 #include "walletview.h"
9 #include "bitcoingui.h"
11 #include <QHBoxLayout>
12 #include <QMessageBox>
13 #include <QStackedWidget>
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);
27 WalletFrame::~WalletFrame()
31 void WalletFrame::setClientModel(ClientModel *clientModel)
33 this->clientModel = clientModel;
36 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
38 if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
41 WalletView *walletView = new WalletView(this);
42 walletView->setBitcoinGUI(gui);
43 walletView->setClientModel(clientModel);
44 walletView->setWalletModel(walletModel);
45 walletView->showOutOfSyncWarning(bOutOfSync);
47 /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
48 walletView->gotoOverviewPage();
49 walletStack->addWidget(walletView);
50 mapWalletViews[name] = walletView;
52 // Ensure a walletView is able to show the main window
53 connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
58 bool WalletFrame::setCurrentWallet(const QString& name)
60 if (mapWalletViews.count(name) == 0)
63 WalletView *walletView = mapWalletViews.value(name);
64 walletStack->setCurrentWidget(walletView);
65 walletView->setEncryptionStatus();
69 bool WalletFrame::removeWallet(const QString &name)
71 if (mapWalletViews.count(name) == 0)
74 WalletView *walletView = mapWalletViews.take(name);
75 walletStack->removeWidget(walletView);
79 void WalletFrame::removeAllWallets()
81 QMap<QString, WalletView*>::const_iterator i;
82 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
83 walletStack->removeWidget(i.value());
84 mapWalletViews.clear();
87 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
89 WalletView *walletView = (WalletView*)walletStack->currentWidget();
93 return walletView->handlePaymentRequest(recipient);
96 void WalletFrame::showOutOfSyncWarning(bool fShow)
99 QMap<QString, WalletView*>::const_iterator i;
100 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
101 i.value()->showOutOfSyncWarning(fShow);
104 void WalletFrame::gotoOverviewPage()
106 QMap<QString, WalletView*>::const_iterator i;
107 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
108 i.value()->gotoOverviewPage();
111 void WalletFrame::gotoHistoryPage()
113 QMap<QString, WalletView*>::const_iterator i;
114 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
115 i.value()->gotoHistoryPage();
118 void WalletFrame::gotoReceiveCoinsPage()
120 QMap<QString, WalletView*>::const_iterator i;
121 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
122 i.value()->gotoReceiveCoinsPage();
125 void WalletFrame::gotoSendCoinsPage(QString addr)
127 QMap<QString, WalletView*>::const_iterator i;
128 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
129 i.value()->gotoSendCoinsPage(addr);
132 void WalletFrame::gotoSignMessageTab(QString addr)
134 WalletView *walletView = (WalletView*)walletStack->currentWidget();
136 walletView->gotoSignMessageTab(addr);
139 void WalletFrame::gotoVerifyMessageTab(QString addr)
141 WalletView *walletView = (WalletView*)walletStack->currentWidget();
143 walletView->gotoVerifyMessageTab(addr);
146 void WalletFrame::encryptWallet(bool status)
148 WalletView *walletView = (WalletView*)walletStack->currentWidget();
150 walletView->encryptWallet(status);
153 void WalletFrame::backupWallet()
155 WalletView *walletView = (WalletView*)walletStack->currentWidget();
157 walletView->backupWallet();
160 void WalletFrame::changePassphrase()
162 WalletView *walletView = (WalletView*)walletStack->currentWidget();
164 walletView->changePassphrase();
167 void WalletFrame::unlockWallet()
169 WalletView *walletView = (WalletView*)walletStack->currentWidget();
171 walletView->unlockWallet();
174 void WalletFrame::setEncryptionStatus()
176 WalletView *walletView = (WalletView*)walletStack->currentWidget();
178 walletView->setEncryptionStatus();
181 void WalletFrame::usedSendingAddresses()
183 WalletView *walletView = (WalletView*)walletStack->currentWidget();
185 walletView->usedSendingAddresses();
188 void WalletFrame::usedReceivingAddresses()
190 WalletView *walletView = (WalletView*)walletStack->currentWidget();
192 walletView->usedReceivingAddresses();