Anoncoin  0.9.4
P2P Digital Currency
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Copyright (c) 2013-2014 The Anoncoin Core developers
3 // Distributed under the MIT/X11 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 "anoncoingui.h"
11 #include "clientmodel.h"
12 #include "guiutil.h"
13 #include "optionsmodel.h"
14 #include "overviewpage.h"
15 #include "receivecoinsdialog.h"
16 #include "sendcoinsdialog.h"
18 #include "transactiontablemodel.h"
19 #include "transactionview.h"
20 #include "walletmodel.h"
21 
22 #include "ui_interface.h"
23 
24 #include <QAction>
25 #include <QActionGroup>
26 #include <QFileDialog>
27 #include <QHBoxLayout>
28 #include <QProgressDialog>
29 #include <QPushButton>
30 #include <QVBoxLayout>
31 
32 WalletView::WalletView(QWidget *parent):
33  QStackedWidget(parent),
34  clientModel(0),
35  walletModel(0)
36 {
37  // Create tabs
38  overviewPage = new OverviewPage();
39 
40  transactionsPage = new QWidget(this);
41  QVBoxLayout *vbox = new QVBoxLayout();
42  QHBoxLayout *hbox_buttons = new QHBoxLayout();
43  transactionView = new TransactionView(this);
44  vbox->addWidget(transactionView);
45  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
46  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
47 #ifndef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
48  exportButton->setIcon(QIcon(":/icons/export"));
49 #endif
50  hbox_buttons->addStretch();
51  hbox_buttons->addWidget(exportButton);
52  vbox->addLayout(hbox_buttons);
53  transactionsPage->setLayout(vbox);
54 
57 
58  addWidget(overviewPage);
59  addWidget(transactionsPage);
60  addWidget(receiveCoinsPage);
61  addWidget(sendCoinsPage);
62 
63  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
64  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
65 
66  // Double-clicking on a transaction on the transaction history page shows details
67  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
68 
69  // Clicking on "Export" allows to export the transaction list
70  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
71 
72  // Pass through messages from sendCoinsPage
73  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
74  // Pass through messages from transactionView
75  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
76 }
77 
79 {
80 }
81 
83 {
84  if (gui)
85  {
86  // Clicking on a transaction on the overview page simply sends you to transaction history page
87  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
88 
89  // Receive and report messages
90  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
91 
92  // Pass through encryption status changed signals
93  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
94 
95  // Pass through transaction notifications
96  connect(this, SIGNAL(incomingTransaction(QString,int,qint64,QString,QString)), gui, SLOT(incomingTransaction(QString,int,qint64,QString,QString)));
97  }
98 }
99 
101 {
102  this->clientModel = clientModel;
103 
104  overviewPage->setClientModel(clientModel);
105 }
106 
108 {
109  this->walletModel = walletModel;
110 
111  // Put transaction list in tabs
112  transactionView->setModel(walletModel);
113  overviewPage->setWalletModel(walletModel);
114  receiveCoinsPage->setModel(walletModel);
115  sendCoinsPage->setModel(walletModel);
116 
117  if (walletModel)
118  {
119  // Receive and pass through messages from wallet model
120  connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
121 
122  // Handle changes in encryption status
123  connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
125 
126  // Balloon pop-up for new transaction
127  connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
128  this, SLOT(processNewTransaction(QModelIndex,int,int)));
129 
130  // Ask for passphrase if needed
131  connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
132 
133  // Show progress dialog
134  connect(walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
135  }
136 }
137 
138 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
139 {
140  // Prevent balloon-spam when initial block download is in progress
142  return;
143 
145 
146  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
147  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
148  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
149  QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString();
150 
151  emit incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
152 }
153 
155 {
156  setCurrentWidget(overviewPage);
157 }
158 
160 {
161  setCurrentWidget(transactionsPage);
162 }
163 
165 {
166  setCurrentWidget(receiveCoinsPage);
167 }
168 
170 {
171  setCurrentWidget(sendCoinsPage);
172 
173  if (!addr.isEmpty())
174  sendCoinsPage->setAddress(addr);
175 }
176 
178 {
179  // calls show() in showTab_SM()
180  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
181  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
182  signVerifyMessageDialog->setModel(walletModel);
183  signVerifyMessageDialog->showTab_SM(true);
184 
185  if (!addr.isEmpty())
186  signVerifyMessageDialog->setAddress_SM(addr);
187 }
188 
190 {
191  // calls show() in showTab_VM()
192  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
193  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
194  signVerifyMessageDialog->setModel(walletModel);
195  signVerifyMessageDialog->showTab_VM(true);
196 
197  if (!addr.isEmpty())
198  signVerifyMessageDialog->setAddress_VM(addr);
199 }
200 
202 {
203  return sendCoinsPage->handlePaymentRequest(recipient);
204 }
205 
207 {
209 }
210 
212 {
214 }
215 
216 void WalletView::encryptWallet(bool status)
217 {
218  if(!walletModel)
219  return;
221  dlg.setModel(walletModel);
222  dlg.exec();
223 
225 }
226 
228 {
229  QString filename = GUIUtil::getSaveFileName(this,
230  tr("Backup Wallet"), QString(),
231  tr("Wallet Data (*.dat)"), NULL);
232 
233  if (filename.isEmpty())
234  return;
235 
236  if (!walletModel->backupWallet(filename)) {
237  emit message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
239  }
240  else {
241  emit message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
243  }
244 }
245 
247 {
249  dlg.setModel(walletModel);
250  dlg.exec();
251 }
252 
254 {
255  if(!walletModel)
256  return;
257  // Unlock wallet when requested by wallet model
259  {
261  dlg.setModel(walletModel);
262  dlg.exec();
263  }
264 }
265 
267 {
268  if(!walletModel)
269  return;
271  dlg->setAttribute(Qt::WA_DeleteOnClose);
273  dlg->show();
274 }
275 
277 {
278  if(!walletModel)
279  return;
281  dlg->setAttribute(Qt::WA_DeleteOnClose);
283  dlg->show();
284 }
285 
286 void WalletView::showProgress(const QString &title, int nProgress)
287 {
288  if (nProgress == 0)
289  {
290  progressDialog = new QProgressDialog(title, "", 0, 100);
291  progressDialog->setWindowModality(Qt::ApplicationModal);
292  progressDialog->setMinimumDuration(0);
293  progressDialog->setCancelButton(0);
294  progressDialog->setAutoClose(false);
295  progressDialog->setValue(0);
296  }
297  else if (nProgress == 100)
298  {
299  if (progressDialog)
300  {
301  progressDialog->close();
302  progressDialog->deleteLater();
303  }
304  }
305  else if (progressDialog)
306  progressDialog->setValue(nProgress);
307 }
QWidget * transactionsPage
Definition: walletview.h:59
bool processingQueuedTransactions()
Definition: walletmodel.h:137
Dialog for requesting payment of anoncoins.
void setWalletModel(WalletModel *walletModel)
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:189
OverviewPage * overviewPage
Definition: walletview.h:58
TransactionView * transactionView
Definition: walletview.h:63
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:266
void setAddress_VM(const QString &address)
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:246
ClientModel * clientModel
Definition: walletview.h:55
WalletView(QWidget *parent)
Definition: walletview.cpp:32
Ask passphrase twice and encrypt.
bool backupWallet(const QString &filename)
Anoncoin GUI main class.
Definition: anoncoingui.h:47
WalletModel * walletModel
Definition: walletview.h:56
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Open address book for editing.
void incomingTransaction(const QString &date, int unit, qint64 amount, const QString &type, const QString &address)
Notify that a new transaction appeared.
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:169
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:211
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:138
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:61
void setModel(WalletModel *model)
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:159
Ask passphrase and unlock.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:276
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:107
void setAddress(const QString &address)
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:253
Dialog for sending anoncoins.
TransactionTableModel * getTransactionTableModel()
int getDisplayUnit()
Definition: optionsmodel.h:87
Widget that shows a list of sending or receiving addresses.
UI model for the transaction table of a wallet.
Model for Anoncoin network client.
Definition: clientmodel.h:45
void setModel(WalletModel *model)
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:227
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:201
EncryptionStatus getEncryptionStatus() const
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:154
void showOutOfSyncWarning(bool fShow)
void setModel(WalletModel *model)
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:177
Interface to Anoncoin wallet from Qt view code.
Definition: walletmodel.h:97
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:286
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:260
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:100
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
void setAnoncoinGUI(AnoncoinGUI *gui)
Definition: walletview.cpp:82
Ask old passphrase + new passphrase twice.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:216
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:60
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:164
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void setModel(WalletModel *model)
Overview ("home") page widget.
Definition: overviewpage.h:25
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:206
QProgressDialog * progressDialog
Definition: walletview.h:65
OptionsModel * getOptionsModel()
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:75
void setAddress_SM(const QString &address)
void setModel(WalletModel *model)