Fabcoin Core  0.16.2
P2P Digital Currency
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 <fabcoingui.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>
20 #include <tokentransactionrecord.h>
21 #include <transactionview.h>
22 #include <walletmodel.h>
23 #include <createcontract.h>
24 #include <sendtocontract.h>
25 #include <callcontract.h>
26 #include <qrctoken.h>
27 #include <restoredialog.h>
28 
29 #include <ui_interface.h>
30 
31 #include <QAction>
32 #include <QActionGroup>
33 #include <QFileDialog>
34 #include <QHBoxLayout>
35 #include <QProgressDialog>
36 #include <QPushButton>
37 #include <QVBoxLayout>
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->MultiStatesIcon(":/icons/export", PlatformStyle::PushButton));
57  }
58  hbox_buttons->addStretch();
59  hbox_buttons->addWidget(exportButton);
60  vbox->addLayout(hbox_buttons);
61  transactionsPage->setLayout(vbox);
62 
65 
68 
72 
74 
75  addWidget(overviewPage);
76  addWidget(transactionsPage);
77  addWidget(receiveCoinsPage);
78  addWidget(sendCoinsPage);
79  addWidget(createContractPage);
80  addWidget(sendToContractPage);
81  addWidget(callContractPage);
82  addWidget(QRCTokenPage);
83 
84  connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
85 
86  // Double-clicking on a transaction on the transaction history page shows details
87  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
88 
89  // Clicking on "Export" allows to export the transaction list
90  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
91 
92  // Pass through messages from sendCoinsPage
93  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
94  // Pass through messages from transactionView
95  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
96 }
97 
99 {
100 }
101 
103 {
104  if (gui)
105  {
106  // Clicking on a show more button sends you to transaction history page
107  connect(overviewPage, SIGNAL(showMoreClicked()), gui, SLOT(gotoHistoryPage()));
108 
109  // Receive and report messages
110  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
111 
112  // Pass through encryption status changed signals
113  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
114 
115  // Pass through transaction notifications
116  connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString)));
117 
118  // Pass through token transaction notifications
119  connect(this, SIGNAL(incomingTokenTransaction(QString,QString,QString,QString,QString,QString)), gui, SLOT(incomingTokenTransaction(QString,QString,QString,QString,QString,QString)));
120 
121  // Connect HD enabled state signal
122  connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
123 
124  // Clicking on add token button sends you to add token page
125  connect(overviewPage, SIGNAL(addTokenClicked()), gui, SLOT(gotoAddTokenPage()));
126  }
127 }
128 
130 {
131  this->clientModel = _clientModel;
132 
133  overviewPage->setClientModel(_clientModel);
134  sendCoinsPage->setClientModel(_clientModel);
135  createContractPage->setClientModel(_clientModel);
136  sendToContractPage->setClientModel(_clientModel);
137  callContractPage->setClientModel(_clientModel);
138  QRCTokenPage->setClientModel(_clientModel);
139 }
140 
142 {
143  this->walletModel = _walletModel;
144 
145  // Put transaction list in tabs
146  transactionView->setModel(_walletModel);
147  overviewPage->setWalletModel(_walletModel);
148  receiveCoinsPage->setModel(_walletModel);
149  sendCoinsPage->setModel(_walletModel);
150  createContractPage->setModel(_walletModel);
151  sendToContractPage->setModel(_walletModel);
152  callContractPage->setModel(_walletModel);
153  QRCTokenPage->setModel(_walletModel);
156 
157  if (_walletModel)
158  {
159  // Receive and pass through messages from wallet model
160  connect(_walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
161 
162  // Handle changes in encryption status
163  connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
165 
166  // update HD status
167  Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled());
168 
169  // Balloon pop-up for new transaction
170  connect(_walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
171  this, SLOT(processNewTransaction(QModelIndex,int,int)));
172 
173  // Balloon pop-up for new token transaction
174  connect(_walletModel->getTokenTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
175  this, SLOT(processNewTokenTransaction(QModelIndex,int,int)));
176 
177  // Ask for passphrase if needed
178  connect(_walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
179 
180  // Show progress dialog
181  connect(_walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
182  }
183 }
184 
185 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
186 {
187  // Prevent balloon-spam when initial block download is in progress
189  return;
190 
192  if (!ttm || ttm->processingQueuedTransactions())
193  return;
194 
195  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
196  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
197  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
198  QModelIndex index = ttm->index(start, 0, parent);
199  QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
200  QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
201 
202  Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label);
203 }
204 
205 void WalletView::processNewTokenTransaction(const QModelIndex &parent, int start, int /*end*/)
206 {
207  // Prevent balloon-spam when initial block download is in progress
209  return;
210 
212  if (!tttm || tttm->processingQueuedTransactions())
213  return;
214 
215  QString date = tttm->index(start, TokenTransactionTableModel::Date, parent).data().toString();
216  QString amount(tttm->index(start, TokenTransactionTableModel::Amount, parent).data(TokenTransactionTableModel::FormattedAmountWithUnitRole).toString());
217  QString type = tttm->index(start, TokenTransactionTableModel::Type, parent).data().toString();
218  QModelIndex index = tttm->index(start, 0, parent);
219  QString address = tttm->data(index, TokenTransactionTableModel::AddressRole).toString();
220  QString label = tttm->data(index, TokenTransactionTableModel::LabelRole).toString();
221  QString title;
222  int txType = tttm->data(index, TokenTransactionTableModel::TypeRole).toInt();
223  switch (txType)
224  {
227  title = tr("Incoming transaction");
228  break;
229  default:
230  title = tr("Sent transaction");
231  break;
232  }
233  Q_EMIT incomingTokenTransaction(date, amount, type, address, label, title);
234 }
235 
237 {
238  setCurrentWidget(overviewPage);
239 }
240 
242 {
243  setCurrentWidget(transactionsPage);
244 }
245 
247 {
248  setCurrentWidget(receiveCoinsPage);
249 }
250 
252 {
253  setCurrentWidget(sendCoinsPage);
254 
255  if (!addr.isEmpty())
256  sendCoinsPage->setAddress(addr);
257 }
258 
260 {
261  setCurrentWidget(createContractPage);
262 }
263 
265 {
266  setCurrentWidget(sendToContractPage);
267 }
268 
270 {
271  setCurrentWidget(callContractPage);
272 }
273 
275 {
276  setCurrentWidget(QRCTokenPage);
278 }
279 
281 {
282  setCurrentWidget(QRCTokenPage);
284 }
285 
287 {
288  setCurrentWidget(QRCTokenPage);
290 }
291 
293 {
294  // calls show() in showTab_SM()
295  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
296  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
297  signVerifyMessageDialog->setModel(walletModel);
298  signVerifyMessageDialog->showTab_SM(true);
299 
300  if (!addr.isEmpty())
301  signVerifyMessageDialog->setAddress_SM(addr);
302 }
303 
305 {
306  // calls show() in showTab_VM()
307  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
308  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
309  signVerifyMessageDialog->setModel(walletModel);
310  signVerifyMessageDialog->showTab_VM(true);
311 
312  if (!addr.isEmpty())
313  signVerifyMessageDialog->setAddress_VM(addr);
314 }
315 
317 {
318  return sendCoinsPage->handlePaymentRequest(recipient);
319 }
320 
322 {
324 }
325 
327 {
329 }
330 
331 void WalletView::encryptWallet(bool status)
332 {
333  if(!walletModel)
334  return;
336  dlg.setModel(walletModel);
337  dlg.exec();
338 
340 }
341 
343 {
344  QString filename = GUIUtil::getSaveFileName(this,
345  tr("Backup Wallet"), QString(),
346  tr("Wallet Data (*.dat)"), nullptr);
347 
348  if (filename.isEmpty())
349  return;
350 
351  if (!walletModel->backupWallet(filename)) {
352  Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
354  }
355  else {
356  Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
358  }
359 }
360 
362 {
363  RestoreDialog dlg(this);
364  dlg.setModel(walletModel);
365  dlg.exec();
366 }
367 
369 {
371  dlg.setModel(walletModel);
372  dlg.exec();
373 }
374 
375 void WalletView::unlockWallet(bool fromMenu)
376 {
377  if(!walletModel)
378  return;
379  // Unlock wallet when requested by wallet model
381  {
382  AskPassphraseDialog::Mode mode = fromMenu ?
384  AskPassphraseDialog dlg(mode, this);
385  dlg.setModel(walletModel);
386  dlg.exec();
387  }
388 }
389 
391 {
392  if(!walletModel)
393  return;
394 
396 }
397 
399 {
400  if(!walletModel)
401  return;
402 
403  usedSendingAddressesPage->show();
404  usedSendingAddressesPage->raise();
405  usedSendingAddressesPage->activateWindow();
406 }
407 
409 {
410  if(!walletModel)
411  return;
412 
415  usedReceivingAddressesPage->activateWindow();
416 }
417 
418 void WalletView::showProgress(const QString &title, int nProgress)
419 {
420  if (nProgress == 0)
421  {
422  progressDialog = new QProgressDialog(title, "", 0, 100);
423  progressDialog->setWindowModality(Qt::ApplicationModal);
424  progressDialog->setMinimumDuration(0);
425  progressDialog->setCancelButton(0);
426  progressDialog->setAutoClose(false);
427  progressDialog->setValue(0);
428  }
429  else if (nProgress == 100)
430  {
431  if (progressDialog)
432  {
433  progressDialog->close();
434  progressDialog->deleteLater();
435  }
436  }
437  else if (progressDialog)
438  progressDialog->setValue(nProgress);
439 }
440 
442 {
443  Q_EMIT outOfSyncWarningClicked();
444 }
Ask passphrase and unlock staking only.
void unlockWallet(bool fromMenu=false)
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:375
QWidget * transactionsPage
Definition: walletview.h:66
QVariant data(const QModelIndex &index, int role) const
Dialog for requesting payment of fabcoins.
void incomingTokenTransaction(const QString &date, const QString &amount, const QString &type, const QString &address, const QString &label, const QString &title)
Notify that a new token transaction appeared.
void setWalletModel(WalletModel *walletModel)
void setModel(WalletModel *model)
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:304
void gotoSendToContractPage()
Switch to send contract page.
Definition: walletview.cpp:264
OverviewPage * overviewPage
Definition: walletview.h:65
TransactionView * transactionView
Definition: walletview.h:76
void setModel(WalletModel *model)
void setClientModel(ClientModel *clientModel)
Definition: qrctoken.cpp:187
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:398
void setAddress_VM(const QString &address)
void gotoCreateContractPage()
Switch to create contract page.
Definition: walletview.cpp:259
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:368
ClientModel * clientModel
Definition: walletview.h:62
Ask passphrase twice and encrypt.
evm_mode mode
Definition: SmartVM.cpp:47
bool backupWallet(const QString &filename)
QVariant data(const QModelIndex &index, int role) const
void requestedSyncWarningInfo()
User has requested more information about the out of sync state.
Definition: walletview.cpp:441
void processNewTokenTransaction(const QModelIndex &parent, int start, int)
Show incoming token transaction notification for new token transactions.
Definition: walletview.cpp:205
WalletModel * walletModel
Definition: walletview.h:63
Fabcoin GUI main class.
Definition: fabcoingui.h:51
CallContract * callContractPage
Definition: walletview.h:73
QRCToken * QRCTokenPage
Definition: walletview.h:74
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void setModel(WalletModel *model)
setModel Set wallet model
Open address book for editing.
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
const PlatformStyle * platformStyle
Definition: walletview.h:79
void gotoAddTokenPage()
Switch to Add Token page.
Definition: walletview.cpp:286
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:251
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:326
TokenTransactionTableModel * getTokenTransactionTableModel()
CreateContract * createContractPage
Definition: walletview.h:71
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:185
void on_goToReceiveTokenPage()
Definition: qrctoken.cpp:199
void gotoCallContractPage()
Switch to call contract page.
Definition: walletview.cpp:269
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:68
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
void setModel(WalletModel *model)
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) 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:241
Ask passphrase and unlock.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:408
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:141
void setAddress(const QString &address)
void on_goToSendTokenPage()
Definition: qrctoken.cpp:194
void setClientModel(ClientModel *clientModel)
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.
UI model for the transaction table of a wallet.
Widget showing the transaction list for a wallet, including a filter row.
void setClientModel(ClientModel *clientModel)
The RestoreDialog class Restore dialog class.
Definition: restoredialog.h:15
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
Dialog for sending fabcoins.
void setClientModel(ClientModel *clientModel)
TransactionTableModel * getTransactionTableModel()
void restoreWallet()
Restore the wallet.
Definition: walletview.cpp:361
int getDisplayUnit()
Definition: optionsmodel.h:70
Widget that shows a list of sending or receiving addresses.
UI model for the transaction table of a wallet.
Model for Fabcoin network client.
Definition: clientmodel.h:38
void setModel(WalletModel *model)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:342
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:316
EncryptionStatus getEncryptionStatus() const
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:236
void showOutOfSyncWarning(bool fShow)
std::vector< ResultExecute > CallContract(const dev::Address &addrContract, std::vector< unsigned char > opcode, const dev::Address &sender, uint64_t gasLimit)
AddressBookPage * usedSendingAddressesPage
Definition: walletview.h:69
void setModel(WalletModel *model)
void setModel(WalletModel *_model)
Definition: qrctoken.cpp:156
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:292
PlatformStyle::TableColorType type
Definition: rpcconsole.cpp:61
QIcon MultiStatesIcon(const QString &resourcename, StateType type=NavBar, QColor color=Qt::white, QColor colorAlt=0x2d2d2d) const
Get multi-states icon.
Interface to Fabcoin wallet from Qt view code.
Definition: walletmodel.h:103
void setFabcoinGUI(FabcoinGUI *gui)
Definition: walletview.cpp:102
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:418
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:309
void lockWallet()
Lock the wallet.
Definition: walletview.cpp:390
WalletView(const PlatformStyle *platformStyle, QWidget *parent)
Definition: walletview.cpp:39
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:129
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
Label of address related to transaction.
bool getImagesOnButtons() const
Definition: platformstyle.h:21
void gotoReceiveTokenPage()
Switch to Receive Token page.
Definition: walletview.cpp:280
Label of address related to transaction.
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
Ask old passphrase + new passphrase twice.
void setModel(WalletModel *model)
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:331
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:67
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:246
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void gotoSendTokenPage()
Switch to Send Token page.
Definition: walletview.cpp:274
void setModel(WalletModel *model)
SendToContract * sendToContractPage
Definition: walletview.h:72
Overview ("home") page widget.
Definition: overviewpage.h:29
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:321
QProgressDialog * progressDialog
Definition: walletview.h:78
OptionsModel * getOptionsModel()
void setClientModel(ClientModel *clientModel)
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:69
void setAddress_SM(const QString &address)
AddressBookPage * usedReceivingAddressesPage
Definition: walletview.h:70
bool hdEnabled() const
void on_goToAddTokenPage()
Definition: qrctoken.cpp:204
void setModel(WalletModel *model)