Skip to content

Commit 85d5319

Browse files
luke-jrjonasschnelli
authored andcommitted
Qt: Ensure UI updates only come from the currently selected walletView
1 parent e449f9a commit 85d5319

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

src/qt/bitcoingui.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifdef ENABLE_WALLET
2222
#include <qt/walletframe.h>
2323
#include <qt/walletmodel.h>
24+
#include <qt/walletview.h>
2425
#endif // ENABLE_WALLET
2526

2627
#ifdef Q_OS_MAC
@@ -1097,6 +1098,20 @@ void BitcoinGUI::setEncryptionStatus(int status)
10971098
break;
10981099
}
10991100
}
1101+
1102+
void BitcoinGUI::updateWalletStatus()
1103+
{
1104+
if (!walletFrame) {
1105+
return;
1106+
}
1107+
WalletView * const walletView = walletFrame->currentWalletView();
1108+
if (!walletView) {
1109+
return;
1110+
}
1111+
WalletModel * const walletModel = walletView->getWalletModel();
1112+
setEncryptionStatus(walletModel->getEncryptionStatus());
1113+
setHDStatus(walletModel->hdEnabled());
1114+
}
11001115
#endif // ENABLE_WALLET
11011116

11021117
void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)

src/qt/bitcoingui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ public Q_SLOTS:
174174

175175
#ifdef ENABLE_WALLET
176176
bool setCurrentWallet(const QString& name);
177+
/** Set the UI status indicators based on the currently selected wallet.
178+
*/
179+
void updateWalletStatus();
177180

178181
private:
179182
/** Set the encryption status as shown in the UI.
@@ -188,6 +191,7 @@ public Q_SLOTS:
188191
*/
189192
void setHDStatus(int hdEnabled);
190193

194+
public Q_SLOTS:
191195
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
192196

193197
/** Show incoming transaction notification for new transactions. */

src/qt/walletframe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class WalletFrame : public QFrame
5959

6060
const PlatformStyle *platformStyle;
6161

62+
public:
6263
WalletView *currentWalletView();
6364

6465
public Q_SLOTS:

src/qt/walletmodel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ void WalletModel::updateStatus()
110110
{
111111
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
112112

113-
if(cachedEncryptionStatus != newEncryptionStatus)
114-
Q_EMIT encryptionStatusChanged(newEncryptionStatus);
113+
if(cachedEncryptionStatus != newEncryptionStatus) {
114+
Q_EMIT encryptionStatusChanged();
115+
}
115116
}
116117

117118
void WalletModel::pollBalanceChanged()

src/qt/walletmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class WalletModel : public QObject
255255
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
256256

257257
// Encryption status of wallet changed
258-
void encryptionStatusChanged(int status);
258+
void encryptionStatusChanged();
259259

260260
// Signal emitted when wallet needs to be unlocked
261261
// It is valid behaviour for listeners to keep the wallet locked after this signal;

src/qt/walletview.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui)
101101
connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
102102

103103
// Pass through encryption status changed signals
104-
connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
104+
connect(this, SIGNAL(encryptionStatusChanged()), gui, SLOT(updateWalletStatus()));
105105

106106
// Pass through transaction notifications
107107
connect(this, SIGNAL(incomingTransaction(QString,int,CAmount,QString,QString,QString)), gui, SLOT(incomingTransaction(QString,int,CAmount,QString,QString,QString)));
108108

109109
// Connect HD enabled state signal
110-
connect(this, SIGNAL(hdEnabledStatusChanged(int)), gui, SLOT(setHDStatus(int)));
110+
connect(this, SIGNAL(hdEnabledStatusChanged()), gui, SLOT(updateWalletStatus()));
111111
}
112112
}
113113

@@ -137,11 +137,11 @@ void WalletView::setWalletModel(WalletModel *_walletModel)
137137
connect(_walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
138138

139139
// Handle changes in encryption status
140-
connect(_walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
140+
connect(_walletModel, SIGNAL(encryptionStatusChanged()), this, SIGNAL(encryptionStatusChanged()));
141141
updateEncryptionStatus();
142142

143143
// update HD status
144-
Q_EMIT hdEnabledStatusChanged(_walletModel->hdEnabled());
144+
Q_EMIT hdEnabledStatusChanged();
145145

146146
// Balloon pop-up for new transaction
147147
connect(_walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
@@ -234,7 +234,7 @@ void WalletView::showOutOfSyncWarning(bool fShow)
234234

235235
void WalletView::updateEncryptionStatus()
236236
{
237-
Q_EMIT encryptionStatusChanged(walletModel->getEncryptionStatus());
237+
Q_EMIT encryptionStatusChanged();
238238
}
239239

240240
void WalletView::encryptWallet(bool status)

src/qt/walletview.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class WalletView : public QStackedWidget
4444
The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
4545
*/
4646
void setClientModel(ClientModel *clientModel);
47+
WalletModel *getWalletModel() { return walletModel; }
4748
/** Set the wallet model.
4849
The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
4950
functionality.
@@ -119,9 +120,9 @@ public Q_SLOTS:
119120
/** Fired when a message should be reported to the user */
120121
void message(const QString &title, const QString &message, unsigned int style);
121122
/** Encryption status of wallet changed */
122-
void encryptionStatusChanged(int status);
123+
void encryptionStatusChanged();
123124
/** HD-Enabled status of wallet changed (only possible during startup) */
124-
void hdEnabledStatusChanged(int hdEnabled);
125+
void hdEnabledStatusChanged();
125126
/** Notify that a new transaction appeared */
126127
void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label);
127128
/** Notify that the out of sync warning icon has been pressed */

0 commit comments

Comments
 (0)