2015-12-13 17:58:29 +01:00
|
|
|
// Copyright (c) 2011-2015 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 "walletframe.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
#include "bitcoingui.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "walletview.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2015-07-28 15:20:14 +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),
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletFrame::setClientModel(ClientModel *clientModel)
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
this->clientModel = clientModel;
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
|
|
|
|
{
|
2013-10-18 18:05:26 +02:00
|
|
|
if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
|
|
|
|
return false;
|
|
|
|
|
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);
|
|
|
|
|
2013-10-18 18:43:07 +02:00
|
|
|
/* TODO we should goto the currently selected page once dynamically adding wallets is supported */
|
|
|
|
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
|
|
|
|
connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
|
|
|
|
|
|
|
|
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);
|
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);
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|