2013-03-22 18:32:49 +01:00
|
|
|
/*
|
|
|
|
* Qt4 bitcoin GUI.
|
|
|
|
*
|
|
|
|
* W.J. van der Laan 2011-2012
|
|
|
|
* The Bitcoin Developers 2011-2013
|
|
|
|
*/
|
|
|
|
#include "walletview.h"
|
|
|
|
#include "bitcoingui.h"
|
|
|
|
#include "transactiontablemodel.h"
|
|
|
|
#include "addressbookpage.h"
|
|
|
|
#include "sendcoinsdialog.h"
|
2013-10-16 15:14:26 +02:00
|
|
|
#include "receivecoinsdialog.h"
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "signverifymessagedialog.h"
|
|
|
|
#include "clientmodel.h"
|
|
|
|
#include "walletmodel.h"
|
|
|
|
#include "optionsmodel.h"
|
|
|
|
#include "transactionview.h"
|
|
|
|
#include "overviewpage.h"
|
|
|
|
#include "askpassphrasedialog.h"
|
|
|
|
#include "ui_interface.h"
|
2013-10-26 19:28:47 +02:00
|
|
|
#include "guiutil.h"
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2013-04-25 16:10:01 +02:00
|
|
|
#include <QHBoxLayout>
|
2013-03-22 18:32:49 +01:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QAction>
|
2013-04-12 12:24:41 +02:00
|
|
|
#include <QPushButton>
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2013-10-18 18:05:26 +02:00
|
|
|
WalletView::WalletView(QWidget *parent):
|
2013-03-22 18:32:49 +01:00
|
|
|
QStackedWidget(parent),
|
|
|
|
clientModel(0),
|
2013-04-03 17:29:02 +02:00
|
|
|
walletModel(0)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
// Create tabs
|
|
|
|
overviewPage = new OverviewPage();
|
|
|
|
|
|
|
|
transactionsPage = new QWidget(this);
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout();
|
2013-04-12 12:24:41 +02:00
|
|
|
QHBoxLayout *hbox_buttons = new QHBoxLayout();
|
2013-03-22 18:32:49 +01:00
|
|
|
transactionView = new TransactionView(this);
|
|
|
|
vbox->addWidget(transactionView);
|
2013-04-25 16:10:01 +02:00
|
|
|
QPushButton *exportButton = new QPushButton(tr("&Export"), this);
|
2013-04-12 12:24:41 +02:00
|
|
|
exportButton->setToolTip(tr("Export the data in the current tab to a file"));
|
|
|
|
#ifndef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
|
|
|
|
exportButton->setIcon(QIcon(":/icons/export"));
|
|
|
|
#endif
|
|
|
|
hbox_buttons->addStretch();
|
|
|
|
hbox_buttons->addWidget(exportButton);
|
|
|
|
vbox->addLayout(hbox_buttons);
|
2013-03-22 18:32:49 +01:00
|
|
|
transactionsPage->setLayout(vbox);
|
|
|
|
|
2013-10-25 15:09:15 +02:00
|
|
|
receiveCoinsPage = new ReceiveCoinsDialog();
|
|
|
|
sendCoinsPage = new SendCoinsDialog();
|
2013-03-22 18:32:49 +01:00
|
|
|
|
|
|
|
addWidget(overviewPage);
|
|
|
|
addWidget(transactionsPage);
|
|
|
|
addWidget(receiveCoinsPage);
|
|
|
|
addWidget(sendCoinsPage);
|
|
|
|
|
|
|
|
// Clicking on a transaction on the overview page simply sends you to transaction history page
|
|
|
|
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
|
|
|
|
|
|
|
|
// Double-clicking on a transaction on the transaction history page shows details
|
|
|
|
connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
|
|
|
|
|
2013-04-12 12:24:41 +02:00
|
|
|
// Clicking on "Export" allows to export the transaction list
|
|
|
|
connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
|
2013-10-25 16:10:43 +02:00
|
|
|
|
|
|
|
// Pass through messages from sendCoinsPage
|
|
|
|
connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WalletView::~WalletView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::setBitcoinGUI(BitcoinGUI *gui)
|
|
|
|
{
|
2013-10-24 15:49:13 +02:00
|
|
|
if (gui)
|
2013-10-18 18:43:07 +02:00
|
|
|
{
|
2013-10-24 15:49:13 +02:00
|
|
|
// Clicking on a transaction on the overview page sends you to the transactions tab
|
2013-10-18 18:43:07 +02:00
|
|
|
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
|
2013-10-24 15:49:13 +02:00
|
|
|
|
|
|
|
// Receive and report messages
|
|
|
|
connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
|
2013-10-25 16:10:43 +02:00
|
|
|
|
|
|
|
// Pass through encryption status changed signals
|
|
|
|
connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
|
|
|
|
|
|
|
|
// Pass through transaction notifications
|
|
|
|
connect(this, SIGNAL(incomingTransaction(QString,int,qint64,QString,QString)), gui, SLOT(incomingTransaction(QString,int,qint64,QString,QString)));
|
2013-10-18 18:43:07 +02:00
|
|
|
}
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::setClientModel(ClientModel *clientModel)
|
|
|
|
{
|
|
|
|
this->clientModel = clientModel;
|
2013-10-25 16:10:43 +02:00
|
|
|
|
|
|
|
overviewPage->setClientModel(clientModel);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::setWalletModel(WalletModel *walletModel)
|
|
|
|
{
|
|
|
|
this->walletModel = walletModel;
|
2013-10-25 16:10:43 +02:00
|
|
|
|
|
|
|
// Put transaction list in tabs
|
|
|
|
transactionView->setModel(walletModel);
|
|
|
|
overviewPage->setWalletModel(walletModel);
|
|
|
|
receiveCoinsPage->setModel(walletModel);
|
|
|
|
sendCoinsPage->setModel(walletModel);
|
|
|
|
|
|
|
|
if (walletModel)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
// Receive and report messages from wallet thread
|
2013-10-25 16:10:43 +02:00
|
|
|
connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2013-10-25 16:10:43 +02:00
|
|
|
// Handle changes in encryption status
|
|
|
|
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
|
|
|
|
updateEncryptionStatus();
|
2013-03-22 18:32:49 +01:00
|
|
|
|
|
|
|
// Balloon pop-up for new transaction
|
|
|
|
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
|
2013-10-25 16:10:43 +02:00
|
|
|
this, SLOT(processNewTransaction(QModelIndex,int,int)));
|
2013-03-22 18:32:49 +01:00
|
|
|
|
|
|
|
// Ask for passphrase if needed
|
|
|
|
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 16:10:43 +02:00
|
|
|
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
// Prevent balloon-spam when initial block download is in progress
|
2013-08-02 13:53:03 +02:00
|
|
|
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
|
2013-03-22 18:32:49 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
|
|
|
|
|
2013-04-25 16:10:01 +02:00
|
|
|
QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
|
|
|
|
qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
|
|
|
|
QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
|
|
|
|
QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString();
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2013-10-25 16:10:43 +02:00
|
|
|
emit incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoOverviewPage()
|
|
|
|
{
|
|
|
|
setCurrentWidget(overviewPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoHistoryPage()
|
|
|
|
{
|
|
|
|
setCurrentWidget(transactionsPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoReceiveCoinsPage()
|
|
|
|
{
|
|
|
|
setCurrentWidget(receiveCoinsPage);
|
|
|
|
}
|
|
|
|
|
2013-04-01 14:43:50 +02:00
|
|
|
void WalletView::gotoSendCoinsPage(QString addr)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
setCurrentWidget(sendCoinsPage);
|
|
|
|
|
2013-04-03 17:29:02 +02:00
|
|
|
if (!addr.isEmpty())
|
2013-04-01 14:43:50 +02:00
|
|
|
sendCoinsPage->setAddress(addr);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoSignMessageTab(QString addr)
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
// calls show() in showTab_SM()
|
|
|
|
SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
|
|
|
|
signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
signVerifyMessageDialog->setModel(walletModel);
|
2013-03-22 18:32:49 +01:00
|
|
|
signVerifyMessageDialog->showTab_SM(true);
|
|
|
|
|
2013-04-03 17:29:02 +02:00
|
|
|
if (!addr.isEmpty())
|
2013-03-22 18:32:49 +01:00
|
|
|
signVerifyMessageDialog->setAddress_SM(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoVerifyMessageTab(QString addr)
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
// calls show() in showTab_VM()
|
|
|
|
SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
|
|
|
|
signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
signVerifyMessageDialog->setModel(walletModel);
|
2013-03-22 18:32:49 +01:00
|
|
|
signVerifyMessageDialog->showTab_VM(true);
|
|
|
|
|
2013-04-03 17:29:02 +02:00
|
|
|
if (!addr.isEmpty())
|
2013-03-22 18:32:49 +01:00
|
|
|
signVerifyMessageDialog->setAddress_VM(addr);
|
|
|
|
}
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2013-10-24 15:49:13 +02:00
|
|
|
return sendCoinsPage->handlePaymentRequest(recipient);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::showOutOfSyncWarning(bool fShow)
|
|
|
|
{
|
|
|
|
overviewPage->showOutOfSyncWarning(fShow);
|
|
|
|
}
|
|
|
|
|
2013-10-25 16:10:43 +02:00
|
|
|
void WalletView::updateEncryptionStatus()
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2013-10-25 16:10:43 +02:00
|
|
|
emit encryptionStatusChanged(walletModel->getEncryptionStatus());
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::encryptWallet(bool status)
|
|
|
|
{
|
|
|
|
if(!walletModel)
|
|
|
|
return;
|
2013-04-25 16:10:01 +02:00
|
|
|
AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt : AskPassphraseDialog::Decrypt, this);
|
2013-03-22 18:32:49 +01:00
|
|
|
dlg.setModel(walletModel);
|
|
|
|
dlg.exec();
|
|
|
|
|
2013-10-25 16:10:43 +02:00
|
|
|
updateEncryptionStatus();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::backupWallet()
|
|
|
|
{
|
2013-10-26 19:28:47 +02:00
|
|
|
QString filename = GUIUtil::getSaveFileName(this,
|
|
|
|
tr("Backup Wallet"), QString(),
|
|
|
|
tr("Wallet Data (*.dat)"));
|
|
|
|
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!walletModel->backupWallet(filename)) {
|
|
|
|
emit message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
|
|
|
|
CClientUIInterface::MSG_ERROR);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
2013-10-26 19:28:47 +02:00
|
|
|
else {
|
|
|
|
emit message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
|
|
|
|
CClientUIInterface::MSG_INFORMATION);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::changePassphrase()
|
|
|
|
{
|
|
|
|
AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
|
|
|
|
dlg.setModel(walletModel);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::unlockWallet()
|
|
|
|
{
|
|
|
|
if(!walletModel)
|
|
|
|
return;
|
|
|
|
// Unlock wallet when requested by wallet model
|
2013-04-03 17:29:02 +02:00
|
|
|
if (walletModel->getEncryptionStatus() == WalletModel::Locked)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
|
|
|
|
dlg.setModel(walletModel);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 15:14:26 +02:00
|
|
|
|
|
|
|
void WalletView::usedSendingAddresses()
|
|
|
|
{
|
|
|
|
if(!walletModel)
|
|
|
|
return;
|
|
|
|
AddressBookPage *dlg = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab, this);
|
|
|
|
dlg->setModel(walletModel->getAddressTableModel());
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dlg->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::usedReceivingAddresses()
|
|
|
|
{
|
|
|
|
if(!walletModel)
|
|
|
|
return;
|
|
|
|
AddressBookPage *dlg = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this);
|
|
|
|
dlg->setModel(walletModel->getAddressTableModel());
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dlg->show();
|
|
|
|
}
|