Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
walletview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 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 "optionsmodel.h"
13 #include "overviewpage.h"
14 #include "receivecoinsdialog.h"
15 #include "sendcoinsdialog.h"
16 #include "sendmpdialog.h"
18 #include "transactiontablemodel.h"
19 #include "transactionview.h"
20 #include "balancesview.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 <QProgressDialog>
30 #include <QPushButton>
31 #include <QVBoxLayout>
32 
33 #include <QDebug>
34 #include <QTableView>
35 #include <QDialog>
36 #include <QHeaderView>
37 
39  QStackedWidget(parent),
40  clientModel(0),
41  walletModel(0)
42 {
43  // Create tabs
44  overviewPage = new OverviewPage();
45  transactionsPage = new QWidget(this);
46  balancesPage = new QWidget(this);
47 
48  // balances page
49  QVBoxLayout *bvbox = new QVBoxLayout();
50  QHBoxLayout *bhbox_buttons = new QHBoxLayout();
51  balancesView = new BalancesView(this);
52  bvbox->addWidget(balancesView);
53  QPushButton *bexportButton = new QPushButton(tr("&Export"), this);
54  bexportButton->setToolTip(tr("Export the data in the current tab to a file"));
55 #ifndef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
56  bexportButton->setIcon(QIcon(":/icons/export"));
57 #endif
58  bhbox_buttons->addStretch();
59  bhbox_buttons->addWidget(bexportButton);
60  bvbox->addLayout(bhbox_buttons);
61  balancesPage->setLayout(bvbox);
62 
63  // transactions page
64  QVBoxLayout *vbox = new QVBoxLayout();
65  QHBoxLayout *hbox_buttons = new QHBoxLayout();
66  transactionView = new TransactionView(this);
67  vbox->addWidget(transactionView);
68  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
69  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
70 #ifndef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
71  exportButton->setIcon(QIcon(":/icons/export"));
72 #endif
73  hbox_buttons->addStretch();
74  hbox_buttons->addWidget(exportButton);
75  vbox->addLayout(hbox_buttons);
76  transactionsPage->setLayout(vbox);
77 
79 
80  // sending page
81  //sendCoinsPage = new SendCoinsDialog();
82  sendCoinsPage = new QWidget(this);
83  QVBoxLayout *svbox = new QVBoxLayout();
85  sendMPTab = new SendMPDialog();
86  QTabWidget *tabHolder = new QTabWidget();
87  tabHolder->addTab(sendMPTab,tr("Master Protocol"));
88  tabHolder->addTab(sendCoinsTab,tr("Bitcoin"));
89 // tabHolder->addTab(new QWidget(),tr("Smart Properties"));
90  svbox->addWidget(tabHolder);
91  sendCoinsPage->setLayout(svbox);
92 
93  // add pages
94  addWidget(overviewPage);
95  addWidget(balancesPage);
96  addWidget(transactionsPage);
97  addWidget(receiveCoinsPage);
98  addWidget(sendCoinsPage);
99 
100  // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
101  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
102 
103 // connect(showAllBalancesLabel, SIGNAL(clicked()), overviewPage, SLOT(WalletView::gotoBalancesPage()));
104 
105  // Double-clicking on a transaction on the transaction history page shows details
106  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
107 
108  // Clicking on "Export" allows to export the transaction list
109  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
110 
111  // Pass through messages from sendCoinsPage
112  connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
113  // Pass through messages from transactionView
114  connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
115 }
116 
118 {
119 }
120 
122 {
123  if (gui)
124  {
125  // Clicking on a transaction on the overview page simply sends you to transaction history page
126  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
127 
128  // Receive and report messages
129  connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
130 
131  // Pass through encryption status changed signals
132  connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
133 
134  // Pass through transaction notifications
135  connect(this, SIGNAL(incomingTransaction(QString,int,qint64,QString,QString)), gui, SLOT(incomingTransaction(QString,int,qint64,QString,QString)));
136  }
137 }
138 
140 {
141  this->clientModel = clientModel;
142 
143  overviewPage->setClientModel(clientModel);
144 }
145 
147 {
148  this->walletModel = walletModel;
149 
150  // Put transaction list in tabs
151  transactionView->setModel(walletModel);
152  overviewPage->setWalletModel(walletModel);
153  receiveCoinsPage->setModel(walletModel);
154  sendCoinsTab->setModel(walletModel);
155  sendMPTab->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  // Balloon pop-up for new transaction
167  connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
168  this, SLOT(processNewTransaction(QModelIndex,int,int)));
169 
170  // Ask for passphrase if needed
171  connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
172 
173  // Show progress dialog
174  connect(walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
175  }
176 }
177 
178 void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
179 {
180  // Prevent balloon-spam when initial block download is in progress
182  return;
183 
185 
186  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
187  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
188  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
189  QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString();
190 
191  emit incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
192 }
193 
195 {
196  setCurrentWidget(overviewPage);
197 }
198 
200 {
201  setCurrentWidget(balancesPage);
202 }
203 
205 {
206  setCurrentWidget(transactionsPage);
207 }
208 
210 {
211  setCurrentWidget(receiveCoinsPage);
212 }
213 
215 {
216  setCurrentWidget(sendCoinsPage);
217 
218  if (!addr.isEmpty())
219  sendCoinsTab->setAddress(addr);
220 }
221 
223 {
224  // calls show() in showTab_SM()
225  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
226  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
227  signVerifyMessageDialog->setModel(walletModel);
228  signVerifyMessageDialog->showTab_SM(true);
229 
230  if (!addr.isEmpty())
231  signVerifyMessageDialog->setAddress_SM(addr);
232 }
233 
235 {
236  // calls show() in showTab_VM()
237  SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
238  signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
239  signVerifyMessageDialog->setModel(walletModel);
240  signVerifyMessageDialog->showTab_VM(true);
241 
242  if (!addr.isEmpty())
243  signVerifyMessageDialog->setAddress_VM(addr);
244 }
245 
247 {
248  return sendCoinsTab->handlePaymentRequest(recipient);
249 }
250 
252 {
254 }
255 
257 {
259 }
260 
261 void WalletView::encryptWallet(bool status)
262 {
263  if(!walletModel)
264  return;
266  dlg.setModel(walletModel);
267  dlg.exec();
268 
270 }
271 
273 {
274  QString filename = GUIUtil::getSaveFileName(this,
275  tr("Backup Wallet"), QString(),
276  tr("Wallet Data (*.dat)"), NULL);
277 
278  if (filename.isEmpty())
279  return;
280 
281  if (!walletModel->backupWallet(filename)) {
282  emit message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
284  }
285  else {
286  emit message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
288  }
289 }
290 
292 {
294  dlg.setModel(walletModel);
295  dlg.exec();
296 }
297 
299 {
300  if(!walletModel)
301  return;
302  // Unlock wallet when requested by wallet model
304  {
306  dlg.setModel(walletModel);
307  dlg.exec();
308  }
309 }
310 
312 {
313  if(!walletModel)
314  return;
316  dlg->setAttribute(Qt::WA_DeleteOnClose);
318  dlg->show();
319 }
320 
322 {
323  if(!walletModel)
324  return;
326  dlg->setAttribute(Qt::WA_DeleteOnClose);
328  dlg->show();
329 }
330 
331 void WalletView::showProgress(const QString &title, int nProgress)
332 {
333  if (nProgress == 0)
334  {
335  progressDialog = new QProgressDialog(title, "", 0, 100);
336  progressDialog->setWindowModality(Qt::ApplicationModal);
337  progressDialog->setMinimumDuration(0);
338  progressDialog->setCancelButton(0);
339  progressDialog->setAutoClose(false);
340  progressDialog->setValue(0);
341  }
342  else if (nProgress == 100)
343  {
344  if (progressDialog)
345  {
346  progressDialog->close();
347  progressDialog->deleteLater();
348  }
349  }
350  else if (progressDialog)
351  progressDialog->setValue(nProgress);
352 }
QWidget * transactionsPage
Definition: walletview.h:60
Dialog for requesting payment of bitcoins.
void setWalletModel(WalletModel *walletModel)
QWidget * balancesPage
Definition: walletview.h:61
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:234
OverviewPage * overviewPage
Definition: walletview.h:59
TransactionView * transactionView
Definition: walletview.h:69
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:311
void setAddress_VM(const QString &address)
void setModel(AddressTableModel *model)
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:291
ClientModel * clientModel
Definition: walletview.h:56
WalletView(QWidget *parent)
Definition: walletview.cpp:38
Ask passphrase twice and encrypt.
bool backupWallet(const QString &filename)
Dialog for sending Master Protocol tokens.
Definition: sendmpdialog.h:26
WalletModel * walletModel
Definition: walletview.h:57
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Open address book for editing.
Bitcoin GUI main class.
Definition: bitcoingui.h:35
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:214
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:256
BalancesView * balancesView
Definition: walletview.h:70
void processNewTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:178
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:204
Ask passphrase and unlock.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:121
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:321
void gotoBalancesPage()
Switch to balances page.
Definition: walletview.cpp:199
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:146
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:298
Dialog for sending bitcoins.
TransactionTableModel * getTransactionTableModel()
int getDisplayUnit()
Definition: optionsmodel.h:58
Widget that shows a list of sending or receiving addresses.
Widget showing the transaction list for a wallet, including a filter row.
Definition: balancesview.h:29
UI model for the transaction table of a wallet.
Model for Bitcoin network client.
Definition: clientmodel.h:36
void setModel(WalletModel *model)
SendMPDialog * sendMPTab
Definition: walletview.h:67
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:272
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:246
EncryptionStatus getEncryptionStatus() const
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:194
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:222
SendCoinsDialog * sendCoinsTab
Definition: walletview.h:66
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:96
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
Definition: walletview.cpp:331
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:254
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:139
void setModel(WalletModel *model)
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
Ask old passphrase + new passphrase twice.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:261
ReceiveCoinsDialog * receiveCoinsPage
Definition: walletview.h:63
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:209
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QWidget * sendCoinsPage
Definition: walletview.h:65
void setModel(WalletModel *model)
Overview ("home") page widget.
Definition: overviewpage.h:24
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:251
QProgressDialog * progressDialog
Definition: walletview.h:72
OptionsModel * getOptionsModel()
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:69
void setAddress_SM(const QString &address)
void setModel(WalletModel *model)