Bitcoin ABC 0.32.4
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/fs.h>
14#include <util/fs_helpers.h>
15
16#include <QGroupBox>
17#include <QHBoxLayout>
18#include <QLabel>
19#include <QPushButton>
20#include <QVBoxLayout>
21
22#include <cassert>
23#include <fstream>
24#include <string>
25
27 : QFrame(_gui), gui(_gui), platformStyle(_platformStyle),
28 m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint()) {
29 // Leave HBox hook for adding a list view later
30 QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
31 setContentsMargins(0, 0, 0, 0);
32 walletStack = new QStackedWidget(this);
33 walletFrameLayout->setContentsMargins(0, 0, 0, 0);
34 walletFrameLayout->addWidget(walletStack);
35
36 // hbox for no wallet
37 QGroupBox *no_wallet_group = new QGroupBox(walletStack);
38 QVBoxLayout *no_wallet_layout = new QVBoxLayout(no_wallet_group);
39
40 QLabel *noWallet = new QLabel(tr("No wallet has been loaded.\nGo to File > "
41 "Open Wallet to load a wallet.\n- OR -"));
42 noWallet->setAlignment(Qt::AlignCenter);
43 no_wallet_layout->addWidget(noWallet, 0,
44 Qt::AlignHCenter | Qt::AlignBottom);
45
46 // A button for create wallet dialog
47 QPushButton *create_wallet_button =
48 new QPushButton(tr("Create a new wallet"), walletStack);
49 connect(create_wallet_button, &QPushButton::clicked, [this] {
50 auto activity =
51 new CreateWalletActivity(gui->getWalletController(), this);
52 connect(activity, &CreateWalletActivity::finished, activity,
53 &QObject::deleteLater);
54 activity->create();
55 });
56 no_wallet_layout->addWidget(create_wallet_button, 0,
57 Qt::AlignHCenter | Qt::AlignTop);
58 no_wallet_group->setLayout(no_wallet_layout);
59
60 walletStack->addWidget(no_wallet_group);
61}
62
64
66 this->clientModel = _clientModel;
67
68 for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd();
69 ++i) {
70 i.value()->setClientModel(_clientModel);
71 }
72}
73
75 if (!gui || !clientModel || !walletModel) {
76 return false;
77 }
78
79 if (mapWalletViews.count(walletModel) > 0) {
80 return false;
81 }
82
83 WalletView *walletView = new WalletView(platformStyle, walletModel, this);
84 walletView->setClientModel(clientModel);
87
88 WalletView *current_wallet_view = currentWalletView();
89 if (current_wallet_view) {
90 walletView->setCurrentIndex(current_wallet_view->currentIndex());
91 } else {
92 walletView->gotoOverviewPage();
93 }
94
95 walletStack->addWidget(walletView);
96 mapWalletViews[walletModel] = walletView;
97
98 connect(walletView, &WalletView::outOfSyncWarningClicked, this,
100 connect(walletView, &WalletView::transactionClicked, gui,
101 &BitcoinGUI::gotoHistoryPage);
102 connect(walletView, &WalletView::coinsSent, gui,
103 &BitcoinGUI::gotoHistoryPage);
104 connect(
105 walletView, &WalletView::message,
106 [this](const QString &title, const QString &message,
107 unsigned int style) { gui->message(title, message, style); });
108 connect(walletView, &WalletView::encryptionStatusChanged, gui,
109 &BitcoinGUI::updateWalletStatus);
110 connect(walletView, &WalletView::incomingTransaction, gui,
111 &BitcoinGUI::incomingTransaction);
112 connect(walletView, &WalletView::hdEnabledStatusChanged, gui,
113 &BitcoinGUI::updateWalletStatus);
114 connect(gui, &BitcoinGUI::setPrivacy, walletView, &WalletView::setPrivacy);
115
116 return true;
117}
118
120 if (mapWalletViews.count(wallet_model) == 0) {
121 return;
122 }
123
124 WalletView *walletView = mapWalletViews.value(wallet_model);
125 walletStack->setCurrentWidget(walletView);
126 assert(walletView);
127 walletView->updateEncryptionStatus();
128}
129
131 if (mapWalletViews.count(wallet_model) == 0) {
132 return;
133 }
134
135 WalletView *walletView = mapWalletViews.take(wallet_model);
136 walletStack->removeWidget(walletView);
137 delete walletView;
138}
139
141 QMap<WalletModel *, WalletView *>::const_iterator i;
142 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
143 walletStack->removeWidget(i.value());
144 }
145 mapWalletViews.clear();
146}
147
149 WalletView *walletView = currentWalletView();
150 if (!walletView) {
151 return false;
152 }
153
154 return walletView->handlePaymentRequest(recipient);
155}
156
158 bOutOfSync = fShow;
159 QMap<WalletModel *, WalletView *>::const_iterator i;
160 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
161 i.value()->showOutOfSyncWarning(fShow);
162 }
163}
164
166 QMap<WalletModel *, WalletView *>::const_iterator i;
167 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
168 i.value()->gotoOverviewPage();
169 }
170}
171
173 QMap<WalletModel *, WalletView *>::const_iterator i;
174 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
175 i.value()->gotoHistoryPage();
176 }
177}
178
180 QMap<WalletModel *, WalletView *>::const_iterator i;
181 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
182 i.value()->gotoReceiveCoinsPage();
183 }
184}
185
187 QMap<WalletModel *, WalletView *>::const_iterator i;
188 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
189 i.value()->gotoSendCoinsPage(addr);
190 }
191}
192
194 WalletView *walletView = currentWalletView();
195 if (walletView) {
196 walletView->gotoSignMessageTab(addr);
197 }
198}
199
201 WalletView *walletView = currentWalletView();
202 if (walletView) {
203 walletView->gotoVerifyMessageTab(addr);
204 }
205}
206
208 WalletView *walletView = currentWalletView();
209 if (walletView) {
210 walletView->gotoLoadPSBT();
211 }
212 // TODO: apply core-gui#336 when adding PSBTOperationsDialog
213}
214
216 WalletView *walletView = currentWalletView();
217 if (walletView) {
218 walletView->encryptWallet();
219 }
220}
221
223 WalletView *walletView = currentWalletView();
224 if (walletView) {
225 walletView->backupWallet();
226 }
227}
228
230 WalletView *walletView = currentWalletView();
231 if (walletView) {
232 walletView->changePassphrase();
233 }
234}
235
237 WalletView *walletView = currentWalletView();
238 if (walletView) {
239 walletView->unlockWallet();
240 }
241}
242
244 WalletView *walletView = currentWalletView();
245 if (walletView) {
246 walletView->usedSendingAddresses();
247 }
248}
249
251 WalletView *walletView = currentWalletView();
252 if (walletView) {
253 walletView->usedReceivingAddresses();
254 }
255}
256
258 return qobject_cast<WalletView *>(walletStack->currentWidget());
259}
260
262 WalletView *wallet_view = currentWalletView();
263 return wallet_view ? wallet_view->getWalletModel() : nullptr;
264}
265
268}
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:43
Overview ("home") page widget.
Definition: overviewpage.h:28
void removeAllWallets()
bool addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:74
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:65
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:26
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:235
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:344
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:390
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:117
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:222
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:411
void encryptWallet()
Encrypt the wallet.
Definition: walletview.cpp:356
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:367
void gotoLoadPSBT()
Load Partially Signed Bitcoin Transaction.
Definition: walletview.cpp:248
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:396
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:202
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:419
void transactionClicked()
WalletModel * getWalletModel()
Definition: walletview.h:48
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:352
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:348
void encryptionStatusChanged()
Encryption status of wallet changed.
assert(!tx.IsCoinBase())