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 
7 #include <qt/bitcoingui.h>
9 #include <qt/overviewpage.h>
10 #include <qt/walletcontroller.h>
11 #include <qt/walletmodel.h>
12 #include <qt/walletview.h>
13 
14 #include <cassert>
15 
16 #include <QGroupBox>
17 #include <QHBoxLayout>
18 #include <QLabel>
19 #include <QPushButton>
20 #include <QVBoxLayout>
21 
22 WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, BitcoinGUI* _gui)
23  : QFrame(_gui),
24  gui(_gui),
25  platformStyle(_platformStyle),
26  m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint())
27 {
28  // Leave HBox hook for adding a list view later
29  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
30  setContentsMargins(0,0,0,0);
31  walletStack = new QStackedWidget(this);
32  walletFrameLayout->setContentsMargins(0,0,0,0);
33  walletFrameLayout->addWidget(walletStack);
34 
35  // hbox for no wallet
36  QGroupBox* no_wallet_group = new QGroupBox(walletStack);
37  QVBoxLayout* no_wallet_layout = new QVBoxLayout(no_wallet_group);
38 
39  QLabel *noWallet = new QLabel(tr("No wallet has been loaded.\nGo to File > Open Wallet to load a wallet.\n- OR -"));
40  noWallet->setAlignment(Qt::AlignCenter);
41  no_wallet_layout->addWidget(noWallet, 0, Qt::AlignHCenter | Qt::AlignBottom);
42 
43  // A button for create wallet dialog
44  QPushButton* create_wallet_button = new QPushButton(tr("Create a new wallet"), walletStack);
45  connect(create_wallet_button, &QPushButton::clicked, [this] {
46  auto activity = new CreateWalletActivity(gui->getWalletController(), this);
47  connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
48  activity->create();
49  });
50  no_wallet_layout->addWidget(create_wallet_button, 0, Qt::AlignHCenter | Qt::AlignTop);
51  no_wallet_group->setLayout(no_wallet_layout);
52 
53  walletStack->addWidget(no_wallet_group);
54 }
55 
57 {
58 }
59 
61 {
62  this->clientModel = _clientModel;
63 
64  for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
65  i.value()->setClientModel(_clientModel);
66  }
67 }
68 
70 {
71  if (!gui || !clientModel || !walletModel) return false;
72 
73  if (mapWalletViews.count(walletModel) > 0) return false;
74 
75  WalletView *walletView = new WalletView(platformStyle, this);
76  walletView->setClientModel(clientModel);
77  walletView->setWalletModel(walletModel);
78  walletView->showOutOfSyncWarning(bOutOfSync);
79  walletView->setPrivacy(gui->isPrivacyModeActivated());
80 
81  WalletView* current_wallet_view = currentWalletView();
82  if (current_wallet_view) {
83  walletView->setCurrentIndex(current_wallet_view->currentIndex());
84  } else {
85  walletView->gotoOverviewPage();
86  }
87 
88  walletStack->addWidget(walletView);
89  mapWalletViews[walletModel] = walletView;
90 
92  connect(walletView, &WalletView::transactionClicked, gui, &BitcoinGUI::gotoHistoryPage);
93  connect(walletView, &WalletView::coinsSent, gui, &BitcoinGUI::gotoHistoryPage);
94  connect(walletView, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
95  gui->message(title, message, style);
96  });
97  connect(walletView, &WalletView::encryptionStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
98  connect(walletView, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
99  connect(walletView, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
100  connect(gui, &BitcoinGUI::setPrivacy, walletView, &WalletView::setPrivacy);
101 
102  return true;
103 }
104 
106 {
107  if (mapWalletViews.count(wallet_model) == 0) return;
108 
109  WalletView *walletView = mapWalletViews.value(wallet_model);
110  walletStack->setCurrentWidget(walletView);
111  assert(walletView);
112  walletView->updateEncryptionStatus();
113 }
114 
116 {
117  if (mapWalletViews.count(wallet_model) == 0) return;
118 
119  WalletView *walletView = mapWalletViews.take(wallet_model);
120  walletStack->removeWidget(walletView);
121  delete walletView;
122 }
123 
125 {
126  QMap<WalletModel*, WalletView*>::const_iterator i;
127  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
128  walletStack->removeWidget(i.value());
129  mapWalletViews.clear();
130 }
131 
133 {
134  WalletView *walletView = currentWalletView();
135  if (!walletView)
136  return false;
137 
138  return walletView->handlePaymentRequest(recipient);
139 }
140 
142 {
143  bOutOfSync = fShow;
144  QMap<WalletModel*, WalletView*>::const_iterator i;
145  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
146  i.value()->showOutOfSyncWarning(fShow);
147 }
148 
150 {
151  QMap<WalletModel*, WalletView*>::const_iterator i;
152  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
153  i.value()->gotoOverviewPage();
154 }
155 
157 {
158  QMap<WalletModel*, WalletView*>::const_iterator i;
159  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
160  i.value()->gotoHistoryPage();
161 }
162 
164 {
165  QMap<WalletModel*, WalletView*>::const_iterator i;
166  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
167  i.value()->gotoReceiveCoinsPage();
168 }
169 
171 {
172  QMap<WalletModel*, WalletView*>::const_iterator i;
173  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
174  i.value()->gotoSendCoinsPage(addr);
175 }
176 
178 {
179  WalletView *walletView = currentWalletView();
180  if (walletView)
181  walletView->gotoSignMessageTab(addr);
182 }
183 
185 {
186  WalletView *walletView = currentWalletView();
187  if (walletView)
188  walletView->gotoVerifyMessageTab(addr);
189 }
190 
191 void WalletFrame::gotoLoadPSBT(bool from_clipboard)
192 {
193  WalletView *walletView = currentWalletView();
194  if (walletView) {
195  walletView->gotoLoadPSBT(from_clipboard);
196  }
197 }
198 
199 void WalletFrame::encryptWallet(bool status)
200 {
201  WalletView *walletView = currentWalletView();
202  if (walletView)
203  walletView->encryptWallet(status);
204 }
205 
207 {
208  WalletView *walletView = currentWalletView();
209  if (walletView)
210  walletView->backupWallet();
211 }
212 
214 {
215  WalletView *walletView = currentWalletView();
216  if (walletView)
217  walletView->changePassphrase();
218 }
219 
221 {
222  WalletView *walletView = currentWalletView();
223  if (walletView)
224  walletView->unlockWallet();
225 }
226 
228 {
229  WalletView *walletView = currentWalletView();
230  if (walletView)
231  walletView->usedSendingAddresses();
232 }
233 
235 {
236  WalletView *walletView = currentWalletView();
237  if (walletView)
238  walletView->usedReceivingAddresses();
239 }
240 
242 {
243  return qobject_cast<WalletView*>(walletStack->currentWidget());
244 }
245 
247 {
248  WalletView* wallet_view = currentWalletView();
249  return wallet_view ? wallet_view->getWalletModel() : nullptr;
250 }
251 
253 {
254  Q_EMIT requestedSyncWarningInfo();
255 }
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:60
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:311
ClientModel * clientModel
Definition: walletframe.h:57
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:291
void setCurrentWallet(WalletModel *wallet_model)
QMap< WalletModel *, WalletView * > mapWalletViews
Definition: walletframe.h:58
void setPrivacy(bool privacy)
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:55
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:66
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:60
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:106
WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui=nullptr)
Definition: walletframe.cpp:22
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
BitcoinGUI * gui
Definition: walletframe.h:56
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:62
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:69
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)
void gotoLoadPSBT(bool from_clipboard=false)
Load Partially Signed Bitcoin Transaction.
void coinsSent()
void transactionClicked()
Overview ("home") page widget.
Definition: overviewpage.h:28
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.