qt: Use WalletModel* instead of wallet name in main window
This commit is contained in:
parent
d2a1adffeb
commit
b2ce86c3ad
5 changed files with 31 additions and 34 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
@ -431,7 +431,7 @@ void BitcoinApplication::addWallet(WalletModel* walletModel)
|
|||
window->addWallet(walletModel);
|
||||
|
||||
if (m_wallet_models.empty()) {
|
||||
window->setCurrentWallet(walletModel->getWalletName());
|
||||
window->setCurrentWallet(walletModel);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BIP70
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
@ -569,10 +569,9 @@ bool BitcoinGUI::addWallet(WalletModel *walletModel)
|
|||
{
|
||||
if(!walletFrame)
|
||||
return false;
|
||||
const QString name = walletModel->getWalletName();
|
||||
const QString display_name = walletModel->getDisplayName();
|
||||
setWalletActionsEnabled(true);
|
||||
m_wallet_selector->addItem(display_name, name);
|
||||
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
|
||||
if (m_wallet_selector->count() == 2) {
|
||||
m_wallet_selector_label_action->setVisible(true);
|
||||
m_wallet_selector_action->setVisible(true);
|
||||
|
@ -584,8 +583,7 @@ bool BitcoinGUI::addWallet(WalletModel *walletModel)
|
|||
bool BitcoinGUI::removeWallet(WalletModel* walletModel)
|
||||
{
|
||||
if (!walletFrame) return false;
|
||||
QString name = walletModel->getWalletName();
|
||||
int index = m_wallet_selector->findData(name);
|
||||
int index = m_wallet_selector->findData(QVariant::fromValue(walletModel));
|
||||
m_wallet_selector->removeItem(index);
|
||||
if (m_wallet_selector->count() == 0) {
|
||||
setWalletActionsEnabled(false);
|
||||
|
@ -594,20 +592,20 @@ bool BitcoinGUI::removeWallet(WalletModel* walletModel)
|
|||
m_wallet_selector_action->setVisible(false);
|
||||
}
|
||||
rpcConsole->removeWallet(walletModel);
|
||||
return walletFrame->removeWallet(name);
|
||||
return walletFrame->removeWallet(walletModel);
|
||||
}
|
||||
|
||||
bool BitcoinGUI::setCurrentWallet(const QString& name)
|
||||
bool BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
|
||||
{
|
||||
if(!walletFrame)
|
||||
return false;
|
||||
return walletFrame->setCurrentWallet(name);
|
||||
return walletFrame->setCurrentWallet(wallet_model);
|
||||
}
|
||||
|
||||
bool BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
|
||||
{
|
||||
QString internal_name = m_wallet_selector->itemData(index).toString();
|
||||
return setCurrentWallet(internal_name);
|
||||
WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
|
||||
return setCurrentWallet(wallet_model);
|
||||
}
|
||||
|
||||
void BitcoinGUI::removeAllWallets()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
@ -206,7 +206,7 @@ public Q_SLOTS:
|
|||
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
bool setCurrentWallet(const QString& name);
|
||||
bool setCurrentWallet(WalletModel* wallet_model);
|
||||
bool setCurrentWalletBySelectorIndex(int index);
|
||||
/** Set the UI status indicators based on the currently selected wallet.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
@ -46,8 +46,7 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
|
|||
return false;
|
||||
}
|
||||
|
||||
const QString name = walletModel->getWalletName();
|
||||
if (mapWalletViews.count(name) > 0) {
|
||||
if (mapWalletViews.count(walletModel) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -65,7 +64,7 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
|
|||
}
|
||||
|
||||
walletStack->addWidget(walletView);
|
||||
mapWalletViews[name] = walletView;
|
||||
mapWalletViews[walletModel] = walletView;
|
||||
|
||||
// Ensure a walletView is able to show the main window
|
||||
connect(walletView, &WalletView::showNormalIfMinimized, [this]{
|
||||
|
@ -77,24 +76,24 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool WalletFrame::setCurrentWallet(const QString& name)
|
||||
bool WalletFrame::setCurrentWallet(WalletModel* wallet_model)
|
||||
{
|
||||
if (mapWalletViews.count(name) == 0)
|
||||
if (mapWalletViews.count(wallet_model) == 0)
|
||||
return false;
|
||||
|
||||
WalletView *walletView = mapWalletViews.value(name);
|
||||
WalletView *walletView = mapWalletViews.value(wallet_model);
|
||||
walletStack->setCurrentWidget(walletView);
|
||||
assert(walletView);
|
||||
walletView->updateEncryptionStatus();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalletFrame::removeWallet(const QString &name)
|
||||
bool WalletFrame::removeWallet(WalletModel* wallet_model)
|
||||
{
|
||||
if (mapWalletViews.count(name) == 0)
|
||||
if (mapWalletViews.count(wallet_model) == 0)
|
||||
return false;
|
||||
|
||||
WalletView *walletView = mapWalletViews.take(name);
|
||||
WalletView *walletView = mapWalletViews.take(wallet_model);
|
||||
walletStack->removeWidget(walletView);
|
||||
delete walletView;
|
||||
return true;
|
||||
|
@ -102,7 +101,7 @@ bool WalletFrame::removeWallet(const QString &name)
|
|||
|
||||
void WalletFrame::removeAllWallets()
|
||||
{
|
||||
QMap<QString, WalletView*>::const_iterator i;
|
||||
QMap<WalletModel*, WalletView*>::const_iterator i;
|
||||
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
||||
walletStack->removeWidget(i.value());
|
||||
mapWalletViews.clear();
|
||||
|
@ -120,35 +119,35 @@ bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
|
|||
void WalletFrame::showOutOfSyncWarning(bool fShow)
|
||||
{
|
||||
bOutOfSync = fShow;
|
||||
QMap<QString, WalletView*>::const_iterator i;
|
||||
QMap<WalletModel*, WalletView*>::const_iterator i;
|
||||
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
||||
i.value()->showOutOfSyncWarning(fShow);
|
||||
}
|
||||
|
||||
void WalletFrame::gotoOverviewPage()
|
||||
{
|
||||
QMap<QString, WalletView*>::const_iterator i;
|
||||
QMap<WalletModel*, WalletView*>::const_iterator i;
|
||||
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
||||
i.value()->gotoOverviewPage();
|
||||
}
|
||||
|
||||
void WalletFrame::gotoHistoryPage()
|
||||
{
|
||||
QMap<QString, WalletView*>::const_iterator i;
|
||||
QMap<WalletModel*, WalletView*>::const_iterator i;
|
||||
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
||||
i.value()->gotoHistoryPage();
|
||||
}
|
||||
|
||||
void WalletFrame::gotoReceiveCoinsPage()
|
||||
{
|
||||
QMap<QString, WalletView*>::const_iterator i;
|
||||
QMap<WalletModel*, WalletView*>::const_iterator i;
|
||||
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
||||
i.value()->gotoReceiveCoinsPage();
|
||||
}
|
||||
|
||||
void WalletFrame::gotoSendCoinsPage(QString addr)
|
||||
{
|
||||
QMap<QString, WalletView*>::const_iterator i;
|
||||
QMap<WalletModel*, WalletView*>::const_iterator i;
|
||||
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
||||
i.value()->gotoSendCoinsPage(addr);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
||||
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
@ -37,8 +37,8 @@ public:
|
|||
void setClientModel(ClientModel *clientModel);
|
||||
|
||||
bool addWallet(WalletModel *walletModel);
|
||||
bool setCurrentWallet(const QString& name);
|
||||
bool removeWallet(const QString &name);
|
||||
bool setCurrentWallet(WalletModel* wallet_model);
|
||||
bool removeWallet(WalletModel* wallet_model);
|
||||
void removeAllWallets();
|
||||
|
||||
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
QStackedWidget *walletStack;
|
||||
BitcoinGUI *gui;
|
||||
ClientModel *clientModel;
|
||||
QMap<QString, WalletView*> mapWalletViews;
|
||||
QMap<WalletModel*, WalletView*> mapWalletViews;
|
||||
|
||||
bool bOutOfSync;
|
||||
|
||||
|
|
Loading…
Reference in a new issue