Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
walletview.cpp
Go to the documentation of this file.
1 /*
2  * Qt4 bitcoin GUI.
3  *
4  * W.J. van der Laan 2011-2012
5  * The Bitcoin Developers 2011-2013
6  */
7 #include "walletview.h"
8 #include "bitcoingui.h"
10 #include "addressbookpage.h"
11 #include "sendcoinsdialog.h"
13 #include "clientmodel.h"
14 #include "walletmodel.h"
15 #include "optionsmodel.h"
16 #include "transactionview.h"
17 #include "overviewpage.h"
18 #include "askpassphrasedialog.h"
19 #include "ui_interface.h"
20 
21 #include <QHBoxLayout>
22 #include <QVBoxLayout>
23 #include <QAction>
24 #if QT_VERSION < 0x050000
25 #include <QDesktopServices>
26 #else
27 #include <QStandardPaths>
28 #endif
29 #include <QFileDialog>
30 #include <QPushButton>
31 
32 WalletView::WalletView(QWidget *parent, BitcoinGUI *_gui):
33  QStackedWidget(parent),
34  gui(_gui),
35  clientModel(0),
36  walletModel(0)
37 {
38  // Create tabs
39  overviewPage = new OverviewPage();
40 
41  transactionsPage = new QWidget(this);
42  QVBoxLayout *vbox = new QVBoxLayout();
43  QHBoxLayout *hbox_buttons = new QHBoxLayout();
44  transactionView = new TransactionView(this);
45  vbox->addWidget(transactionView);
46  QPushButton *exportButton = new QPushButton(tr("&Export"), this);
47  exportButton->setToolTip(tr("Export the data in the current tab to a file"));
48 #ifndef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
49  exportButton->setIcon(QIcon(":/icons/export"));
50 #endif
51  hbox_buttons->addStretch();
52  hbox_buttons->addWidget(exportButton);
53  vbox->addLayout(hbox_buttons);
54  transactionsPage->setLayout(vbox);
55 
57 
59 
61 
63 
64  addWidget(overviewPage);
65  addWidget(transactionsPage);
66  addWidget(addressBookPage);
67  addWidget(receiveCoinsPage);
68  addWidget(sendCoinsPage);
69 
70  // Clicking on a transaction on the overview page simply sends you to transaction history page
71  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
72  connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
73 
74  // Double-clicking on a transaction on the transaction history page shows details
75  connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
76 
77  connect(receiveCoinsPage, SIGNAL(importWallet(QString)), this, SLOT(importWallet(QString)));
78  // Clicking on "Send Coins" in the address book sends you to the send coins tab
79  connect(addressBookPage, SIGNAL(sendCoins(QString)), this, SLOT(gotoSendCoinsPage(QString)));
80  // Clicking on "Send to QR" sends you to the send coins tab after snapping and reading image
81  connect(sendCoinsPage, SIGNAL(sendCoins(QString)), this, SLOT(gotoSendCoinsPage(QString)));
82  // Clicking on "Verify Message" in the address book opens the verify message tab in the Sign/Verify Message dialog
83  connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
84  // Clicking on "Sign Message" in the receive coins page opens the sign message tab in the Sign/Verify Message dialog
85  connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
86  // Clicking on "Export" allows to export the transaction list
87  connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
88 
90 }
91 
93 {
94 }
95 
97 {
98  this->gui = gui;
99 }
100 
102 {
103  this->clientModel = clientModel;
104  if (clientModel)
105  {
106  overviewPage->setClientModel(clientModel);
109  }
110 }
111 
113 {
114  this->walletModel = walletModel;
115  if (walletModel)
116  {
117  // Receive and report messages from wallet thread
118  connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
119 
120  // Put transaction list in tabs
121  transactionView->setModel(walletModel);
122  overviewPage->setWalletModel(walletModel);
125  sendCoinsPage->setModel(walletModel);
126  signVerifyMessageDialog->setModel(walletModel);
127 
129  connect(walletModel, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
130 
131  // Balloon pop-up for new transaction
132  connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
133  this, SLOT(incomingTransaction(QModelIndex,int,int)));
134 
135  // Ask for passphrase if needed
136  connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
137  }
138 }
139 
140 void WalletView::incomingTransaction(const QModelIndex& parent, int start, int /*end*/)
141 {
142  // Prevent balloon-spam when initial block download is in progress
144  return;
145 
147 
148  QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
149  qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
150  QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
151  QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString();
152 
153  gui->incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
154 }
155 
157 {
158  gui->getOverviewAction()->setChecked(true);
159  setCurrentWidget(overviewPage);
160 }
161 
163 {
164  gui->getHistoryAction()->setChecked(true);
165  setCurrentWidget(transactionsPage);
166 }
167 
169 {
170  gui->getAddressBookAction()->setChecked(true);
171  setCurrentWidget(addressBookPage);
172 }
173 
175 {
176  gui->getReceiveCoinsAction()->setChecked(true);
177  setCurrentWidget(receiveCoinsPage);
178 }
179 
181 {
182  gui->getSendCoinsAction()->setChecked(true);
183  setCurrentWidget(sendCoinsPage);
184 
185  if (!addr.isEmpty())
186  sendCoinsPage->setAddress(addr);
187 }
188 
190 {
191  // call show() in showTab_SM()
193 
194  if (!addr.isEmpty())
196 }
197 
199 {
200  // call show() in showTab_VM()
202 
203  if (!addr.isEmpty())
205 }
206 
207 void WalletView::importWallet(QString privateKey)
208 {
209  bool b =walletModel->importPrivateKey(privateKey);
210 }
211 
212 bool WalletView::handleURI(const QString& strURI)
213 {
214  // URI has to be valid
215  if (sendCoinsPage->handleURI(strURI))
216  {
218  emit showNormalIfMinimized();
219  return true;
220  }
221  else
222  return false;
223 }
224 
226 {
228 }
229 
231 {
233 }
234 
235 void WalletView::encryptWallet(bool status)
236 {
237  if(!walletModel)
238  return;
240  dlg.setModel(walletModel);
241  dlg.exec();
242 
244 }
245 
247 {
248 #if QT_VERSION < 0x050000
249  QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
250 #else
251  QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
252 #endif
253  QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
254  if (!filename.isEmpty()) {
255  if (!walletModel->backupWallet(filename)) {
256  gui->message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."),
258  }
259  else
260  gui->message(tr("Backup Successful"), tr("The wallet data was successfully saved to the new location."),
262  }
263 }
264 
266 {
268  dlg.setModel(walletModel);
269  dlg.exec();
270 }
271 
273 {
274  if(!walletModel)
275  return;
276  // Unlock wallet when requested by wallet model
278  {
280  dlg.setModel(walletModel);
281  dlg.exec();
282  }
283 }
QWidget * transactionsPage
Definition: walletview.h:62
void gotoAddressBookPage()
Switch to address book page.
Definition: walletview.cpp:168
void setWalletModel(WalletModel *walletModel)
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:198
OverviewPage * overviewPage
Definition: walletview.h:61
TransactionView * transactionView
Definition: walletview.h:68
void setAddress_VM(const QString &address)
void setModel(AddressTableModel *model)
QAction * getHistoryAction()
Definition: bitcoingui.h:66
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:265
ClientModel * clientModel
Definition: walletview.h:58
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:190
void importWallet(QString privateKey)
Import a wallet from a string.
Definition: walletview.cpp:207
bool start
Definition: db_bench.cc:282
Ask passphrase twice and encrypt.
bool backupWallet(const QString &filename)
AddressBookPage * receiveCoinsPage
Definition: walletview.h:64
WalletModel * walletModel
Definition: walletview.h:59
OptionsModel * getOptionsModel()
Open address book for editing.
Bitcoin GUI main class.
Definition: bitcoingui.h:39
void incomingTransaction(const QModelIndex &parent, int start, int)
Show incoming transaction notification for new transactions.
Definition: walletview.cpp:140
AddressTableModel * getAddressTableModel()
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletview.cpp:180
SendCoinsDialog * sendCoinsPage
Definition: walletview.h:65
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletview.cpp:162
QAction * getOverviewAction()
Used by WalletView to allow access to needed QActions.
Definition: bitcoingui.h:65
Ask passphrase and unlock.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:96
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:112
void setAddress(const QString &address)
Widget showing the transaction list for a wallet, including a filter row.
bool handleURI(const QString &uri)
void incomingTransaction(const QString &date, int unit, qint64 amount, const QString &type, const QString &address)
Show incoming transaction notification for new transactions.
Definition: bitcoingui.cpp:715
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:272
Dialog for sending bitcoins.
void setOptionsModel(OptionsModel *optionsModel)
TransactionTableModel * getTransactionTableModel()
int getDisplayUnit()
Definition: optionsmodel.h:50
Widget that shows a list of sending or receiving addresses.
UI model for the transaction table of a wallet.
QAction * getReceiveCoinsAction()
Definition: bitcoingui.h:68
Model for Bitcoin network client.
Definition: clientmodel.h:24
void setModel(WalletModel *model)
void showNormalIfMinimized()
Signal that we want to show the main window.
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:246
EncryptionStatus getEncryptionStatus() const
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:156
AddressBookPage * addressBookPage
Definition: walletview.h:63
void showOutOfSyncWarning(bool fShow)
QAction * getAddressBookAction()
Definition: bitcoingui.h:67
void setModel(WalletModel *model)
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:189
bool importPrivateKey(QString privKey)
BitcoinGUI * gui
Definition: walletview.h:57
void setEncryptionStatus(int status)
Set the encryption status as shown in the UI.
Definition: bitcoingui.cpp:779
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:36
Multifunctional dialog to ask for passphrases.
SignVerifyMessageDialog * signVerifyMessageDialog
Definition: walletview.h:66
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:101
Ask passphrase and decrypt wallet.
void setClientModel(ClientModel *clientModel)
Ask old passphrase + new passphrase twice.
void message(const QString &title, const QString &message, unsigned int style, bool *ret=NULL)
Notify the user of an event from the core network or transaction handling code.
Definition: bitcoingui.cpp:619
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:235
bool handleURI(const QString &uri)
Definition: walletview.cpp:212
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletview.cpp:174
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void setModel(WalletModel *model)
WalletView(QWidget *parent, BitcoinGUI *_gui)
Definition: walletview.cpp:32
Overview ("home") page widget.
Definition: overviewpage.h:19
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:225
OptionsModel * getOptionsModel()
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:65
QAction * getSendCoinsAction()
Definition: bitcoingui.h:69
void setEncryptionStatus()
Definition: walletview.cpp:230
void setAddress_SM(const QString &address)
void setModel(WalletModel *model)