Skip to content

Commit 32efa79

Browse files
jonlsluke-jr
authored andcommitted
Qt: Add GUI feedback and control of network activity state.
Add getNetworkActive()/setNetworkActive() method to client model. Send network active status through NotifyNetworkActiveChanged. Indicate in tool tip of gui status bar network indicator whether network activity is disabled. Indicate in debug window whether network activity is disabled and add button to allow user to toggle network activity state.
1 parent e38993b commit 32efa79

File tree

8 files changed

+97
-7
lines changed

8 files changed

+97
-7
lines changed

src/net.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,8 @@ void CConnman::SetNetworkActive(bool active)
20502050
} else {
20512051
fNetworkActive = true;
20522052
}
2053+
2054+
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
20532055
}
20542056

20552057
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)

src/qt/bitcoingui.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
459459
createTrayIconMenu();
460460

461461
// Keep up to date with client
462-
setNumConnections(_clientModel->getNumConnections());
462+
updateNetworkState();
463463
connect(_clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
464+
connect(_clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
464465

465466
setNumBlocks(_clientModel->getNumBlocks(), _clientModel->getLastBlockDate(), _clientModel->getVerificationProgress(NULL), false);
466467
connect(_clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
@@ -686,8 +687,9 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr)
686687
}
687688
#endif // ENABLE_WALLET
688689

689-
void BitcoinGUI::setNumConnections(int count)
690+
void BitcoinGUI::updateNetworkState()
690691
{
692+
int count = clientModel->getNumConnections();
691693
QString icon;
692694
switch(count)
693695
{
@@ -698,7 +700,22 @@ void BitcoinGUI::setNumConnections(int count)
698700
default: icon = ":/icons/connect_4"; break;
699701
}
700702
labelConnectionsIcon->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
701-
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
703+
704+
if (clientModel->getNetworkActive()) {
705+
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
706+
} else {
707+
labelConnectionsIcon->setToolTip(tr("Network activity disabled"));
708+
}
709+
}
710+
711+
void BitcoinGUI::setNumConnections(int count)
712+
{
713+
updateNetworkState();
714+
}
715+
716+
void BitcoinGUI::setNetworkActive(bool networkActive)
717+
{
718+
updateNetworkState();
702719
}
703720

704721
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)

src/qt/bitcoingui.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,18 @@ class BitcoinGUI : public QMainWindow
144144
/** Disconnect core signals from GUI client */
145145
void unsubscribeFromCoreSignals();
146146

147+
/** Update UI with latest network info from model. */
148+
void updateNetworkState();
149+
147150
Q_SIGNALS:
148151
/** Signal raised when a URI was entered or dragged to the GUI */
149152
void receivedURI(const QString &uri);
150153

151154
public Q_SLOTS:
152155
/** Set number of connections shown in the UI */
153156
void setNumConnections(int count);
157+
/** Set network state shown in the UI */
158+
void setNetworkActive(bool networkActive);
154159
/** Set number of blocks and last block date shown in the UI */
155160
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
156161

src/qt/clientmodel.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ void ClientModel::updateNumConnections(int numConnections)
128128
Q_EMIT numConnectionsChanged(numConnections);
129129
}
130130

131+
void ClientModel::updateNetworkActive(bool networkActive)
132+
{
133+
Q_EMIT networkActiveChanged(networkActive);
134+
}
135+
131136
void ClientModel::updateAlert()
132137
{
133138
Q_EMIT alertsChanged(getStatusBarWarnings());
@@ -150,6 +155,21 @@ enum BlockSource ClientModel::getBlockSource() const
150155
return BLOCK_SOURCE_NONE;
151156
}
152157

158+
void ClientModel::setNetworkActive(bool active)
159+
{
160+
if (g_connman) {
161+
g_connman->SetNetworkActive(active);
162+
}
163+
}
164+
165+
bool ClientModel::getNetworkActive() const
166+
{
167+
if (g_connman) {
168+
return g_connman->GetNetworkActive();
169+
}
170+
return false;
171+
}
172+
153173
QString ClientModel::getStatusBarWarnings() const
154174
{
155175
return QString::fromStdString(GetWarnings("gui"));
@@ -216,6 +236,12 @@ static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConn
216236
Q_ARG(int, newNumConnections));
217237
}
218238

239+
static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive)
240+
{
241+
QMetaObject::invokeMethod(clientmodel, "updateNetworkActive", Qt::QueuedConnection,
242+
Q_ARG(bool, networkActive));
243+
}
244+
219245
static void NotifyAlertChanged(ClientModel *clientmodel)
220246
{
221247
qDebug() << "NotifyAlertChanged";
@@ -256,6 +282,7 @@ void ClientModel::subscribeToCoreSignals()
256282
// Connect signals to client
257283
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
258284
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
285+
uiInterface.NotifyNetworkActiveChanged.connect(boost::bind(NotifyNetworkActiveChanged, this, _1));
259286
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this));
260287
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
261288
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false));
@@ -267,6 +294,7 @@ void ClientModel::unsubscribeFromCoreSignals()
267294
// Disconnect signals from client
268295
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
269296
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
297+
uiInterface.NotifyNetworkActiveChanged.disconnect(boost::bind(NotifyNetworkActiveChanged, this, _1));
270298
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this));
271299
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
272300
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false));

src/qt/clientmodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ClientModel : public QObject
6767
bool inInitialBlockDownload() const;
6868
//! Return true if core is importing blocks
6969
enum BlockSource getBlockSource() const;
70+
//! Return true if network activity in core is enabled
71+
bool getNetworkActive() const;
72+
//! Toggle network activity state in core
73+
void setNetworkActive(bool active);
7074
//! Return warnings to be displayed in status bar
7175
QString getStatusBarWarnings() const;
7276

@@ -90,6 +94,7 @@ class ClientModel : public QObject
9094
void numConnectionsChanged(int count);
9195
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
9296
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
97+
void networkActiveChanged(bool networkActive);
9398
void alertsChanged(const QString &warnings);
9499
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
95100

@@ -102,6 +107,7 @@ class ClientModel : public QObject
102107
public Q_SLOTS:
103108
void updateTimer();
104109
void updateNumConnections(int numConnections);
110+
void updateNetworkActive(bool networkActive);
105111
void updateAlert();
106112
void updateBanlist();
107113
};

src/qt/rpcconsole.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ void RPCConsole::setClientModel(ClientModel *model)
456456
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL), false);
457457
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
458458

459+
updateNetworkState();
460+
connect(model, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
461+
459462
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
460463
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
461464

@@ -670,16 +673,30 @@ void RPCConsole::message(int category, const QString &message, bool html)
670673
ui->messagesWidget->append(out);
671674
}
672675

676+
void RPCConsole::updateNetworkState()
677+
{
678+
QString connections = QString::number(clientModel->getNumConnections()) + " (";
679+
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
680+
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
681+
682+
if(!clientModel->getNetworkActive()) {
683+
connections += " (" + tr("Network activity disabled") + ")";
684+
}
685+
686+
ui->numberOfConnections->setText(connections);
687+
}
688+
673689
void RPCConsole::setNumConnections(int count)
674690
{
675691
if (!clientModel)
676692
return;
677693

678-
QString connections = QString::number(count) + " (";
679-
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
680-
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
694+
updateNetworkState();
695+
}
681696

682-
ui->numberOfConnections->setText(connections);
697+
void RPCConsole::setNetworkActive(bool networkActive)
698+
{
699+
updateNetworkState();
683700
}
684701

685702
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
@@ -1036,3 +1053,8 @@ void RPCConsole::setTabFocus(enum TabTypes tabType)
10361053
{
10371054
ui->tabWidget->setCurrentIndex(tabType);
10381055
}
1056+
1057+
void RPCConsole::on_toggleNetworkActiveButton_clicked()
1058+
{
1059+
clientModel->setNetworkActive(!clientModel->getNetworkActive());
1060+
}

src/qt/rpcconsole.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class RPCConsole: public QWidget
6161
private Q_SLOTS:
6262
void on_lineEdit_returnPressed();
6363
void on_tabWidget_currentChanged(int index);
64+
/** toggle network activity */
65+
void on_toggleNetworkActiveButton_clicked();
6466
/** open the debug.log from the current datadir */
6567
void on_openDebugLogfileButton_clicked();
6668
/** change the time range of the network traffic graph */
@@ -88,6 +90,8 @@ public Q_SLOTS:
8890
void message(int category, const QString &message, bool html = false);
8991
/** Set number of connections shown in the UI */
9092
void setNumConnections(int count);
93+
/** Set network state shown in the UI */
94+
void setNetworkActive(bool networkActive);
9195
/** Set number of blocks and last block date shown in the UI */
9296
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
9397
/** Set size (number of transactions and memory usage) of the mempool in the UI */
@@ -142,6 +146,9 @@ public Q_SLOTS:
142146
QMenu *banTableContextMenu;
143147
int consoleFontSize;
144148
QCompleter *autoCompleter;
149+
150+
/** Update UI with latest network info from model. */
151+
void updateNetworkState();
145152
};
146153

147154
#endif // BITCOIN_QT_RPCCONSOLE_H

src/ui_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class CClientUIInterface
8585
/** Number of network connections changed. */
8686
boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
8787

88+
/** Network activity state changed. */
89+
boost::signals2::signal<void (bool networkActive)> NotifyNetworkActiveChanged;
90+
8891
/**
8992
* Status bar alerts changed.
9093
*/

0 commit comments

Comments
 (0)