]> Git Repo - VerusCoin.git/blob - src/qt/walletframe.cpp
Merge pull request #5286
[VerusCoin.git] / src / qt / walletframe.cpp
1 // Copyright (c) 2011-2013 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 "bitcoingui.h"
8 #include "walletview.h"
9
10 #include <cstdio>
11
12 #include <QHBoxLayout>
13 #include <QLabel>
14
15 WalletFrame::WalletFrame(BitcoinGUI *_gui) :
16     QFrame(_gui),
17     gui(_gui)
18 {
19     // Leave HBox hook for adding a list view later
20     QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
21     setContentsMargins(0,0,0,0);
22     walletStack = new QStackedWidget(this);
23     walletFrameLayout->setContentsMargins(0,0,0,0);
24     walletFrameLayout->addWidget(walletStack);
25
26     QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
27     noWallet->setAlignment(Qt::AlignCenter);
28     walletStack->addWidget(noWallet);
29 }
30
31 WalletFrame::~WalletFrame()
32 {
33 }
34
35 void WalletFrame::setClientModel(ClientModel *clientModel)
36 {
37     this->clientModel = clientModel;
38 }
39
40 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
41 {
42     if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
43         return false;
44
45     WalletView *walletView = new WalletView(this);
46     walletView->setBitcoinGUI(gui);
47     walletView->setClientModel(clientModel);
48     walletView->setWalletModel(walletModel);
49     walletView->showOutOfSyncWarning(bOutOfSync);
50
51      /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
52     walletView->gotoOverviewPage();
53     walletStack->addWidget(walletView);
54     mapWalletViews[name] = walletView;
55
56     // Ensure a walletView is able to show the main window
57     connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
58
59     return true;
60 }
61
62 bool WalletFrame::setCurrentWallet(const QString& name)
63 {
64     if (mapWalletViews.count(name) == 0)
65         return false;
66
67     WalletView *walletView = mapWalletViews.value(name);
68     walletStack->setCurrentWidget(walletView);
69     walletView->updateEncryptionStatus();
70     return true;
71 }
72
73 bool WalletFrame::removeWallet(const QString &name)
74 {
75     if (mapWalletViews.count(name) == 0)
76         return false;
77
78     WalletView *walletView = mapWalletViews.take(name);
79     walletStack->removeWidget(walletView);
80     return true;
81 }
82
83 void WalletFrame::removeAllWallets()
84 {
85     QMap<QString, WalletView*>::const_iterator i;
86     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
87         walletStack->removeWidget(i.value());
88     mapWalletViews.clear();
89 }
90
91 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
92 {
93     WalletView *walletView = currentWalletView();
94     if (!walletView)
95         return false;
96
97     return walletView->handlePaymentRequest(recipient);
98 }
99
100 void WalletFrame::showOutOfSyncWarning(bool fShow)
101 {
102     bOutOfSync = fShow;
103     QMap<QString, WalletView*>::const_iterator i;
104     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
105         i.value()->showOutOfSyncWarning(fShow);
106 }
107
108 void WalletFrame::gotoOverviewPage()
109 {
110     QMap<QString, WalletView*>::const_iterator i;
111     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
112         i.value()->gotoOverviewPage();
113 }
114
115 void WalletFrame::gotoHistoryPage()
116 {
117     QMap<QString, WalletView*>::const_iterator i;
118     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
119         i.value()->gotoHistoryPage();
120 }
121
122 void WalletFrame::gotoReceiveCoinsPage()
123 {
124     QMap<QString, WalletView*>::const_iterator i;
125     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
126         i.value()->gotoReceiveCoinsPage();
127 }
128
129 void WalletFrame::gotoSendCoinsPage(QString addr)
130 {
131     QMap<QString, WalletView*>::const_iterator i;
132     for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
133         i.value()->gotoSendCoinsPage(addr);
134 }
135
136 void WalletFrame::gotoSignMessageTab(QString addr)
137 {
138     WalletView *walletView = currentWalletView();
139     if (walletView)
140         walletView->gotoSignMessageTab(addr);
141 }
142
143 void WalletFrame::gotoVerifyMessageTab(QString addr)
144 {
145     WalletView *walletView = currentWalletView();
146     if (walletView)
147         walletView->gotoVerifyMessageTab(addr);
148 }
149
150 void WalletFrame::encryptWallet(bool status)
151 {
152     WalletView *walletView = currentWalletView();
153     if (walletView)
154         walletView->encryptWallet(status);
155 }
156
157 void WalletFrame::backupWallet()
158 {
159     WalletView *walletView = currentWalletView();
160     if (walletView)
161         walletView->backupWallet();
162 }
163
164 void WalletFrame::changePassphrase()
165 {
166     WalletView *walletView = currentWalletView();
167     if (walletView)
168         walletView->changePassphrase();
169 }
170
171 void WalletFrame::unlockWallet()
172 {
173     WalletView *walletView = currentWalletView();
174     if (walletView)
175         walletView->unlockWallet();
176 }
177
178 void WalletFrame::usedSendingAddresses()
179 {
180     WalletView *walletView = currentWalletView();
181     if (walletView)
182         walletView->usedSendingAddresses();
183 }
184
185 void WalletFrame::usedReceivingAddresses()
186 {
187     WalletView *walletView = currentWalletView();
188     if (walletView)
189         walletView->usedReceivingAddresses();
190 }
191
192 WalletView *WalletFrame::currentWalletView()
193 {
194     return qobject_cast<WalletView*>(walletStack->currentWidget());
195 }
196
This page took 0.034083 seconds and 4 git commands to generate.