Raven Core  3.0.0
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "walletframe.h"
7 
8 #include "ravengui.h"
9 #include "walletview.h"
10 
11 #include <cassert>
12 #include <cstdio>
13 
14 #include <QHBoxLayout>
15 #include <QLabel>
16 
17 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, RavenGUI *_gui) :
18  QFrame(_gui),
19  gui(_gui),
20  platformStyle(_platformStyle)
21 {
22  // Leave HBox hook for adding a list view later
23  QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
24  setContentsMargins(0,0,0,0);
25  walletStack = new QStackedWidget(this);
26  walletFrameLayout->setContentsMargins(0,0,0,0);
27  walletFrameLayout->addWidget(walletStack);
28 
29  QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
30  noWallet->setAlignment(Qt::AlignCenter);
31  walletStack->addWidget(noWallet);
32 }
33 
35 {
36 }
37 
39 {
40  this->clientModel = _clientModel;
41 }
42 
43 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
44 {
45  if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
46  return false;
47 
48  WalletView *walletView = new WalletView(platformStyle, this);
49  walletView->setRavenGUI(gui);
50  walletView->setClientModel(clientModel);
51  walletView->setWalletModel(walletModel);
52  walletView->showOutOfSyncWarning(bOutOfSync);
53 
54  /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
55  walletView->gotoOverviewPage();
56  walletStack->addWidget(walletView);
57  mapWalletViews[name] = walletView;
58 
59  // Ensure a walletView is able to show the main window
60  connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
61 
62  connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
63 
64  return true;
65 }
66 
67 bool WalletFrame::setCurrentWallet(const QString& name)
68 {
69  if (mapWalletViews.count(name) == 0)
70  return false;
71 
72  WalletView *walletView = mapWalletViews.value(name);
73  walletStack->setCurrentWidget(walletView);
74  assert(walletView);
75  walletView->updateEncryptionStatus();
76  return true;
77 }
78 
79 bool WalletFrame::removeWallet(const QString &name)
80 {
81  if (mapWalletViews.count(name) == 0)
82  return false;
83 
84  WalletView *walletView = mapWalletViews.take(name);
85  walletStack->removeWidget(walletView);
86  return true;
87 }
88 
90 {
91  QMap<QString, WalletView*>::const_iterator i;
92  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
93  walletStack->removeWidget(i.value());
94  mapWalletViews.clear();
95 }
96 
98 {
99  WalletView *walletView = currentWalletView();
100  if (!walletView)
101  return false;
102 
103  return walletView->handlePaymentRequest(recipient);
104 }
105 
107 {
108  bOutOfSync = fShow;
109  QMap<QString, WalletView*>::const_iterator i;
110  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
111  i.value()->showOutOfSyncWarning(fShow);
112 }
113 
115 {
116  QMap<QString, WalletView*>::const_iterator i;
117  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
118  i.value()->gotoOverviewPage();
119 }
120 
122 {
123  QMap<QString, WalletView*>::const_iterator i;
124  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
125  i.value()->gotoHistoryPage();
126 }
127 
129 {
130  QMap<QString, WalletView*>::const_iterator i;
131  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
132  i.value()->gotoReceiveCoinsPage();
133 }
134 
136 {
137  QMap<QString, WalletView*>::const_iterator i;
138  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
139  i.value()->gotoSendCoinsPage(addr);
140 }
141 
143 {
144  WalletView *walletView = currentWalletView();
145  if (walletView)
146  walletView->gotoSignMessageTab(addr);
147 }
148 
150 {
151  WalletView *walletView = currentWalletView();
152  if (walletView)
153  walletView->gotoVerifyMessageTab(addr);
154 }
155 
156 void WalletFrame::encryptWallet(bool status)
157 {
158  WalletView *walletView = currentWalletView();
159  if (walletView)
160  walletView->encryptWallet(status);
161 }
162 
164 {
165  WalletView *walletView = currentWalletView();
166  if (walletView)
167  walletView->backupWallet();
168 }
169 
171 {
172  WalletView *walletView = currentWalletView();
173  if (walletView)
174  walletView->changePassphrase();
175 }
176 
178 {
179  WalletView *walletView = currentWalletView();
180  if (walletView)
181  walletView->unlockWallet();
182 }
183 
185 {
186  WalletView *walletView = currentWalletView();
187  if (walletView)
188  walletView->usedSendingAddresses();
189 }
190 
192 {
193  WalletView *walletView = currentWalletView();
194  if (walletView)
195  walletView->usedReceivingAddresses();
196 }
197 
199 {
200  return qobject_cast<WalletView*>(walletStack->currentWidget());
201 }
202 
204 {
205  Q_EMIT requestedSyncWarningInfo();
206 }
207 
210 {
211  QMap<QString, WalletView*>::const_iterator i;
212  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
213  i.value()->gotoAssetsPage();
214 }
215 
217 {
218  QMap<QString, WalletView*>::const_iterator i;
219  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
220  i.value()->gotoCreateAssetsPage();
221 }
222 
224 {
225  QMap<QString, WalletView*>::const_iterator i;
226  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
227  i.value()->gotoManageAssetsPage();
228 }
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletframe.cpp:97
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:67
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:274
RavenGUI * gui
Definition: walletframe.h:55
bool bOutOfSync
Definition: walletframe.h:59
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:351
WalletView * currentWalletView()
ClientModel * clientModel
Definition: walletframe.h:56
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:331
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:54
void encryptWallet(bool status)
Encrypt the wallet.
void outOfSyncWarningClicked()
Pass on signal over requested out-of-sync-warning information.
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:57
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:296
void removeAllWallets()
Definition: walletframe.cpp:89
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
void gotoCreateAssetsPage()
void gotoOverviewPage()
Switch to overview (home) page.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:361
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:38
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:157
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
bool addWallet(const QString &name, WalletModel *walletModel)
Definition: walletframe.cpp:43
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:338
void changePassphrase()
Change encrypted wallet passphrase.
Model for Raven network client.
Definition: clientmodel.h:39
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:312
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:286
void gotoOverviewPage()
RVN END.
Definition: walletview.cpp:238
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
const PlatformStyle * platformStyle
Definition: walletframe.h:61
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
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:262
Interface to Raven wallet from Qt view code.
Definition: walletmodel.h:165
Raven GUI main class.
Definition: ravengui.h:47
bool removeWallet(const QString &name)
Definition: walletframe.cpp:79
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:149
void gotoManageAssetsPage()
void backupWallet()
Backup the wallet.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:301
void setRavenGUI(RavenGUI *gui)
Definition: walletview.cpp:113
void gotoAssetsPage()
RVN START.
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:291
WalletFrame(const PlatformStyle *platformStyle, RavenGUI *_gui=0)
Definition: walletframe.cpp:17