LCOV - code coverage report
Current view: top level - src/qt - walletframe.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 153 0.0 %
Date: 2020-09-26 01:30:44 Functions: 0 29 0.0 %

          Line data    Source code
       1             : // Copyright (c) 2011-2020 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <qt/walletframe.h>
       6             : #include <qt/walletmodel.h>
       7             : 
       8             : #include <qt/bitcoingui.h>
       9             : #include <qt/walletview.h>
      10             : 
      11             : #include <cassert>
      12             : 
      13             : #include <QHBoxLayout>
      14             : #include <QLabel>
      15             : 
      16           0 : WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
      17           0 :     QFrame(_gui),
      18           0 :     gui(_gui),
      19           0 :     platformStyle(_platformStyle)
      20           0 : {
      21             :     // Leave HBox hook for adding a list view later
      22           0 :     QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
      23           0 :     setContentsMargins(0,0,0,0);
      24           0 :     walletStack = new QStackedWidget(this);
      25           0 :     walletFrameLayout->setContentsMargins(0,0,0,0);
      26           0 :     walletFrameLayout->addWidget(walletStack);
      27             : 
      28           0 :     QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
      29           0 :     noWallet->setAlignment(Qt::AlignCenter);
      30           0 :     walletStack->addWidget(noWallet);
      31           0 : }
      32             : 
      33           0 : WalletFrame::~WalletFrame()
      34           0 : {
      35           0 : }
      36             : 
      37           0 : void WalletFrame::setClientModel(ClientModel *_clientModel)
      38             : {
      39           0 :     this->clientModel = _clientModel;
      40             : 
      41           0 :     for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
      42           0 :         i.value()->setClientModel(_clientModel);
      43             :     }
      44           0 : }
      45             : 
      46           0 : bool WalletFrame::addWallet(WalletModel *walletModel)
      47             : {
      48           0 :     if (!gui || !clientModel || !walletModel) return false;
      49             : 
      50           0 :     if (mapWalletViews.count(walletModel) > 0) return false;
      51             : 
      52           0 :     WalletView *walletView = new WalletView(platformStyle, this);
      53           0 :     walletView->setClientModel(clientModel);
      54           0 :     walletView->setWalletModel(walletModel);
      55           0 :     walletView->showOutOfSyncWarning(bOutOfSync);
      56           0 :     walletView->setPrivacy(gui->isPrivacyModeActivated());
      57             : 
      58           0 :     WalletView* current_wallet_view = currentWalletView();
      59           0 :     if (current_wallet_view) {
      60           0 :         walletView->setCurrentIndex(current_wallet_view->currentIndex());
      61           0 :     } else {
      62           0 :         walletView->gotoOverviewPage();
      63             :     }
      64             : 
      65           0 :     walletStack->addWidget(walletView);
      66           0 :     mapWalletViews[walletModel] = walletView;
      67             : 
      68           0 :     connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked);
      69           0 :     connect(walletView, &WalletView::transactionClicked, gui, &BitcoinGUI::gotoHistoryPage);
      70           0 :     connect(walletView, &WalletView::coinsSent, gui, &BitcoinGUI::gotoHistoryPage);
      71           0 :     connect(walletView, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
      72           0 :         gui->message(title, message, style);
      73           0 :     });
      74           0 :     connect(walletView, &WalletView::encryptionStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
      75           0 :     connect(walletView, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
      76           0 :     connect(walletView, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
      77           0 :     connect(gui, &BitcoinGUI::setPrivacy, walletView, &WalletView::setPrivacy);
      78             : 
      79             :     return true;
      80           0 : }
      81             : 
      82           0 : void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
      83             : {
      84           0 :     if (mapWalletViews.count(wallet_model) == 0) return;
      85             : 
      86           0 :     WalletView *walletView = mapWalletViews.value(wallet_model);
      87           0 :     walletStack->setCurrentWidget(walletView);
      88           0 :     assert(walletView);
      89           0 :     walletView->updateEncryptionStatus();
      90           0 : }
      91             : 
      92           0 : void WalletFrame::removeWallet(WalletModel* wallet_model)
      93             : {
      94           0 :     if (mapWalletViews.count(wallet_model) == 0) return;
      95             : 
      96           0 :     WalletView *walletView = mapWalletViews.take(wallet_model);
      97           0 :     walletStack->removeWidget(walletView);
      98           0 :     delete walletView;
      99           0 : }
     100             : 
     101           0 : void WalletFrame::removeAllWallets()
     102             : {
     103           0 :     QMap<WalletModel*, WalletView*>::const_iterator i;
     104           0 :     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
     105           0 :         walletStack->removeWidget(i.value());
     106           0 :     mapWalletViews.clear();
     107           0 : }
     108             : 
     109           0 : bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
     110             : {
     111           0 :     WalletView *walletView = currentWalletView();
     112           0 :     if (!walletView)
     113           0 :         return false;
     114             : 
     115           0 :     return walletView->handlePaymentRequest(recipient);
     116           0 : }
     117             : 
     118           0 : void WalletFrame::showOutOfSyncWarning(bool fShow)
     119             : {
     120           0 :     bOutOfSync = fShow;
     121           0 :     QMap<WalletModel*, WalletView*>::const_iterator i;
     122           0 :     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
     123           0 :         i.value()->showOutOfSyncWarning(fShow);
     124           0 : }
     125             : 
     126           0 : void WalletFrame::gotoOverviewPage()
     127             : {
     128           0 :     QMap<WalletModel*, WalletView*>::const_iterator i;
     129           0 :     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
     130           0 :         i.value()->gotoOverviewPage();
     131           0 : }
     132             : 
     133           0 : void WalletFrame::gotoHistoryPage()
     134             : {
     135           0 :     QMap<WalletModel*, WalletView*>::const_iterator i;
     136           0 :     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
     137           0 :         i.value()->gotoHistoryPage();
     138           0 : }
     139             : 
     140           0 : void WalletFrame::gotoReceiveCoinsPage()
     141             : {
     142           0 :     QMap<WalletModel*, WalletView*>::const_iterator i;
     143           0 :     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
     144           0 :         i.value()->gotoReceiveCoinsPage();
     145           0 : }
     146             : 
     147           0 : void WalletFrame::gotoSendCoinsPage(QString addr)
     148             : {
     149           0 :     QMap<WalletModel*, WalletView*>::const_iterator i;
     150           0 :     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
     151           0 :         i.value()->gotoSendCoinsPage(addr);
     152           0 : }
     153             : 
     154           0 : void WalletFrame::gotoSignMessageTab(QString addr)
     155             : {
     156           0 :     WalletView *walletView = currentWalletView();
     157           0 :     if (walletView)
     158           0 :         walletView->gotoSignMessageTab(addr);
     159           0 : }
     160             : 
     161           0 : void WalletFrame::gotoVerifyMessageTab(QString addr)
     162             : {
     163           0 :     WalletView *walletView = currentWalletView();
     164           0 :     if (walletView)
     165           0 :         walletView->gotoVerifyMessageTab(addr);
     166           0 : }
     167             : 
     168           0 : void WalletFrame::gotoLoadPSBT(bool from_clipboard)
     169             : {
     170           0 :     WalletView *walletView = currentWalletView();
     171           0 :     if (walletView) {
     172           0 :         walletView->gotoLoadPSBT(from_clipboard);
     173           0 :     }
     174           0 : }
     175             : 
     176           0 : void WalletFrame::encryptWallet(bool status)
     177             : {
     178           0 :     WalletView *walletView = currentWalletView();
     179           0 :     if (walletView)
     180           0 :         walletView->encryptWallet(status);
     181           0 : }
     182             : 
     183           0 : void WalletFrame::backupWallet()
     184             : {
     185           0 :     WalletView *walletView = currentWalletView();
     186           0 :     if (walletView)
     187           0 :         walletView->backupWallet();
     188           0 : }
     189             : 
     190           0 : void WalletFrame::changePassphrase()
     191             : {
     192           0 :     WalletView *walletView = currentWalletView();
     193           0 :     if (walletView)
     194           0 :         walletView->changePassphrase();
     195           0 : }
     196             : 
     197           0 : void WalletFrame::unlockWallet()
     198             : {
     199           0 :     WalletView *walletView = currentWalletView();
     200           0 :     if (walletView)
     201           0 :         walletView->unlockWallet();
     202           0 : }
     203             : 
     204           0 : void WalletFrame::usedSendingAddresses()
     205             : {
     206           0 :     WalletView *walletView = currentWalletView();
     207           0 :     if (walletView)
     208           0 :         walletView->usedSendingAddresses();
     209           0 : }
     210             : 
     211           0 : void WalletFrame::usedReceivingAddresses()
     212             : {
     213           0 :     WalletView *walletView = currentWalletView();
     214           0 :     if (walletView)
     215           0 :         walletView->usedReceivingAddresses();
     216           0 : }
     217             : 
     218           0 : WalletView* WalletFrame::currentWalletView() const
     219             : {
     220           0 :     return qobject_cast<WalletView*>(walletStack->currentWidget());
     221             : }
     222             : 
     223           0 : WalletModel* WalletFrame::currentWalletModel() const
     224             : {
     225           0 :     WalletView* wallet_view = currentWalletView();
     226           0 :     return wallet_view ? wallet_view->getWalletModel() : nullptr;
     227             : }
     228             : 
     229           0 : void WalletFrame::outOfSyncWarningClicked()
     230             : {
     231           0 :     Q_EMIT requestedSyncWarningInfo();
     232           0 : }

Generated by: LCOV version 1.15