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