Dogecoin Core  1.14.2
P2P Digital Currency
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 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 "walletview.h"
6 
7 #include "addressbookpage.h"
8 #include "askpassphrasedialog.h"
9 #include "bitcoingui.h"
10 #include "clientmodel.h"
11 #include "guiutil.h"
12 #include "optionsmodel.h"
13 #include "overviewpage.h"
14 #include "platformstyle.h"
15 #include "receivecoinsdialog.h"
16 #include "sendcoinsdialog.h"
18 #include "transactiontablemodel.h"
19 #include "transactionview.h"
20 #include "walletmodel.h"
21 #include "utilitydialog.h"
22 
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(0),
36  walletModel(0),
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
69  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
70  connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
71 
72  // Double-clicking on a transaction on the transaction history page shows details
73  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
74 
75  // Clicking on "Export" allows to export the transaction list
76  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
77 
78  // Pass through messages from sendCoinsPage
79  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
80  // Pass through messages from transactionView
81  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
82 }
83 
85 {
86 }
87 
89 {
90  if (gui)
91  {
92  // Clicking on a transaction on the overview page simply sends you to transaction history page
93  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
94 
95  // Receive and report messages
96  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
97 
98  // Pass through encryption status changed signals
99  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
100 
101  // Pass through transaction notifications
102  connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString)));
103 
104  // Connect HD enabled state signal
105  connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
106  }
107 }
108 
110 {
111  this->clientModel = _clientModel;
112 
113  overviewPage->setClientModel(_clientModel);
114  sendCoinsPage->setClientModel(_clientModel);
115 }
116 
118 {
119  this->walletModel = _walletModel;
120 
121  // Put transaction list in tabs
122  transactionView->setModel(_walletModel);
123  overviewPage->setWalletModel(_walletModel);
124  receiveCoinsPage->setModel(_walletModel);
125  sendCoinsPage->setModel(_walletModel);
128 
129  if (_walletModel)
130  {
131  // Receive and pass through messages from wallet model
132  connect(_walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
133 
134  // Handle changes in encryption status
135  connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
137 
138  // update HD status
139  Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled());
140 
141  // Balloon pop-up for new transaction
142  connect(_walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
143  this, SLOT(processNewTransaction(QModelIndex,int,int)));
144 
145  // Ask for passphrase if needed
146  connect(_walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
147 
148  // Show progress dialog
149  connect(_walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
150  }
151 }
152 
153 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
154 {
155  // Prevent balloon-spam when initial block download is in progress
157  return;
158 
160  if (!ttm || ttm->processingQueuedTransactions())
161  return;
162 
163  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
164  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
165  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
166  QModelIndex index = ttm->index(start, 0, parent);
167  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
168  QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
169 
170  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label);
171 }
172 
174 {
175  setCurrentWidget(overviewPage);
176 }
177 
179 {
180  setCurrentWidget(transactionsPage);
181 }
182 
184 {
185  setCurrentWidget(receiveCoinsPage);
186 }
187 
189 {
190  setCurrentWidget(sendCoinsPage);
191 
192  if (!addr.isEmpty())
193  sendCoinsPage->setAddress(addr);
194 }
195 
197 {
198  // calls show() in showTab_SM()
199  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
200  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
201  signVerifyMessageDialog->setModel(walletModel);
202  signVerifyMessageDialog->showTab_SM(true);
203 
204  if (!addr.isEmpty())
205  signVerifyMessageDialog->setAddress_SM(addr);
206 }
207 
209 {
210  // calls show() in showTab_VM()
211  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
212  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
213  signVerifyMessageDialog->setModel(walletModel);
214  signVerifyMessageDialog->showTab_VM(true);
215 
216  if (!addr.isEmpty())
217  signVerifyMessageDialog->setAddress_VM(addr);
218 }
219 
221 {
222  return sendCoinsPage->handlePaymentRequest(recipient);
223 }
224 
226 {
228 }
229 
231 {
233 }
234 
235 void WalletView::encryptWallet(bool status)
236 {
237  if(!walletModel)
238  return;
240  dlg.setModel(walletModel);
241  dlg.exec();
242 
244 }
245 
247 {
248  QString filename = GUIUtil::getSaveFileName(this,
249  tr("Backup Wallet"), QString(),
250  tr("Wallet Data (*.dat)"), NULL);
251 
252  if (filename.isEmpty())
253  return;
254 
255  if (!walletModel->backupWallet(filename)) {
256  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
258  }
259  else {
260  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
262  }
263 }
264 
266 {
268  dlg.setModel(walletModel);
269  dlg.exec();
270 }
271 
273 {
274  if(!walletModel)
275  return;
276  // Unlock wallet when requested by wallet model
278  {
280  dlg.setModel(walletModel);
281  dlg.exec();
282  }
283 }
284 
286 {
287  if(!walletModel)
288  return;
289 
290  usedSendingAddressesPage->show();
291  usedSendingAddressesPage->raise();
292  usedSendingAddressesPage->activateWindow();
293 }
294 
296 {
297  if(!walletModel)
298  return;
299 
302  usedReceivingAddressesPage->activateWindow();
303 }
304 
305 void WalletView::showProgress(const QString &title, int nProgress)
306 {
307  if (nProgress == 0)
308  {
309  progressDialog = new QProgressDialog(title, "", 0, 100);
310  progressDialog->setWindowModality(Qt::ApplicationModal);
311  progressDialog->setMinimumDuration(0);
312  progressDialog->setCancelButton(0);
313  progressDialog->setAutoClose(false);
314  progressDialog->setValue(0);
315  }
316  else if (nProgress == 100)
317  {
318  if (progressDialog)
319  {
320  progressDialog->close();
321  progressDialog->deleteLater();
322  }
323  }
324  else if (progressDialog)
325  progressDialog->setValue(nProgress);
326 }
327 
329 {
330  Q_EMIT outOfSyncWarningClicked();
331 }
332 
334 {
335  if(!walletModel)
336  return;
337 
338  PaperWalletDialog dlg(this);
339  dlg.setModel(walletModel);
341  dlg.exec();
342 }
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:15
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.
@ Decrypt
Ask passphrase and decrypt wallet.
@ ChangePass
Ask old passphrase + new passphrase twice.
Bitcoin GUI main class.
Definition: bitcoingui.h:47
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:71
Model for Bitcoin network client.
Definition: clientmodel.h:42
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
int getDisplayUnit()
Definition: optionsmodel.h:65
Overview ("home") page widget.
Definition: overviewpage.h:29
void setWalletModel(WalletModel *walletModel)
void setClientModel(ClientModel *clientModel)
void showOutOfSyncWarning(bool fShow)
"Paper Wallet" dialog box
Definition: utilitydialog.h:22
void setClientModel(ClientModel *clientModel)
void setModel(WalletModel *model)
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 setAddress_SM(const QString &address)
void setModel(WalletModel *model)
void setAddress_VM(const QString &address)
UI model for the transaction table of a wallet.
QVariant data(const QModelIndex &index, int role) const
@ LabelRole
Label of address related to transaction.
@ AddressRole
Address of transaction.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Widget showing the transaction list for a wallet, including a filter row.
void setModel(WalletModel *model)
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:99
bool hdEnabled() const
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
bool backupWallet(const QString &filename)
EncryptionStatus getEncryptionStatus() const
TransactionTableModel * getTransactionTableModel()
const PlatformStyle * platformStyle
Definition: walletview.h:71
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:178
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:208
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:117
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:220
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:235
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:188
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:265
QProgressDialog * progressDialog
Definition: walletview.h:70
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:64
OverviewPage * overviewPage
Definition: walletview.h:61
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:88
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:109
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:183
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:196
QWidget * transactionsPage
Definition: walletview.h:62
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:285
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:63
void hdEnabledStatusChanged(int hdEnabled)
HD-Enabled status of wallet changed (only possible during startup)
TransactionView * transactionView
Definition: walletview.h:68
void printPaperWallets()
Open the print paper wallets dialog.
Definition: walletview.cpp:333
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:305
WalletView(const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:33
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:246
void encryptionStatusChanged(int status)
Encryption status of wallet changed.
ClientModel * clientModel
Definition: walletview.h:58
void requestedSyncWarningInfo()
User has requested more information about the out of sync state.
Definition: walletview.cpp:328
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:65
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:272
WalletModel * walletModel
Definition: walletview.h:59
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:173
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:295
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:230
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:153
void incomingTransaction(const QString &date, int unit, const CAmount &amount, const QString &type, const QString &address, const QString &label)
Notify that a new transaction appeared.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:225
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:294