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(const PlatformStyle
*platformStyle
, BitcoinGUI
*_gui
) :
18 platformStyle(platformStyle
)
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
);
27 QLabel
*noWallet
= new QLabel(tr("No wallet has been loaded."));
28 noWallet
->setAlignment(Qt::AlignCenter
);
29 walletStack
->addWidget(noWallet
);
32 WalletFrame::~WalletFrame()
36 void WalletFrame::setClientModel(ClientModel
*clientModel
)
38 this->clientModel
= clientModel
;
41 bool WalletFrame::addWallet(const QString
& name
, WalletModel
*walletModel
)
43 if (!gui
|| !clientModel
|| !walletModel
|| mapWalletViews
.count(name
) > 0)
46 WalletView
*walletView
= new WalletView(platformStyle
, this);
47 walletView
->setBitcoinGUI(gui
);
48 walletView
->setClientModel(clientModel
);
49 walletView
->setWalletModel(walletModel
);
50 walletView
->showOutOfSyncWarning(bOutOfSync
);
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
;
57 // Ensure a walletView is able to show the main window
58 connect(walletView
, SIGNAL(showNormalIfMinimized()), gui
, SLOT(showNormalIfMinimized()));
63 bool WalletFrame::setCurrentWallet(const QString
& name
)
65 if (mapWalletViews
.count(name
) == 0)
68 WalletView
*walletView
= mapWalletViews
.value(name
);
69 walletStack
->setCurrentWidget(walletView
);
70 walletView
->updateEncryptionStatus();
74 bool WalletFrame::removeWallet(const QString
&name
)
76 if (mapWalletViews
.count(name
) == 0)
79 WalletView
*walletView
= mapWalletViews
.take(name
);
80 walletStack
->removeWidget(walletView
);
84 void WalletFrame::removeAllWallets()
86 QMap
<QString
, WalletView
*>::const_iterator i
;
87 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
88 walletStack
->removeWidget(i
.value());
89 mapWalletViews
.clear();
92 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient
&recipient
)
94 WalletView
*walletView
= currentWalletView();
98 return walletView
->handlePaymentRequest(recipient
);
101 void WalletFrame::showOutOfSyncWarning(bool fShow
)
104 QMap
<QString
, WalletView
*>::const_iterator i
;
105 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
106 i
.value()->showOutOfSyncWarning(fShow
);
109 void WalletFrame::gotoOverviewPage()
111 QMap
<QString
, WalletView
*>::const_iterator i
;
112 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
113 i
.value()->gotoOverviewPage();
116 void WalletFrame::gotoHistoryPage()
118 QMap
<QString
, WalletView
*>::const_iterator i
;
119 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
120 i
.value()->gotoHistoryPage();
123 void WalletFrame::gotoReceiveCoinsPage()
125 QMap
<QString
, WalletView
*>::const_iterator i
;
126 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
127 i
.value()->gotoReceiveCoinsPage();
130 void WalletFrame::gotoSendCoinsPage(QString addr
)
132 QMap
<QString
, WalletView
*>::const_iterator i
;
133 for (i
= mapWalletViews
.constBegin(); i
!= mapWalletViews
.constEnd(); ++i
)
134 i
.value()->gotoSendCoinsPage(addr
);
137 void WalletFrame::gotoSignMessageTab(QString addr
)
139 WalletView
*walletView
= currentWalletView();
141 walletView
->gotoSignMessageTab(addr
);
144 void WalletFrame::gotoVerifyMessageTab(QString addr
)
146 WalletView
*walletView
= currentWalletView();
148 walletView
->gotoVerifyMessageTab(addr
);
151 void WalletFrame::encryptWallet(bool status
)
153 WalletView
*walletView
= currentWalletView();
155 walletView
->encryptWallet(status
);
158 void WalletFrame::backupWallet()
160 WalletView
*walletView
= currentWalletView();
162 walletView
->backupWallet();
165 void WalletFrame::changePassphrase()
167 WalletView
*walletView
= currentWalletView();
169 walletView
->changePassphrase();
172 void WalletFrame::unlockWallet()
174 WalletView
*walletView
= currentWalletView();
176 walletView
->unlockWallet();
179 void WalletFrame::usedSendingAddresses()
181 WalletView
*walletView
= currentWalletView();
183 walletView
->usedSendingAddresses();
186 void WalletFrame::usedReceivingAddresses()
188 WalletView
*walletView
= currentWalletView();
190 walletView
->usedReceivingAddresses();
193 WalletView
*WalletFrame::currentWalletView()
195 return qobject_cast
<WalletView
*>(walletStack
->currentWidget());