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 
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/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 
33 WalletView::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 
128 void 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 
146  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, GUIUtil::HtmlEscape(walletModel->getWalletName()));
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())
169  sendCoinsPage->setAddress(addr);
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  dlg.exec();
211 
212  Q_EMIT encryptionStatusChanged();
213 }
214 
216 {
217  QString filename = GUIUtil::getSaveFileName(this,
218  tr("Backup Wallet"), QString(),
219  //: Name of the wallet data file format.
220  tr("Wallet Data") + QLatin1String(" (*.dat)"), nullptr);
221 
222  if (filename.isEmpty())
223  return;
224 
225  if (!walletModel->wallet().backupWallet(filename.toLocal8Bit().data())) {
226  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
228  }
229  else {
230  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
232  }
233 }
234 
236 {
238  dlg.setModel(walletModel);
239  dlg.exec();
240 }
241 
243 {
244  // Unlock wallet when requested by wallet model
246  {
248  dlg.setModel(walletModel);
249  dlg.exec();
250  }
251 }
252 
254 {
256 }
257 
259 {
261 }
262 
263 void WalletView::showProgress(const QString &title, int nProgress)
264 {
265  if (nProgress == 0) {
266  progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
268  progressDialog->setWindowModality(Qt::ApplicationModal);
269  progressDialog->setAutoClose(false);
270  progressDialog->setValue(0);
271  } else if (nProgress == 100) {
272  if (progressDialog) {
273  progressDialog->close();
274  progressDialog->deleteLater();
275  progressDialog = nullptr;
276  }
277  } else if (progressDialog) {
278  if (progressDialog->wasCanceled()) {
280  } else {
281  progressDialog->setValue(nProgress);
282  }
283  }
284 }
WalletView::sendCoinsPage
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:63
signverifymessagedialog.h
TransactionView
Widget showing the transaction list for a wallet, including a filter row.
Definition: transactionview.h:32
CClientUIInterface::MSG_INFORMATION
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:66
WalletModel::getOptionsModel
OptionsModel * getOptionsModel()
Definition: walletmodel.cpp:284
transactiontablemodel.h
WalletView::platformStyle
const PlatformStyle * platformStyle
Definition: walletview.h:70
AddressBookPage::setModel
void setModel(AddressTableModel *model)
Definition: addressbookpage.cpp:136
AddressBookPage::SendingTab
@ SendingTab
Definition: addressbookpage.h:32
assert
assert(!tx.IsCoinBase())
ReceiveCoinsDialog
Dialog for requesting payment of bitcoins.
Definition: receivecoinsdialog.h:30
SendCoinsDialog::coinsSent
void coinsSent(const uint256 &txid)
WalletView::transactionView
TransactionView * transactionView
Definition: walletview.h:67
AskPassphraseDialog::Unlock
@ Unlock
Ask passphrase and unlock.
Definition: askpassphrasedialog.h:27
ReceiveCoinsDialog::setModel
void setModel(WalletModel *model)
Definition: receivecoinsdialog.cpp:72
TransactionTableModel::Date
@ Date
Definition: transactiontablemodel.h:37
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
OverviewPage::outOfSyncWarningClicked
void outOfSyncWarningClicked()
TransactionTableModel::AddressRole
@ AddressRole
Address of transaction.
Definition: transactiontablemodel.h:58
SignVerifyMessageDialog::setAddress_VM
void setAddress_VM(const QString &address)
Definition: signverifymessagedialog.cpp:70
WalletView::showOutOfSyncWarning
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:201
PlatformStyle::SingleColorIcon
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
Definition: platformstyle.cpp:105
WalletView::usedSendingAddressesPage
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:64
addressbookpage.h
SignVerifyMessageDialog::showTab_VM
void showTab_VM(bool fShow)
Definition: signverifymessagedialog.cpp:83
WalletView::getWalletModel
WalletModel * getWalletModel() const noexcept
Definition: walletview.h:45
sendcoinsdialog.h
TransactionView::focusTransaction
void focusTransaction(const QModelIndex &)
Definition: transactionview.cpp:590
walletmodel.h
WalletView::gotoReceiveCoinsPage
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:159
WalletView::overviewPage
OverviewPage * overviewPage
Definition: walletview.h:60
WalletModel::getAddressTableModel
AddressTableModel * getAddressTableModel()
Definition: walletmodel.cpp:289
ClientModel::node
interfaces::Node & node() const
Definition: clientmodel.h:55
WalletView::WalletView
WalletView(WalletModel *wallet_model, const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:33
OverviewPage
Overview ("home") page widget.
Definition: overviewpage.h:28
AskPassphraseDialog
Multifunctional dialog to ask for passphrases.
Definition: askpassphrasedialog.h:20
WalletView::showProgress
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:263
WalletView::clientModel
ClientModel * clientModel
Definition: walletview.h:52
WalletModel::getTransactionTableModel
TransactionTableModel * getTransactionTableModel()
Definition: walletmodel.cpp:294
GUIUtil::bringToFront
void bringToFront(QWidget *w)
Definition: guiutil.cpp:384
WalletView::setPrivacy
void setPrivacy(bool privacy)
WalletView::handlePaymentRequest
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:196
SignVerifyMessageDialog::setModel
void setModel(WalletModel *model)
Definition: signverifymessagedialog.cpp:59
WalletView::gotoSendCoinsPage
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:164
WalletView::gotoSignMessageTab
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:172
WalletView::encryptWallet
void encryptWallet()
Encrypt the wallet.
Definition: walletview.cpp:206
WalletModel::setClientModel
void setClientModel(ClientModel *client_model)
Definition: walletmodel.cpp:75
SignVerifyMessageDialog
Definition: signverifymessagedialog.h:17
overviewpage.h
WalletView::incomingTransaction
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.
WalletView::processNewTransaction
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:128
TransactionTableModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: transactiontablemodel.cpp:702
strencodings.h
SendCoinsRecipient
Definition: sendcoinsrecipient.h:19
WalletModel::wallet
interfaces::Wallet & wallet() const
Definition: walletmodel.h:144
WalletView::walletModel
WalletModel *const walletModel
The wallet model represents a bitcoin wallet, and offers access to the list of transactions,...
Definition: walletview.h:58
WalletModel::showProgress
void showProgress(const QString &title, int nProgress)
WalletView::setClientModel
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:119
WalletModel::encryptionStatusChanged
void encryptionStatusChanged()
WalletModel::message
void message(const QString &title, const QString &message, unsigned int style)
PlatformStyle::getImagesOnButtons
bool getImagesOnButtons() const
Definition: platformstyle.h:21
node.h
SendCoinsDialog::handlePaymentRequest
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: sendcoinsdialog.cpp:666
WalletView::usedReceivingAddressesPage
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:65
OverviewPage::setClientModel
void setClientModel(ClientModel *clientModel)
Definition: overviewpage.cpp:249
WalletView::message
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
WalletModel::getEncryptionStatus
EncryptionStatus getEncryptionStatus() const
Definition: walletmodel.cpp:304
GUIUtil::PolishProgressDialog
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:849
AddressBookPage
Widget that shows a list of sending or receiving addresses.
Definition: addressbookpage.h:26
SendCoinsDialog
Dialog for sending bitcoins.
Definition: sendcoinsdialog.h:31
guiutil.h
WalletModel::getWalletName
QString getWalletName() const
Definition: walletmodel.cpp:572
WalletView::transactionsPage
QWidget * transactionsPage
Definition: walletview.h:61
TransactionView::message
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
interfaces::Wallet::backupWallet
virtual bool backupWallet(const std::string &filename)=0
Back up wallet.
WalletView::encryptionStatusChanged
void encryptionStatusChanged()
Encryption status of wallet changed.
TransactionTableModel::Amount
@ Amount
Definition: transactiontablemodel.h:40
SendCoinsDialog::setAddress
void setAddress(const QString &address)
Definition: sendcoinsdialog.cpp:622
WalletView::gotoVerifyMessageTab
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:184
WalletModel::Locked
@ Locked
Definition: walletmodel.h:75
walletview.h
interfaces::Node::isInitialBlockDownload
virtual bool isInitialBlockDownload()=0
Is initial block download.
TransactionTableModel::processingQueuedTransactions
bool processingQueuedTransactions() const
Definition: transactiontablemodel.h:84
SignVerifyMessageDialog::setAddress_SM
void setAddress_SM(const QString &address)
Definition: signverifymessagedialog.cpp:64
ui_interface.h
OverviewPage::transactionClicked
void transactionClicked(const QModelIndex &index)
GUIUtil::getSaveFileName
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:279
platformstyle.h
CClientUIInterface::MSG_ERROR
@ MSG_ERROR
Definition: ui_interface.h:68
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:47
TransactionTableModel
UI model for the transaction table of a wallet.
Definition: transactiontablemodel.h:26
WalletView::outOfSyncWarningClicked
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
WalletView::~WalletView
~WalletView()
Definition: walletview.cpp:115
receivecoinsdialog.h
GUIUtil::HtmlEscape
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:232
WalletView::coinsSent
void coinsSent()
WalletView::gotoOverviewPage
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:149
OptionsModel::getDisplayUnit
int getDisplayUnit() const
Definition: optionsmodel.h:88
SendCoinsDialog::setClientModel
void setClientModel(ClientModel *clientModel)
Definition: sendcoinsdialog.cpp:136
WalletView::changePassphrase
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:235
interfaces::Wallet::abortRescan
virtual void abortRescan()=0
Abort a rescan.
TransactionTableModel::Type
@ Type
Definition: transactiontablemodel.h:38
TransactionView::setModel
void setModel(WalletModel *model)
Definition: transactionview.cpp:207
WalletModel::requireUnlock
void requireUnlock()
SendCoinsDialog::setModel
void setModel(WalletModel *model)
Definition: sendcoinsdialog.cpp:145
WalletView::unlockWallet
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:242
WalletView::backupWallet
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:215
SendCoinsDialog::message
void message(const QString &title, const QString &message, unsigned int style)
WalletView::receiveCoinsPage
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:62
transactionview.h
OverviewPage::setWalletModel
void setWalletModel(WalletModel *walletModel)
Definition: overviewpage.cpp:262
OverviewPage::setPrivacy
void setPrivacy(bool privacy)
Definition: overviewpage.cpp:178
AskPassphraseDialog::ChangePass
@ ChangePass
Ask old passphrase + new passphrase twice.
Definition: askpassphrasedialog.h:28
WalletView::usedSendingAddresses
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:253
optionsmodel.h
WalletView::usedReceivingAddresses
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:258
PlatformStyle
Definition: platformstyle.h:13
WalletView::transactionClicked
void transactionClicked()
OverviewPage::showOutOfSyncWarning
void showOutOfSyncWarning(bool fShow)
Definition: overviewpage.cpp:329
AskPassphraseDialog::Encrypt
@ Encrypt
Ask passphrase twice and encrypt.
Definition: askpassphrasedialog.h:26
SignVerifyMessageDialog::showTab_SM
void showTab_SM(bool fShow)
Definition: signverifymessagedialog.cpp:76
WalletView::gotoHistoryPage
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:154
TransactionView::exportClicked
void exportClicked()
Definition: transactionview.cpp:346
TransactionTableModel::LabelRole
@ LabelRole
Label of address related to transaction.
Definition: transactiontablemodel.h:60
askpassphrasedialog.h
AddressBookPage::ForEditing
@ ForEditing
Open address book for editing.
Definition: addressbookpage.h:38
clientmodel.h
WalletView::progressDialog
QProgressDialog * progressDialog
Definition: walletview.h:69
AddressBookPage::ReceivingTab
@ ReceivingTab
Definition: addressbookpage.h:33
AskPassphraseDialog::setModel
void setModel(WalletModel *model)
Definition: askpassphrasedialog.cpp:81
TransactionTableModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: transactiontablemodel.cpp:529