Bitcoin Core  24.99.0
P2P Digital Currency
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2022 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 
7 #include <qt/addressbookpage.h>
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>
14 #include <qt/receivecoinsdialog.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/interface_ui.h>
23 #include <util/strencodings.h>
24 
25 #include <QAction>
26 #include <QFileDialog>
27 #include <QHBoxLayout>
28 #include <QProgressDialog>
29 #include <QPushButton>
30 #include <QVBoxLayout>
31 
32 WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platformStyle, QWidget* parent)
33  : QStackedWidget(parent),
34  walletModel(wallet_model),
35  platformStyle(_platformStyle)
36 {
38 
39  // Create tabs
42 
43  transactionsPage = new QWidget(this);
44  QVBoxLayout *vbox = new QVBoxLayout();
45  QHBoxLayout *hbox_buttons = new QHBoxLayout();
48 
49  vbox->addWidget(transactionView);
50  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
51  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
53  exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
54  }
55  hbox_buttons->addStretch();
56  hbox_buttons->addWidget(exportButton);
57  vbox->addLayout(hbox_buttons);
58  transactionsPage->setLayout(vbox);
59 
62 
65 
68 
71 
72  addWidget(overviewPage);
73  addWidget(transactionsPage);
74  addWidget(receiveCoinsPage);
75  addWidget(sendCoinsPage);
76 
78  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
80 
82 
84  // Highlight transaction after send
86 
87  // Clicking on "Export" allows to export the transaction list
88  connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);
89 
90  // Pass through messages from sendCoinsPage
92  // Pass through messages from transactionView
94 
96 
97  // Receive and pass through messages from wallet model
99 
100  // Handle changes in encryption status
102 
103  // Balloon pop-up for new transaction
104  connect(walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);
105 
106  // Ask for passphrase if needed
108 
109  // Show progress dialog
111 }
112 
113 WalletView::~WalletView() = default;
114 
116 {
117  this->clientModel = _clientModel;
118 
119  overviewPage->setClientModel(_clientModel);
120  sendCoinsPage->setClientModel(_clientModel);
121  walletModel->setClientModel(_clientModel);
122 }
123 
124 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
125 {
126  // Prevent balloon-spam when initial block download is in progress
128  return;
129  }
130 
132  if (!ttm || ttm->processingQueuedTransactions())
133  return;
134 
135  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
136  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
137  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
138  QModelIndex index = ttm->index(start, 0, parent);
139  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
140  QString label = GUIUtil::HtmlEscape(ttm->data(index, TransactionTableModel::LabelRole).toString());
141 
142  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, GUIUtil::HtmlEscape(walletModel->getWalletName()));
143 }
144 
146 {
147  setCurrentWidget(overviewPage);
148 }
149 
151 {
152  setCurrentWidget(transactionsPage);
153 }
154 
156 {
157  setCurrentWidget(receiveCoinsPage);
158 }
159 
161 {
162  setCurrentWidget(sendCoinsPage);
163 
164  if (!addr.isEmpty())
165  sendCoinsPage->setAddress(addr);
166 }
167 
169 {
170  // calls show() in showTab_SM()
171  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
172  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
173  signVerifyMessageDialog->setModel(walletModel);
174  signVerifyMessageDialog->showTab_SM(true);
175 
176  if (!addr.isEmpty())
177  signVerifyMessageDialog->setAddress_SM(addr);
178 }
179 
181 {
182  // calls show() in showTab_VM()
183  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
184  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
185  signVerifyMessageDialog->setModel(walletModel);
186  signVerifyMessageDialog->showTab_VM(true);
187 
188  if (!addr.isEmpty())
189  signVerifyMessageDialog->setAddress_VM(addr);
190 }
191 
193 {
194  return sendCoinsPage->handlePaymentRequest(recipient);
195 }
196 
198 {
200 }
201 
203 {
205  dlg->setModel(walletModel);
206  connect(dlg, &QDialog::finished, this, &WalletView::encryptionStatusChanged);
208 }
209 
211 {
212  QString filename = GUIUtil::getSaveFileName(this,
213  tr("Backup Wallet"), QString(),
214  //: Name of the wallet data file format.
215  tr("Wallet Data") + QLatin1String(" (*.dat)"), nullptr);
216 
217  if (filename.isEmpty())
218  return;
219 
220  if (!walletModel->wallet().backupWallet(filename.toLocal8Bit().data())) {
221  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
223  }
224  else {
225  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
227  }
228 }
229 
231 {
233  dlg->setModel(walletModel);
235 }
236 
238 {
239  // Unlock wallet when requested by wallet model
242  dlg.setModel(walletModel);
243  // A modal dialog must be synchronous here as expected
244  // in the WalletModel::requestUnlock() function.
245  dlg.exec();
246  }
247 }
248 
250 {
252 }
253 
255 {
257 }
258 
259 void WalletView::showProgress(const QString &title, int nProgress)
260 {
261  if (nProgress == 0) {
262  progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
264  progressDialog->setWindowModality(Qt::ApplicationModal);
265  progressDialog->setAutoClose(false);
266  progressDialog->setValue(0);
267  } else if (nProgress == 100) {
268  if (progressDialog) {
269  progressDialog->close();
270  progressDialog->deleteLater();
271  progressDialog = nullptr;
272  }
273  } else if (progressDialog) {
274  if (progressDialog->wasCanceled()) {
276  } else {
277  progressDialog->setValue(nProgress);
278  }
279  }
280 }
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.
void setModel(WalletModel *model)
@ 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: interface_ui.h:65
Model for Bitcoin network client.
Definition: clientmodel.h:55
interfaces::Node & node() const
Definition: clientmodel.h:62
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:93
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:53
AddressTableModel * getAddressTableModel() const
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:78
interfaces::Wallet & wallet() const
Definition: walletmodel.h:145
EncryptionStatus getEncryptionStatus() const
TransactionTableModel * getTransactionTableModel() const
OptionsModel * getOptionsModel() const
void requireUnlock()
void encryptionStatusChanged()
QString getWalletName() const
const PlatformStyle * platformStyle
Definition: walletview.h:71
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:150
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:180
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:192
WalletModel *const walletModel
The wallet model represents a bitcoin wallet, and offers access to the list of transactions,...
Definition: walletview.h:59
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:160
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:230
QProgressDialog * progressDialog
Definition: walletview.h:70
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:64
OverviewPage * overviewPage
Definition: walletview.h:61
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:115
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:155
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:168
QWidget * transactionsPage
Definition: walletview.h:62
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:249
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:63
void encryptWallet()
Encrypt the wallet.
Definition: walletview.cpp:202
TransactionView * transactionView
Definition: walletview.h:68
WalletView(WalletModel *wallet_model, const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:32
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:259
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:66
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:210
void incomingTransaction(const QString &date, BitcoinUnit unit, const CAmount &amount, const QString &type, const QString &address, const QString &label, const QString &walletName)
Notify that a new transaction appeared.
ClientModel * clientModel
Definition: walletview.h:53
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:65
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:237
WalletModel * getWalletModel() const noexcept
Definition: walletview.h:46
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:145
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:254
void transactionClicked()
void coinsSent()
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:124
void setPrivacy(bool privacy)
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:197
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:240
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
Definition: guiutil.cpp:989
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:881
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:304
void bringToFront(QWidget *w)
Definition: guiutil.cpp:397
assert(!tx.IsCoinBase())