Files
thehub/hub-qt/walletframe.cpp
T

212 lines
5.8 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2011-2015 The Bitcoin Core developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-11-04 16:20:43 +01:00
#include "walletframe.h"
2013-04-13 00:13:08 -05:00
#include "bitcoingui.h"
2013-04-13 00:13:08 -05:00
#include "walletview.h"
#include <cstdio>
2013-05-31 14:02:24 +02:00
#include <QHBoxLayout>
2013-11-12 14:54:43 +01:00
#include <QLabel>
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)
{
// Leave HBox hook for adding a list view later
QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
setContentsMargins(0,0,0,0);
2013-10-18 18:05:26 +02:00
walletStack = new QStackedWidget(this);
walletFrameLayout->setContentsMargins(0,0,0,0);
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);
}
WalletFrame::~WalletFrame()
{
}
void WalletFrame::setClientModel(ClientModel *clientModel)
{
2013-10-18 18:05:26 +02:00
this->clientModel = clientModel;
}
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;
}
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);
walletView->updateEncryptionStatus();
2013-10-18 18:05:26 +02:00
return true;
}
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;
}
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();
}
bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
{
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);
}
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);
}
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();
}
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();
}
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();
}
void WalletFrame::gotoSendCoinsPage(QString addr)
{
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);
}
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);
}
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);
}
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);
}
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();
}
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();
}
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-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());
}