Bitcoin Core  0.20.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  walletView->setPrivacy(gui->isPrivacyModeActivated());
57 
58  WalletView* current_wallet_view = currentWalletView();
59  if (current_wallet_view) {
60  walletView->setCurrentIndex(current_wallet_view->currentIndex());
61  } else {
62  walletView->gotoOverviewPage();
63  }
64 
65  walletStack->addWidget(walletView);
66  mapWalletViews[walletModel] = walletView;
67 
69  connect(walletView, &WalletView::transactionClicked, gui, &BitcoinGUI::gotoHistoryPage);
70  connect(walletView, &WalletView::coinsSent, gui, &BitcoinGUI::gotoHistoryPage);
71  connect(walletView, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
72  gui->message(title, message, style);
73  });
74  connect(walletView, &WalletView::encryptionStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
75  connect(walletView, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
76  connect(walletView, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
77  connect(gui, &BitcoinGUI::setPrivacy, walletView, &WalletView::setPrivacy);
78 
79  return true;
80 }
81 
83 {
84  if (mapWalletViews.count(wallet_model) == 0) return;
85 
86  WalletView *walletView = mapWalletViews.value(wallet_model);
87  walletStack->setCurrentWidget(walletView);
88  assert(walletView);
89  walletView->updateEncryptionStatus();
90 }
91 
93 {
94  if (mapWalletViews.count(wallet_model) == 0) return;
95 
96  WalletView *walletView = mapWalletViews.take(wallet_model);
97  walletStack->removeWidget(walletView);
98  delete walletView;
99 }
100 
102 {
103  QMap<WalletModel*, WalletView*>::const_iterator i;
104  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
105  walletStack->removeWidget(i.value());
106  mapWalletViews.clear();
107 }
108 
110 {
111  WalletView *walletView = currentWalletView();
112  if (!walletView)
113  return false;
114 
115  return walletView->handlePaymentRequest(recipient);
116 }
117 
119 {
120  bOutOfSync = fShow;
121  QMap<WalletModel*, WalletView*>::const_iterator i;
122  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
123  i.value()->showOutOfSyncWarning(fShow);
124 }
125 
127 {
128  QMap<WalletModel*, WalletView*>::const_iterator i;
129  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
130  i.value()->gotoOverviewPage();
131 }
132 
134 {
135  QMap<WalletModel*, WalletView*>::const_iterator i;
136  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
137  i.value()->gotoHistoryPage();
138 }
139 
141 {
142  QMap<WalletModel*, WalletView*>::const_iterator i;
143  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
144  i.value()->gotoReceiveCoinsPage();
145 }
146 
148 {
149  QMap<WalletModel*, WalletView*>::const_iterator i;
150  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
151  i.value()->gotoSendCoinsPage(addr);
152 }
153 
155 {
156  WalletView *walletView = currentWalletView();
157  if (walletView)
158  walletView->gotoSignMessageTab(addr);
159 }
160 
162 {
163  WalletView *walletView = currentWalletView();
164  if (walletView)
165  walletView->gotoVerifyMessageTab(addr);
166 }
167 
168 void WalletFrame::gotoLoadPSBT(bool from_clipboard)
169 {
170  WalletView *walletView = currentWalletView();
171  if (walletView) {
172  walletView->gotoLoadPSBT(from_clipboard);
173  }
174 }
175 
176 void WalletFrame::encryptWallet(bool status)
177 {
178  WalletView *walletView = currentWalletView();
179  if (walletView)
180  walletView->encryptWallet(status);
181 }
182 
184 {
185  WalletView *walletView = currentWalletView();
186  if (walletView)
187  walletView->backupWallet();
188 }
189 
191 {
192  WalletView *walletView = currentWalletView();
193  if (walletView)
194  walletView->changePassphrase();
195 }
196 
198 {
199  WalletView *walletView = currentWalletView();
200  if (walletView)
201  walletView->unlockWallet();
202 }
203 
205 {
206  WalletView *walletView = currentWalletView();
207  if (walletView)
208  walletView->usedSendingAddresses();
209 }
210 
212 {
213  WalletView *walletView = currentWalletView();
214  if (walletView)
215  walletView->usedReceivingAddresses();
216 }
217 
219 {
220  return qobject_cast<WalletView*>(walletStack->currentWidget());
221 }
222 
224 {
225  WalletView* wallet_view = currentWalletView();
226  return wallet_view ? wallet_view->getWalletModel() : nullptr;
227 }
228 
230 {
231  Q_EMIT requestedSyncWarningInfo();
232 }
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:196
bool bOutOfSync
Definition: walletframe.h:58
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:311
ClientModel * clientModel
Definition: walletframe.h:55
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:291
void setCurrentWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:82
QMap< WalletModel *, WalletView * > mapWalletViews
Definition: walletframe.h:56
void setPrivacy(bool privacy)
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:65
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
bool isPrivacyModeActivated() const
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:256
void removeAllWallets()
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:319
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:37
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:106
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:298
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:46
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 message(const QString &title, QString message, unsigned int style, bool *ret=nullptr, const QString &detailed_message=QString())
Notify the user of an event from the core network or transaction handling code.
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:161
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:184
void setPrivacy(bool privacy)
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
void gotoLoadPSBT(bool from_clipboard=false)
Load Partially Signed Bitcoin Transaction.
Definition: walletview.cpp:208
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:97
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:261
void removeWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:92
void gotoLoadPSBT(bool from_clipboard=false)
Load Partially Signed Bitcoin Transaction.
void coinsSent()
void transactionClicked()
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:251
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.