Raven Core  3.0.0
P2P Digital Currency
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "walletview.h"
7 
8 #include "addressbookpage.h"
9 #include "askpassphrasedialog.h"
10 #include "ravengui.h"
11 #include "clientmodel.h"
12 #include "guiutil.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 "assettablemodel.h"
21 #include "transactionview.h"
22 #include "walletmodel.h"
23 #include "assetsdialog.h"
24 #include "createassetdialog.h"
25 #include "reissueassetdialog.h"
26 #include <validation.h>
27 
28 #include "ui_interface.h"
29 
30 #include <QAction>
31 #include <QActionGroup>
32 #include <QFileDialog>
33 #include <QHBoxLayout>
34 #include <QProgressDialog>
35 #include <QPushButton>
36 #include <QVBoxLayout>
37 
38 
39 WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
40  QStackedWidget(parent),
41  clientModel(0),
42  walletModel(0),
43  platformStyle(_platformStyle)
44 {
45  // Create tabs
47 
48  transactionsPage = new QWidget(this);
49  QVBoxLayout *vbox = new QVBoxLayout();
50  QHBoxLayout *hbox_buttons = new QHBoxLayout();
52  vbox->addWidget(transactionView);
53  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
54  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
56  exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
57  }
58  hbox_buttons->addStretch();
59  hbox_buttons->addWidget(exportButton);
60  vbox->addLayout(hbox_buttons);
61  transactionsPage->setLayout(vbox);
64 
68 
71 
72  addWidget(overviewPage);
73  addWidget(transactionsPage);
74  addWidget(receiveCoinsPage);
75  addWidget(sendCoinsPage);
76 
78  addWidget(assetsPage);
79  addWidget(createAssetsPage);
80  addWidget(manageAssetsPage);
83  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
84  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
85  connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
86 
87  // Double-clicking on a transaction on the transaction history page shows details
88  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
89 
90  // Clicking on "Export" allows to export the transaction list
91  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
92 
93  // Pass through messages from sendCoinsPage
94  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
95  // Pass through messages from transactionView
96  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
97 
99  connect(assetsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
100  connect(createAssetsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
101  connect(manageAssetsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
102  connect(overviewPage, SIGNAL(assetSendClicked(QModelIndex)), assetsPage, SLOT(focusAsset(QModelIndex)));
103  connect(overviewPage, SIGNAL(assetIssueSubClicked(QModelIndex)), createAssetsPage, SLOT(focusSubAsset(QModelIndex)));
104  connect(overviewPage, SIGNAL(assetIssueUniqueClicked(QModelIndex)), createAssetsPage, SLOT(focusUniqueAsset(QModelIndex)));
105  connect(overviewPage, SIGNAL(assetReissueClicked(QModelIndex)), manageAssetsPage, SLOT(focusReissueAsset(QModelIndex)));
107 }
108 
110 {
111 }
112 
114 {
115  if (gui)
116  {
117  // Clicking on a transaction on the overview page simply sends you to transaction history page
118  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
119 
120  // Clicking on a asset menu item Send
121  connect(overviewPage, SIGNAL(assetSendClicked(QModelIndex)), gui, SLOT(gotoAssetsPage()));
122 
123  // Clicking on a asset menu item Issue Sub
124  connect(overviewPage, SIGNAL(assetIssueSubClicked(QModelIndex)), gui, SLOT(gotoCreateAssetsPage()));
125 
126  // Clicking on a asset menu item Issue Unique
127  connect(overviewPage, SIGNAL(assetIssueUniqueClicked(QModelIndex)), gui, SLOT(gotoCreateAssetsPage()));
128 
129  // Clicking on a asset menu item Reissue
130  connect(overviewPage, SIGNAL(assetReissueClicked(QModelIndex)), gui, SLOT(gotoManageAssetsPage()));
131 
132  // Receive and report messages
133  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
134 
135  // Pass through encryption status changed signals
136  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
137 
138  // Pass through transaction notifications
139  connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString,QString)));
140 
141  // Connect HD enabled state signal
142  connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
143 
144  // Pass through checkAssets calls to the GUI
145  connect(this, SIGNAL(checkAssets()), gui, SLOT(checkAssets()));
146  }
147 }
148 
150 {
151  this->clientModel = _clientModel;
152 
153  overviewPage->setClientModel(_clientModel);
154  sendCoinsPage->setClientModel(_clientModel);
155 }
156 
158 {
159  this->walletModel = _walletModel;
160 
161  // Put transaction list in tabs
162  transactionView->setModel(_walletModel);
163  overviewPage->setWalletModel(_walletModel);
164  receiveCoinsPage->setModel(_walletModel);
165  sendCoinsPage->setModel(_walletModel);
166  usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
167  usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
168 
170  assetsPage->setModel(_walletModel);
171  createAssetsPage->setModel(_walletModel);
172  manageAssetsPage->setModel(_walletModel);
173 
174  if (_walletModel)
175  {
176  // Receive and pass through messages from wallet model
177  connect(_walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
178 
179  // Handle changes in encryption status
180  connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
182 
183  // update HD status
184  Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled());
185 
186  // Balloon pop-up for new transaction
187  connect(_walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
188  this, SLOT(processNewTransaction(QModelIndex,int,int)));
189 
190  // Ask for passphrase if needed
191  connect(_walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
192 
193  // Show progress dialog
194  connect(_walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
195  }
196 }
197 
198 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int end)
199 {
200  // Prevent balloon-spam when initial block download is in progress
202  return;
203 
205  if (!ttm || ttm->processingQueuedTransactions())
206  return;
207 
209  // With the addition of asset transactions, there can be multiple transaction that need notifications
210  // so we need to loop through all new transaction that were added to the transaction table and display
211  // notifications for each individual transaction
212  QString assetName = "";
213  for (int i = start; i <= end; i++) {
214  QString date = ttm->index(i, TransactionTableModel::Date, parent).data().toString();
215  qint64 amount = ttm->index(i, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
216  QString type = ttm->index(i, TransactionTableModel::Type, parent).data().toString();
217  QModelIndex index = ttm->index(i, 0, parent);
218  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
219  QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
220  assetName = ttm->data(index, TransactionTableModel::AssetNameRole).toString();
221 
222  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label,
223  assetName);
224  }
230  Q_EMIT checkAssets();
231 
235 
236 }
237 
239 {
240  setCurrentWidget(overviewPage);
241  Q_EMIT checkAssets();
242 }
243 
245 {
246  setCurrentWidget(transactionsPage);
247 }
248 
250 {
251  setCurrentWidget(receiveCoinsPage);
252 }
253 
255 {
256  setCurrentWidget(sendCoinsPage);
257 
258  if (!addr.isEmpty())
259  sendCoinsPage->setAddress(addr);
260 }
261 
263 {
264  // calls show() in showTab_SM()
265  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
266  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
267  signVerifyMessageDialog->setModel(walletModel);
268  signVerifyMessageDialog->showTab_SM(true);
269 
270  if (!addr.isEmpty())
271  signVerifyMessageDialog->setAddress_SM(addr);
272 }
273 
275 {
276  // calls show() in showTab_VM()
277  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
278  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
279  signVerifyMessageDialog->setModel(walletModel);
280  signVerifyMessageDialog->showTab_VM(true);
281 
282  if (!addr.isEmpty())
283  signVerifyMessageDialog->setAddress_VM(addr);
284 }
285 
287 {
288  return sendCoinsPage->handlePaymentRequest(recipient);
289 }
290 
292 {
294 }
295 
297 {
299 }
300 
301 void WalletView::encryptWallet(bool status)
302 {
303  if(!walletModel)
304  return;
306  dlg.setModel(walletModel);
307  dlg.exec();
308 
310 }
311 
313 {
314  QString filename = GUIUtil::getSaveFileName(this,
315  tr("Backup Wallet"), QString(),
316  tr("Wallet Data (*.dat)"), nullptr);
317 
318  if (filename.isEmpty())
319  return;
320 
321  if (!walletModel->backupWallet(filename)) {
322  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
324  }
325  else {
326  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
328  }
329 }
330 
332 {
334  dlg.setModel(walletModel);
335  dlg.exec();
336 }
337 
339 {
340  if(!walletModel)
341  return;
342  // Unlock wallet when requested by wallet model
344  {
346  dlg.setModel(walletModel);
347  dlg.exec();
348  }
349 }
350 
352 {
353  if(!walletModel)
354  return;
355 
356  usedSendingAddressesPage->show();
357  usedSendingAddressesPage->raise();
358  usedSendingAddressesPage->activateWindow();
359 }
360 
362 {
363  if(!walletModel)
364  return;
365 
368  usedReceivingAddressesPage->activateWindow();
369 }
370 
371 void WalletView::showProgress(const QString &title, int nProgress)
372 {
373  if (nProgress == 0)
374  {
375  progressDialog = new QProgressDialog(title, "", 0, 100);
376  progressDialog->setWindowModality(Qt::ApplicationModal);
377  progressDialog->setMinimumDuration(0);
378  progressDialog->setCancelButton(0);
379  progressDialog->setAutoClose(false);
380  progressDialog->setValue(0);
381  }
382  else if (nProgress == 100)
383  {
384  if (progressDialog)
385  {
386  progressDialog->close();
387  progressDialog->deleteLater();
388  }
389  }
390  else if (progressDialog)
391  progressDialog->setValue(nProgress);
392 }
393 
395 {
396  Q_EMIT outOfSyncWarningClicked();
397 }
398 
399 bool fFirstVisit = true;
402 {
403  if (fFirstVisit){
404  fFirstVisit = false;
406  }
407  setCurrentWidget(assetsPage);
409 }
410 
412 {
413  setCurrentWidget(createAssetsPage);
414 }
415 
417 {
418  setCurrentWidget(manageAssetsPage);
419 }
QWidget * transactionsPage
Definition: walletview.h:66
Dialog for requesting payment of ravens.
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
void processNewTransaction(const QModelIndex &parent, int start, int end)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:198
void setWalletModel(WalletModel *walletModel)
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:274
OverviewPage * overviewPage
Definition: walletview.h:65
TransactionView * transactionView
Definition: walletview.h:72
void handleFirstSelection()
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:351
void setAddress_VM(const QString &address)
Dialog showing transaction details.
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:331
ClientModel * clientModel
Definition: walletview.h:62
void gotoAssetsPage()
RVN START.
Definition: walletview.cpp:401
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:394
WalletModel * walletModel
Definition: walletview.h:63
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
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:75
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:254
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:296
EncryptionStatus getEncryptionStatus() const
int getDisplayUnit() const
Definition: optionsmodel.h:68
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:68
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
void processNewTransaction()
void setModel(WalletModel *model)
bool processingQueuedTransactions() const
void hdEnabledStatusChanged(int hdEnabled)
HD-Enabled status of wallet changed (only possible during startup)
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:244
Ask passphrase and unlock.
void gotoManageAssetsPage()
Definition: walletview.cpp:416
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:361
void setModel(WalletModel *model)
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:157
void setAddress(const QString &address)
void setClientModel(ClientModel *clientModel)
void encryptionStatusChanged(int status)
Encryption status of wallet changed.
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.
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:338
Dialog for sending ravens.
void setModel(WalletModel *model)
TransactionTableModel * getTransactionTableModel()
Widget that shows a list of sending or receiving addresses.
UI model for the transaction table of a wallet.
ReissueAssetDialog * manageAssetsPage
Definition: walletview.h:81
Model for Raven network client.
Definition: clientmodel.h:39
void setModel(WalletModel *model)
void setModel(WalletModel *model)
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:312
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:286
void gotoOverviewPage()
RVN END.
Definition: walletview.cpp:238
void showOutOfSyncWarning(bool fShow)
QVariant data(const QModelIndex &index, int role) const
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:69
void setModel(WalletModel *model)
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:262
bool hdEnabled() const
CreateAssetDialog * createAssetsPage
Definition: walletview.h:80
bool fFirstVisit
Definition: walletview.cpp:399
Interface to Raven wallet from Qt view code.
Definition: walletmodel.h:165
Raven GUI main class.
Definition: ravengui.h:47
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:371
Multifunctional dialog to ask for passphrases.
AssetsDialog * assetsPage
RVN START.
Definition: walletview.h:79
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:375
WalletView(const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:39
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:149
Dialog showing transaction details.
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
Label of address related to transaction.
Dialog for sending ravens.
Definition: assetsdialog.h:30
void incomingTransaction(const QString &date, int unit, const CAmount &amount, const QString &type, const QString &address, const QString &label, const QString &assetName)
Notify that a new transaction appeared.
Ask old passphrase + new passphrase twice.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:301
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:67
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:249
void setRavenGUI(RavenGUI *gui)
Definition: walletview.cpp:113
void setModel(WalletModel *model)
Overview ("home") page widget.
Definition: overviewpage.h:34
void checkAssets()
Show the assets GUI.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:291
QProgressDialog * progressDialog
Definition: walletview.h:74
void gotoCreateAssetsPage()
Definition: walletview.cpp:411
bool getImagesOnButtons() const
Definition: platformstyle.h:24
void focusAssetListBox()
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:70
void setModel(WalletModel *model)