Dogecoin Core  1.14.2
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 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 "walletframe.h"
6 
7 #include "bitcoingui.h"
8 #include "walletview.h"
9 
10 #include <cstdio>
11 #include <iostream>
12 
13 #include <QHBoxLayout>
14 #include <QLabel>
15 
16 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
17  QFrame(_gui),
18  gui(_gui),
19  platformStyle(_platformStyle)
20 {
21  // Leave HBox hook for adding a list view later
22  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
23  setContentsMargins(0,0,0,0);
24  walletStack = new QStackedWidget(this);
25  walletFrameLayout->setContentsMargins(0,0,0,0);
26  walletFrameLayout->addWidget(walletStack);
27 
28  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
29  noWallet->setAlignment(Qt::AlignCenter);
30  walletStack->addWidget(noWallet);
31 }
32 
34 {
35 }
36 
38 {
39  this->clientModel = _clientModel;
40 }
41 
42 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
43 {
44  if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
45  return false;
46 
47  WalletView *walletView = new WalletView(platformStyle, this);
48  walletView->setBitcoinGUI(gui);
49  walletView->setClientModel(clientModel);
50  walletView->setWalletModel(walletModel);
51  walletView->showOutOfSyncWarning(bOutOfSync);
52 
53  /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
54  walletView->gotoOverviewPage();
55  walletStack->addWidget(walletView);
56  mapWalletViews[name] = walletView;
57 
58  // Ensure a walletView is able to show the main window
59  connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
60 
61  connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
62 
63  return true;
64 }
65 
66 bool WalletFrame::setCurrentWallet(const QString& name)
67 {
68  if (mapWalletViews.count(name) == 0)
69  return false;
70 
71  WalletView *walletView = mapWalletViews.value(name);
72  walletStack->setCurrentWidget(walletView);
73  walletView->updateEncryptionStatus();
74  return true;
75 }
76 
77 bool WalletFrame::removeWallet(const QString &name)
78 {
79  if (mapWalletViews.count(name) == 0)
80  return false;
81 
82  WalletView *walletView = mapWalletViews.take(name);
83  walletStack->removeWidget(walletView);
84  return true;
85 }
86 
88 {
89  QMap<QString, WalletView*>::const_iterator i;
90  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
91  walletStack->removeWidget(i.value());
92  mapWalletViews.clear();
93 }
94 
96 {
97  WalletView *walletView = currentWalletView();
98  if (!walletView)
99  return false;
100 
101  return walletView->handlePaymentRequest(recipient);
102 }
103 
105 {
106  bOutOfSync = fShow;
107  QMap<QString, WalletView*>::const_iterator i;
108  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
109  i.value()->showOutOfSyncWarning(fShow);
110 }
111 
113 {
114  QMap<QString, WalletView*>::const_iterator i;
115  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
116  i.value()->gotoOverviewPage();
117 }
118 
120 {
121  QMap<QString, WalletView*>::const_iterator i;
122  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
123  i.value()->gotoHistoryPage();
124 }
125 
127 {
128  QMap<QString, WalletView*>::const_iterator i;
129  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
130  i.value()->gotoReceiveCoinsPage();
131 }
132 
134 {
135  QMap<QString, WalletView*>::const_iterator i;
136  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
137  i.value()->gotoSendCoinsPage(addr);
138 }
139 
141 {
142  WalletView *walletView = currentWalletView();
143  if (walletView)
144  walletView->gotoSignMessageTab(addr);
145 }
146 
148 {
149  WalletView *walletView = currentWalletView();
150  if (walletView)
151  walletView->gotoVerifyMessageTab(addr);
152 }
153 
154 void WalletFrame::encryptWallet(bool status)
155 {
156  WalletView *walletView = currentWalletView();
157  if (walletView)
158  walletView->encryptWallet(status);
159 }
160 
162 {
163  WalletView *walletView = currentWalletView();
164  if (walletView)
165  walletView->backupWallet();
166 }
167 
169 {
170  WalletView *walletView = currentWalletView();
171  if (walletView)
172  walletView->changePassphrase();
173 }
174 
176 {
177  WalletView *walletView = currentWalletView();
178  if (walletView)
179  walletView->unlockWallet();
180 }
181 
183 {
184  WalletView *walletView = currentWalletView();
185  if (walletView)
186  walletView->printPaperWallets();
187 }
188 
190 {
191  WalletView *walletView = currentWalletView();
192  if (walletView)
193  walletView->usedSendingAddresses();
194 }
195 
197 {
198  WalletView *walletView = currentWalletView();
199  if (walletView)
200  walletView->usedReceivingAddresses();
201 }
202 
204 {
205  return qobject_cast<WalletView*>(walletStack->currentWidget());
206 }
207 
209 {
210  Q_EMIT requestedSyncWarningInfo();
211 }
Bitcoin GUI main class.
Definition: bitcoingui.h:47
Model for Bitcoin network client.
Definition: clientmodel.h:42
void removeAllWallets()
Definition: walletframe.cpp:87
WalletView * currentWalletView()
void changePassphrase()
Change encrypted wallet passphrase.
bool removeWallet(const QString &name)
Definition: walletframe.cpp:77
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
void gotoHistoryPage()
Switch to history (transactions) page.
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
void gotoOverviewPage()
Switch to overview (home) page.
ClientModel * clientModel
Definition: walletframe.h:55
const PlatformStyle * platformStyle
Definition: walletframe.h:60
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:37
bool bOutOfSync
Definition: walletframe.h:58
void backupWallet()
Backup the wallet.
QStackedWidget * walletStack
Definition: walletframe.h:53
void usedSendingAddresses()
Show used sending addresses.
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:56
void encryptWallet(bool status)
Encrypt the wallet.
void usedReceivingAddresses()
Show used receiving addresses.
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
bool addWallet(const QString &name, WalletModel *walletModel)
Definition: walletframe.cpp:42
WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui=0)
Definition: walletframe.cpp:16
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletframe.cpp:95
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:66
BitcoinGUI * gui
Definition: walletframe.h:54
void printPaperWallets()
void showOutOfSyncWarning(bool fShow)
void gotoReceiveCoinsPage()
Switch to receive coins page.
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:99
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:208
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:117
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:220
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:235
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:265
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:88
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:109
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:196
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:285
void printPaperWallets()
Open the print paper wallets dialog.
Definition: walletview.cpp:333
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:246
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:272
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:173
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:295
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:230
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:225