Skip to content

Commit dbc0a6a

Browse files
author
Philip Kaufmann
committed
Bitcoin-Qt: tweak Qt walletXXX.cpp/h code
WalletView: - add new signal showNormalIfMinimized() - emit the new signal in handleURI() to fix a bug, preventing the main window to show up when using bitcoin: URIs WalletStack: - connect the showNormalIfMinimized() signal from WalletView with the showNormalIfMinimized() slot in BitcoinGUI - rework setCurrentWallet() to return a bool - add check for valid walletModel in addWallet() - add missing gui attribute initialisation in constructor WalletFrame: - remove unused or unneded class attributes gui and clientModel - add a check for valid clientModel in setClientModel() General: - small code formatting changes
1 parent e62f8d7 commit dbc0a6a

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

src/qt/walletframe.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
#include <QMessageBox>
1313

1414
WalletFrame::WalletFrame(BitcoinGUI *_gui) :
15-
QFrame(_gui),
16-
gui(_gui),
17-
clientModel(0)
15+
QFrame(_gui)
1816
{
1917
// Leave HBox hook for adding a list view later
2018
QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
2119
setContentsMargins(0,0,0,0);
2220
walletStack = new WalletStack(this);
23-
walletStack->setBitcoinGUI(gui);
21+
walletStack->setBitcoinGUI(_gui);
2422
walletFrameLayout->setContentsMargins(0,0,0,0);
2523
walletFrameLayout->addWidget(walletStack);
2624
}
@@ -31,8 +29,8 @@ WalletFrame::~WalletFrame()
3129

3230
void WalletFrame::setClientModel(ClientModel *clientModel)
3331
{
34-
this->clientModel = clientModel;
35-
walletStack->setClientModel(clientModel);
32+
if (clientModel)
33+
walletStack->setClientModel(clientModel);
3634
}
3735

3836
bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
@@ -43,8 +41,7 @@ bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
4341
bool WalletFrame::setCurrentWallet(const QString& name)
4442
{
4543
// TODO: Check if valid name
46-
walletStack->setCurrentWallet(name);
47-
return true;
44+
return walletStack->setCurrentWallet(name);
4845
}
4946

5047
void WalletFrame::removeAllWallets()

src/qt/walletframe.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class WalletFrame : public QFrame
3535
void showOutOfSyncWarning(bool fShow);
3636

3737
private:
38-
BitcoinGUI *gui;
39-
ClientModel *clientModel;
4038
WalletStack *walletStack;
4139

4240
public slots:

src/qt/walletstack.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
WalletStack::WalletStack(QWidget *parent) :
1515
QStackedWidget(parent),
16+
gui(0),
1617
clientModel(0),
1718
bOutOfSync(true)
1819
{
@@ -25,7 +26,7 @@ WalletStack::~WalletStack()
2526

2627
bool WalletStack::addWallet(const QString& name, WalletModel *walletModel)
2728
{
28-
if (!gui || !clientModel || mapWalletViews.count(name) > 0)
29+
if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
2930
return false;
3031

3132
WalletView *walletView = new WalletView(this, gui);
@@ -35,12 +36,18 @@ bool WalletStack::addWallet(const QString& name, WalletModel *walletModel)
3536
walletView->showOutOfSyncWarning(bOutOfSync);
3637
addWidget(walletView);
3738
mapWalletViews[name] = walletView;
39+
40+
// Ensure a walletView is able to show the main window
41+
connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
42+
3843
return true;
3944
}
4045

4146
bool WalletStack::removeWallet(const QString& name)
4247
{
43-
if (mapWalletViews.count(name) == 0) return false;
48+
if (mapWalletViews.count(name) == 0)
49+
return false;
50+
4451
WalletView *walletView = mapWalletViews.take(name);
4552
removeWidget(walletView);
4653
return true;
@@ -57,7 +64,8 @@ void WalletStack::removeAllWallets()
5764
bool WalletStack::handlePaymentRequest(const SendCoinsRecipient &recipient)
5865
{
5966
WalletView *walletView = (WalletView*)currentWidget();
60-
if (!walletView) return false;
67+
if (!walletView)
68+
return false;
6169

6270
return walletView->handlePaymentRequest(recipient);
6371
}
@@ -108,49 +116,59 @@ void WalletStack::gotoSendCoinsPage(QString addr)
108116
void WalletStack::gotoSignMessageTab(QString addr)
109117
{
110118
WalletView *walletView = (WalletView*)currentWidget();
111-
if (walletView) walletView->gotoSignMessageTab(addr);
119+
if (walletView)
120+
walletView->gotoSignMessageTab(addr);
112121
}
113122

114123
void WalletStack::gotoVerifyMessageTab(QString addr)
115124
{
116125
WalletView *walletView = (WalletView*)currentWidget();
117-
if (walletView) walletView->gotoVerifyMessageTab(addr);
126+
if (walletView)
127+
walletView->gotoVerifyMessageTab(addr);
118128
}
119129

120130
void WalletStack::encryptWallet(bool status)
121131
{
122132
WalletView *walletView = (WalletView*)currentWidget();
123-
if (walletView) walletView->encryptWallet(status);
133+
if (walletView)
134+
walletView->encryptWallet(status);
124135
}
125136

126137
void WalletStack::backupWallet()
127138
{
128139
WalletView *walletView = (WalletView*)currentWidget();
129-
if (walletView) walletView->backupWallet();
140+
if (walletView)
141+
walletView->backupWallet();
130142
}
131143

132144
void WalletStack::changePassphrase()
133145
{
134146
WalletView *walletView = (WalletView*)currentWidget();
135-
if (walletView) walletView->changePassphrase();
147+
if (walletView)
148+
walletView->changePassphrase();
136149
}
137150

138151
void WalletStack::unlockWallet()
139152
{
140153
WalletView *walletView = (WalletView*)currentWidget();
141-
if (walletView) walletView->unlockWallet();
154+
if (walletView)
155+
walletView->unlockWallet();
142156
}
143157

144158
void WalletStack::setEncryptionStatus()
145159
{
146160
WalletView *walletView = (WalletView*)currentWidget();
147-
if (walletView) walletView->setEncryptionStatus();
161+
if (walletView)
162+
walletView->setEncryptionStatus();
148163
}
149164

150-
void WalletStack::setCurrentWallet(const QString& name)
165+
bool WalletStack::setCurrentWallet(const QString& name)
151166
{
152-
if (mapWalletViews.count(name) == 0) return;
167+
if (mapWalletViews.count(name) == 0)
168+
return false;
169+
153170
WalletView *walletView = mapWalletViews.value(name);
154171
setCurrentWidget(walletView);
155172
walletView->setEncryptionStatus();
173+
return true;
156174
}

src/qt/walletstack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class WalletStack : public QStackedWidget
6767
bool bOutOfSync;
6868

6969
public slots:
70-
void setCurrentWallet(const QString& name);
70+
bool setCurrentWallet(const QString& name);
7171

7272
/** Switch to overview (home) page */
7373
void gotoOverviewPage();

src/qt/walletview.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void WalletView::setWalletModel(WalletModel *walletModel)
137137
void WalletView::incomingTransaction(const QModelIndex& parent, int start, int /*end*/)
138138
{
139139
// Prevent balloon-spam when initial block download is in progress
140-
if(!walletModel || !clientModel || clientModel->inInitialBlockDownload())
140+
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
141141
return;
142142

143143
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
@@ -207,6 +207,7 @@ bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)
207207
if (sendCoinsPage->handlePaymentRequest(recipient))
208208
{
209209
gotoSendCoinsPage();
210+
emit showNormalIfMinimized();
210211
return true;
211212
}
212213
else

src/qt/walletview.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public slots:
100100
void unlockWallet();
101101

102102
void setEncryptionStatus();
103+
104+
signals:
105+
/** Signal that we want to show the main window */
106+
void showNormalIfMinimized();
103107
};
104108

105109
#endif // WALLETVIEW_H

0 commit comments

Comments
 (0)