2018-07-27 00:36:45 +02:00
|
|
|
// Copyright (c) 2011-2018 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.
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/walletframe.h>
|
2017-10-12 09:22:48 +02:00
|
|
|
#include <qt/walletmodel.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/bitcoingui.h>
|
|
|
|
#include <qt/walletview.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2017-08-28 09:24:17 +02:00
|
|
|
#include <cassert>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <cstdio>
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2013-05-31 14:02:24 +02:00
|
|
|
#include <QHBoxLayout>
|
2013-11-12 14:54:43 +01:00
|
|
|
#include <QLabel>
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
|
2013-10-18 18:05:26 +02:00
|
|
|
QFrame(_gui),
|
2015-07-28 15:20:14 +02:00
|
|
|
gui(_gui),
|
2016-09-09 13:43:29 +02:00
|
|
|
platformStyle(_platformStyle)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
|
|
|
// Leave HBox hook for adding a list view later
|
|
|
|
QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
|
2013-04-26 07:38:24 +02:00
|
|
|
setContentsMargins(0,0,0,0);
|
2013-10-18 18:05:26 +02:00
|
|
|
walletStack = new QStackedWidget(this);
|
2013-04-26 07:38:24 +02:00
|
|
|
walletFrameLayout->setContentsMargins(0,0,0,0);
|
2013-03-22 18:32:49 +01:00
|
|
|
walletFrameLayout->addWidget(walletStack);
|
2013-11-12 14:54:43 +01:00
|
|
|
|
|
|
|
QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
|
|
|
|
noWallet->setAlignment(Qt::AlignCenter);
|
|
|
|
walletStack->addWidget(noWallet);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WalletFrame::~WalletFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void WalletFrame::setClientModel(ClientModel *_clientModel)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->clientModel = _clientModel;
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 09:22:48 +02:00
|
|
|
bool WalletFrame::addWallet(WalletModel *walletModel)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2017-10-12 09:22:48 +02:00
|
|
|
if (!gui || !clientModel || !walletModel) {
|
2013-10-18 18:05:26 +02:00
|
|
|
return false;
|
2017-10-12 09:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString name = walletModel->getWalletName();
|
|
|
|
if (mapWalletViews.count(name) > 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-18 18:05:26 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
WalletView *walletView = new WalletView(platformStyle, this);
|
2013-10-18 18:05:26 +02:00
|
|
|
walletView->setBitcoinGUI(gui);
|
|
|
|
walletView->setClientModel(clientModel);
|
|
|
|
walletView->setWalletModel(walletModel);
|
|
|
|
walletView->showOutOfSyncWarning(bOutOfSync);
|
|
|
|
|
2018-05-18 01:46:44 +02:00
|
|
|
WalletView* current_wallet_view = currentWalletView();
|
|
|
|
if (current_wallet_view) {
|
|
|
|
walletView->setCurrentIndex(current_wallet_view->currentIndex());
|
|
|
|
} else {
|
|
|
|
walletView->gotoOverviewPage();
|
|
|
|
}
|
|
|
|
|
2013-10-18 18:05:26 +02:00
|
|
|
walletStack->addWidget(walletView);
|
|
|
|
mapWalletViews[name] = walletView;
|
|
|
|
|
|
|
|
// Ensure a walletView is able to show the main window
|
2018-06-24 17:18:22 +02:00
|
|
|
connect(walletView, &WalletView::showNormalIfMinimized, [this]{
|
|
|
|
gui->showNormalIfMinimized();
|
|
|
|
});
|
2013-10-18 18:05:26 +02:00
|
|
|
|
2018-06-24 17:18:22 +02:00
|
|
|
connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked);
|
2016-07-19 15:27:14 +02:00
|
|
|
|
2013-10-18 18:05:26 +02:00
|
|
|
return true;
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WalletFrame::setCurrentWallet(const QString& name)
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
if (mapWalletViews.count(name) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WalletView *walletView = mapWalletViews.value(name);
|
|
|
|
walletStack->setCurrentWidget(walletView);
|
2017-08-28 09:24:17 +02:00
|
|
|
assert(walletView);
|
2013-10-25 16:10:43 +02:00
|
|
|
walletView->updateEncryptionStatus();
|
2013-10-18 18:05:26 +02:00
|
|
|
return true;
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2013-10-18 18:43:07 +02:00
|
|
|
bool WalletFrame::removeWallet(const QString &name)
|
|
|
|
{
|
|
|
|
if (mapWalletViews.count(name) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WalletView *walletView = mapWalletViews.take(name);
|
|
|
|
walletStack->removeWidget(walletView);
|
2018-06-20 15:15:12 +02:00
|
|
|
delete walletView;
|
2013-10-18 18:43:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
void WalletFrame::removeAllWallets()
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
QMap<QString, WalletView*>::const_iterator i;
|
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
walletStack->removeWidget(i.value());
|
|
|
|
mapWalletViews.clear();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (!walletView)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return walletView->handlePaymentRequest(recipient);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::showOutOfSyncWarning(bool fShow)
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
bOutOfSync = fShow;
|
|
|
|
QMap<QString, WalletView*>::const_iterator i;
|
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->showOutOfSyncWarning(fShow);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoOverviewPage()
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
QMap<QString, WalletView*>::const_iterator i;
|
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoOverviewPage();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoHistoryPage()
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
QMap<QString, WalletView*>::const_iterator i;
|
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoHistoryPage();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoReceiveCoinsPage()
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
QMap<QString, WalletView*>::const_iterator i;
|
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoReceiveCoinsPage();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2013-04-01 14:43:50 +02:00
|
|
|
void WalletFrame::gotoSendCoinsPage(QString addr)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
QMap<QString, WalletView*>::const_iterator i;
|
|
|
|
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
|
|
|
i.value()->gotoSendCoinsPage(addr);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoSignMessageTab(QString addr)
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->gotoSignMessageTab(addr);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::gotoVerifyMessageTab(QString addr)
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->gotoVerifyMessageTab(addr);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::encryptWallet(bool status)
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->encryptWallet(status);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::backupWallet()
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->backupWallet();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::changePassphrase()
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->changePassphrase();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::unlockWallet()
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-18 18:05:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->unlockWallet();
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
2013-10-16 15:14:26 +02:00
|
|
|
void WalletFrame::usedSendingAddresses()
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-16 15:14:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->usedSendingAddresses();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::usedReceivingAddresses()
|
|
|
|
{
|
2013-11-12 14:54:43 +01:00
|
|
|
WalletView *walletView = currentWalletView();
|
2013-10-16 15:14:26 +02:00
|
|
|
if (walletView)
|
|
|
|
walletView->usedReceivingAddresses();
|
|
|
|
}
|
2013-11-12 14:54:43 +01:00
|
|
|
|
|
|
|
WalletView *WalletFrame::currentWalletView()
|
|
|
|
{
|
|
|
|
return qobject_cast<WalletView*>(walletStack->currentWidget());
|
|
|
|
}
|
|
|
|
|
2016-07-19 15:27:14 +02:00
|
|
|
void WalletFrame::outOfSyncWarningClicked()
|
|
|
|
{
|
2016-09-21 10:29:57 +02:00
|
|
|
Q_EMIT requestedSyncWarningInfo();
|
|
|
|
}
|