Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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 
7 #include <qt/bitcoingui.h>
8 #include <qt/walletview.h>
9 
10 #include <cassert>
11 #include <cstdio>
12 
13 #include <QHBoxLayout>
14 #include <QLabel>
15 
17  QFrame(_gui),
18  gui(_gui)
19 {
20  // Leave HBox hook for adding a list view later
21  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
22  setContentsMargins(0,0,0,0);
23  walletStack = new QStackedWidget(this);
24  walletFrameLayout->setContentsMargins(0,0,0,0);
25  walletFrameLayout->addWidget(walletStack);
26 
27  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
28  noWallet->setAlignment(Qt::AlignCenter);
29  walletStack->addWidget(noWallet);
30 }
31 
33 {
34 }
35 
37 {
38  this->clientModel = _clientModel;
39 }
40 
41 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
42 {
43  if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
44  return false;
45 
46  WalletView* walletView = new WalletView(this);
47  walletView->setBitcoinGUI(gui);
48  walletView->setClientModel(clientModel);
49  walletView->setWalletModel(walletModel);
50  walletView->showOutOfSyncWarning(bOutOfSync);
51 
52  /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
53  walletView->gotoOverviewPage();
54  walletStack->addWidget(walletView);
55  mapWalletViews[name] = walletView;
56 
57  // Ensure a walletView is able to show the main window
58  connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
59 
60  connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
61 
62  return true;
63 }
64 
65 bool WalletFrame::setCurrentWallet(const QString& name)
66 {
67  if (mapWalletViews.count(name) == 0)
68  return false;
69 
70  WalletView *walletView = mapWalletViews.value(name);
71  walletStack->setCurrentWidget(walletView);
72  assert(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()->gotoMasternodePage();
131 }
132 
134 {
135  QMap<QString, WalletView*>::const_iterator i;
136  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
137  i.value()->gotoReceiveCoinsPage();
138 }
139 
141 {
142  QMap<QString, WalletView*>::const_iterator i;
143  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
144  i.value()->gotoSendCoinsPage(addr);
145 }
146 
148 {
149  QMap<QString, WalletView*>::const_iterator i;
150  for (auto i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) {
151  i.value()->gotoPrivateSendCoinsPage(addr);
152  }
153 }
154 
156 {
157  WalletView *walletView = currentWalletView();
158  if (walletView)
159  walletView->gotoSignMessageTab(addr);
160 }
161 
163 {
164  WalletView *walletView = currentWalletView();
165  if (walletView)
166  walletView->gotoVerifyMessageTab(addr);
167 }
168 
169 void WalletFrame::encryptWallet(bool status)
170 {
171  WalletView *walletView = currentWalletView();
172  if (walletView)
173  walletView->encryptWallet(status);
174 }
175 
177 {
178  WalletView *walletView = currentWalletView();
179  if (walletView)
180  walletView->backupWallet();
181 }
182 
184 {
185  WalletView *walletView = currentWalletView();
186  if (walletView)
187  walletView->changePassphrase();
188 }
189 
191 {
192  WalletView *walletView = currentWalletView();
193  if (walletView)
194  walletView->unlockWallet();
195 }
196 
198 {
199  WalletView *walletView = currentWalletView();
200  if (walletView)
201  walletView->lockWallet();
202 }
203 
205 {
206  WalletView *walletView = currentWalletView();
207  if (walletView)
208  walletView->usedSendingAddresses();
209 }
210 
212 {
213  WalletView *walletView = currentWalletView();
214  if (walletView)
215  walletView->usedReceivingAddresses();
216 }
217 
219 {
220  return qobject_cast<WalletView*>(walletStack->currentWidget());
221 }
222 
224 {
225  Q_EMIT requestedSyncWarningInfo();
226 }
void lockWallet()
Lock wallet.
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletframe.cpp:95
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:65
void unlockWallet(bool fAnonymizeOnly=false)
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:339
void gotoMasternodePage()
Switch to masternode page.
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:275
bool bOutOfSync
Definition: walletframe.h:57
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:361
WalletView * currentWalletView()
ClientModel * clientModel
Definition: walletframe.h:54
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:332
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:52
void encryptWallet(bool status)
Encrypt the wallet.
Bitcoin GUI main class.
Definition: bitcoingui.h:49
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:55
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:297
void removeAllWallets()
Definition: walletframe.cpp:87
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
void gotoOverviewPage()
Switch to overview (home) page.
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:119
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:369
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:36
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:153
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
BitcoinGUI * gui
Definition: walletframe.h:53
const char * name
Definition: rest.cpp:36
bool addWallet(const QString &name, WalletModel *walletModel)
Definition: walletframe.cpp:41
void gotoPrivateSendCoinsPage(QString addr="")
Switch to PrivateSend coins page.
void changePassphrase()
Change encrypted wallet passphrase.
Model for Dash network client.
Definition: clientmodel.h:42
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 backupWallet()
Backup the wallet.
Definition: walletview.cpp:313
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:287
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:223
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
WalletFrame(BitcoinGUI *_gui=0)
Definition: walletframe.cpp:16
void gotoReceiveCoinsPage()
Switch to receive coins page.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:263
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:100
void lockWallet()
Lock wallet.
Definition: walletview.cpp:353
bool removeWallet(const QString &name)
Definition: walletframe.cpp:77
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:140
void backupWallet()
Backup the wallet.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:302
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:292
Released under the MIT license