Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 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 
16  QFrame(_gui),
17  gui(_gui)
18 {
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);
25 
26  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
27  noWallet->setAlignment(Qt::AlignCenter);
28  walletStack->addWidget(noWallet);
29 }
30 
32 {
33 }
34 
36 {
37  this->clientModel = clientModel;
38 }
39 
40 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
41 {
42  if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
43  return false;
44 
45  WalletView *walletView = new WalletView(this);
46  walletView->setBitcoinGUI(gui);
47  walletView->setClientModel(clientModel);
48  walletView->setWalletModel(walletModel);
49  walletView->showOutOfSyncWarning(bOutOfSync);
50 
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;
55 
56  // Ensure a walletView is able to show the main window
57  connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
58 
59  return true;
60 }
61 
62 bool WalletFrame::setCurrentWallet(const QString& name)
63 {
64  if (mapWalletViews.count(name) == 0)
65  return false;
66 
67  WalletView *walletView = mapWalletViews.value(name);
68  walletStack->setCurrentWidget(walletView);
69  walletView->updateEncryptionStatus();
70  return true;
71 }
72 
73 bool WalletFrame::removeWallet(const QString &name)
74 {
75  if (mapWalletViews.count(name) == 0)
76  return false;
77 
78  WalletView *walletView = mapWalletViews.take(name);
79  walletStack->removeWidget(walletView);
80  return true;
81 }
82 
84 {
85  QMap<QString, WalletView*>::const_iterator i;
86  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
87  walletStack->removeWidget(i.value());
88  mapWalletViews.clear();
89 }
90 
92 {
93  WalletView *walletView = currentWalletView();
94  if (!walletView)
95  return false;
96 
97  return walletView->handlePaymentRequest(recipient);
98 }
99 
101 {
102  bOutOfSync = fShow;
103  QMap<QString, WalletView*>::const_iterator i;
104  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
105  i.value()->showOutOfSyncWarning(fShow);
106 }
107 
109 {
110  QMap<QString, WalletView*>::const_iterator i;
111  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
112  i.value()->gotoOverviewPage();
113 }
114 
116 {
117  QMap<QString, WalletView*>::const_iterator i;
118  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
119  i.value()->gotoBalancesPage();
120 }
121 
123 {
124  QMap<QString, WalletView*>::const_iterator i;
125  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
126  i.value()->gotoHistoryPage();
127 }
128 
130 {
131  QMap<QString, WalletView*>::const_iterator i;
132  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
133  i.value()->gotoReceiveCoinsPage();
134 }
135 
137 {
138  QMap<QString, WalletView*>::const_iterator i;
139  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
140  i.value()->gotoSendCoinsPage(addr);
141 }
142 
144 {
145  WalletView *walletView = currentWalletView();
146  if (walletView)
147  walletView->gotoSignMessageTab(addr);
148 }
149 
151 {
152  WalletView *walletView = currentWalletView();
153  if (walletView)
154  walletView->gotoVerifyMessageTab(addr);
155 }
156 
157 void WalletFrame::encryptWallet(bool status)
158 {
159  WalletView *walletView = currentWalletView();
160  if (walletView)
161  walletView->encryptWallet(status);
162 }
163 
165 {
166  WalletView *walletView = currentWalletView();
167  if (walletView)
168  walletView->backupWallet();
169 }
170 
172 {
173  WalletView *walletView = currentWalletView();
174  if (walletView)
175  walletView->changePassphrase();
176 }
177 
179 {
180  WalletView *walletView = currentWalletView();
181  if (walletView)
182  walletView->unlockWallet();
183 }
184 
186 {
187  WalletView *walletView = currentWalletView();
188  if (walletView)
189  walletView->usedSendingAddresses();
190 }
191 
193 {
194  WalletView *walletView = currentWalletView();
195  if (walletView)
196  walletView->usedReceivingAddresses();
197 }
198 
200 {
201  return qobject_cast<WalletView*>(walletStack->currentWidget());
202 }
203 
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletframe.cpp:91
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:62
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:234
bool bOutOfSync
Definition: walletframe.h:46
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:311
WalletView * currentWalletView()
ClientModel * clientModel
Definition: walletframe.h:43
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:291
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:41
void encryptWallet(bool status)
Encrypt the wallet.
Bitcoin GUI main class.
Definition: bitcoingui.h:35
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:44
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:256
void removeAllWallets()
Definition: walletframe.cpp:83
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
void gotoOverviewPage()
Switch to overview (home) page.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:121
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:321
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:35
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:146
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
BitcoinGUI * gui
Definition: walletframe.h:42
bool addWallet(const QString &name, WalletModel *walletModel)
Definition: walletframe.cpp:40
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:298
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:36
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:272
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:246
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:194
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
WalletFrame(BitcoinGUI *_gui=0)
Definition: walletframe.cpp:15
void gotoReceiveCoinsPage()
Switch to receive coins page.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:222
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:96
bool removeWallet(const QString &name)
Definition: walletframe.cpp:73
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:139
void backupWallet()
Backup the wallet.
void gotoBalancesPage()
Switch to balances page.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:261
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:251