Anoncoin  0.9.4
P2P Digital Currency
walletframe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Copyright (c) 2013-2014 The Anoncoin Core developers
3 // Distributed under the MIT/X11 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 "anoncoingui.h"
9 #include "walletview.h"
10 
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->setAnoncoinGUI(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  return true;
61 }
62 
63 bool WalletFrame::setCurrentWallet(const QString& name)
64 {
65  if (mapWalletViews.count(name) == 0)
66  return false;
67 
68  WalletView *walletView = mapWalletViews.value(name);
69  walletStack->setCurrentWidget(walletView);
70  walletView->updateEncryptionStatus();
71  return true;
72 }
73 
74 bool WalletFrame::removeWallet(const QString &name)
75 {
76  if (mapWalletViews.count(name) == 0)
77  return false;
78 
79  WalletView *walletView = mapWalletViews.take(name);
80  walletStack->removeWidget(walletView);
81  return true;
82 }
83 
85 {
86  QMap<QString, WalletView*>::const_iterator i;
87  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
88  walletStack->removeWidget(i.value());
89  mapWalletViews.clear();
90 }
91 
93 {
94  WalletView *walletView = currentWalletView();
95  if (!walletView)
96  return false;
97 
98  return walletView->handlePaymentRequest(recipient);
99 }
100 
102 {
103  bOutOfSync = fShow;
104  QMap<QString, WalletView*>::const_iterator i;
105  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
106  i.value()->showOutOfSyncWarning(fShow);
107 }
108 
110 {
111  QMap<QString, WalletView*>::const_iterator i;
112  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
113  i.value()->gotoOverviewPage();
114 }
115 
117 {
118  QMap<QString, WalletView*>::const_iterator i;
119  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
120  i.value()->gotoHistoryPage();
121 }
122 
124 {
125  QMap<QString, WalletView*>::const_iterator i;
126  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
127  i.value()->gotoReceiveCoinsPage();
128 }
129 
131 {
132  QMap<QString, WalletView*>::const_iterator i;
133  for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
134  i.value()->gotoSendCoinsPage(addr);
135 }
136 
138 {
139  WalletView *walletView = currentWalletView();
140  if (walletView)
141  walletView->gotoSignMessageTab(addr);
142 }
143 
145 {
146  WalletView *walletView = currentWalletView();
147  if (walletView)
148  walletView->gotoVerifyMessageTab(addr);
149 }
150 
151 void WalletFrame::encryptWallet(bool status)
152 {
153  WalletView *walletView = currentWalletView();
154  if (walletView)
155  walletView->encryptWallet(status);
156 }
157 
159 {
160  WalletView *walletView = currentWalletView();
161  if (walletView)
162  walletView->backupWallet();
163 }
164 
166 {
167  WalletView *walletView = currentWalletView();
168  if (walletView)
169  walletView->changePassphrase();
170 }
171 
173 {
174  WalletView *walletView = currentWalletView();
175  if (walletView)
176  walletView->unlockWallet();
177 }
178 
180 {
181  WalletView *walletView = currentWalletView();
182  if (walletView)
183  walletView->usedSendingAddresses();
184 }
185 
187 {
188  WalletView *walletView = currentWalletView();
189  if (walletView)
190  walletView->usedReceivingAddresses();
191 }
192 
194 {
195  return qobject_cast<WalletView*>(walletStack->currentWidget());
196 }
197 
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletframe.cpp:92
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:63
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Definition: walletview.cpp:189
bool bOutOfSync
Definition: walletframe.h:47
void usedSendingAddresses()
Show used sending addresses.
Definition: walletview.cpp:266
WalletView * currentWalletView()
ClientModel * clientModel
Definition: walletframe.h:44
void changePassphrase()
Change encrypted wallet passphrase.
Definition: walletview.cpp:246
void usedReceivingAddresses()
Show used receiving addresses.
QStackedWidget * walletStack
Definition: walletframe.h:42
Anoncoin GUI main class.
Definition: anoncoingui.h:47
void encryptWallet(bool status)
Encrypt the wallet.
QMap< QString, WalletView * > mapWalletViews
Definition: walletframe.h:45
void updateEncryptionStatus()
Re-emit encryption status signal.
Definition: walletview.cpp:211
void removeAllWallets()
Definition: walletframe.cpp:84
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:276
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:36
void setWalletModel(WalletModel *walletModel)
Set the wallet model.
Definition: walletview.cpp:107
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:41
void unlockWallet()
Ask for passphrase to unlock wallet temporarily.
Definition: walletview.cpp:253
AnoncoinGUI * gui
Definition: walletframe.h:43
void changePassphrase()
Change encrypted wallet passphrase.
Model for Anoncoin network client.
Definition: clientmodel.h:45
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:227
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
Definition: walletview.cpp:201
void gotoOverviewPage()
Switch to overview (home) page.
Definition: walletview.cpp:154
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:177
Interface to Anoncoin wallet from Qt view code.
Definition: walletmodel.h:97
bool removeWallet(const QString &name)
Definition: walletframe.cpp:74
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: walletview.cpp:100
void backupWallet()
Backup the wallet.
void setAnoncoinGUI(AnoncoinGUI *gui)
Definition: walletview.cpp:82
void encryptWallet(bool status)
Encrypt the wallet.
Definition: walletview.cpp:216
WalletFrame(AnoncoinGUI *_gui=0)
Definition: walletframe.cpp:16
void usedSendingAddresses()
Show used sending addresses.
void showOutOfSyncWarning(bool fShow)
Definition: walletview.cpp:206