Replaces numbered place marker %2 with %1.
[bitcoinplatinum.git] / src / qt / walletframe.cpp
blobc0b9d042695084cf9e1aaa73cb9a59ae8685386c
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.
5 #include <qt/walletframe.h>
7 #include <qt/bitcoingui.h>
8 #include <qt/walletview.h>
10 #include <cassert>
11 #include <cstdio>
13 #include <QHBoxLayout>
14 #include <QLabel>
16 WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
17 QFrame(_gui),
18 gui(_gui),
19 platformStyle(_platformStyle)
21 // Leave HBox hook for adding a list view later
22 QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
23 setContentsMargins(0,0,0,0);
24 walletStack = new QStackedWidget(this);
25 walletFrameLayout->setContentsMargins(0,0,0,0);
26 walletFrameLayout->addWidget(walletStack);
28 QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
29 noWallet->setAlignment(Qt::AlignCenter);
30 walletStack->addWidget(noWallet);
33 WalletFrame::~WalletFrame()
37 void WalletFrame::setClientModel(ClientModel *_clientModel)
39 this->clientModel = _clientModel;
42 bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
44 if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
45 return false;
47 WalletView *walletView = new WalletView(platformStyle, this);
48 walletView->setBitcoinGUI(gui);
49 walletView->setClientModel(clientModel);
50 walletView->setWalletModel(walletModel);
51 walletView->showOutOfSyncWarning(bOutOfSync);
53 /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
54 walletView->gotoOverviewPage();
55 walletStack->addWidget(walletView);
56 mapWalletViews[name] = walletView;
58 // Ensure a walletView is able to show the main window
59 connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
61 connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
63 return true;
66 bool WalletFrame::setCurrentWallet(const QString& name)
68 if (mapWalletViews.count(name) == 0)
69 return false;
71 WalletView *walletView = mapWalletViews.value(name);
72 walletStack->setCurrentWidget(walletView);
73 assert(walletView);
74 walletView->updateEncryptionStatus();
75 return true;
78 bool WalletFrame::removeWallet(const QString &name)
80 if (mapWalletViews.count(name) == 0)
81 return false;
83 WalletView *walletView = mapWalletViews.take(name);
84 walletStack->removeWidget(walletView);
85 return true;
88 void WalletFrame::removeAllWallets()
90 QMap<QString, WalletView*>::const_iterator i;
91 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
92 walletStack->removeWidget(i.value());
93 mapWalletViews.clear();
96 bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
98 WalletView *walletView = currentWalletView();
99 if (!walletView)
100 return false;
102 return walletView->handlePaymentRequest(recipient);
105 void WalletFrame::showOutOfSyncWarning(bool fShow)
107 bOutOfSync = fShow;
108 QMap<QString, WalletView*>::const_iterator i;
109 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
110 i.value()->showOutOfSyncWarning(fShow);
113 void WalletFrame::gotoOverviewPage()
115 QMap<QString, WalletView*>::const_iterator i;
116 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
117 i.value()->gotoOverviewPage();
120 void WalletFrame::gotoHistoryPage()
122 QMap<QString, WalletView*>::const_iterator i;
123 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
124 i.value()->gotoHistoryPage();
127 void WalletFrame::gotoReceiveCoinsPage()
129 QMap<QString, WalletView*>::const_iterator i;
130 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
131 i.value()->gotoReceiveCoinsPage();
134 void WalletFrame::gotoSendCoinsPage(QString addr)
136 QMap<QString, WalletView*>::const_iterator i;
137 for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
138 i.value()->gotoSendCoinsPage(addr);
141 void WalletFrame::gotoSignMessageTab(QString addr)
143 WalletView *walletView = currentWalletView();
144 if (walletView)
145 walletView->gotoSignMessageTab(addr);
148 void WalletFrame::gotoVerifyMessageTab(QString addr)
150 WalletView *walletView = currentWalletView();
151 if (walletView)
152 walletView->gotoVerifyMessageTab(addr);
155 void WalletFrame::encryptWallet(bool status)
157 WalletView *walletView = currentWalletView();
158 if (walletView)
159 walletView->encryptWallet(status);
162 void WalletFrame::backupWallet()
164 WalletView *walletView = currentWalletView();
165 if (walletView)
166 walletView->backupWallet();
169 void WalletFrame::changePassphrase()
171 WalletView *walletView = currentWalletView();
172 if (walletView)
173 walletView->changePassphrase();
176 void WalletFrame::unlockWallet()
178 WalletView *walletView = currentWalletView();
179 if (walletView)
180 walletView->unlockWallet();
183 void WalletFrame::usedSendingAddresses()
185 WalletView *walletView = currentWalletView();
186 if (walletView)
187 walletView->usedSendingAddresses();
190 void WalletFrame::usedReceivingAddresses()
192 WalletView *walletView = currentWalletView();
193 if (walletView)
194 walletView->usedReceivingAddresses();
197 WalletView *WalletFrame::currentWalletView()
199 return qobject_cast<WalletView*>(walletStack->currentWidget());
202 void WalletFrame::outOfSyncWarningClicked()
204 Q_EMIT requestedSyncWarningInfo();