Dash Core  0.12.2.1
P2P Digital Currency
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 "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 "masternodeconfig.h"
13 #include "optionsmodel.h"
14 #include "overviewpage.h"
15 #include "platformstyle.h"
16 #include "receivecoinsdialog.h"
17 #include "sendcoinsdialog.h"
19 #include "transactiontablemodel.h"
20 #include "transactionview.h"
21 #include "walletmodel.h"
22 
23 #include "ui_interface.h"
24 
25 #include <QAction>
26 #include <QActionGroup>
27 #include <QFileDialog>
28 #include <QHBoxLayout>
29 #include <QLabel>
30 #include <QProgressDialog>
31 #include <QPushButton>
32 #include <QSettings>
33 #include <QVBoxLayout>
34 
35 WalletView::WalletView(const PlatformStyle *platformStyle, QWidget *parent):
36  QStackedWidget(parent),
37  clientModel(0),
38  walletModel(0),
39  platformStyle(platformStyle)
40 {
41  // Create tabs
43 
44  transactionsPage = new QWidget(this);
45  QVBoxLayout *vbox = new QVBoxLayout();
46  QHBoxLayout *hbox_buttons = new QHBoxLayout();
48  vbox->addWidget(transactionView);
49  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
50  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
52  QString theme = GUIUtil::getThemeName();
53  exportButton->setIcon(QIcon(":/icons/" + theme + "/export"));
54  }
55  hbox_buttons->addStretch();
56 
57  // Sum of selected transactions
58  QLabel *transactionSumLabel = new QLabel(); // Label
59  transactionSumLabel->setObjectName("transactionSumLabel"); // Label ID as CSS-reference
60  transactionSumLabel->setText(tr("Selected amount:"));
61  hbox_buttons->addWidget(transactionSumLabel);
62 
63  transactionSum = new QLabel(); // Amount
64  transactionSum->setObjectName("transactionSum"); // Label ID as CSS-reference
65  transactionSum->setMinimumSize(200, 8);
66  transactionSum->setTextInteractionFlags(Qt::TextSelectableByMouse);
67  hbox_buttons->addWidget(transactionSum);
68 
69  hbox_buttons->addWidget(exportButton);
70  vbox->addLayout(hbox_buttons);
71  transactionsPage->setLayout(vbox);
72 
75 
78 
79  addWidget(overviewPage);
80  addWidget(transactionsPage);
81  addWidget(receiveCoinsPage);
82  addWidget(sendCoinsPage);
83 
84  QSettings settings;
85  if (settings.value("fShowMasternodesTab").toBool()) {
87  addWidget(masternodeListPage);
88  }
89 
90  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
91  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
92  connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
93 
94  // Double-clicking on a transaction on the transaction history page shows details
95  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
96 
97  // Update wallet with sum of selected transactions
98  connect(transactionView, SIGNAL(trxAmount(QString)), this, SLOT(trxAmount(QString)));
99 
100  // Clicking on "Export" allows to export the transaction list
101  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
102 
103  // Pass through messages from sendCoinsPage
104  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
105 
106  // Pass through messages from transactionView
107  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
108 }
109 
111 {
112 }
113 
115 {
116  if (gui)
117  {
118  // Clicking on a transaction on the overview page simply sends you to transaction history page
119  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
120 
121  // Receive and report messages
122  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
123 
124  // Pass through encryption status changed signals
125  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
126 
127  // Pass through transaction notifications
128  connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString)));
129 
130  // Connect HD enabled state signal
131  connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
132  }
133 }
134 
136 {
137  this->clientModel = clientModel;
138 
141  QSettings settings;
142  if (settings.value("fShowMasternodesTab").toBool()) {
144  }
145 }
146 
148 {
149  this->walletModel = walletModel;
150 
151  // Put transaction list in tabs
154  QSettings settings;
155  if (settings.value("fShowMasternodesTab").toBool()) {
157  }
162 
163  if (walletModel)
164  {
165  // Receive and pass through messages from wallet model
166  connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
167 
168  // Handle changes in encryption status
169  connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
171 
172  // update HD status
174 
175  // Balloon pop-up for new transaction
176  connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
177  this, SLOT(processNewTransaction(QModelIndex,int,int)));
178 
179  // Ask for passphrase if needed
180  connect(walletModel, SIGNAL(requireUnlock(bool)), this, SLOT(unlockWallet(bool)));
181 
182  // Show progress dialog
183  connect(walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
184  }
185 }
186 
187 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
188 {
189  // Prevent balloon-spam when initial block download is in progress
191  return;
192 
194  if (!ttm || ttm->processingQueuedTransactions())
195  return;
196 
197  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
198  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
199  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
200  QModelIndex index = ttm->index(start, 0, parent);
201  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
202  QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
203 
204  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label);
205 }
206 
208 {
209  setCurrentWidget(overviewPage);
210 }
211 
213 {
214  setCurrentWidget(transactionsPage);
215 }
216 
218 {
219  QSettings settings;
220  if (settings.value("fShowMasternodesTab").toBool()) {
221  setCurrentWidget(masternodeListPage);
222  }
223 }
224 
226 {
227  setCurrentWidget(receiveCoinsPage);
228 }
229 
231 {
232  setCurrentWidget(sendCoinsPage);
233 
234  if (!addr.isEmpty())
235  sendCoinsPage->setAddress(addr);
236 }
237 
239 {
240  // calls show() in showTab_SM()
241  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
242  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
243  signVerifyMessageDialog->setModel(walletModel);
244  signVerifyMessageDialog->showTab_SM(true);
245 
246  if (!addr.isEmpty())
247  signVerifyMessageDialog->setAddress_SM(addr);
248 }
249 
251 {
252  // calls show() in showTab_VM()
253  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
254  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
255  signVerifyMessageDialog->setModel(walletModel);
256  signVerifyMessageDialog->showTab_VM(true);
257 
258  if (!addr.isEmpty())
259  signVerifyMessageDialog->setAddress_VM(addr);
260 }
261 
263 {
264  return sendCoinsPage->handlePaymentRequest(recipient);
265 }
266 
268 {
270 }
271 
273 {
275 }
276 
277 void WalletView::encryptWallet(bool status)
278 {
279  if(!walletModel)
280  return;
282  dlg.setModel(walletModel);
283  dlg.exec();
284 
286 }
287 
289 {
290  QString filename = GUIUtil::getSaveFileName(this,
291  tr("Backup Wallet"), QString(),
292  tr("Wallet Data (*.dat)"), NULL);
293 
294  if (filename.isEmpty())
295  return;
296 
297  if (!walletModel->backupWallet(filename)) {
298  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
300  }
301  else {
302  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
304  }
305 }
306 
308 {
310  dlg.setModel(walletModel);
311  dlg.exec();
312 }
313 
314 void WalletView::unlockWallet(bool fForMixingOnly)
315 {
316  if(!walletModel)
317  return;
318  // Unlock wallet when requested by wallet model
319 
321  {
323  dlg.setModel(walletModel);
324  dlg.exec();
325  }
326 }
327 
329 {
330  if(!walletModel)
331  return;
332 
334 }
335 
337 {
338  if(!walletModel)
339  return;
340 
341  usedSendingAddressesPage->show();
342  usedSendingAddressesPage->raise();
343  usedSendingAddressesPage->activateWindow();
344 }
345 
347 {
348  if(!walletModel)
349  return;
350 
353  usedReceivingAddressesPage->activateWindow();
354 }
355 
356 void WalletView::showProgress(const QString &title, int nProgress)
357 {
358  if (nProgress == 0)
359  {
360  progressDialog = new QProgressDialog(title, "", 0, 100);
361  progressDialog->setWindowModality(Qt::ApplicationModal);
362  progressDialog->setMinimumDuration(0);
363  progressDialog->setCancelButton(0);
364  progressDialog->setAutoClose(false);
365  progressDialog->setValue(0);
366  }
367  else if (nProgress == 100)
368  {
369  if (progressDialog)
370  {
371  progressDialog->close();
372  progressDialog->deleteLater();
373  }
374  }
375  else if (progressDialog)
376  progressDialog->setValue(nProgress);
377 }
378 
380 {
381  Q_EMIT outOfSyncWarningClicked();
382 }
383 
385 void WalletView::trxAmount(QString amount)
386 {
387  transactionSum->setText(amount);
388 }
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString(), bool fMixing=false)
void encryptWallet(bool status)
Definition: walletview.cpp:277
void setAddress_VM(const QString &address)
void incomingTransaction(const QString &date, int unit, const CAmount &amount, const QString &type, const QString &address, const QString &label)
void trxAmount(QString amount)
Definition: walletview.cpp:385
TransactionView * transactionView
Definition: walletview.h:71
void setWalletModel(WalletModel *walletModel)
QVariant data(const QModelIndex &index, int role) const
void setModel(WalletModel *model)
void usedReceivingAddresses()
Definition: walletview.cpp:346
void setClientModel(ClientModel *clientModel)
Definition: walletview.cpp:135
void backupWallet()
Definition: walletview.cpp:288
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
QWidget * transactionsPage
Definition: walletview.h:64
void gotoSignMessageTab(QString addr="")
Definition: walletview.cpp:238
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:66
void setModel(WalletModel *model)
void requestedSyncWarningInfo()
Definition: walletview.cpp:379
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:114
void updateEncryptionStatus()
Definition: walletview.cpp:272
QProgressDialog * progressDialog
Definition: walletview.h:73
EncryptionStatus getEncryptionStatus() const
MasternodeList * masternodeListPage
Definition: walletview.h:69
void showOutOfSyncWarning(bool fShow)
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:68
void gotoOverviewPage()
Definition: walletview.cpp:207
void gotoReceiveCoinsPage()
Definition: walletview.cpp:225
TransactionTableModel * getTransactionTableModel()
dictionary settings
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void usedSendingAddresses()
Definition: walletview.cpp:336
int64_t CAmount
Definition: amount.h:14
void outOfSyncWarningClicked()
void message(const QString &title, const QString &message, unsigned int style)
void setWalletModel(WalletModel *walletModel)
void setClientModel(ClientModel *clientModel)
void setModel(WalletModel *model)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Definition: guiutil.cpp:301
void unlockWallet(bool fAnonymizeOnly=false)
Definition: walletview.cpp:314
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:67
void gotoVerifyMessageTab(QString addr="")
Definition: walletview.cpp:250
const PlatformStyle * platformStyle
Definition: walletview.h:75
OptionsModel * getOptionsModel()
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void setClientModel(ClientModel *clientModel)
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:267
void setClientModel(ClientModel *clientModel)
void gotoHistoryPage()
Definition: walletview.cpp:212
void setAddress_SM(const QString &address)
bool getImagesOnButtons() const
Definition: platformstyle.h:21
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:65
void setAddress(const QString &address)
void changePassphrase()
Definition: walletview.cpp:307
WalletView(const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:35
QString getThemeName()
Definition: guiutil.cpp:902
void setModel(WalletModel *model)
ClientModel * clientModel
Definition: walletview.h:60
void lockWallet()
Definition: walletview.cpp:328
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:262
OverviewPage * overviewPage
Definition: walletview.h:63
int getDisplayUnit()
Definition: optionsmodel.h:73
bool backupWallet(const QString &filename)
void processNewTransaction(const QModelIndex &parent, int start, int)
Definition: walletview.cpp:187
WalletModel * walletModel
Definition: walletview.h:61
void setWalletModel(WalletModel *walletModel)
Definition: walletview.cpp:147
void gotoSendCoinsPage(QString addr="")
Definition: walletview.cpp:230
void setModel(WalletModel *model)
void encryptionStatusChanged(int status)
AddressTableModel * getAddressTableModel()
void hdEnabledStatusChanged(int hdEnabled)
bool hdEnabled() const
void gotoMasternodePage()
Definition: walletview.cpp:217
void setModel(AddressTableModel *model)
QLabel * transactionSum
Definition: walletview.h:74
void showProgress(const QString &title, int nProgress)
Definition: walletview.cpp:356