Bitcoin Core  0.18.99
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2019 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) return;
46 
47  if (mapWalletViews.count(walletModel) > 0) return;
48 
49  WalletView *walletView = new WalletView(platformStyle, this);
50  walletView->setBitcoinGUI(gui);
51  walletView->setClientModel(clientModel);
52  walletView->setWalletModel(walletModel);
53  walletView->showOutOfSyncWarning(bOutOfSync);
54 
55  WalletView* current_wallet_view = currentWalletView();
56  if (current_wallet_view) {
57  walletView->setCurrentIndex(current_wallet_view->currentIndex());
58  } else {
59  walletView->gotoOverviewPage();
60  }
61 
62  walletStack->addWidget(walletView);
63  mapWalletViews[walletModel] = walletView;
64 
65  // Ensure a walletView is able to show the main window
66  connect(walletView, &WalletView::showNormalIfMinimized, [this]{
68  });
69 
71 }
72 
74 {
75  if (mapWalletViews.count(wallet_model) == 0) return;
76 
77  WalletView *walletView = mapWalletViews.value(wallet_model);
78  walletStack->setCurrentWidget(walletView);
79  assert(walletView);
80  walletView->updateEncryptionStatus();
81 }
82 
84 {
85  if (mapWalletViews.count(wallet_model) == 0) return;
86 
87  WalletView *walletView = mapWalletViews.take(wallet_model);
88  walletStack->removeWidget(walletView);
89  delete walletView;
90 }
91 
93 {
94  QMap<WalletModel*, WalletView*>::const_iterator i;
95  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
96  walletStack->removeWidget(i.value());
97  mapWalletViews.clear();
98 }
99 
101 {
102  WalletView *walletView = currentWalletView();
103  if (!walletView)
104  return false;
105 
106  return walletView->handlePaymentRequest(recipient);
107 }
108 
110 {
111  bOutOfSync = fShow;
112  QMap<WalletModel*, WalletView*>::const_iterator i;
113  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
114  i.value()->showOutOfSyncWarning(fShow);
115 }
116 
118 {
119  QMap<WalletModel*, WalletView*>::const_iterator i;
120  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
121  i.value()->gotoOverviewPage();
122 }
123 
125 {
126  QMap<WalletModel*, WalletView*>::const_iterator i;
127  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
128  i.value()->gotoHistoryPage();
129 }
130 
132 {
133  QMap<WalletModel*, WalletView*>::const_iterator i;
134  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
135  i.value()->gotoReceiveCoinsPage();
136 }
137 
139 {
140  QMap<WalletModel*, WalletView*>::const_iterator i;
141  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
142  i.value()->gotoSendCoinsPage(addr);
143 }
144 
146 {
147  WalletView *walletView = currentWalletView();
148  if (walletView)
149  walletView->gotoSignMessageTab(addr);
150 }
151 
153 {
154  WalletView *walletView = currentWalletView();
155  if (walletView)
156  walletView->gotoVerifyMessageTab(addr);
157 }
158 
159 void WalletFrame::encryptWallet(bool status)
160 {
161  WalletView *walletView = currentWalletView();
162  if (walletView)
163  walletView->encryptWallet(status);
164 }
165 
167 {
168  WalletView *walletView = currentWalletView();
169  if (walletView)
170  walletView->backupWallet();
171 }
172 
174 {
175  WalletView *walletView = currentWalletView();
176  if (walletView)
177  walletView->changePassphrase();
178 }
179 
181 {
182  WalletView *walletView = currentWalletView();
183  if (walletView)
184  walletView->unlockWallet();
185 }
186 
188 {
189  WalletView *walletView = currentWalletView();
190  if (walletView)
191  walletView->usedSendingAddresses();
192 }
193 
195 {
196  WalletView *walletView = currentWalletView();
197  if (walletView)
198  walletView->usedReceivingAddresses();
199 }
200 
202 {
203  return qobject_cast<WalletView*>(walletStack->currentWidget());
204 }
205 
207 {
208  WalletView* wallet_view = currentWalletView();
209  return wallet_view ? wallet_view->getWalletModel() : nullptr;
210 }
211 
213 {
214  Q_EMIT requestedSyncWarningInfo();
215 }
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
WalletModel * currentWalletModel() const
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:295
bool bOutOfSync
Definition: walletframe.h:58
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:290
ClientModel * clientModel
Definition: walletframe.h:55
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:270
void setCurrentWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:73
QMap< WalletModel *, WalletView * > mapWalletViews
Definition: walletframe.h:56
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:53
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:64
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:235
void removeAllWallets()
Definition: walletframe.cpp:92
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
WalletModel * getWalletModel()
Definition: walletview.h:47
void gotoOverviewPage()
Switch to overview (home) page.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:89
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:298
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:38
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:123
WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui=nullptr)
Definition: walletframe.cpp:17
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
BitcoinGUI * gui
Definition: walletframe.h:54
WalletView * currentWalletView() const
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:277
void addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:43
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
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:115
void backupWallet()
Backup the wallet.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:240
void removeWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:83
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:230