2016-12-31 19:01:21 +01:00
|
|
|
// Copyright (c) 2011-2016 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "walletview.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "addressbookpage.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "askpassphrasedialog.h"
|
|
|
|
#include "bitcoingui.h"
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "clientmodel.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "guiutil.h"
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "optionsmodel.h"
|
|
|
|
#include "overviewpage.h"
|
2015-07-28 15:20:14 +02:00
|
|
|
#include "platformstyle.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "receivecoinsdialog.h"
|
|
|
|
#include "sendcoinsdialog.h"
|
|
|
|
#include "signverifymessagedialog.h"
|
|
|
|
#include "transactiontablemodel.h"
|
|
|
|
#include "transactionview.h"
|
|
|
|
#include "walletmodel.h"
|
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "ui_interface.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QActionGroup>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QHBoxLayout>
|
2014-03-19 00:26:14 +01:00
|
|
|
#include <QProgressDialog>
|
2013-04-12 12:24:41 +02:00
|
|
|
#include <QPushButton>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QVBoxLayout>
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
|
2013-03-22 18:32:49 +01:00
|
|
|
QStackedWidget(parent),
|
|
|
|
clientModel(0),
|
2015-07-28 15:20:14 +02:00
|
|
|
walletModel(0),
|
2016-09-09 13:43:29 +02:00
|
|
|
platformStyle(_platformStyle)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
// Create tabs
|
2015-07-28 15:20:14 +02:00
|
|
|
overviewPage = new OverviewPage(platformStyle);
|
2013-03-22 18:32:49 +01:00
|
|
|
|
|
|
|
transactionsPage = new QWidget(this);
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout();
|
2013-04-12 12:24:41 +02:00
|
|
|
QHBoxLayout *hbox_buttons = new QHBoxLayout();
|
2015-07-28 15:20:14 +02:00
|
|
|
transactionView = new TransactionView(platformStyle, this);
|
2013-03-22 18:32:49 +01:00
|
|
|
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"));
|
2015-07-28 15:20:14 +02:00
|
|
|
if (platformStyle->getImagesOnButtons()) {
|
|
|
|
exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
|
|
|
|
}
|
2013-04-12 12:24:41 +02:00
|
|
|
hbox_buttons->addStretch();
|
|
|
|
hbox_buttons->addWidget(exportButton);
|
|
|
|
vbox->addLayout(hbox_buttons);
|
2013-03-22 18:32:49 +01:00
|
|
|
transactionsPage->setLayout(vbox);
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
receiveCoinsPage = new ReceiveCoinsDialog(platformStyle);
|
|
|
|
sendCoinsPage = new SendCoinsDialog(platformStyle);
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2015-08-27 21:53:16 +02:00
|
|
|
usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this);
|
|
|
|
usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this);
|
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
addWidget(overviewPage);
|
|
|
|
addWidget(transactionsPage);
|
|
|
|
addWidget(receiveCoinsPage);
|
|
|
|
addWidget(sendCoinsPage);
|
|
|
|
|
2013-10-26 19:31:42 +02:00
|
|
|
// Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
|
2013-03-22 18:32:49 +01:00
|
|
|
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
|
2016-09-21 10:29:57 +02:00
|
|
|
connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
|
2013-03-22 18:32:49 +01:00
|
|
|
|
|
|
|
// 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-10-26 19:12:29 +02:00
|
|
|
// Pass through messages from transactionView
|
|
|
|
connect(transactionView, 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-26 19:31:42 +02:00
|
|
|
// Clicking on a transaction on the overview page simply sends you to transaction history page
|
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
|
2015-02-26 21:57:08 +01:00
|
|
|
connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString)));
|
2016-08-17 14:09:47 +02:00
|
|
|
|
|
|
|
// Connect HD enabled state signal
|
|
|
|
connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
|
2013-10-18 18:43:07 +02:00
|
|
|
}
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void WalletView::setClientModel(ClientModel *_clientModel)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->clientModel = _clientModel;
|
2013-10-25 16:10:43 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
overviewPage->setClientModel(_clientModel);
|
|
|
|
sendCoinsPage->setClientModel(_clientModel);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void WalletView::setWalletModel(WalletModel *_walletModel)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->walletModel = _walletModel;
|
2013-10-25 16:10:43 +02:00
|
|
|
|
|
|
|
// Put transaction list in tabs
|
2016-09-09 13:43:29 +02:00
|
|
|
transactionView->setModel(_walletModel);
|
|
|
|
overviewPage->setWalletModel(_walletModel);
|
|
|
|
receiveCoinsPage->setModel(_walletModel);
|
|
|
|
sendCoinsPage->setModel(_walletModel);
|
2017-10-02 17:20:08 +02:00
|
|
|
usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
|
|
|
|
usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
|
2016-09-09 13:43:29 +02:00
|
|
|
|
|
|
|
if (_walletModel)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2013-10-26 19:12:29 +02:00
|
|
|
// Receive and pass through messages from wallet model
|
2016-09-09 13:43:29 +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
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
|
2013-10-25 16:10:43 +02:00
|
|
|
updateEncryptionStatus();
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2016-08-17 14:09:47 +02:00
|
|
|
// update HD status
|
2016-09-09 13:43:29 +02:00
|
|
|
Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled());
|
2016-08-17 14:09:47 +02:00
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
// Balloon pop-up for new transaction
|
2016-09-09 13:43:29 +02:00
|
|
|
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
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
|
2014-03-19 00:26:14 +01:00
|
|
|
|
|
|
|
// Show progress dialog
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2014-10-28 19:52:21 +01:00
|
|
|
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
|
2013-03-22 18:32:49 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
|
2014-10-28 19:52:21 +01:00
|
|
|
if (!ttm || ttm->processingQueuedTransactions())
|
|
|
|
return;
|
2013-03-22 18:32:49 +01:00
|
|
|
|
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();
|
2015-02-26 21:57:08 +01:00
|
|
|
QModelIndex index = ttm->index(start, 0, parent);
|
|
|
|
QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
|
|
|
|
QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label);
|
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()
|
2015-07-28 15:20:14 +02:00
|
|
|
SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
|
2013-10-18 18:05:26 +02:00
|
|
|
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()
|
2015-07-28 15:20:14 +02:00
|
|
|
SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);
|
2013-10-18 18:05:26 +02:00
|
|
|
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
|
|
|
{
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_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(),
|
2017-08-07 07:36:37 +02:00
|
|
|
tr("Wallet Data (*.dat)"), nullptr);
|
2013-10-26 19:28:47 +02:00
|
|
|
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!walletModel->backupWallet(filename)) {
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),
|
2013-10-26 19:28:47 +02:00
|
|
|
CClientUIInterface::MSG_ERROR);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
2013-10-26 19:28:47 +02:00
|
|
|
else {
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),
|
2013-10-26 19:28:47 +02:00
|
|
|
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;
|
2015-08-27 21:53:16 +02:00
|
|
|
|
|
|
|
usedSendingAddressesPage->show();
|
|
|
|
usedSendingAddressesPage->raise();
|
|
|
|
usedSendingAddressesPage->activateWindow();
|
2013-10-16 15:14:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletView::usedReceivingAddresses()
|
|
|
|
{
|
|
|
|
if(!walletModel)
|
|
|
|
return;
|
2015-08-27 21:53:16 +02:00
|
|
|
|
|
|
|
usedReceivingAddressesPage->show();
|
|
|
|
usedReceivingAddressesPage->raise();
|
|
|
|
usedReceivingAddressesPage->activateWindow();
|
2013-10-16 15:14:26 +02:00
|
|
|
}
|
2014-03-19 00:26:14 +01:00
|
|
|
|
|
|
|
void WalletView::showProgress(const QString &title, int nProgress)
|
|
|
|
{
|
|
|
|
if (nProgress == 0)
|
|
|
|
{
|
|
|
|
progressDialog = new QProgressDialog(title, "", 0, 100);
|
|
|
|
progressDialog->setWindowModality(Qt::ApplicationModal);
|
|
|
|
progressDialog->setMinimumDuration(0);
|
|
|
|
progressDialog->setCancelButton(0);
|
|
|
|
progressDialog->setAutoClose(false);
|
|
|
|
progressDialog->setValue(0);
|
|
|
|
}
|
|
|
|
else if (nProgress == 100)
|
|
|
|
{
|
|
|
|
if (progressDialog)
|
|
|
|
{
|
|
|
|
progressDialog->close();
|
|
|
|
progressDialog->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (progressDialog)
|
|
|
|
progressDialog->setValue(nProgress);
|
|
|
|
}
|
2016-07-19 15:27:14 +02:00
|
|
|
|
2016-09-21 10:29:57 +02:00
|
|
|
void WalletView::requestedSyncWarningInfo()
|
2016-07-19 15:27:14 +02:00
|
|
|
{
|
|
|
|
Q_EMIT outOfSyncWarningClicked();
|
|
|
|
}
|