You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

walletframe.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "walletframe.h"
  5. #include "starwelsgui.h"
  6. #include "walletview.h"
  7. #include <cstdio>
  8. #include <QHBoxLayout>
  9. #include <QLabel>
  10. WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, StarwelsGUI *_gui) :
  11. QFrame(_gui),
  12. gui(_gui),
  13. platformStyle(_platformStyle)
  14. {
  15. // Leave HBox hook for adding a list view later
  16. QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
  17. setContentsMargins(0,0,0,0);
  18. walletStack = new QStackedWidget(this);
  19. walletFrameLayout->setContentsMargins(0,0,0,0);
  20. walletFrameLayout->addWidget(walletStack);
  21. QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
  22. noWallet->setAlignment(Qt::AlignCenter);
  23. walletStack->addWidget(noWallet);
  24. }
  25. WalletFrame::~WalletFrame()
  26. {
  27. }
  28. void WalletFrame::setClientModel(ClientModel *_clientModel)
  29. {
  30. this->clientModel = _clientModel;
  31. }
  32. bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
  33. {
  34. if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
  35. return false;
  36. WalletView *walletView = new WalletView(platformStyle, this);
  37. walletView->setStarwelsGUI(gui);
  38. walletView->setClientModel(clientModel);
  39. walletView->setWalletModel(walletModel);
  40. walletView->showOutOfSyncWarning(bOutOfSync);
  41. /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
  42. walletView->gotoOverviewPage();
  43. walletStack->addWidget(walletView);
  44. mapWalletViews[name] = walletView;
  45. // Ensure a walletView is able to show the main window
  46. connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
  47. connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
  48. return true;
  49. }
  50. bool WalletFrame::setCurrentWallet(const QString& name)
  51. {
  52. if (mapWalletViews.count(name) == 0)
  53. return false;
  54. WalletView *walletView = mapWalletViews.value(name);
  55. walletStack->setCurrentWidget(walletView);
  56. walletView->updateEncryptionStatus();
  57. return true;
  58. }
  59. bool WalletFrame::removeWallet(const QString &name)
  60. {
  61. if (mapWalletViews.count(name) == 0)
  62. return false;
  63. WalletView *walletView = mapWalletViews.take(name);
  64. walletStack->removeWidget(walletView);
  65. return true;
  66. }
  67. void WalletFrame::removeAllWallets()
  68. {
  69. QMap<QString, WalletView*>::const_iterator i;
  70. for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
  71. walletStack->removeWidget(i.value());
  72. mapWalletViews.clear();
  73. }
  74. bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
  75. {
  76. WalletView *walletView = currentWalletView();
  77. if (!walletView)
  78. return false;
  79. return walletView->handlePaymentRequest(recipient);
  80. }
  81. void WalletFrame::showOutOfSyncWarning(bool fShow)
  82. {
  83. bOutOfSync = fShow;
  84. QMap<QString, WalletView*>::const_iterator i;
  85. for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
  86. i.value()->showOutOfSyncWarning(fShow);
  87. }
  88. void WalletFrame::gotoOverviewPage()
  89. {
  90. QMap<QString, WalletView*>::const_iterator i;
  91. for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
  92. i.value()->gotoOverviewPage();
  93. }
  94. void WalletFrame::gotoHistoryPage()
  95. {
  96. QMap<QString, WalletView*>::const_iterator i;
  97. for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
  98. i.value()->gotoHistoryPage();
  99. }
  100. void WalletFrame::gotoReceiveCoinsPage()
  101. {
  102. QMap<QString, WalletView*>::const_iterator i;
  103. for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
  104. i.value()->gotoReceiveCoinsPage();
  105. }
  106. void WalletFrame::gotoSendCoinsPage(QString addr)
  107. {
  108. QMap<QString, WalletView*>::const_iterator i;
  109. for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
  110. i.value()->gotoSendCoinsPage(addr);
  111. }
  112. void WalletFrame::gotoSignMessageTab(QString addr)
  113. {
  114. WalletView *walletView = currentWalletView();
  115. if (walletView)
  116. walletView->gotoSignMessageTab(addr);
  117. }
  118. void WalletFrame::gotoVerifyMessageTab(QString addr)
  119. {
  120. WalletView *walletView = currentWalletView();
  121. if (walletView)
  122. walletView->gotoVerifyMessageTab(addr);
  123. }
  124. void WalletFrame::encryptWallet(bool status)
  125. {
  126. WalletView *walletView = currentWalletView();
  127. if (walletView)
  128. walletView->encryptWallet(status);
  129. }
  130. void WalletFrame::backupWallet()
  131. {
  132. WalletView *walletView = currentWalletView();
  133. if (walletView)
  134. walletView->backupWallet();
  135. }
  136. void WalletFrame::changePassphrase()
  137. {
  138. WalletView *walletView = currentWalletView();
  139. if (walletView)
  140. walletView->changePassphrase();
  141. }
  142. void WalletFrame::unlockWallet()
  143. {
  144. WalletView *walletView = currentWalletView();
  145. if (walletView)
  146. walletView->unlockWallet();
  147. }
  148. void WalletFrame::usedSendingAddresses()
  149. {
  150. WalletView *walletView = currentWalletView();
  151. if (walletView)
  152. walletView->usedSendingAddresses();
  153. }
  154. void WalletFrame::usedReceivingAddresses()
  155. {
  156. WalletView *walletView = currentWalletView();
  157. if (walletView)
  158. walletView->usedReceivingAddresses();
  159. }
  160. WalletView *WalletFrame::currentWalletView()
  161. {
  162. return qobject_cast<WalletView*>(walletStack->currentWidget());
  163. }
  164. void WalletFrame::outOfSyncWarningClicked()
  165. {
  166. Q_EMIT requestedSyncWarningInfo();
  167. }