Bitcoin Core  0.19.99
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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 
13 #include <QHBoxLayout>
14 #include <QLabel>
15 
16 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
17  QFrame(_gui),
18  gui(_gui),
19  platformStyle(_platformStyle)
20 {
21  // Leave HBox hook for adding a list view later
22  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
23  setContentsMargins(0,0,0,0);
24  walletStack = new QStackedWidget(this);
25  walletFrameLayout->setContentsMargins(0,0,0,0);
26  walletFrameLayout->addWidget(walletStack);
27 
28  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
29  noWallet->setAlignment(Qt::AlignCenter);
30  walletStack->addWidget(noWallet);
31 }
32 
34 {
35 }
36 
38 {
39  this->clientModel = _clientModel;
40 
41  for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
42  i.value()->setClientModel(_clientModel);
43  }
44 }
45 
47 {
48  if (!gui || !clientModel || !walletModel) return false;
49 
50  if (mapWalletViews.count(walletModel) > 0) return false;
51 
52  WalletView *walletView = new WalletView(platformStyle, this);
53  walletView->setClientModel(clientModel);
54  walletView->setWalletModel(walletModel);
55  walletView->showOutOfSyncWarning(bOutOfSync);
56 
57  WalletView* current_wallet_view = currentWalletView();
58  if (current_wallet_view) {
59  walletView->setCurrentIndex(current_wallet_view->currentIndex());
60  } else {
61  walletView->gotoOverviewPage();
62  }
63 
64  walletStack->addWidget(walletView);
65  mapWalletViews[walletModel] = walletView;
66 
68  connect(walletView, &WalletView::transactionClicked, gui, &BitcoinGUI::gotoHistoryPage);
69  connect(walletView, &WalletView::coinsSent, gui, &BitcoinGUI::gotoHistoryPage);
70  connect(walletView, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
71  gui->message(title, message, style);
72  });
73  connect(walletView, &WalletView::encryptionStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
74  connect(walletView, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
75  connect(walletView, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
76 
77  return true;
78 }
79 
81 {
82  if (mapWalletViews.count(wallet_model) == 0) return;
83 
84  WalletView *walletView = mapWalletViews.value(wallet_model);
85  walletStack->setCurrentWidget(walletView);
86  assert(walletView);
87  walletView->updateEncryptionStatus();
88 }
89 
91 {
92  if (mapWalletViews.count(wallet_model) == 0) return;
93 
94  WalletView *walletView = mapWalletViews.take(wallet_model);
95  walletStack->removeWidget(walletView);
96  delete walletView;
97 }
98 
100 {
101  QMap<WalletModel*, WalletView*>::const_iterator i;
102  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
103  walletStack->removeWidget(i.value());
104  mapWalletViews.clear();
105 }
106 
108 {
109  WalletView *walletView = currentWalletView();
110  if (!walletView)
111  return false;
112 
113  return walletView->handlePaymentRequest(recipient);
114 }
115 
117 {
118  bOutOfSync = fShow;
119  QMap<WalletModel*, WalletView*>::const_iterator i;
120  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
121  i.value()->showOutOfSyncWarning(fShow);
122 }
123 
125 {
126  QMap<WalletModel*, WalletView*>::const_iterator i;
127  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
128  i.value()->gotoOverviewPage();
129 }
130 
132 {
133  QMap<WalletModel*, WalletView*>::const_iterator i;
134  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
135  i.value()->gotoHistoryPage();
136 }
137 
139 {
140  QMap<WalletModel*, WalletView*>::const_iterator i;
141  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
142  i.value()->gotoReceiveCoinsPage();
143 }
144 
146 {
147  QMap<WalletModel*, WalletView*>::const_iterator i;
148  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
149  i.value()->gotoSendCoinsPage(addr);
150 }
151 
153 {
154  WalletView *walletView = currentWalletView();
155  if (walletView)
156  walletView->gotoSignMessageTab(addr);
157 }
158 
160 {
161  WalletView *walletView = currentWalletView();
162  if (walletView)
163  walletView->gotoVerifyMessageTab(addr);
164 }
165 
166 void WalletFrame::encryptWallet(bool status)
167 {
168  WalletView *walletView = currentWalletView();
169  if (walletView)
170  walletView->encryptWallet(status);
171 }
172 
174 {
175  WalletView *walletView = currentWalletView();
176  if (walletView)
177  walletView->backupWallet();
178 }
179 
181 {
182  WalletView *walletView = currentWalletView();
183  if (walletView)
184  walletView->changePassphrase();
185 }
186 
188 {
189  WalletView *walletView = currentWalletView();
190  if (walletView)
191  walletView->unlockWallet();
192 }
193 
195 {
196  WalletView *walletView = currentWalletView();
197  if (walletView)
198  walletView->usedSendingAddresses();
199 }
200 
202 {
203  WalletView *walletView = currentWalletView();
204  if (walletView)
205  walletView->usedReceivingAddresses();
206 }
207 
209 {
210  return qobject_cast<WalletView*>(walletStack->currentWidget());
211 }
212 
214 {
215  WalletView* wallet_view = currentWalletView();
216  return wallet_view ? wallet_view->getWalletModel() : nullptr;
217 }
218 
220 {
221  Q_EMIT requestedSyncWarningInfo();
222 }
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:188
bool bOutOfSync
Definition: walletframe.h:58
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:265
ClientModel * clientModel
Definition: walletframe.h:55
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:245
void setCurrentWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:80
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:210
void removeAllWallets()
Definition: walletframe.cpp:99
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
WalletModel * getWalletModel()
Definition: walletview.h:45
void gotoOverviewPage()
Switch to overview (home) page.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:273
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:37
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:98
WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui=nullptr)
Definition: walletframe.cpp:16
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 message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:252
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 gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr)
Notify the user of an event from the core network or transaction handling code.
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:226
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:200
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:153
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
void encryptionStatusChanged()
Encryption status of wallet changed.
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:176
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:50
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:90
bool addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:46
void hdEnabledStatusChanged()
HD-Enabled status of wallet changed (only possible during startup)
void backupWallet()
Backup the wallet.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:215
void removeWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:90
void coinsSent()
void transactionClicked()
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:205
void incomingTransaction(const QString &date, int unit, const CAmount &amount, const QString &type, const QString &address, const QString &label, const QString &walletName)
Notify that a new transaction appeared.