Bitcoin ABC  0.26.3
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>
9 #include <qt/overviewpage.h>
10 #include <qt/walletcontroller.h>
11 #include <qt/walletmodel.h>
12 #include <qt/walletview.h>
13 #include <util/system.h>
14 
15 #include <QGroupBox>
16 #include <QHBoxLayout>
17 #include <QLabel>
18 #include <QPushButton>
19 #include <QVBoxLayout>
20 
21 #include <cassert>
22 
23 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui)
24  : QFrame(_gui), gui(_gui), platformStyle(_platformStyle),
25  m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint()) {
26  // Leave HBox hook for adding a list view later
27  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
28  setContentsMargins(0, 0, 0, 0);
29  walletStack = new QStackedWidget(this);
30  walletFrameLayout->setContentsMargins(0, 0, 0, 0);
31  walletFrameLayout->addWidget(walletStack);
32 
33  // hbox for no wallet
34  QGroupBox *no_wallet_group = new QGroupBox(walletStack);
35  QVBoxLayout *no_wallet_layout = new QVBoxLayout(no_wallet_group);
36 
37  QLabel *noWallet = new QLabel(tr("No wallet has been loaded.\nGo to File > "
38  "Open Wallet to load a wallet.\n- OR -"));
39  noWallet->setAlignment(Qt::AlignCenter);
40  no_wallet_layout->addWidget(noWallet, 0,
41  Qt::AlignHCenter | Qt::AlignBottom);
42 
43  // A button for create wallet dialog
44  QPushButton *create_wallet_button =
45  new QPushButton(tr("Create a new wallet"), walletStack);
46  connect(create_wallet_button, &QPushButton::clicked, [this] {
47  auto activity =
48  new CreateWalletActivity(gui->getWalletController(), this);
49  connect(activity, &CreateWalletActivity::finished, activity,
50  &QObject::deleteLater);
51  activity->create();
52  });
53  no_wallet_layout->addWidget(create_wallet_button, 0,
54  Qt::AlignHCenter | Qt::AlignTop);
55  no_wallet_group->setLayout(no_wallet_layout);
56 
57  walletStack->addWidget(no_wallet_group);
58 }
59 
61 
63  this->clientModel = _clientModel;
64 
65  for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd();
66  ++i) {
67  i.value()->setClientModel(_clientModel);
68  }
69 }
70 
71 bool WalletFrame::addWallet(WalletModel *walletModel) {
72  if (!gui || !clientModel || !walletModel) {
73  return false;
74  }
75 
76  if (mapWalletViews.count(walletModel) > 0) {
77  return false;
78  }
79 
80  WalletView *walletView = new WalletView(platformStyle, walletModel, this);
81  walletView->setClientModel(clientModel);
82  walletView->showOutOfSyncWarning(bOutOfSync);
83  walletView->setPrivacy(gui->isPrivacyModeActivated());
84 
85  WalletView *current_wallet_view = currentWalletView();
86  if (current_wallet_view) {
87  walletView->setCurrentIndex(current_wallet_view->currentIndex());
88  } else {
89  walletView->gotoOverviewPage();
90  }
91 
92  walletStack->addWidget(walletView);
93  mapWalletViews[walletModel] = walletView;
94 
95  connect(walletView, &WalletView::outOfSyncWarningClicked, this,
97  connect(walletView, &WalletView::transactionClicked, gui,
98  &BitcoinGUI::gotoHistoryPage);
99  connect(walletView, &WalletView::coinsSent, gui,
100  &BitcoinGUI::gotoHistoryPage);
101  connect(
102  walletView, &WalletView::message,
103  [this](const QString &title, const QString &message,
104  unsigned int style) { gui->message(title, message, style); });
105  connect(walletView, &WalletView::encryptionStatusChanged, gui,
106  &BitcoinGUI::updateWalletStatus);
107  connect(walletView, &WalletView::incomingTransaction, gui,
108  &BitcoinGUI::incomingTransaction);
109  connect(walletView, &WalletView::hdEnabledStatusChanged, gui,
110  &BitcoinGUI::updateWalletStatus);
111  connect(gui, &BitcoinGUI::setPrivacy, walletView, &WalletView::setPrivacy);
112 
113  return true;
114 }
115 
117  if (mapWalletViews.count(wallet_model) == 0) {
118  return;
119  }
120 
121  WalletView *walletView = mapWalletViews.value(wallet_model);
122  walletStack->setCurrentWidget(walletView);
123  assert(walletView);
124  walletView->updateEncryptionStatus();
125 }
126 
128  if (mapWalletViews.count(wallet_model) == 0) {
129  return;
130  }
131 
132  WalletView *walletView = mapWalletViews.take(wallet_model);
133  walletStack->removeWidget(walletView);
134  delete walletView;
135 }
136 
138  QMap<WalletModel *, WalletView *>::const_iterator i;
139  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
140  walletStack->removeWidget(i.value());
141  }
142  mapWalletViews.clear();
143 }
144 
146  WalletView *walletView = currentWalletView();
147  if (!walletView) {
148  return false;
149  }
150 
151  return walletView->handlePaymentRequest(recipient);
152 }
153 
155  bOutOfSync = fShow;
156  QMap<WalletModel *, WalletView *>::const_iterator i;
157  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
158  i.value()->showOutOfSyncWarning(fShow);
159  }
160 }
161 
163  QMap<WalletModel *, WalletView *>::const_iterator i;
164  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
165  i.value()->gotoOverviewPage();
166  }
167 }
168 
170  QMap<WalletModel *, WalletView *>::const_iterator i;
171  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
172  i.value()->gotoHistoryPage();
173  }
174 }
175 
177  QMap<WalletModel *, WalletView *>::const_iterator i;
178  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
179  i.value()->gotoReceiveCoinsPage();
180  }
181 }
182 
183 void WalletFrame::gotoSendCoinsPage(QString addr) {
184  QMap<WalletModel *, WalletView *>::const_iterator i;
185  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
186  i.value()->gotoSendCoinsPage(addr);
187  }
188 }
189 
191  WalletView *walletView = currentWalletView();
192  if (walletView) {
193  walletView->gotoSignMessageTab(addr);
194  }
195 }
196 
198  WalletView *walletView = currentWalletView();
199  if (walletView) {
200  walletView->gotoVerifyMessageTab(addr);
201  }
202 }
203 
205  WalletView *walletView = currentWalletView();
206  if (walletView) {
207  walletView->gotoLoadPSBT();
208  }
209 }
210 
212  WalletView *walletView = currentWalletView();
213  if (walletView) {
214  walletView->encryptWallet();
215  }
216 }
217 
219  WalletView *walletView = currentWalletView();
220  if (walletView) {
221  walletView->backupWallet();
222  }
223 }
224 
226  WalletView *walletView = currentWalletView();
227  if (walletView) {
228  walletView->changePassphrase();
229  }
230 }
231 
233  WalletView *walletView = currentWalletView();
234  if (walletView) {
235  walletView->unlockWallet();
236  }
237 }
238 
240  WalletView *walletView = currentWalletView();
241  if (walletView) {
242  walletView->usedSendingAddresses();
243  }
244 }
245 
247  WalletView *walletView = currentWalletView();
248  if (walletView) {
249  walletView->usedReceivingAddresses();
250  }
251 }
252 
254  return qobject_cast<WalletView *>(walletStack->currentWidget());
255 }
256 
258  WalletView *wallet_view = currentWalletView();
259  return wallet_view ? wallet_view->getWalletModel() : nullptr;
260 }
261 
263  Q_EMIT requestedSyncWarningInfo();
264 }
Bitcoin GUI main class.
Definition: bitcoingui.h:68
void setPrivacy(bool privacy)
bool isPrivacyModeActivated() const
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.
Model for Bitcoin network client.
Definition: clientmodel.h:36
Overview ("home") page widget.
Definition: overviewpage.h:28
void removeAllWallets()
bool addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:71
void changePassphrase()
Change encrypted wallet passphrase.
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
WalletModel * currentWalletModel() const
void gotoHistoryPage()
Switch to history (transactions) page.
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
WalletView * currentWalletView() const
void gotoOverviewPage()
Switch to overview (home) page.
QMap< WalletModel *, WalletView * > mapWalletViews
Definition: walletframe.h:59
ClientModel * clientModel
Definition: walletframe.h:58
const PlatformStyle * platformStyle
Definition: walletframe.h:63
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
void removeWallet(WalletModel *wallet_model)
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:62
bool bOutOfSync
Definition: walletframe.h:61
void backupWallet()
Backup the wallet.
QStackedWidget * walletStack
Definition: walletframe.h:56
void usedSendingAddresses()
Show used sending addresses.
void encryptWallet()
Encrypt the wallet.
void gotoLoadPSBT()
Load Partially Signed Bitcoin Transaction.
void usedReceivingAddresses()
Show used receiving addresses.
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
void setCurrentWallet(WalletModel *wallet_model)
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui=nullptr)
Definition: walletframe.cpp:23
BitcoinGUI * gui
Definition: walletframe.h:57
void showOutOfSyncWarning(bool fShow)
void gotoReceiveCoinsPage()
Switch to receive coins page.
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
WalletView class.
Definition: walletview.h:34
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:229
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:337
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 changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:383
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:111
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:216
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:402
void encryptWallet()
Encrypt the wallet.
Definition: walletview.cpp:349
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:360
void gotoLoadPSBT()
Load Partially Signed Bitcoin Transaction.
Definition: walletview.cpp:242
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:389
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:196
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:410
void transactionClicked()
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:345
void hdEnabledStatusChanged()
HD-Enabled status of wallet changed (only possible during startup)
void coinsSent()
void setPrivacy(bool privacy)
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:341
void encryptionStatusChanged()
Encryption status of wallet changed.
WalletModel * getWalletModel()
Definition: walletview.h:48
assert(!tx.IsCoinBase())