|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
#include "receivecoinsdialog.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QAction>
|
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#else
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#endif
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
WalletView::WalletView(QWidget *parent):
|
|
|
|
QStackedWidget(parent),
|
|
|
|
clientModel(0),
|
|
|
|
walletModel(0)
|
|
|
|
{
|
|
|
|
// Create tabs
|
|
|
|
overviewPage = new OverviewPage();
|
|
|
|
|
|
|
|
transactionsPage = new QWidget(this);
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout();
|
|
|
|
QHBoxLayout *hbox_buttons = new QHBoxLayout();
|
|
|
|
transactionView = new TransactionView(this);
|
|
|
|
vbox->addWidget(transactionView);
|
|
|
|
QPushButton *exportButton = new QPushButton(tr("&Export"), this);
|
|
|
|
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);
|
|
|
|
transactionsPage->setLayout(vbox);
|
|
|
|
|
|
|
|
receiveCoinsPage = new ReceiveCoinsDialog();
|
|
|
|
sendCoinsPage = new SendCoinsDialog();
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
|
|
|
// Clicking on "Export" allows to export the transaction list
|
|
|
|
connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
|
|
|
|
|
|
|
|
// Pass through messages from sendCoinsPage
|
|
|
|
connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletView::~WalletView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::setBitcoinGUI(BitcoinGUI *gui)
|
|
|
|
{
|
|
|
|
if (gui)
|
|
|
|
{
|
|
|
|
// Clicking on a transaction on the overview page sends you to the transactions tab
|
|
|
|
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
|
|
|
|
|
|
|
|
// Receive and report messages
|
|
|
|
connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
|
|
|
|
|
|
|
|
// 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)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::setClientModel(ClientModel *clientModel)
|
|
|
|
{
|
|
|
|
this->clientModel = clientModel;
|
|
|
|
|
|
|
|
overviewPage->setClientModel(clientModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::setWalletModel(WalletModel *walletModel)
|
|
|
|
{
|
|
|
|
this->walletModel = walletModel;
|
|
|
|
|
|
|
|
// Put transaction list in tabs
|
|
|
|
transactionView->setModel(walletModel);
|
|
|
|
overviewPage->setWalletModel(walletModel);
|
|
|
|
receiveCoinsPage->setModel(walletModel);
|
|
|
|
sendCoinsPage->setModel(walletModel);
|
|
|
|
|
|
|
|
if (walletModel)
|
|
|
|
{
|
|
|
|
// Receive and report messages from wallet thread
|
|
|
|
connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
|
|
|
|
|
|
|
|
// Handle changes in encryption status
|
|
|
|
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
|
|
|
|
updateEncryptionStatus();
|
|
|
|
|
|
|
|
// Balloon pop-up for new transaction
|
|
|
|
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
|
|
this, SLOT(processNewTransaction(QModelIndex,int,int)));
|
|
|
|
|
|
|
|
// Ask for passphrase if needed
|
|
|
|
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
|
|
|
|
{
|
|
|
|
// Prevent balloon-spam when initial block download is in progress
|
|
|
|
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
|
|
|
|
return;
|
|
|
|
|
|
|
|
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
emit incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoOverviewPage()
|
|
|
|
{
|
|
|
|
setCurrentWidget(overviewPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoHistoryPage()
|
|
|
|
{
|
|
|
|
setCurrentWidget(transactionsPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoReceiveCoinsPage()
|
|
|
|
{
|
|
|
|
setCurrentWidget(receiveCoinsPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoSendCoinsPage(QString addr)
|
|
|
|
{
|
|
|
|
setCurrentWidget(sendCoinsPage);
|
|
|
|
|
|
|
|
if (!addr.isEmpty())
|
|
|
|
sendCoinsPage->setAddress(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoSignMessageTab(QString addr)
|
|
|
|
{
|
|
|
|
// calls show() in showTab_SM()
|
|
|
|
SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
|
|
|
|
signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
signVerifyMessageDialog->setModel(walletModel);
|
|
|
|
signVerifyMessageDialog->showTab_SM(true);
|
|
|
|
|
|
|
|
if (!addr.isEmpty())
|
|
|
|
signVerifyMessageDialog->setAddress_SM(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::gotoVerifyMessageTab(QString addr)
|
|
|
|
{
|
|
|
|
// calls show() in showTab_VM()
|
|
|
|
SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
|
|
|
|
signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
signVerifyMessageDialog->setModel(walletModel);
|
|
|
|
signVerifyMessageDialog->showTab_VM(true);
|
|
|
|
|
|
|
|
if (!addr.isEmpty())
|
|
|
|
signVerifyMessageDialog->setAddress_VM(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)
|
|
|
|
{
|
|
|
|
return sendCoinsPage->handlePaymentRequest(recipient);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::showOutOfSyncWarning(bool fShow)
|
|
|
|
{
|
|
|
|
overviewPage->showOutOfSyncWarning(fShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::updateEncryptionStatus()
|
|
|
|
{
|
|
|
|
emit encryptionStatusChanged(walletModel->getEncryptionStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::encryptWallet(bool status)
|
|
|
|
{
|
|
|
|
if(!walletModel)
|
|
|
|
return;
|
|
|
|
AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt : AskPassphraseDialog::Decrypt, this);
|
|
|
|
dlg.setModel(walletModel);
|
|
|
|
dlg.exec();
|
|
|
|
|
|
|
|
updateEncryptionStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::backupWallet()
|
|
|
|
{
|
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
|
|
|
|
#else
|
|
|
|
QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
|
|
|
#endif
|
|
|
|
QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
if (!walletModel->backupWallet(filename)) {
|
|
|
|
emit message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."),
|
|
|
|
CClientUIInterface::MSG_ERROR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
emit message(tr("Backup Successful"), tr("The wallet data was successfully saved to the new location."),
|
|
|
|
CClientUIInterface::MSG_INFORMATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
if (walletModel->getEncryptionStatus() == WalletModel::Locked)
|
|
|
|
{
|
|
|
|
AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
|
|
|
|
dlg.setModel(walletModel);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|