Bitcoin ABC  0.22.13
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 
7 #include <qt/bitcoingui.h>
8 #include <qt/walletmodel.h>
9 #include <qt/walletview.h>
10 
11 #include <QHBoxLayout>
12 #include <QLabel>
13 
14 #include <cassert>
15 
16 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui)
17  : QFrame(_gui), gui(_gui), platformStyle(_platformStyle) {
18  // Leave HBox hook for adding a list view later
19  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
20  setContentsMargins(0, 0, 0, 0);
21  walletStack = new QStackedWidget(this);
22  walletFrameLayout->setContentsMargins(0, 0, 0, 0);
23  walletFrameLayout->addWidget(walletStack);
24 
25  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
26  noWallet->setAlignment(Qt::AlignCenter);
27  walletStack->addWidget(noWallet);
28 }
29 
31 
33  this->clientModel = _clientModel;
34 
35  for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd();
36  ++i) {
37  i.value()->setClientModel(_clientModel);
38  }
39 }
40 
41 bool WalletFrame::addWallet(WalletModel *walletModel) {
42  if (!gui || !clientModel || !walletModel) {
43  return false;
44  }
45 
46  if (mapWalletViews.count(walletModel) > 0) {
47  return false;
48  }
49 
50  WalletView *walletView = new WalletView(platformStyle, walletModel, this);
51  walletView->setClientModel(clientModel);
52  walletView->showOutOfSyncWarning(bOutOfSync);
53 
54  WalletView *current_wallet_view = currentWalletView();
55  if (current_wallet_view) {
56  walletView->setCurrentIndex(current_wallet_view->currentIndex());
57  } else {
58  walletView->gotoOverviewPage();
59  }
60 
61  walletStack->addWidget(walletView);
62  mapWalletViews[walletModel] = walletView;
63 
64  connect(walletView, &WalletView::outOfSyncWarningClicked, this,
66  connect(walletView, &WalletView::transactionClicked, gui,
67  &BitcoinGUI::gotoHistoryPage);
68  connect(walletView, &WalletView::coinsSent, gui,
69  &BitcoinGUI::gotoHistoryPage);
70  connect(
71  walletView, &WalletView::message,
72  [this](const QString &title, const QString &message,
73  unsigned int style) { gui->message(title, message, style); });
74  connect(walletView, &WalletView::encryptionStatusChanged, gui,
75  &BitcoinGUI::updateWalletStatus);
76  connect(walletView, &WalletView::incomingTransaction, gui,
77  &BitcoinGUI::incomingTransaction);
78  connect(walletView, &WalletView::hdEnabledStatusChanged, gui,
79  &BitcoinGUI::updateWalletStatus);
80 
81  return true;
82 }
83 
85  if (mapWalletViews.count(wallet_model) == 0) {
86  return;
87  }
88 
89  WalletView *walletView = mapWalletViews.value(wallet_model);
90  walletStack->setCurrentWidget(walletView);
91  assert(walletView);
92  walletView->updateEncryptionStatus();
93 }
94 
96  if (mapWalletViews.count(wallet_model) == 0) {
97  return;
98  }
99 
100  WalletView *walletView = mapWalletViews.take(wallet_model);
101  walletStack->removeWidget(walletView);
102  delete walletView;
103 }
104 
106  QMap<WalletModel *, WalletView *>::const_iterator i;
107  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
108  walletStack->removeWidget(i.value());
109  }
110  mapWalletViews.clear();
111 }
112 
114  WalletView *walletView = currentWalletView();
115  if (!walletView) {
116  return false;
117  }
118 
119  return walletView->handlePaymentRequest(recipient);
120 }
121 
123  bOutOfSync = fShow;
124  QMap<WalletModel *, WalletView *>::const_iterator i;
125  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
126  i.value()->showOutOfSyncWarning(fShow);
127  }
128 }
129 
131  QMap<WalletModel *, WalletView *>::const_iterator i;
132  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
133  i.value()->gotoOverviewPage();
134  }
135 }
136 
138  QMap<WalletModel *, WalletView *>::const_iterator i;
139  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
140  i.value()->gotoHistoryPage();
141  }
142 }
143 
145  QMap<WalletModel *, WalletView *>::const_iterator i;
146  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
147  i.value()->gotoReceiveCoinsPage();
148  }
149 }
150 
151 void WalletFrame::gotoSendCoinsPage(QString addr) {
152  QMap<WalletModel *, WalletView *>::const_iterator i;
153  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
154  i.value()->gotoSendCoinsPage(addr);
155  }
156 }
157 
159  WalletView *walletView = currentWalletView();
160  if (walletView) {
161  walletView->gotoSignMessageTab(addr);
162  }
163 }
164 
166  WalletView *walletView = currentWalletView();
167  if (walletView) {
168  walletView->gotoVerifyMessageTab(addr);
169  }
170 }
171 
173  WalletView *walletView = currentWalletView();
174  if (walletView) {
175  walletView->gotoLoadPSBT();
176  }
177 }
178 
179 void WalletFrame::encryptWallet(bool status) {
180  WalletView *walletView = currentWalletView();
181  if (walletView) {
182  walletView->encryptWallet(status);
183  }
184 }
185 
187  WalletView *walletView = currentWalletView();
188  if (walletView) {
189  walletView->backupWallet();
190  }
191 }
192 
194  WalletView *walletView = currentWalletView();
195  if (walletView) {
196  walletView->changePassphrase();
197  }
198 }
199 
201  WalletView *walletView = currentWalletView();
202  if (walletView) {
203  walletView->unlockWallet();
204  }
205 }
206 
208  WalletView *walletView = currentWalletView();
209  if (walletView) {
210  walletView->usedSendingAddresses();
211  }
212 }
213 
215  WalletView *walletView = currentWalletView();
216  if (walletView) {
217  walletView->usedReceivingAddresses();
218  }
219 }
220 
222  return qobject_cast<WalletView *>(walletStack->currentWidget());
223 }
224 
226  WalletView *wallet_view = currentWalletView();
227  return wallet_view ? wallet_view->getWalletModel() : nullptr;
228 }
229 
231  Q_EMIT requestedSyncWarningInfo();
232 }
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
WalletModel * currentWalletModel() const
WalletView class.
Definition: walletview.h:34
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:224
bool bOutOfSync
Definition: walletframe.h:59
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:400
ClientModel * clientModel
Definition: walletframe.h:56
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:381
void setCurrentWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:84
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:54
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:67
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:340
void removeAllWallets()
void gotoLoadPSBT()
Load Partially Signed Bitcoin Transaction.
Definition: walletview.cpp:237
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
WalletModel * getWalletModel()
Definition: walletview.h:48
void gotoOverviewPage()
Switch to overview (home) page.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:408
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:32
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:55
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:387
QMap< WalletModel *, WalletView * > mapWalletViews
Definition: walletframe.h:57
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:34
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:358
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:332
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:191
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
void incomingTransaction(const QString &date, int unit, const Amount amount, const QString &type, const QString &address, const QString &label, const QString &walletName)
Notify that a new transaction appeared.
void encryptionStatusChanged()
Encryption status of wallet changed.
void gotoLoadPSBT()
Load Partially Signed Bitcoin Transaction.
const PlatformStyle * platformStyle
Definition: walletframe.h:61
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:211
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:109
bool addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:41
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:344
void removeWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:95
void coinsSent()
void transactionClicked()
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:336