Browse Source

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.
0.14
Jon Lund Steffensen 12 years ago committed by Luke Dashjr
parent
commit
32efa79e0e
  1. 2
      src/net.cpp
  2. 23
      src/qt/bitcoingui.cpp
  3. 5
      src/qt/bitcoingui.h
  4. 28
      src/qt/clientmodel.cpp
  5. 6
      src/qt/clientmodel.h
  6. 30
      src/qt/rpcconsole.cpp
  7. 7
      src/qt/rpcconsole.h
  8. 3
      src/ui_interface.h

2
src/net.cpp

@ -2050,6 +2050,8 @@ void CConnman::SetNetworkActive(bool active)
} else { } else {
fNetworkActive = true; fNetworkActive = true;
} }
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
} }
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In) CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)

23
src/qt/bitcoingui.cpp

@ -459,8 +459,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
createTrayIconMenu(); createTrayIconMenu();
// Keep up to date with client // Keep up to date with client
setNumConnections(_clientModel->getNumConnections()); updateNetworkState();
connect(_clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); connect(_clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
connect(_clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
setNumBlocks(_clientModel->getNumBlocks(), _clientModel->getLastBlockDate(), _clientModel->getVerificationProgress(NULL), false); setNumBlocks(_clientModel->getNumBlocks(), _clientModel->getLastBlockDate(), _clientModel->getVerificationProgress(NULL), false);
connect(_clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool))); connect(_clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
@ -686,8 +687,9 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr)
} }
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
void BitcoinGUI::setNumConnections(int count) void BitcoinGUI::updateNetworkState()
{ {
int count = clientModel->getNumConnections();
QString icon; QString icon;
switch(count) switch(count)
{ {
@ -698,7 +700,22 @@ void BitcoinGUI::setNumConnections(int count)
default: icon = ":/icons/connect_4"; break; default: icon = ":/icons/connect_4"; break;
} }
labelConnectionsIcon->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); labelConnectionsIcon->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
if (clientModel->getNetworkActive()) {
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
} else {
labelConnectionsIcon->setToolTip(tr("Network activity disabled"));
}
}
void BitcoinGUI::setNumConnections(int count)
{
updateNetworkState();
}
void BitcoinGUI::setNetworkActive(bool networkActive)
{
updateNetworkState();
} }
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header) void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)

5
src/qt/bitcoingui.h

@ -144,6 +144,9 @@ private:
/** Disconnect core signals from GUI client */ /** Disconnect core signals from GUI client */
void unsubscribeFromCoreSignals(); void unsubscribeFromCoreSignals();
/** Update UI with latest network info from model. */
void updateNetworkState();
Q_SIGNALS: Q_SIGNALS:
/** Signal raised when a URI was entered or dragged to the GUI */ /** Signal raised when a URI was entered or dragged to the GUI */
void receivedURI(const QString &uri); void receivedURI(const QString &uri);
@ -151,6 +154,8 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
/** Set number of connections shown in the UI */ /** Set number of connections shown in the UI */
void setNumConnections(int count); void setNumConnections(int count);
/** Set network state shown in the UI */
void setNetworkActive(bool networkActive);
/** Set number of blocks and last block date shown in the UI */ /** Set number of blocks and last block date shown in the UI */
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers); void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);

28
src/qt/clientmodel.cpp

@ -128,6 +128,11 @@ void ClientModel::updateNumConnections(int numConnections)
Q_EMIT numConnectionsChanged(numConnections); Q_EMIT numConnectionsChanged(numConnections);
} }
void ClientModel::updateNetworkActive(bool networkActive)
{
Q_EMIT networkActiveChanged(networkActive);
}
void ClientModel::updateAlert() void ClientModel::updateAlert()
{ {
Q_EMIT alertsChanged(getStatusBarWarnings()); Q_EMIT alertsChanged(getStatusBarWarnings());
@ -150,6 +155,21 @@ enum BlockSource ClientModel::getBlockSource() const
return BLOCK_SOURCE_NONE; return BLOCK_SOURCE_NONE;
} }
void ClientModel::setNetworkActive(bool active)
{
if (g_connman) {
g_connman->SetNetworkActive(active);
}
}
bool ClientModel::getNetworkActive() const
{
if (g_connman) {
return g_connman->GetNetworkActive();
}
return false;
}
QString ClientModel::getStatusBarWarnings() const QString ClientModel::getStatusBarWarnings() const
{ {
return QString::fromStdString(GetWarnings("gui")); return QString::fromStdString(GetWarnings("gui"));
@ -216,6 +236,12 @@ static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConn
Q_ARG(int, newNumConnections)); Q_ARG(int, newNumConnections));
} }
static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive)
{
QMetaObject::invokeMethod(clientmodel, "updateNetworkActive", Qt::QueuedConnection,
Q_ARG(bool, networkActive));
}
static void NotifyAlertChanged(ClientModel *clientmodel) static void NotifyAlertChanged(ClientModel *clientmodel)
{ {
qDebug() << "NotifyAlertChanged"; qDebug() << "NotifyAlertChanged";
@ -256,6 +282,7 @@ void ClientModel::subscribeToCoreSignals()
// Connect signals to client // Connect signals to client
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1)); uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyNetworkActiveChanged.connect(boost::bind(NotifyNetworkActiveChanged, this, _1));
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this)); uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this));
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this)); uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false)); uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false));
@ -267,6 +294,7 @@ void ClientModel::unsubscribeFromCoreSignals()
// Disconnect signals from client // Disconnect signals from client
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2)); uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1)); uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyNetworkActiveChanged.disconnect(boost::bind(NotifyNetworkActiveChanged, this, _1));
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this)); uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this));
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this)); uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false)); uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false));

6
src/qt/clientmodel.h

@ -67,6 +67,10 @@ public:
bool inInitialBlockDownload() const; bool inInitialBlockDownload() const;
//! Return true if core is importing blocks //! Return true if core is importing blocks
enum BlockSource getBlockSource() const; enum BlockSource getBlockSource() const;
//! Return true if network activity in core is enabled
bool getNetworkActive() const;
//! Toggle network activity state in core
void setNetworkActive(bool active);
//! Return warnings to be displayed in status bar //! Return warnings to be displayed in status bar
QString getStatusBarWarnings() const; QString getStatusBarWarnings() const;
@ -90,6 +94,7 @@ Q_SIGNALS:
void numConnectionsChanged(int count); void numConnectionsChanged(int count);
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header); void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes); void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
void networkActiveChanged(bool networkActive);
void alertsChanged(const QString &warnings); void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
@ -102,6 +107,7 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
void updateTimer(); void updateTimer();
void updateNumConnections(int numConnections); void updateNumConnections(int numConnections);
void updateNetworkActive(bool networkActive);
void updateAlert(); void updateAlert();
void updateBanlist(); void updateBanlist();
}; };

30
src/qt/rpcconsole.cpp

@ -456,6 +456,9 @@ void RPCConsole::setClientModel(ClientModel *model)
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL), false); setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL), false);
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool))); connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
updateNetworkState();
connect(model, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent()); updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64))); connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
@ -670,16 +673,30 @@ void RPCConsole::message(int category, const QString &message, bool html)
ui->messagesWidget->append(out); ui->messagesWidget->append(out);
} }
void RPCConsole::updateNetworkState()
{
QString connections = QString::number(clientModel->getNumConnections()) + " (";
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
if(!clientModel->getNetworkActive()) {
connections += " (" + tr("Network activity disabled") + ")";
}
ui->numberOfConnections->setText(connections);
}
void RPCConsole::setNumConnections(int count) void RPCConsole::setNumConnections(int count)
{ {
if (!clientModel) if (!clientModel)
return; return;
QString connections = QString::number(count) + " ("; updateNetworkState();
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / "; }
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
ui->numberOfConnections->setText(connections); void RPCConsole::setNetworkActive(bool networkActive)
{
updateNetworkState();
} }
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers) void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
@ -1036,3 +1053,8 @@ void RPCConsole::setTabFocus(enum TabTypes tabType)
{ {
ui->tabWidget->setCurrentIndex(tabType); ui->tabWidget->setCurrentIndex(tabType);
} }
void RPCConsole::on_toggleNetworkActiveButton_clicked()
{
clientModel->setNetworkActive(!clientModel->getNetworkActive());
}

7
src/qt/rpcconsole.h

@ -61,6 +61,8 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void on_lineEdit_returnPressed(); void on_lineEdit_returnPressed();
void on_tabWidget_currentChanged(int index); void on_tabWidget_currentChanged(int index);
/** toggle network activity */
void on_toggleNetworkActiveButton_clicked();
/** open the debug.log from the current datadir */ /** open the debug.log from the current datadir */
void on_openDebugLogfileButton_clicked(); void on_openDebugLogfileButton_clicked();
/** change the time range of the network traffic graph */ /** change the time range of the network traffic graph */
@ -88,6 +90,8 @@ public Q_SLOTS:
void message(int category, const QString &message, bool html = false); void message(int category, const QString &message, bool html = false);
/** Set number of connections shown in the UI */ /** Set number of connections shown in the UI */
void setNumConnections(int count); void setNumConnections(int count);
/** Set network state shown in the UI */
void setNetworkActive(bool networkActive);
/** Set number of blocks and last block date shown in the UI */ /** Set number of blocks and last block date shown in the UI */
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers); void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
/** Set size (number of transactions and memory usage) of the mempool in the UI */ /** Set size (number of transactions and memory usage) of the mempool in the UI */
@ -142,6 +146,9 @@ private:
QMenu *banTableContextMenu; QMenu *banTableContextMenu;
int consoleFontSize; int consoleFontSize;
QCompleter *autoCompleter; QCompleter *autoCompleter;
/** Update UI with latest network info from model. */
void updateNetworkState();
}; };
#endif // BITCOIN_QT_RPCCONSOLE_H #endif // BITCOIN_QT_RPCCONSOLE_H

3
src/ui_interface.h

@ -85,6 +85,9 @@ public:
/** Number of network connections changed. */ /** Number of network connections changed. */
boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged; boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
/** Network activity state changed. */
boost::signals2::signal<void (bool networkActive)> NotifyNetworkActiveChanged;
/** /**
* Status bar alerts changed. * Status bar alerts changed.
*/ */

Loading…
Cancel
Save