diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index d7acdeb95..44bf4559e 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -1,216 +1,214 @@ // 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. #include #include #include #include #include #include #include WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) : QFrame(_gui), gui(_gui), platformStyle(_platformStyle) { // Leave HBox hook for adding a list view later QHBoxLayout *walletFrameLayout = new QHBoxLayout(this); setContentsMargins(0, 0, 0, 0); walletStack = new QStackedWidget(this); walletFrameLayout->setContentsMargins(0, 0, 0, 0); walletFrameLayout->addWidget(walletStack); QLabel *noWallet = new QLabel(tr("No wallet has been loaded.")); noWallet->setAlignment(Qt::AlignCenter); walletStack->addWidget(noWallet); } WalletFrame::~WalletFrame() {} void WalletFrame::setClientModel(ClientModel *_clientModel) { this->clientModel = _clientModel; } bool WalletFrame::addWallet(WalletModel *walletModel) { if (!gui || !clientModel || !walletModel) { return false; } if (mapWalletViews.count(walletModel) > 0) { return false; } WalletView *walletView = new WalletView(platformStyle, walletModel, this); walletView->setBitcoinGUI(gui); walletView->setClientModel(clientModel); walletView->showOutOfSyncWarning(bOutOfSync); WalletView *current_wallet_view = currentWalletView(); if (current_wallet_view) { walletView->setCurrentIndex(current_wallet_view->currentIndex()); } else { walletView->gotoOverviewPage(); } walletStack->addWidget(walletView); mapWalletViews[walletModel] = walletView; connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked); return true; } -bool WalletFrame::setCurrentWallet(WalletModel *wallet_model) { +void WalletFrame::setCurrentWallet(WalletModel *wallet_model) { if (mapWalletViews.count(wallet_model) == 0) { - return false; + return; } WalletView *walletView = mapWalletViews.value(wallet_model); walletStack->setCurrentWidget(walletView); assert(walletView); walletView->updateEncryptionStatus(); - return true; } -bool WalletFrame::removeWallet(WalletModel *wallet_model) { +void WalletFrame::removeWallet(WalletModel *wallet_model) { if (mapWalletViews.count(wallet_model) == 0) { - return false; + return; } WalletView *walletView = mapWalletViews.take(wallet_model); walletStack->removeWidget(walletView); delete walletView; - return true; } void WalletFrame::removeAllWallets() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) { walletStack->removeWidget(i.value()); } mapWalletViews.clear(); } bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient) { WalletView *walletView = currentWalletView(); if (!walletView) { return false; } return walletView->handlePaymentRequest(recipient); } void WalletFrame::showOutOfSyncWarning(bool fShow) { bOutOfSync = fShow; QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) { i.value()->showOutOfSyncWarning(fShow); } } void WalletFrame::gotoOverviewPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) { i.value()->gotoOverviewPage(); } } void WalletFrame::gotoHistoryPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) { i.value()->gotoHistoryPage(); } } void WalletFrame::gotoReceiveCoinsPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) { i.value()->gotoReceiveCoinsPage(); } } void WalletFrame::gotoSendCoinsPage(QString addr) { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) { i.value()->gotoSendCoinsPage(addr); } } void WalletFrame::gotoSignMessageTab(QString addr) { WalletView *walletView = currentWalletView(); if (walletView) { walletView->gotoSignMessageTab(addr); } } void WalletFrame::gotoVerifyMessageTab(QString addr) { WalletView *walletView = currentWalletView(); if (walletView) { walletView->gotoVerifyMessageTab(addr); } } void WalletFrame::gotoLoadPSBT() { WalletView *walletView = currentWalletView(); if (walletView) { walletView->gotoLoadPSBT(); } } void WalletFrame::encryptWallet(bool status) { WalletView *walletView = currentWalletView(); if (walletView) { walletView->encryptWallet(status); } } void WalletFrame::backupWallet() { WalletView *walletView = currentWalletView(); if (walletView) { walletView->backupWallet(); } } void WalletFrame::changePassphrase() { WalletView *walletView = currentWalletView(); if (walletView) { walletView->changePassphrase(); } } void WalletFrame::unlockWallet() { WalletView *walletView = currentWalletView(); if (walletView) { walletView->unlockWallet(); } } void WalletFrame::usedSendingAddresses() { WalletView *walletView = currentWalletView(); if (walletView) { walletView->usedSendingAddresses(); } } void WalletFrame::usedReceivingAddresses() { WalletView *walletView = currentWalletView(); if (walletView) { walletView->usedReceivingAddresses(); } } WalletView *WalletFrame::currentWalletView() const { return qobject_cast(walletStack->currentWidget()); } WalletModel *WalletFrame::currentWalletModel() const { WalletView *wallet_view = currentWalletView(); return wallet_view ? wallet_view->getWalletModel() : nullptr; } void WalletFrame::outOfSyncWarningClicked() { Q_EMIT requestedSyncWarningInfo(); } diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 1ec9a87f9..e456dc3ee 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -1,102 +1,102 @@ // 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. #ifndef BITCOIN_QT_WALLETFRAME_H #define BITCOIN_QT_WALLETFRAME_H #include #include class BitcoinGUI; class ClientModel; class PlatformStyle; class SendCoinsRecipient; class WalletModel; class WalletView; QT_BEGIN_NAMESPACE class QStackedWidget; QT_END_NAMESPACE /** * A container for embedding all wallet-related * controls into BitcoinGUI. The purpose of this class is to allow future * refinements of the wallet controls with minimal need for further * modifications to BitcoinGUI, thus greatly simplifying merges while * reducing the risk of breaking top-level stuff. */ class WalletFrame : public QFrame { Q_OBJECT public: explicit WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui = nullptr); ~WalletFrame(); void setClientModel(ClientModel *clientModel); bool addWallet(WalletModel *walletModel); - bool setCurrentWallet(WalletModel *wallet_model); - bool removeWallet(WalletModel *wallet_model); + void setCurrentWallet(WalletModel *wallet_model); + void removeWallet(WalletModel *wallet_model); void removeAllWallets(); bool handlePaymentRequest(const SendCoinsRecipient &recipient); void showOutOfSyncWarning(bool fShow); Q_SIGNALS: /** Notify that the user has requested more information about the * out-of-sync warning */ void requestedSyncWarningInfo(); private: QStackedWidget *walletStack; BitcoinGUI *gui; ClientModel *clientModel; QMap mapWalletViews; bool bOutOfSync; const PlatformStyle *platformStyle; public: WalletView *currentWalletView() const; WalletModel *currentWalletModel() const; public Q_SLOTS: /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ void gotoHistoryPage(); /** Switch to receive coins page */ void gotoReceiveCoinsPage(); /** Switch to send coins page */ void gotoSendCoinsPage(QString addr = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); /** Show Sign/Verify Message dialog and switch to verify message tab */ void gotoVerifyMessageTab(QString addr = ""); /** Load Partially Signed Bitcoin Transaction */ void gotoLoadPSBT(); /** Encrypt the wallet */ void encryptWallet(bool status); /** Backup the wallet */ void backupWallet(); /** Change encrypted wallet passphrase */ void changePassphrase(); /** Ask for passphrase to unlock wallet temporarily */ void unlockWallet(); /** Show used sending addresses */ void usedSendingAddresses(); /** Show used receiving addresses */ void usedReceivingAddresses(); /** Pass on signal over requested out-of-sync-warning information */ void outOfSyncWarningClicked(); }; #endif // BITCOIN_QT_WALLETFRAME_H