Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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/receivecoinsdialog.h>
15 #include <qt/sendcoinsdialog.h>
17 #include <qt/transactionrecord.h>
19 #include <qt/transactionview.h>
20 #include <qt/walletmodel.h>
21 
22 #include <ui_interface.h>
23 
24 #include <QAction>
25 #include <QActionGroup>
26 #include <QFileDialog>
27 #include <QHBoxLayout>
28 #include <QLabel>
29 #include <QProgressDialog>
30 #include <QPushButton>
31 #include <QSettings>
32 #include <QVBoxLayout>
33 
34 WalletView::WalletView(QWidget* parent) :
35  QStackedWidget(parent),
36  clientModel(0),
37  walletModel(0)
38 {
39  // Create tabs
40  overviewPage = new OverviewPage();
41 
42  transactionsPage = new QWidget(this);
43  QVBoxLayout *vbox = new QVBoxLayout();
44  QHBoxLayout *hbox_buttons = new QHBoxLayout();
45  transactionView = new TransactionView(this);
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"));
49  hbox_buttons->addStretch();
50 
51  // Sum of selected transactions
52  QLabel *transactionSumLabel = new QLabel(); // Label
53  transactionSumLabel->setObjectName("transactionSumLabel"); // Label ID as CSS-reference
54  transactionSumLabel->setText(tr("Selected amount:"));
55  hbox_buttons->addWidget(transactionSumLabel);
56 
57  transactionSum = new QLabel(); // Amount
58  transactionSum->setObjectName("transactionSum"); // Label ID as CSS-reference
59  transactionSum->setMinimumSize(200, 8);
60  transactionSum->setTextInteractionFlags(Qt::TextSelectableByMouse);
61 
62  GUIUtil::setFont({transactionSumLabel,
66 
67  hbox_buttons->addWidget(transactionSum);
68 
69  hbox_buttons->addWidget(exportButton);
70  vbox->addLayout(hbox_buttons);
71  transactionsPage->setLayout(vbox);
72 
76 
79 
80  addWidget(overviewPage);
81  addWidget(transactionsPage);
82  addWidget(receiveCoinsPage);
83  addWidget(sendCoinsPage);
84  addWidget(privateSendCoinsPage);
85 
86  QSettings settings;
87  if (settings.value("fShowMasternodesTab").toBool()) {
89  addWidget(masternodeListPage);
90  }
91 
92  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
93  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
94  connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
95 
96  // Double-clicking on a transaction on the transaction history page shows details
97  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
98 
99  // Update wallet with sum of selected transactions
100  connect(transactionView, SIGNAL(trxAmount(QString)), this, SLOT(trxAmount(QString)));
101 
102  // Clicking on "Export" allows to export the transaction list
103  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
104 
105  // Pass through messages from SendCoinsDialog
106  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
107  connect(privateSendCoinsPage, SIGNAL(message(QString, QString, unsigned int)), this, SIGNAL(message(QString, QString, unsigned int)));
108 
109  // Pass through messages from transactionView
110  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
111 
113 }
114 
116 {
117 }
118 
120 {
121  if (gui)
122  {
123  // Clicking on a transaction on the overview page simply sends you to transaction history page
124  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
125 
126  // Receive and report messages
127  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
128 
129  // Pass through encryption status changed signals
130  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
131 
132  // Pass through transaction notifications
133  connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString)));
134 
135  // Connect HD enabled state signal
136  connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
137  }
138 }
139 
141 {
142  this->clientModel = _clientModel;
143 
144  overviewPage->setClientModel(_clientModel);
145  sendCoinsPage->setClientModel(_clientModel);
146  privateSendCoinsPage->setClientModel(_clientModel);
147  QSettings settings;
148  if (settings.value("fShowMasternodesTab").toBool()) {
149  masternodeListPage->setClientModel(_clientModel);
150  }
151 }
152 
154 {
155  this->walletModel = _walletModel;
156 
157  // Put transaction list in tabs
158  transactionView->setModel(_walletModel);
159  overviewPage->setWalletModel(_walletModel);
160  QSettings settings;
161  if (settings.value("fShowMasternodesTab").toBool()) {
162  masternodeListPage->setWalletModel(_walletModel);
163  }
164  receiveCoinsPage->setModel(_walletModel);
165  sendCoinsPage->setModel(_walletModel);
166  privateSendCoinsPage->setModel(_walletModel);
167  usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
168  usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
169 
170  if (_walletModel)
171  {
172  // Receive and pass through messages from wallet model
173  connect(_walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
174 
175  // Handle changes in encryption status
176  connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
178 
179  // update HD status
180  Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled());
181 
182  // Balloon pop-up for new transaction
183  connect(_walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
184  this, SLOT(processNewTransaction(QModelIndex,int,int)));
185 
186  // Ask for passphrase if needed
187  connect(_walletModel, SIGNAL(requireUnlock(bool)), this, SLOT(unlockWallet(bool)));
188 
189  // Show progress dialog
190  connect(_walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
191  }
192 }
193 
194 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
195 {
196  // Prevent balloon-spam when initial block download is in progress
198  return;
199 
201  if (!ttm || ttm->processingQueuedTransactions())
202  return;
203 
204  QModelIndex index = ttm->index(start, 0, parent);
205  QSettings settings;
206  if (!settings.value("fShowPrivateSendPopups").toBool()) {
207  QVariant nType = ttm->data(index, TransactionTableModel::TypeRole);
212  }
213 
214  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
215  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
216  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
217  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
218  QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
219 
220  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label);
221 }
222 
224 {
225  setCurrentWidget(overviewPage);
226 }
227 
229 {
230  setCurrentWidget(transactionsPage);
231 }
232 
234 {
235  QSettings settings;
236  if (settings.value("fShowMasternodesTab").toBool()) {
237  setCurrentWidget(masternodeListPage);
238  }
239 }
240 
242 {
243  setCurrentWidget(receiveCoinsPage);
244 }
245 
247 {
248  setCurrentWidget(sendCoinsPage);
249 
250  if (!addr.isEmpty()) {
251  sendCoinsPage->setAddress(addr);
252  }
253 }
254 
256 {
257  setCurrentWidget(privateSendCoinsPage);
258 
259  if (!addr.isEmpty())
261 }
262 
264 {
265  // calls show() in showTab_SM()
266  SignVerifyMessageDialog* signVerifyMessageDialog = new SignVerifyMessageDialog(this);
267  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
268  signVerifyMessageDialog->setModel(walletModel);
269  signVerifyMessageDialog->showTab_SM(true);
270 
271  if (!addr.isEmpty())
272  signVerifyMessageDialog->setAddress_SM(addr);
273 }
274 
276 {
277  // calls show() in showTab_VM()
278  SignVerifyMessageDialog* signVerifyMessageDialog = new SignVerifyMessageDialog(this);
279  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
280  signVerifyMessageDialog->setModel(walletModel);
281  signVerifyMessageDialog->showTab_VM(true);
282 
283  if (!addr.isEmpty())
284  signVerifyMessageDialog->setAddress_VM(addr);
285 }
286 
288 {
289  return sendCoinsPage->handlePaymentRequest(recipient);
290 }
291 
293 {
295 }
296 
298 {
300 }
301 
302 void WalletView::encryptWallet(bool status)
303 {
304  if(!walletModel)
305  return;
307  dlg.setModel(walletModel);
308  dlg.exec();
309 
311 }
312 
314 {
315  QString filename = GUIUtil::getSaveFileName(this,
316  tr("Backup Wallet"), QString(),
317  tr("Wallet Data (*.dat)"), nullptr);
318 
319  if (filename.isEmpty())
320  return;
321 
322  if (!walletModel->backupWallet(filename)) {
323  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
325  }
326  else {
327  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
329  }
330 }
331 
333 {
335  dlg.setModel(walletModel);
336  dlg.exec();
337 }
338 
339 void WalletView::unlockWallet(bool fForMixingOnly)
340 {
341  if(!walletModel)
342  return;
343  // Unlock wallet when requested by wallet model
344 
346  {
348  dlg.setModel(walletModel);
349  dlg.exec();
350  }
351 }
352 
354 {
355  if(!walletModel)
356  return;
357 
359 }
360 
362 {
363  if(!walletModel)
364  return;
365 
367 }
368 
370 {
371  if(!walletModel)
372  return;
373 
375 }
376 
377 void WalletView::showProgress(const QString &title, int nProgress)
378 {
379  if (nProgress == 0)
380  {
381  progressDialog = new QProgressDialog(title, "", 0, 100, this);
382  progressDialog->setWindowModality(Qt::ApplicationModal);
383  progressDialog->setMinimumDuration(0);
384  progressDialog->setCancelButton(0);
385  progressDialog->setAutoClose(false);
386  progressDialog->setValue(0);
387  }
388  else if (nProgress == 100)
389  {
390  if (progressDialog)
391  {
392  progressDialog->close();
393  progressDialog->deleteLater();
394  }
395  }
396  else if (progressDialog)
397  progressDialog->setValue(nProgress);
398 }
399 
401 {
402  Q_EMIT outOfSyncWarningClicked();
403 }
404 
406 void WalletView::trxAmount(QString amount)
407 {
408  transactionSum->setText(amount);
409 }
QWidget * transactionsPage
Definition: walletview.h:64
void trxAmount(QString amount)
Update selected DASH amount from transactionview.
Definition: walletview.cpp:406
Dialog for requesting payment of bitcoins.
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
void setWalletModel(WalletModel *walletModel)
void unlockWallet(bool fAnonymizeOnly=false)
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:339
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:275
OverviewPage * overviewPage
Definition: walletview.h:63
TransactionView * transactionView
Definition: walletview.h:72
Ask passphrase and unlock only for mixing.
void setFont(const std::vector< QWidget *> &vecWidgets, FontWeight weight, int nPointSize, bool fItalic)
Workaround to set correct font styles in all themes since there is a bug in macOS which leads to issu...
Definition: guiutil.cpp:1552
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:361
void setAddress_VM(const QString &address)
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:332
ClientModel * clientModel
Definition: walletview.h:60
WalletView(QWidget *parent)
Definition: walletview.cpp:34
void setWalletModel(WalletModel *walletModel)
Ask passphrase twice and encrypt.
bool backupWallet(const QString &filename)
void requestedSyncWarningInfo()
User has requested more information about the out of sync state.
Definition: walletview.cpp:400
WalletModel * walletModel
Definition: walletview.h:61
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:49
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:246
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:297
void bringToFront(QWidget *w)
Definition: guiutil.cpp:634
EncryptionStatus getEncryptionStatus() const
int getDisplayUnit() const
Definition: optionsmodel.h:82
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:194
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:66
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void setModel(WalletModel *model)
bool processingQueuedTransactions() const
void updateFonts()
Update the font of all widgets where a custom font has been set with GUIUtil::setFont.
Definition: guiutil.cpp:1563
void hdEnabledStatusChanged(int hdEnabled)
HD-Enabled status of wallet changed (only possible during startup)
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:228
Ask passphrase and unlock.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:119
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:369
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:153
void setAddress(const QString &address)
void setClientModel(ClientModel *clientModel)
SendCoinsDialog * privateSendCoinsPage
Definition: walletview.h:67
void encryptionStatusChanged(int status)
Encryption status of wallet changed.
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.
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.
Dialog for sending bitcoins.
TransactionTableModel * getTransactionTableModel()
Widget that shows a list of sending or receiving addresses.
UI model for the transaction table of a wallet.
Model for Dash network client.
Definition: clientmodel.h:42
void setModel(WalletModel *model)
Masternode Manager page widget.
void disableMacFocusRect(const QWidget *w)
Disable the OS default focus rect for macOS because we have custom focus rects set in the css files...
Definition: guiutil.cpp:1789
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:313
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:287
QLabel * transactionSum
Definition: walletview.h:75
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:223
void showOutOfSyncWarning(bool fShow)
QVariant data(const QModelIndex &index, int role) const
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:68
void setModel(WalletModel *model)
void gotoPrivateSendCoinsPage(QString addr="")
Switch to PrivateSend coins page.
Definition: walletview.cpp:255
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:263
bool hdEnabled() const
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:100
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:377
Multifunctional dialog to ask for passphrases.
MasternodeList * masternodeListPage
Definition: walletview.h:70
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:521
void lockWallet()
Lock wallet.
Definition: walletview.cpp:353
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:140
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
Label of address related to transaction.
Ask old passphrase + new passphrase twice.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:302
void gotoMasternodePage()
Switch to masternode page.
Definition: walletview.cpp:233
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:65
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:241
void setModel(WalletModel *model)
void setClientModel(ClientModel *clientModel)
Overview ("home") page widget.
Definition: overviewpage.h:27
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:292
QProgressDialog * progressDialog
Definition: walletview.h:74
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString(), bool fMixing=false)
OptionsModel * getOptionsModel()
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:70
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void setAddress_SM(const QString &address)
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:69
void setModel(WalletModel *model)
Released under the MIT license