2020-01-14 16:17:38 -03:00
|
|
|
// Copyright (c) 2011-2020 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 12:20:43 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/walletframe.h>
|
2013-04-13 02:13:08 -03:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/bitcoingui.h>
|
2020-10-25 16:12:58 -03:00
|
|
|
#include <qt/createwalletdialog.h>
|
|
|
|
#include <qt/overviewpage.h>
|
|
|
|
#include <qt/walletcontroller.h>
|
|
|
|
#include <qt/walletmodel.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/walletview.h>
|
2013-04-13 02:13:08 -03:00
|
|
|
|
2017-08-28 04:24:17 -03:00
|
|
|
#include <cassert>
|
2013-03-22 14:32:49 -03:00
|
|
|
|
2019-02-20 15:35:58 -03:00
|
|
|
#include <QGroupBox>
|
2013-05-31 08:02:24 -04:00
|
|
|
#include <QHBoxLayout>
|
2013-11-12 10:54:43 -03:00
|
|
|
#include <QLabel>
|
2019-02-20 15:35:58 -03:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
2013-03-22 14:32:49 -03:00
|
|
|
|
2020-10-25 16:12:58 -03:00
|
|
|
WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, BitcoinGUI* _gui)
|
|
|
|
: QFrame(_gui),
|
|
|
|
gui(_gui),
|
|
|
|
platformStyle(_platformStyle),
|
|
|
|
m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint())
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
|
|
|
// Leave HBox hook for adding a list view later
|
|
|
|
QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
|
2013-04-26 02:38:24 -03:00
|
|
|
setContentsMargins(0,0,0,0);
|
2013-10-18 13:05:26 -03:00
|
|
|
walletStack = new QStackedWidget(this);
|
2013-04-26 02:38:24 -03:00
|
|
|
walletFrameLayout->setContentsMargins(0,0,0,0);
|
2013-03-22 14:32:49 -03:00
|
|
|
walletFrameLayout->addWidget(walletStack);
|
2013-11-12 10:54:43 -03:00
|
|
|
|
2019-02-20 15:35:58 -03:00
|
|
|
// hbox for no wallet
|
|
|
|
QGroupBox* no_wallet_group = new QGroupBox(walletStack);
|
|
|
|
QVBoxLayout* no_wallet_layout = new QVBoxLayout(no_wallet_group);
|
|
|
|
|
|
|
|
QLabel *noWallet = new QLabel(tr("No wallet has been loaded.\nGo to File > Open Wallet to load a wallet.\n- OR -"));
|
2013-11-12 10:54:43 -03:00
|
|
|
noWallet->setAlignment(Qt::AlignCenter);
|
2019-02-20 15:35:58 -03:00
|
|
|
no_wallet_layout->addWidget(noWallet, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
|
|
|
|
|
|
|
// A button for create wallet dialog
|
|
|
|
QPushButton* create_wallet_button = new QPushButton(tr("Create a new wallet"), walletStack);
|
|
|
|
connect(create_wallet_button, &QPushButton::clicked, [this] {
|
|
|
|
auto activity = new CreateWalletActivity(gui->getWalletController(), this);
|
|
|
|
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
|
|
|
|
activity->create();
|
|
|
|
});
|
|
|
|
no_wallet_layout->addWidget(create_wallet_button, 0, Qt::AlignHCenter | Qt::AlignTop);
|
|
|
|
no_wallet_group->setLayout(no_wallet_layout);
|
|
|
|
|
|
|
|
walletStack->addWidget(no_wallet_group);
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
WalletFrame::~WalletFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
void WalletFrame::setClientModel(ClientModel *_clientModel)
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
2016-09-09 08:43:29 -03:00
|
|
|
this->clientModel = _clientModel;
|
2020-02-07 05:38:43 -03:00
|
|
|
|
|
|
|
for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
|
|
|
|
i.value()->setClientModel(_clientModel);
|
|
|
|
}
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2021-05-15 15:57:35 -04:00
|
|
|
bool WalletFrame::addWallet(WalletModel* walletModel, WalletView* walletView)
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
2019-09-26 17:43:44 -03:00
|
|
|
if (!gui || !clientModel || !walletModel) return false;
|
2017-10-12 04:22:48 -03:00
|
|
|
|
2019-09-26 17:43:44 -03:00
|
|
|
if (mapWalletViews.count(walletModel) > 0) return false;
|
2013-10-18 13:05:26 -03:00
|
|
|
|
|
|
|
walletView->setClientModel(clientModel);
|
|
|
|
walletView->setWalletModel(walletModel);
|
|
|
|
walletView->showOutOfSyncWarning(bOutOfSync);
|
|
|
|
|
2018-05-17 19:46:44 -04:00
|
|
|
WalletView* current_wallet_view = currentWalletView();
|
|
|
|
if (current_wallet_view) {
|
|
|
|
walletView->setCurrentIndex(current_wallet_view->currentIndex());
|
|
|
|
} else {
|
|
|
|
walletView->gotoOverviewPage();
|
|
|
|
}
|
|
|
|
|
2013-10-18 13:05:26 -03:00
|
|
|
walletStack->addWidget(walletView);
|
2018-11-22 08:36:07 -03:00
|
|
|
mapWalletViews[walletModel] = walletView;
|
2013-10-18 13:05:26 -03:00
|
|
|
|
2019-09-26 17:43:44 -03:00
|
|
|
return true;
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2019-02-22 13:26:00 -03:00
|
|
|
void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
2019-02-22 13:26:00 -03:00
|
|
|
if (mapWalletViews.count(wallet_model) == 0) return;
|
2013-10-18 13:05:26 -03:00
|
|
|
|
2021-01-05 17:33:28 -03:00
|
|
|
// Stop the effect of hidden widgets on the size hint of the shown one in QStackedWidget.
|
|
|
|
WalletView* view_about_to_hide = currentWalletView();
|
|
|
|
if (view_about_to_hide) {
|
|
|
|
QSizePolicy sp = view_about_to_hide->sizePolicy();
|
|
|
|
sp.setHorizontalPolicy(QSizePolicy::Ignored);
|
|
|
|
view_about_to_hide->setSizePolicy(sp);
|
|
|
|
}
|
|
|
|
|
2018-11-22 08:36:07 -03:00
|
|
|
WalletView *walletView = mapWalletViews.value(wallet_model);
|
2017-08-28 04:24:17 -03:00
|
|
|
assert(walletView);
|
2021-01-05 17:33:28 -03:00
|
|
|
|
|
|
|
// Set or restore the default QSizePolicy which could be set to QSizePolicy::Ignored previously.
|
|
|
|
QSizePolicy sp = walletView->sizePolicy();
|
|
|
|
sp.setHorizontalPolicy(QSizePolicy::Preferred);
|
|
|
|
walletView->setSizePolicy(sp);
|
|
|
|
walletView->updateGeometry();
|
|
|
|
|
|
|
|
walletStack->setCurrentWidget(walletView);
|
2013-10-25 11:10:43 -03:00
|
|
|
walletView->updateEncryptionStatus();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2019-02-22 13:26:00 -03:00
|
|
|
void WalletFrame::removeWallet(WalletModel* wallet_model)
|
2013-10-18 13:43:07 -03:00
|
|
|
{
|
2019-02-22 13:26:00 -03:00
|
|
|
if (mapWalletViews.count(wallet_model) == 0) return;
|
2013-10-18 13:43:07 -03:00
|
|
|
|
2018-11-22 08:36:07 -03:00
|
|
|
WalletView *walletView = mapWalletViews.take(wallet_model);
|
2013-10-18 13:43:07 -03:00
|
|
|
walletStack->removeWidget(walletView);
|
2018-06-20 09:15:12 -04:00
|
|
|
delete walletView;
|
2013-10-18 13:43:07 -03:00
|
|
|
}
|
|
|
|
|
2013-03-22 14:32:49 -03:00
|
|
|
void WalletFrame::removeAllWallets()
|
|
|
|
{
|
2018-11-22 08:36:07 -03:00
|
|
|
QMap<WalletModel*, WalletView*>::const_iterator i;
|
2013-10-18 13:05:26 -03:00
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
walletStack->removeWidget(i.value());
|
|
|
|
mapWalletViews.clear();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2013-07-22 02:50:39 -04:00
|
|
|
bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (!walletView)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return walletView->handlePaymentRequest(recipient);
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::showOutOfSyncWarning(bool fShow)
|
|
|
|
{
|
2013-10-18 13:05:26 -03:00
|
|
|
bOutOfSync = fShow;
|
2018-11-22 08:36:07 -03:00
|
|
|
QMap<WalletModel*, WalletView*>::const_iterator i;
|
2013-10-18 13:05:26 -03:00
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->showOutOfSyncWarning(fShow);
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoOverviewPage()
|
|
|
|
{
|
2018-11-22 08:36:07 -03:00
|
|
|
QMap<WalletModel*, WalletView*>::const_iterator i;
|
2013-10-18 13:05:26 -03:00
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoOverviewPage();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoHistoryPage()
|
|
|
|
{
|
2018-11-22 08:36:07 -03:00
|
|
|
QMap<WalletModel*, WalletView*>::const_iterator i;
|
2013-10-18 13:05:26 -03:00
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoHistoryPage();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoReceiveCoinsPage()
|
|
|
|
{
|
2018-11-22 08:36:07 -03:00
|
|
|
QMap<WalletModel*, WalletView*>::const_iterator i;
|
2013-10-18 13:05:26 -03:00
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoReceiveCoinsPage();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2013-04-01 09:43:50 -03:00
|
|
|
void WalletFrame::gotoSendCoinsPage(QString addr)
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
2018-11-22 08:36:07 -03:00
|
|
|
QMap<WalletModel*, WalletView*>::const_iterator i;
|
2013-10-18 13:05:26 -03:00
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoSendCoinsPage(addr);
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoSignMessageTab(QString addr)
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->gotoSignMessageTab(addr);
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoVerifyMessageTab(QString addr)
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->gotoVerifyMessageTab(addr);
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2020-01-31 20:59:57 -03:00
|
|
|
void WalletFrame::gotoLoadPSBT(bool from_clipboard)
|
2020-01-04 10:13:04 -03:00
|
|
|
{
|
|
|
|
WalletView *walletView = currentWalletView();
|
|
|
|
if (walletView) {
|
2020-01-31 20:59:57 -03:00
|
|
|
walletView->gotoLoadPSBT(from_clipboard);
|
2020-01-04 10:13:04 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 14:07:59 -03:00
|
|
|
void WalletFrame::encryptWallet()
|
2013-03-22 14:32:49 -03:00
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (walletView)
|
2020-10-23 14:07:59 -03:00
|
|
|
walletView->encryptWallet();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::backupWallet()
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->backupWallet();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::changePassphrase()
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->changePassphrase();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::unlockWallet()
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 13:05:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->unlockWallet();
|
2013-03-22 14:32:49 -03:00
|
|
|
}
|
|
|
|
|
2013-10-16 10:14:26 -03:00
|
|
|
void WalletFrame::usedSendingAddresses()
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-16 10:14:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->usedSendingAddresses();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::usedReceivingAddresses()
|
|
|
|
{
|
2013-11-12 10:54:43 -03:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-16 10:14:26 -03:00
|
|
|
if (walletView)
|
|
|
|
walletView->usedReceivingAddresses();
|
|
|
|
}
|
2013-11-12 10:54:43 -03:00
|
|
|
|
2019-01-11 20:49:36 -03:00
|
|
|
WalletView* WalletFrame::currentWalletView() const
|
2013-11-12 10:54:43 -03:00
|
|
|
{
|
|
|
|
return qobject_cast<WalletView*>(walletStack->currentWidget());
|
|
|
|
}
|
|
|
|
|
2019-01-11 20:49:36 -03:00
|
|
|
WalletModel* WalletFrame::currentWalletModel() const
|
|
|
|
{
|
|
|
|
WalletView* wallet_view = currentWalletView();
|
|
|
|
return wallet_view ? wallet_view->getWalletModel() : nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-19 09:27:14 -04:00
|
|
|
void WalletFrame::outOfSyncWarningClicked()
|
|
|
|
{
|
2016-09-21 05:29:57 -03:00
|
|
|
Q_EMIT requestedSyncWarningInfo();
|
|
|
|
}
|