Bitcoin Core 22.99.0
P2P Digital Currency
walletview.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/walletview.h>
6
9#include <qt/clientmodel.h>
10#include <qt/guiutil.h>
11#include <qt/optionsmodel.h>
12#include <qt/overviewpage.h>
13#include <qt/platformstyle.h>
15#include <qt/sendcoinsdialog.h>
18#include <qt/transactionview.h>
19#include <qt/walletmodel.h>
20
21#include <interfaces/node.h>
22#include <node/ui_interface.h>
23#include <util/strencodings.h>
24
25#include <QAction>
26#include <QActionGroup>
27#include <QFileDialog>
28#include <QHBoxLayout>
29#include <QProgressDialog>
30#include <QPushButton>
31#include <QVBoxLayout>
32
33WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platformStyle, QWidget* parent)
34 : QStackedWidget(parent),
35 clientModel(nullptr),
36 walletModel(wallet_model),
37 platformStyle(_platformStyle)
38{
40
41 // Create tabs
44
45 transactionsPage = new QWidget(this);
46 QVBoxLayout *vbox = new QVBoxLayout();
47 QHBoxLayout *hbox_buttons = new QHBoxLayout();
50
51 vbox->addWidget(transactionView);
52 QPushButton *exportButton = new QPushButton(tr("&Export"), this);
53 exportButton->setToolTip(tr("Export the data in the current tab to a file"));
55 exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
56 }
57 hbox_buttons->addStretch();
58 hbox_buttons->addWidget(exportButton);
59 vbox->addLayout(hbox_buttons);
60 transactionsPage->setLayout(vbox);
61
64
67
70
73
74 addWidget(overviewPage);
75 addWidget(transactionsPage);
76 addWidget(receiveCoinsPage);
77 addWidget(sendCoinsPage);
78
80 // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
82
84
86 // Highlight transaction after send
88
89 // Clicking on "Export" allows to export the transaction list
90 connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);
91
92 // Pass through messages from sendCoinsPage
94 // Pass through messages from transactionView
96
98
99 // Receive and pass through messages from wallet model
101
102 // Handle changes in encryption status
104
105 // Balloon pop-up for new transaction
106 connect(walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);
107
108 // Ask for passphrase if needed
110
111 // Show progress dialog
113}
114
116{
117}
118
120{
121 this->clientModel = _clientModel;
122
123 overviewPage->setClientModel(_clientModel);
124 sendCoinsPage->setClientModel(_clientModel);
125 walletModel->setClientModel(_clientModel);
126}
127
128void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
129{
130 // Prevent balloon-spam when initial block download is in progress
132 return;
133 }
134
136 if (!ttm || ttm->processingQueuedTransactions())
137 return;
138
139 QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
140 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
141 QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
142 QModelIndex index = ttm->index(start, 0, parent);
143 QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
144 QString label = GUIUtil::HtmlEscape(ttm->data(index, TransactionTableModel::LabelRole).toString());
145
147}
148
150{
151 setCurrentWidget(overviewPage);
152}
153
155{
156 setCurrentWidget(transactionsPage);
157}
158
160{
161 setCurrentWidget(receiveCoinsPage);
162}
163
165{
166 setCurrentWidget(sendCoinsPage);
167
168 if (!addr.isEmpty())
170}
171
173{
174 // calls show() in showTab_SM()
175 SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
176 signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
177 signVerifyMessageDialog->setModel(walletModel);
178 signVerifyMessageDialog->showTab_SM(true);
179
180 if (!addr.isEmpty())
181 signVerifyMessageDialog->setAddress_SM(addr);
182}
183
185{
186 // calls show() in showTab_VM()
187 SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
188 signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
189 signVerifyMessageDialog->setModel(walletModel);
190 signVerifyMessageDialog->showTab_VM(true);
191
192 if (!addr.isEmpty())
193 signVerifyMessageDialog->setAddress_VM(addr);
194}
195
197{
198 return sendCoinsPage->handlePaymentRequest(recipient);
199}
200
202{
204}
205
207{
209 dlg->setModel(walletModel);
210 connect(dlg, &QDialog::finished, this, &WalletView::encryptionStatusChanged);
212}
213
215{
216 QString filename = GUIUtil::getSaveFileName(this,
217 tr("Backup Wallet"), QString(),
218 //: Name of the wallet data file format.
219 tr("Wallet Data") + QLatin1String(" (*.dat)"), nullptr);
220
221 if (filename.isEmpty())
222 return;
223
224 if (!walletModel->wallet().backupWallet(filename.toLocal8Bit().data())) {
225 Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
227 }
228 else {
229 Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
231 }
232}
233
235{
237 dlg->setModel(walletModel);
239}
240
242{
243 // Unlock wallet when requested by wallet model
246 dlg->setModel(walletModel);
248 }
249}
250
252{
254}
255
257{
259}
260
261void WalletView::showProgress(const QString &title, int nProgress)
262{
263 if (nProgress == 0) {
264 progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
266 progressDialog->setWindowModality(Qt::ApplicationModal);
267 progressDialog->setAutoClose(false);
268 progressDialog->setValue(0);
269 } else if (nProgress == 100) {
270 if (progressDialog) {
271 progressDialog->close();
272 progressDialog->deleteLater();
273 progressDialog = nullptr;
274 }
275 } else if (progressDialog) {
276 if (progressDialog->wasCanceled()) {
278 } else {
279 progressDialog->setValue(nProgress);
280 }
281 }
282}
Widget that shows a list of sending or receiving addresses.
@ ForEditing
Open address book for editing.
void setModel(AddressTableModel *model)
Multifunctional dialog to ask for passphrases.
@ Unlock
Ask passphrase and unlock.
@ Encrypt
Ask passphrase twice and encrypt.
@ ChangePass
Ask old passphrase + new passphrase twice.
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:66
Model for Bitcoin network client.
Definition: clientmodel.h:48
interfaces::Node & node() const
Definition: clientmodel.h:55
int getDisplayUnit() const
Definition: optionsmodel.h:88
Overview ("home") page widget.
Definition: overviewpage.h:29
void setWalletModel(WalletModel *walletModel)
void setClientModel(ClientModel *clientModel)
void transactionClicked(const QModelIndex &index)
void outOfSyncWarningClicked()
void showOutOfSyncWarning(bool fShow)
void setPrivacy(bool privacy)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getImagesOnButtons() const
Definition: platformstyle.h:21
Dialog for requesting payment of bitcoins.
void setModel(WalletModel *model)
Dialog for sending bitcoins.
void setClientModel(ClientModel *clientModel)
void setModel(WalletModel *model)
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void setAddress(const QString &address)
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(const uint256 &txid)
void setAddress_SM(const QString &address)
void setModel(WalletModel *model)
void setAddress_VM(const QString &address)
UI model for the transaction table of a wallet.
@ LabelRole
Label of address related to transaction.
@ AddressRole
Address of transaction.
QVariant data(const QModelIndex &index, int role) const override
bool processingQueuedTransactions() const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Widget showing the transaction list for a wallet, including a filter row.
void setModel(WalletModel *model)
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void focusTransaction(const QModelIndex &)
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:52
void showProgress(const QString &title, int nProgress)
void message(const QString &title, const QString &message, unsigned int style)
void setClientModel(ClientModel *client_model)
Definition: walletmodel.cpp:75
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
EncryptionStatus getEncryptionStatus() const
interfaces::Wallet & wallet() const
Definition: walletmodel.h:144
void encryptionStatusChanged()
QString getWalletName() const
TransactionTableModel * getTransactionTableModel()
const PlatformStyle * platformStyle
Definition: walletview.h:70
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:154
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:184
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:196
WalletModel *const walletModel
The wallet model represents a bitcoin wallet, and offers access to the list of transactions,...
Definition: walletview.h:58
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:164
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:234
QProgressDialog * progressDialog
Definition: walletview.h:69
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:63
OverviewPage * overviewPage
Definition: walletview.h:60
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.
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:119
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
WalletModel * getWalletModel() const noexcept
Definition: walletview.h:45
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:159
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:172
QWidget * transactionsPage
Definition: walletview.h:61
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:251
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:62
void encryptWallet()
Encrypt the wallet.
Definition: walletview.cpp:206
TransactionView * transactionView
Definition: walletview.h:67
WalletView(WalletModel *wallet_model, const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:33
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:261
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:65
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:214
ClientModel * clientModel
Definition: walletview.h:52
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:64
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:241
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:149
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:256
void transactionClicked()
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:128
void setPrivacy(bool privacy)
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:201
void encryptionStatusChanged()
Encryption status of wallet changed.
virtual bool isInitialBlockDownload()=0
Is initial block download.
virtual void abortRescan()=0
Abort a rescan.
virtual bool backupWallet(const std::string &filename)=0
Back up wallet.
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:233
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:868
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
Definition: guiutil.cpp:286
void bringToFront(QWidget *w)
Definition: guiutil.cpp:391
void ShowModalDialogAndDeleteOnClose(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
Definition: guiutil.cpp:980
assert(!tx.IsCoinBase())