PRCYCoin  2.0.0.7rc1
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 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 
12 #include <QHBoxLayout>
13 #include <QLabel>
14 
15 WalletFrame::WalletFrame(BitcoinGUI* _gui) : QFrame(_gui),
16  gui(_gui)
17 {
18  // Leave HBox hook for adding a list view later
19  QHBoxLayout* walletFrameLayout = new QHBoxLayout(this);
20  setContentsMargins(0, 0, 0, 0);
21  walletStack = new QStackedWidget(this);
22  walletFrameLayout->setContentsMargins(0, 0, 0, 0);
23  walletFrameLayout->addWidget(walletStack);
24  walletFrameLayout->setSpacing(0);
25  QLabel* noWallet = new QLabel(tr("No wallet has been loaded."));
26  noWallet->setAlignment(Qt::AlignCenter);
27  walletStack->addWidget(noWallet);
28 }
29 
31 {
32 }
33 
35 {
36  this->clientModel = clientModel;
37 }
38 
39 bool WalletFrame::addWallet(const QString& name, WalletModel* walletModel)
40 {
41  if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
42  return false;
43  WalletView* walletView = new WalletView(walletStack);
44  walletView->setBitcoinGUI(gui);
45  walletView->setClientModel(clientModel);
46  walletView->setWalletModel(walletModel);
47  walletView->showSyncStatus(bOutOfSync);
48 
49  /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
50  walletView->gotoOverviewPage();
51  walletStack->addWidget(walletView);
52 
53  mapWalletViews[name] = walletView;
54 
55  // Ensure a walletView is able to show the main window
56  connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
57  return true;
58 }
59 
60 bool WalletFrame::setCurrentWallet(const QString& name)
61 {
62  if (mapWalletViews.count(name) == 0)
63  return false;
64 
65  WalletView* walletView = mapWalletViews.value(name);
66  walletStack->setCurrentWidget(walletView);
67  walletView->updateEncryptionStatus();
68  return true;
69 }
70 
71 bool WalletFrame::removeWallet(const QString& name)
72 {
73  if (mapWalletViews.count(name) == 0)
74  return false;
75 
76  WalletView* walletView = mapWalletViews.take(name);
77  walletStack->removeWidget(walletView);
78  return true;
79 }
80 
82 {
83  QMap<QString, WalletView*>::const_iterator i;
84  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
85  walletStack->removeWidget(i.value());
86  mapWalletViews.clear();
87 }
88 
90 {
91  bOutOfSync = fShow;
92  QMap<QString, WalletView*>::const_iterator i;
93  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
94  i.value()->showSyncStatus(fShow);
95 }
96 
98 {
99  QMap<QString, WalletView*>::const_iterator i;
100  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
101  i.value()->gotoOverviewPage();
102 }
103 
105 {
106  QMap<QString, WalletView*>::const_iterator i;
107  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
108  i.value()->gotoHistoryPage();
109 }
110 
111 void WalletFrame::gotoMasternodePage() // Masternode list
112 {
113  QMap<QString, WalletView*>::const_iterator i;
114  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
115  i.value()->gotoMasternodePage();
116 }
117 
119 {
120  QMap<QString, WalletView*>::const_iterator i;
121  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
122  i.value()->gotoBlockExplorerPage();
123 }
124 
126 {
127  QMap<QString, WalletView*>::const_iterator i;
128  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
129  i.value()->gotoReceiveCoinsPage();
130 }
131 
133 {
134  QMap<QString, WalletView*>::const_iterator i;
135  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
136  i.value()->gotoOptionsPage();
137 }
138 
140 {
141  QSettings settings;
142  if (settings.value("fLockSendStaking", false).toBool()) {
143  LogPrintf("Attempt to go to Send tab.\n");
144  return;
145  }
146  QMap<QString, WalletView*>::const_iterator i;
147  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
148  i.value()->gotoSendCoinsPage(addr);
149 }
150 
152 {
153  WalletView* walletView = currentWalletView();
154 
155  if (walletView)
156  walletView->gotoMultiSendDialog();
157 }
158 
159 void WalletFrame::encryptWallet(bool status)
160 {
161  WalletView* walletView = currentWalletView();
162  if (walletView)
163  walletView->encryptWallet(status);
164 }
165 
167 {
168  WalletView* walletView = currentWalletView();
169  if (walletView)
170  walletView->backupWallet();
171 }
172 
174 {
175  WalletView* walletView = currentWalletView();
176  if (walletView)
177  walletView->changePassphrase();
178 }
179 
180 void WalletFrame::unlockWallet(bool setContext)
181 {
182  if (setContext) {
184  }
185  else {
187  }
188 }
189 
191 {
192  WalletView* walletView = currentWalletView();
193  if (walletView)
194  walletView->unlockWallet(context);
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->toggleLockWallet();
209 }
210 
212 {
213  WalletView* walletView = currentWalletView();
214  if (walletView)
215  walletView->usedSendingAddresses();
216 }
217 
219 {
220  WalletView* walletView = currentWalletView();
221  if (walletView)
222  walletView->usedReceivingAddresses();
223 }
224 
226 {
227  WalletView* walletView = currentWalletView();
228  if (walletView)
229  walletView->showSeedPhrase();
230 }
231 
233 {
234  return qobject_cast<WalletView*>(walletStack->currentWidget());
235 }
WalletFrame::encryptWallet
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletframe.cpp:159
WalletFrame::WalletFrame
WalletFrame(BitcoinGUI *_gui=0)
Definition: walletframe.cpp:15
WalletFrame::gotoReceiveCoinsPage
void gotoReceiveCoinsPage()
Switch to receive coins page.
Definition: walletframe.cpp:125
WalletFrame::toggleLockWallet
void toggleLockWallet()
Toggle Wallet Lock State.
Definition: walletframe.cpp:204
WalletView
Definition: walletview.h:38
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:102
AskPassphraseDialog::Context
Context
Definition: askpassphrasedialog.h:34
AskPassphraseDialog::Context::Unlock_Menu
@ Unlock_Menu
WalletFrame::removeWallet
bool removeWallet(const QString &name)
Definition: walletframe.cpp:71
WalletFrame::changePassphrase
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletframe.cpp:173
WalletFrame::showSeedPhrase
void showSeedPhrase()
Show 24 word seed phrase.
Definition: walletframe.cpp:225
WalletFrame::backupWallet
void backupWallet()
Backup the wallet.
Definition: walletframe.cpp:166
WalletFrame::gotoMultiSendDialog
void gotoMultiSendDialog()
Show MultiSend Dialog.
Definition: walletframe.cpp:151
WalletFrame::bOutOfSync
bool bOutOfSync
Definition: walletframe.h:45
WalletView::setClientModel
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:125
WalletFrame::~WalletFrame
~WalletFrame()
Definition: walletframe.cpp:30
WalletFrame::usedReceivingAddresses
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletframe.cpp:218
WalletFrame::gotoOptionsPage
void gotoOptionsPage()
Switch to options page.
Definition: walletframe.cpp:132
WalletFrame::lockWallet
void lockWallet()
Lock wallet.
Definition: walletframe.cpp:197
WalletView::updateEncryptionStatus
void updateEncryptionStatus()
Re-Q_EMIT encryption status signal.
Definition: walletview.cpp:241
AskPassphraseDialog::Context::Unlock_Full
@ Unlock_Full
Unlock wallet from menu
WalletFrame::gotoBlockExplorerPage
void gotoBlockExplorerPage()
Switch to explorer page.
Definition: walletframe.cpp:118
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
WalletView::toggleLockWallet
void toggleLockWallet()
Toggle wallet lock state.
Definition: walletview.cpp:367
WalletFrame::gui
BitcoinGUI * gui
Definition: walletframe.h:42
WalletFrame::setCurrentWallet
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:60
walletview.h
WalletFrame::clientModel
ClientModel * clientModel
Definition: walletframe.h:43
WalletFrame::usedSendingAddresses
void usedSendingAddresses()
Show used sending addresses.
Definition: walletframe.cpp:211
WalletFrame::gotoSendCoinsPage
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
Definition: walletframe.cpp:139
WalletFrame::gotoMasternodePage
void gotoMasternodePage()
Switch to masternode page.
Definition: walletframe.cpp:111
name
const char * name
Definition: rest.cpp:34
ClientModel
Model for PRCY network client.
Definition: clientmodel.h:44
WalletView::unlockWallet
void unlockWallet(AskPassphraseDialog::Context context)
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:347
WalletView::showSeedPhrase
void showSeedPhrase()
Return 24 word seed phrase.
Definition: walletview.cpp:269
walletframe.h
WalletFrame::setClientModel
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:34
WalletView::gotoOverviewPage
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:187
WalletView::setWalletModel
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:135
WalletFrame::unlockWallet
void unlockWallet(AskPassphraseDialog::Context context)
Ask for passphrase to unlock wallet temporarily.
Definition: walletframe.cpp:190
WalletView::changePassphrase
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:341
WalletView::encryptWallet
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:246
WalletFrame::gotoOverviewPage
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletframe.cpp:97
WalletFrame::walletStack
QStackedWidget * walletStack
Definition: walletframe.h:41
bitcoingui.h
WalletFrame::mapWalletViews
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:44
WalletView::backupWallet
void backupWallet()
Backup the wallet.
Definition: walletview.cpp:257
WalletFrame::removeAllWallets
void removeAllWallets()
Definition: walletframe.cpp:81
WalletView::gotoMultiSendDialog
void gotoMultiSendDialog()
Show MultiSend Dialog.
Definition: walletview.cpp:229
WalletView::usedSendingAddresses
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:385
WalletFrame::currentWalletView
WalletView * currentWalletView()
Definition: walletframe.cpp:232
WalletView::setBitcoinGUI
void setBitcoinGUI(BitcoinGUI *gui)
Definition: walletview.cpp:102
WalletView::usedReceivingAddresses
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:395
WalletView::lockWallet
void lockWallet()
Lock wallet.
Definition: walletview.cpp:359
BitcoinGUI
Bitcoin GUI main class.
Definition: bitcoingui.h:48
WalletFrame::gotoHistoryPage
void gotoHistoryPage()
Switch to history (transactions) page.
Definition: walletframe.cpp:104
WalletFrame::showSyncStatus
void showSyncStatus(bool fShow)
Definition: walletframe.cpp:89
WalletFrame::addWallet
bool addWallet(const QString &name, WalletModel *walletModel)
Definition: walletframe.cpp:39
WalletView::showSyncStatus
void showSyncStatus(bool fShow)
Definition: walletview.cpp:236