Bitcoin Core  0.18.99
P2P Digital Currency
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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/bitcoingui.h>
10 #include <qt/clientmodel.h>
11 #include <qt/guiutil.h>
12 #include <qt/optionsmodel.h>
13 #include <qt/overviewpage.h>
14 #include <qt/platformstyle.h>
15 #include <qt/receivecoinsdialog.h>
16 #include <qt/sendcoinsdialog.h>
19 #include <qt/transactionview.h>
20 #include <qt/walletmodel.h>
21 
22 #include <interfaces/node.h>
23 #include <ui_interface.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(const PlatformStyle *_platformStyle, QWidget *parent):
34  QStackedWidget(parent),
35  clientModel(nullptr),
36  walletModel(nullptr),
37  platformStyle(_platformStyle)
38 {
39  // Create tabs
41 
42  transactionsPage = new QWidget(this);
43  QVBoxLayout *vbox = new QVBoxLayout();
44  QHBoxLayout *hbox_buttons = new QHBoxLayout();
46  vbox->addWidget(transactionView);
47  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
48  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
50  exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
51  }
52  hbox_buttons->addStretch();
53  hbox_buttons->addWidget(exportButton);
54  vbox->addLayout(hbox_buttons);
55  transactionsPage->setLayout(vbox);
56 
59 
62 
63  addWidget(overviewPage);
64  addWidget(transactionsPage);
65  addWidget(receiveCoinsPage);
66  addWidget(sendCoinsPage);
67 
68  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
70 
72 
73  // Highlight transaction after send
75 
76  // Clicking on "Export" allows to export the transaction list
77  connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);
78 
79  // Pass through messages from sendCoinsPage
81  // Pass through messages from transactionView
83 }
84 
86 {
87 }
88 
90 {
91  if (gui)
92  {
93  // Clicking on a transaction on the overview page simply sends you to transaction history page
94  connect(overviewPage, &OverviewPage::transactionClicked, gui, &BitcoinGUI::gotoHistoryPage);
95 
96  // Navigate to transaction history page after send
97  connect(sendCoinsPage, &SendCoinsDialog::coinsSent, gui, &BitcoinGUI::gotoHistoryPage);
98 
99  // Receive and report messages
100  connect(this, &WalletView::message, [gui](const QString &title, const QString &message, unsigned int style) {
101  gui->message(title, message, style);
102  });
103 
104  // Pass through encryption status changed signals
105  connect(this, &WalletView::encryptionStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
106 
107  // Pass through transaction notifications
108  connect(this, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
109 
110  // Connect HD enabled state signal
111  connect(this, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
112  }
113 }
114 
116 {
117  this->clientModel = _clientModel;
118 
119  overviewPage->setClientModel(_clientModel);
120  sendCoinsPage->setClientModel(_clientModel);
121 }
122 
124 {
125  this->walletModel = _walletModel;
126 
127  // Put transaction list in tabs
128  transactionView->setModel(_walletModel);
129  overviewPage->setWalletModel(_walletModel);
130  receiveCoinsPage->setModel(_walletModel);
131  sendCoinsPage->setModel(_walletModel);
132  usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
133  usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
134 
135  if (_walletModel)
136  {
137  // Receive and pass through messages from wallet model
138  connect(_walletModel, &WalletModel::message, this, &WalletView::message);
139 
140  // Handle changes in encryption status
143 
144  // update HD status
145  Q_EMIT hdEnabledStatusChanged();
146 
147  // Balloon pop-up for new transaction
148  connect(_walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);
149 
150  // Ask for passphrase if needed
151  connect(_walletModel, &WalletModel::requireUnlock, this, &WalletView::unlockWallet);
152 
153  // Show progress dialog
154  connect(_walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);
155  }
156 }
157 
158 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
159 {
160  // Prevent balloon-spam when initial block download is in progress
162  return;
163 
165  if (!ttm || ttm->processingQueuedTransactions())
166  return;
167 
168  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
169  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
170  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
171  QModelIndex index = ttm->index(start, 0, parent);
172  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
173  QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
174 
175  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, walletModel->getWalletName());
176 }
177 
179 {
180  setCurrentWidget(overviewPage);
181 }
182 
184 {
185  setCurrentWidget(transactionsPage);
186 }
187 
189 {
190  setCurrentWidget(receiveCoinsPage);
191 }
192 
194 {
195  setCurrentWidget(sendCoinsPage);
196 
197  if (!addr.isEmpty())
198  sendCoinsPage->setAddress(addr);
199 }
200 
202 {
203  // calls show() in showTab_SM()
204  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
205  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
206  signVerifyMessageDialog->setModel(walletModel);
207  signVerifyMessageDialog->showTab_SM(true);
208 
209  if (!addr.isEmpty())
210  signVerifyMessageDialog->setAddress_SM(addr);
211 }
212 
214 {
215  // calls show() in showTab_VM()
216  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
217  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
218  signVerifyMessageDialog->setModel(walletModel);
219  signVerifyMessageDialog->showTab_VM(true);
220 
221  if (!addr.isEmpty())
222  signVerifyMessageDialog->setAddress_VM(addr);
223 }
224 
226 {
227  return sendCoinsPage->handlePaymentRequest(recipient);
228 }
229 
231 {
233 }
234 
236 {
237  Q_EMIT encryptionStatusChanged();
238 }
239 
240 void WalletView::encryptWallet(bool status)
241 {
242  if(!walletModel)
243  return;
245  dlg.setModel(walletModel);
246  dlg.exec();
247 
249 }
250 
252 {
253  QString filename = GUIUtil::getSaveFileName(this,
254  tr("Backup Wallet"), QString(),
255  tr("Wallet Data (*.dat)"), nullptr);
256 
257  if (filename.isEmpty())
258  return;
259 
260  if (!walletModel->wallet().backupWallet(filename.toLocal8Bit().data())) {
261  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
263  }
264  else {
265  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
267  }
268 }
269 
271 {
273  dlg.setModel(walletModel);
274  dlg.exec();
275 }
276 
278 {
279  if(!walletModel)
280  return;
281  // Unlock wallet when requested by wallet model
283  {
285  dlg.setModel(walletModel);
286  dlg.exec();
287  }
288 }
289 
291 {
292  if(!walletModel)
293  return;
294 
296 }
297 
299 {
300  if(!walletModel)
301  return;
302 
304 }
305 
306 void WalletView::showProgress(const QString &title, int nProgress)
307 {
308  if (nProgress == 0) {
309  progressDialog = new QProgressDialog(title, tr("Cancel"), 0, 100);
311  progressDialog->setWindowModality(Qt::ApplicationModal);
312  progressDialog->setMinimumDuration(0);
313  progressDialog->setAutoClose(false);
314  progressDialog->setValue(0);
315  } else if (nProgress == 100) {
316  if (progressDialog) {
317  progressDialog->close();
318  progressDialog->deleteLater();
319  progressDialog = nullptr;
320  }
321  } else if (progressDialog) {
322  if (progressDialog->wasCanceled()) {
324  } else {
325  progressDialog->setValue(nProgress);
326  }
327  }
328 }
329 
331 {
332  Q_EMIT outOfSyncWarningClicked();
333 }
QWidget * transactionsPage
Definition: walletview.h:63
Dialog for requesting payment of bitcoins.
void setWalletModel(WalletModel *walletModel)
interfaces::Wallet & wallet() const
Definition: walletmodel.h:223
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:213
OverviewPage * overviewPage
Definition: walletview.h:62
TransactionView * transactionView
Definition: walletview.h:69
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:290
void setAddress_VM(const QString &address)
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:270
ClientModel * clientModel
Definition: walletview.h:59
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:330
WalletModel * walletModel
Definition: walletview.h:60
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
void showProgress(const QString &title, int nProgress)
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Open address book for editing.
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
Bitcoin GUI main class.
Definition: bitcoingui.h:64
const PlatformStyle * platformStyle
Definition: walletview.h:72
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:193
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:235
void outOfSyncWarningClicked()
void bringToFront(QWidget *w)
Definition: guiutil.cpp:360
EncryptionStatus getEncryptionStatus() const
int getDisplayUnit() const
Definition: optionsmodel.h:74
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:158
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:65
void setModel(WalletModel *model)
WalletModel * getWalletModel()
Definition: walletview.h:47
bool processingQueuedTransactions() const
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:183
Ask passphrase and unlock.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:89
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:298
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:123
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:277
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:947
Model for Bitcoin network client.
Definition: clientmodel.h:44
void setModel(WalletModel *model)
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr)
Notify the user of an event from the core network or transaction handling code.
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:251
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:225
void transactionClicked(const QModelIndex &index)
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:178
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:121
void requireUnlock()
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:66
void setModel(WalletModel *model)
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:201
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:306
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:255
void message(const QString &title, const QString &message, unsigned int style)
WalletView(const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:33
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:115
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:240
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:64
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:188
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(const uint256 &txid)
void setModel(WalletModel *model)
Overview ("home") page widget.
Definition: overviewpage.h:28
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:230
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:71
bool getImagesOnButtons() const
Definition: platformstyle.h:21
OptionsModel * getOptionsModel()
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:79
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void setAddress_SM(const QString &address)
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:67
void setModel(WalletModel *model)