Bitcoin Core  0.19.99
P2P Digital Currency
walletview.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/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 <ui_interface.h>
23 
24 #include <QAction>
25 #include <QActionGroup>
26 #include <QFileDialog>
27 #include <QHBoxLayout>
28 #include <QProgressDialog>
29 #include <QPushButton>
30 #include <QVBoxLayout>
31 
32 WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
33  QStackedWidget(parent),
34  clientModel(nullptr),
35  walletModel(nullptr),
36  platformStyle(_platformStyle)
37 {
38  // Create tabs
40 
41  transactionsPage = new QWidget(this);
42  QVBoxLayout *vbox = new QVBoxLayout();
43  QHBoxLayout *hbox_buttons = new QHBoxLayout();
45  vbox->addWidget(transactionView);
46  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
47  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
49  exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
50  }
51  hbox_buttons->addStretch();
52  hbox_buttons->addWidget(exportButton);
53  vbox->addLayout(hbox_buttons);
54  transactionsPage->setLayout(vbox);
55 
58 
61 
62  addWidget(overviewPage);
63  addWidget(transactionsPage);
64  addWidget(receiveCoinsPage);
65  addWidget(sendCoinsPage);
66 
68  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
70 
72 
74  // Highlight transaction after send
76 
77  // Clicking on "Export" allows to export the transaction list
78  connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);
79 
80  // Pass through messages from sendCoinsPage
82  // Pass through messages from transactionView
84 }
85 
87 {
88 }
89 
91 {
92  this->clientModel = _clientModel;
93 
94  overviewPage->setClientModel(_clientModel);
95  sendCoinsPage->setClientModel(_clientModel);
96 }
97 
99 {
100  this->walletModel = _walletModel;
101 
102  // Put transaction list in tabs
103  transactionView->setModel(_walletModel);
104  overviewPage->setWalletModel(_walletModel);
105  receiveCoinsPage->setModel(_walletModel);
106  sendCoinsPage->setModel(_walletModel);
107  usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
108  usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
109 
110  if (_walletModel)
111  {
112  // Receive and pass through messages from wallet model
113  connect(_walletModel, &WalletModel::message, this, &WalletView::message);
114 
115  // Handle changes in encryption status
118 
119  // update HD status
120  Q_EMIT hdEnabledStatusChanged();
121 
122  // Balloon pop-up for new transaction
123  connect(_walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);
124 
125  // Ask for passphrase if needed
126  connect(_walletModel, &WalletModel::requireUnlock, this, &WalletView::unlockWallet);
127 
128  // Show progress dialog
129  connect(_walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);
130  }
131 }
132 
133 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
134 {
135  // Prevent balloon-spam when initial block download is in progress
137  return;
138 
140  if (!ttm || ttm->processingQueuedTransactions())
141  return;
142 
143  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
144  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
145  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
146  QModelIndex index = ttm->index(start, 0, parent);
147  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
148  QString label = GUIUtil::HtmlEscape(ttm->data(index, TransactionTableModel::LabelRole).toString());
149 
150  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, GUIUtil::HtmlEscape(walletModel->getWalletName()));
151 }
152 
154 {
155  setCurrentWidget(overviewPage);
156 }
157 
159 {
160  setCurrentWidget(transactionsPage);
161 }
162 
164 {
165  setCurrentWidget(receiveCoinsPage);
166 }
167 
169 {
170  setCurrentWidget(sendCoinsPage);
171 
172  if (!addr.isEmpty())
173  sendCoinsPage->setAddress(addr);
174 }
175 
177 {
178  // calls show() in showTab_SM()
179  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
180  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
181  signVerifyMessageDialog->setModel(walletModel);
182  signVerifyMessageDialog->showTab_SM(true);
183 
184  if (!addr.isEmpty())
185  signVerifyMessageDialog->setAddress_SM(addr);
186 }
187 
189 {
190  // calls show() in showTab_VM()
191  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
192  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
193  signVerifyMessageDialog->setModel(walletModel);
194  signVerifyMessageDialog->showTab_VM(true);
195 
196  if (!addr.isEmpty())
197  signVerifyMessageDialog->setAddress_VM(addr);
198 }
199 
201 {
202  return sendCoinsPage->handlePaymentRequest(recipient);
203 }
204 
206 {
208 }
209 
211 {
212  Q_EMIT encryptionStatusChanged();
213 }
214 
215 void WalletView::encryptWallet(bool status)
216 {
217  if(!walletModel)
218  return;
220  dlg.setModel(walletModel);
221  dlg.exec();
222 
224 }
225 
227 {
228  QString filename = GUIUtil::getSaveFileName(this,
229  tr("Backup Wallet"), QString(),
230  tr("Wallet Data (*.dat)"), nullptr);
231 
232  if (filename.isEmpty())
233  return;
234 
235  if (!walletModel->wallet().backupWallet(filename.toLocal8Bit().data())) {
236  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
238  }
239  else {
240  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
242  }
243 }
244 
246 {
248  dlg.setModel(walletModel);
249  dlg.exec();
250 }
251 
253 {
254  if(!walletModel)
255  return;
256  // Unlock wallet when requested by wallet model
258  {
260  dlg.setModel(walletModel);
261  dlg.exec();
262  }
263 }
264 
266 {
267  if(!walletModel)
268  return;
269 
271 }
272 
274 {
275  if(!walletModel)
276  return;
277 
279 }
280 
281 void WalletView::showProgress(const QString &title, int nProgress)
282 {
283  if (nProgress == 0) {
284  progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
286  progressDialog->setWindowModality(Qt::ApplicationModal);
287  progressDialog->setMinimumDuration(0);
288  progressDialog->setAutoClose(false);
289  progressDialog->setValue(0);
290  } else if (nProgress == 100) {
291  if (progressDialog) {
292  progressDialog->close();
293  progressDialog->deleteLater();
294  progressDialog = nullptr;
295  }
296  } else if (progressDialog) {
297  if (progressDialog->wasCanceled()) {
299  } else {
300  progressDialog->setValue(nProgress);
301  }
302  }
303 }
304 
306 {
307  Q_EMIT outOfSyncWarningClicked();
308 }
QWidget * transactionsPage
Definition: walletview.h:61
Dialog for requesting payment of bitcoins.
void setWalletModel(WalletModel *walletModel)
interfaces::Wallet & wallet() const
Definition: walletmodel.h:147
virtual bool isInitialBlockDownload()=0
Is initial block download.
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:188
OverviewPage * overviewPage
Definition: walletview.h:60
TransactionView * transactionView
Definition: walletview.h:67
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:265
void setAddress_VM(const QString &address)
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:245
ClientModel * clientModel
Definition: walletview.h:57
void focusTransaction(const QModelIndex &)
Ask passphrase twice and encrypt.
virtual bool backupWallet(const std::string &filename)=0
Back up wallet.
void requestedSyncWarningInfo()
User has requested more information about the out of sync state.
Definition: walletview.cpp:305
WalletModel * walletModel
Definition: walletview.h:58
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
void showProgress(const QString &title, int nProgress)
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:218
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Open address book for editing.
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
const PlatformStyle * platformStyle
Definition: walletview.h:70
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:168
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:210
void outOfSyncWarningClicked()
void bringToFront(QWidget *w)
Definition: guiutil.cpp:363
EncryptionStatus getEncryptionStatus() const
int getDisplayUnit() const
Definition: optionsmodel.h:81
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:133
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:63
void setModel(WalletModel *model)
WalletModel * getWalletModel()
Definition: walletview.h:45
bool processingQueuedTransactions() const
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:158
Ask passphrase and unlock.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:273
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:98
void setAddress(const QString &address)
void setClientModel(ClientModel *clientModel)
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
Widget showing the transaction list for a wallet, including a filter row.
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
interfaces::Node & node() const
Definition: clientmodel.h:52
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:252
Dialog for sending bitcoins.
void encryptionStatusChanged()
QString getWalletName() const
TransactionTableModel * getTransactionTableModel()
Widget that shows a list of sending or receiving addresses.
UI model for the transaction table of a wallet.
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:867
Model for Bitcoin network client.
Definition: clientmodel.h:44
void setModel(WalletModel *model)
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:226
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:200
void transactionClicked(const QModelIndex &index)
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:153
void encryptionStatusChanged()
Encryption status of wallet changed.
void showOutOfSyncWarning(bool fShow)
QVariant data(const QModelIndex &index, int role) const
256-bit opaque blob.
Definition: uint256.h:120
void requireUnlock()
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:64
void setModel(WalletModel *model)
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:176
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:50
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:281
Multifunctional dialog to ask for passphrases.
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:258
void message(const QString &title, const QString &message, unsigned int style)
WalletView(const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:32
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:90
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
Label of address related to transaction.
void hdEnabledStatusChanged()
HD-Enabled status of wallet changed (only possible during startup)
virtual void abortRescan()=0
Abort a rescan.
Ask old passphrase + new passphrase twice.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:215
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:62
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:163
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(const uint256 &txid)
void coinsSent()
void setModel(WalletModel *model)
void transactionClicked()
Overview ("home") page widget.
Definition: overviewpage.h:28
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:205
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.
QProgressDialog * progressDialog
Definition: walletview.h:69
bool getImagesOnButtons() const
Definition: platformstyle.h:21
OptionsModel * getOptionsModel()
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:74
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void setAddress_SM(const QString &address)
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:65
void setModel(WalletModel *model)