Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
31 setContentsMargins(0, 0, 0, 0);
32 walletStack = new QStackedWidget(this);
33 walletFrameLayout->setContentsMargins(0, 0, 0, 0);
35
36 // hbox for no wallet
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
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);
53 &QObject::deleteLater);
54 activity->create();
55 });
57 Qt::AlignHCenter | Qt::AlignTop);
59
60 walletStack->addWidget(no_wallet_group);
61}
62
64
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);
85 walletView->showOutOfSyncWarning(bOutOfSync);
87
90 walletView->setCurrentIndex(current_wallet_view->currentIndex());
91 } else {
92 walletView->gotoOverviewPage();
93 }
94
95 walletStack->addWidget(walletView);
96 mapWalletViews[walletModel] = walletView;
97
101 &BitcoinGUI::gotoHistoryPage);
103 &BitcoinGUI::gotoHistoryPage);
104 connect(
106 [this](const QString &title, const QString &message,
107 unsigned int style) { gui->message(title, message, style); });
109 &BitcoinGUI::updateWalletStatus);
111 &BitcoinGUI::incomingTransaction);
113 &BitcoinGUI::updateWalletStatus);
115
116 return true;
117}
118
120 if (mapWalletViews.count(wallet_model) == 0) {
121 return;
122 }
123
125 walletStack->setCurrentWidget(walletView);
127 walletView->updateEncryptionStatus();
128}
129
131 if (mapWalletViews.count(wallet_model) == 0) {
132 return;
133 }
134
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
150 if (!walletView) {
151 return false;
152 }
153
154 return walletView->handlePaymentRequest(recipient);
155}
156
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
195 if (walletView) {
196 walletView->gotoSignMessageTab(addr);
197 }
198}
199
202 if (walletView) {
203 walletView->gotoVerifyMessageTab(addr);
204 }
205}
206
209 if (walletView) {
210 walletView->gotoLoadPSBT();
211 }
212}
213
216 if (walletView) {
217 walletView->encryptWallet();
218 }
219}
220
223 if (walletView) {
224 walletView->backupWallet();
225 }
226}
227
230 if (walletView) {
231 walletView->changePassphrase();
232 }
233}
234
237 if (walletView) {
238 walletView->unlockWallet();
239 }
240}
241
244 if (walletView) {
245 walletView->usedSendingAddresses();
246 }
247}
248
251 if (walletView) {
252 walletView->usedReceivingAddresses();
253 }
254}
255
259
262 return wallet_view ? wallet_view->getWalletModel() : nullptr;
263}
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:43
Overview ("home") page widget.
void removeAllWallets()
bool addWallet(WalletModel *walletModel)
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)
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)
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 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 outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void transactionClicked()
void hdEnabledStatusChanged()
HD-Enabled status of wallet changed (only possible during startup)
void coinsSent()
void setPrivacy(bool privacy)
void encryptionStatusChanged()
Encryption status of wallet changed.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
assert(!tx.IsCoinBase())