Fabcoin Core  0.16.2
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 <fabcoingui.h>
8 #include <walletview.h>
9 #include <tabbarinfo.h>
10 #include <wallet/wallet.h>
11 
12 #include <cstdio>
13 
14 #include <QHBoxLayout>
15 #include <QLabel>
16 
17 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, FabcoinGUI *_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->setFabcoinGUI(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  connect(walletView, SIGNAL(currentChanged(int)), this, SLOT(pageChanged(int)));
65 
66  return true;
67 }
68 
69 bool WalletFrame::setCurrentWallet(const QString& name)
70 {
71  if (mapWalletViews.count(name) == 0)
72  return false;
73 
74  WalletView *walletView = mapWalletViews.value(name);
75  walletStack->setCurrentWidget(walletView);
76  walletView->updateEncryptionStatus();
77  return true;
78 }
79 
80 bool WalletFrame::removeWallet(const QString &name)
81 {
82  if (mapWalletViews.count(name) == 0)
83  return false;
84 
85  WalletView *walletView = mapWalletViews.take(name);
86  walletStack->removeWidget(walletView);
87  return true;
88 }
89 
91 {
92  QMap<QString, WalletView*>::const_iterator i;
93  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
94  walletStack->removeWidget(i.value());
95  mapWalletViews.clear();
96 }
97 
99 {
100  WalletView *walletView = currentWalletView();
101  if (!walletView)
102  return false;
103 
104  return walletView->handlePaymentRequest(recipient);
105 }
106 
108 {
109  bOutOfSync = fShow;
110  QMap<QString, WalletView*>::const_iterator i;
111  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
112  i.value()->showOutOfSyncWarning(fShow);
113 }
114 
116 {
117  QMap<QString, WalletView*>::const_iterator i;
118  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
119  i.value()->gotoOverviewPage();
120 }
121 
123 {
124  QMap<QString, WalletView*>::const_iterator i;
125  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
126  i.value()->gotoHistoryPage();
127 }
128 
130 {
131  QMap<QString, WalletView*>::const_iterator i;
132  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
133  i.value()->gotoSendTokenPage();
134 }
135 
137 {
138  QMap<QString, WalletView*>::const_iterator i;
139  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
140  i.value()->gotoReceiveTokenPage();
141 }
142 
144 {
145  QMap<QString, WalletView*>::const_iterator i;
146  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
147  i.value()->gotoAddTokenPage();
148 }
149 
151 {
152  QMap<QString, WalletView*>::const_iterator i;
153  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
154  i.value()->gotoReceiveCoinsPage();
155 }
156 
158 {
159  QMap<QString, WalletView*>::const_iterator i;
160  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
161  i.value()->gotoSendCoinsPage(addr);
162 }
163 
165 {
166  QMap<QString, WalletView*>::const_iterator i;
167  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
168  i.value()->gotoCreateContractPage();
169 }
170 
172 {
173  QMap<QString, WalletView*>::const_iterator i;
174  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
175  i.value()->gotoSendToContractPage();
176 }
177 
179 {
180  QMap<QString, WalletView*>::const_iterator i;
181  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
182  i.value()->gotoCallContractPage();
183 }
184 
186 {
187  WalletView *walletView = currentWalletView();
188  if (walletView)
189  walletView->gotoSignMessageTab(addr);
190 }
191 
193 {
194  WalletView *walletView = currentWalletView();
195  if (walletView)
196  walletView->gotoVerifyMessageTab(addr);
197 }
198 
199 void WalletFrame::encryptWallet(bool status)
200 {
201  WalletView *walletView = currentWalletView();
202  if (walletView)
203  walletView->encryptWallet(status);
204 }
205 
207 {
208  WalletView *walletView = currentWalletView();
209  if (walletView)
210  walletView->backupWallet();
211 }
212 
214 {
215  WalletView *walletView = currentWalletView();
216  if (walletView)
217  walletView->restoreWallet();
218 }
219 
221 {
222  WalletView *walletView = currentWalletView();
223  if (walletView)
224  walletView->changePassphrase();
225 }
226 
228 {
229  QObject* object = sender();
230  QString objectName = object ? object->objectName() : "";
231  bool fromMenu = objectName == "unlockWalletAction";
232  WalletView *walletView = currentWalletView();
233  if (walletView)
234  walletView->unlockWallet(fromMenu);
235 }
236 
238 {
239  WalletView *walletView = currentWalletView();
240  if (walletView)
241  {
242  walletView->lockWallet();
243  fWalletUnlockStakingOnly = false;
244  }
245 }
246 
248 {
249  WalletView *walletView = currentWalletView();
250  if (walletView)
251  walletView->usedSendingAddresses();
252 }
253 
255 {
256  WalletView *walletView = currentWalletView();
257  if (walletView)
258  walletView->usedReceivingAddresses();
259 }
260 
262 {
263  return qobject_cast<WalletView*>(walletStack->currentWidget());
264 }
265 
267 {
268  Q_EMIT requestedSyncWarningInfo();
269 }
270 
272 {
273  QObject* obj = sender();
274  if(obj->inherits("WalletView"))
275  {
276  WalletView* walletView = (WalletView*)obj;
277  if(walletView->count() > index)
278  {
279  QWidget* currentPage = walletView->widget(index);
280  QObject* info = currentPage->findChild<TabBarInfo *>("");
281  gui->setTabBarInfo(info);
282  }
283  }
284 }
void unlockWallet(bool fromMenu=false)
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:375
void lockWallet()
Lock the wallet.
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletframe.cpp:98
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:69
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:304
void gotoAddTokenPage()
Switch to Add Token page.
void restoreWallet()
Restore the wallet.
bool bOutOfSync
Definition: walletframe.h:58
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:398
WalletView * currentWalletView()
ClientModel * clientModel
Definition: walletframe.h:55
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:368
void gotoCreateContractPage()
Switch to create contract page.
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:53
Fabcoin GUI main class.
Definition: fabcoingui.h:51
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:56
void gotoSendTokenPage()
Switch to Send Token page.
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:326
void removeAllWallets()
Definition: walletframe.cpp:90
void gotoCallContractPage()
Switch to call contract page.
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
void gotoOverviewPage()
Switch to overview (home) page.
void usedReceivingAddresses()
Show used receiving addresses.
Definition: walletview.cpp:408
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:38
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:141
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
const char * name
Definition: rest.cpp:36
bool addWallet(const QString &name, WalletModel *walletModel)
Definition: walletframe.cpp:43
WalletFrame(const PlatformStyle *platformStyle, FabcoinGUI *_gui=0)
Definition: walletframe.cpp:17
void restoreWallet()
Restore the wallet.
Definition: walletview.cpp:361
void changePassphrase()
Change encrypted wallet passphrase.
Model for Fabcoin network client.
Definition: clientmodel.h:38
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:342
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:316
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:236
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
void pageChanged(int index)
const PlatformStyle * platformStyle
Definition: walletframe.h:60
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
void gotoReceiveCoinsPage()
Switch to receive coins page.
void setTabBarInfo(QObject *into)
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
Definition: walletview.cpp:292
void setFabcoinGUI(FabcoinGUI *gui)
Definition: walletview.cpp:102
Interface to Fabcoin wallet from Qt view code.
Definition: walletmodel.h:103
bool fWalletUnlockStakingOnly
Definition: wallet.cpp:328
void lockWallet()
Lock the wallet.
Definition: walletview.cpp:390
FabcoinGUI * gui
Definition: walletframe.h:54
bool removeWallet(const QString &name)
Definition: walletframe.cpp:80
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:129
The TabBarInfo class Class for informations about tabs.
Definition: tabbarinfo.h:13
void backupWallet()
Backup the wallet.
void gotoSendToContractPage()
Switch to send contract page.
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:331
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:321
void gotoReceiveTokenPage()
Switch to Receive Token page.