BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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 <qt/walletframe.h>
6 #include <qt/walletmodel.h>
7 
8 #include <qt/bitcoingui.h>
9 #include <qt/walletview.h>
10 
11 #include <cassert>
12 #include <cstdio>
13 
14 #include <QHBoxLayout>
15 #include <QLabel>
16 
17 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
18  QFrame(_gui),
19  gui(_gui),
20  platformStyle(_platformStyle)
21 {
22  // Leave HBox hook for adding a list view later
23  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
24  setContentsMargins(0,0,0,0);
25  walletStack = new QStackedWidget(this);
26  walletFrameLayout->setContentsMargins(0,0,0,0);
27  walletFrameLayout->addWidget(walletStack);
28 
29  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
30  noWallet->setAlignment(Qt::AlignCenter);
31  walletStack->addWidget(noWallet);
32 }
33 
35 {
36 }
37 
39 {
40  this->clientModel = _clientModel;
41 }
42 
44 {
45  if (!gui || !clientModel || !walletModel) {
46  return false;
47  }
48 
49  const QString name = walletModel->getWalletName();
50  if (mapWalletViews.count(name) > 0) {
51  return false;
52  }
53 
54  WalletView *walletView = new WalletView(platformStyle, this);
55  walletView->setBitcoinGUI(gui);
56  walletView->setClientModel(clientModel);
57  walletView->setWalletModel(walletModel);
58  walletView->showOutOfSyncWarning(bOutOfSync);
59 
60  WalletView* current_wallet_view = currentWalletView();
61  if (current_wallet_view) {
62  walletView->setCurrentIndex(current_wallet_view->currentIndex());
63  } else {
64  walletView->gotoOverviewPage();
65  }
66 
67  walletStack->addWidget(walletView);
68  mapWalletViews[name] = walletView;
69 
70  // Ensure a walletView is able to show the main window
71  connect(walletView, &WalletView::showNormalIfMinimized, [this]{
73  });
74 
76 
77  return true;
78 }
79 
80 bool WalletFrame::setCurrentWallet(const QString& name)
81 {
82  if (mapWalletViews.count(name) == 0)
83  return false;
84 
85  WalletView *walletView = mapWalletViews.value(name);
86  walletStack->setCurrentWidget(walletView);
87  assert(walletView);
88  walletView->updateEncryptionStatus();
89  return true;
90 }
91 
92 bool WalletFrame::removeWallet(const QString &name)
93 {
94  if (mapWalletViews.count(name) == 0)
95  return false;
96 
97  WalletView *walletView = mapWalletViews.take(name);
98  walletStack->removeWidget(walletView);
99  delete walletView;
100  return true;
101 }
102 
104 {
105  QMap<QString, WalletView*>::const_iterator i;
106  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
107  walletStack->removeWidget(i.value());
108  mapWalletViews.clear();
109 }
110 
112 {
113  WalletView *walletView = currentWalletView();
114  if (!walletView)
115  return false;
116 
117  return walletView->handlePaymentRequest(recipient);
118 }
119 
121 {
122  bOutOfSync = fShow;
123  QMap<QString, WalletView*>::const_iterator i;
124  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
125  i.value()->showOutOfSyncWarning(fShow);
126 }
127 
129 {
130  QMap<QString, WalletView*>::const_iterator i;
131  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
132  i.value()->gotoOverviewPage();
133 }
134 
136 {
137  QMap<QString, WalletView*>::const_iterator i;
138  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
139  i.value()->gotoHistoryPage();
140 }
141 
143 {
144  QMap<QString, WalletView*>::const_iterator i;
145  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
146  i.value()->gotoReceiveCoinsPage();
147 }
148 
150 {
151  QMap<QString, WalletView*>::const_iterator i;
152  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
153  i.value()->gotoSendCoinsPage(addr);
154 }
155 
157 {
158  WalletView *walletView = currentWalletView();
159  if (walletView)
160  walletView->gotoSignMessageTab(addr);
161 }
162 
164 {
165  WalletView *walletView = currentWalletView();
166  if (walletView)
167  walletView->gotoVerifyMessageTab(addr);
168 }
169 
170 void WalletFrame::encryptWallet(bool status)
171 {
172  WalletView *walletView = currentWalletView();
173  if (walletView)
174  walletView->encryptWallet(status);
175 }
176 
178 {
179  WalletView *walletView = currentWalletView();
180  if (walletView)
181  walletView->backupWallet();
182 }
183 
185 {
186  WalletView *walletView = currentWalletView();
187  if (walletView)
188  walletView->changePassphrase();
189 }
190 
192 {
193  WalletView *walletView = currentWalletView();
194  if (walletView)
195  walletView->unlockWallet();
196 }
197 
199 {
200  WalletView *walletView = currentWalletView();
201  if (walletView)
202  walletView->usedSendingAddresses();
203 }
204 
206 {
207  WalletView *walletView = currentWalletView();
208  if (walletView)
209  walletView->usedReceivingAddresses();
210 }
211 
213 {
214  return qobject_cast<WalletView*>(walletStack->currentWidget());
215 }
216 
218 {
219  Q_EMIT requestedSyncWarningInfo();
220 }
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:80
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:213
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:266
bool bOutOfSync
Definition: walletframe.h:58
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:290
WalletView * currentWalletView()
ClientModel * clientModel
Definition: walletframe.h:55
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:270
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:53
WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui=0)
Definition: walletframe.cpp:17
void encryptWallet(bool status)
Encrypt the wallet.
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
Bitcoin GUI main class.
Definition: bitcoingui.h:59
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:56
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:235
void removeAllWallets()
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:89
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:300
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:38
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:123
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
BitcoinGUI * gui
Definition: walletframe.h:54
const char * name
Definition: rest.cpp:37
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:277
QString getWalletName() const
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:44
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
void showNormalIfMinimized()
Signal that we want to show the main window.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:251
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:225
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:178
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
const PlatformStyle * platformStyle
Definition: walletframe.h:60
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
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:201
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
bool removeWallet(const QString &name)
Definition: walletframe.cpp:92
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:115
bool addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:43
void backupWallet()
Backup the wallet.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:240
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:230