Improve lag display
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 8 Dec 2009 18:00:50 +0000 (19:00 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 8 Dec 2009 19:04:33 +0000 (20:04 +0100)
Don't show if we're disconnected. Also, for lag >= 100 ms, show it in seconds.

src/client/coreconnection.cpp
src/client/coreconnection.h
src/qtui/coreconnectionstatuswidget.cpp

index 59d3f8f..460b3b7 100644 (file)
@@ -45,6 +45,12 @@ CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent)
   _progressValue(-1)
 {
   qRegisterMetaType<ConnectionState>("CoreConnection::ConnectionState");
   _progressValue(-1)
 {
   qRegisterMetaType<ConnectionState>("CoreConnection::ConnectionState");
+}
+
+void CoreConnection::init() {
+  Client::signalProxy()->setHeartBeatInterval(30);
+  connect(Client::signalProxy(), SIGNAL(disconnected()), SLOT(coreSocketDisconnected()));
+  connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), SIGNAL(lagUpdated(int)));
 
   _reconnectTimer.setSingleShot(true);
   connect(&_reconnectTimer, SIGNAL(timeout()), SLOT(reconnectTimeout()));
 
   _reconnectTimer.setSingleShot(true);
   connect(&_reconnectTimer, SIGNAL(timeout()), SLOT(reconnectTimeout()));
@@ -53,11 +59,6 @@ CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent)
   connect(Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)),
           SLOT(solidNetworkStatusChanged(Solid::Networking::Status)));
 #endif
   connect(Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)),
           SLOT(solidNetworkStatusChanged(Solid::Networking::Status)));
 #endif
-}
-
-void CoreConnection::init() {
-  Client::signalProxy()->setHeartBeatInterval(30);
-  connect(Client::signalProxy(), SIGNAL(disconnected()), SLOT(coreSocketDisconnected()));
 
   CoreConnectionSettings s;
   s.initAndNotify("PingTimeoutInterval", this, SLOT(pingTimeoutIntervalChanged(QVariant)), 60);
 
   CoreConnectionSettings s;
   s.initAndNotify("PingTimeoutInterval", this, SLOT(pingTimeoutIntervalChanged(QVariant)), 60);
@@ -336,6 +337,7 @@ void CoreConnection::resetConnection(bool wantReconnect) {
 
   setProgressMaximum(-1); // disable
   setState(Disconnected);
 
   setProgressMaximum(-1); // disable
   setState(Disconnected);
+  emit lagUpdated(-1);
 
   emit connectionMsg(tr("Disconnected from core."));
   emit encrypted(false);
 
   emit connectionMsg(tr("Disconnected from core."));
   emit encrypted(false);
index a06a810..a1d6cda 100644 (file)
@@ -84,6 +84,7 @@ signals:
   void stateChanged(CoreConnection::ConnectionState);
   void encrypted(bool isEncrypted = true);
   void synchronized();
   void stateChanged(CoreConnection::ConnectionState);
   void encrypted(bool isEncrypted = true);
   void synchronized();
+  void lagUpdated(int msecs);
 
   void connectionError(const QString &errorMsg);
   void connectionErrorPopup(const QString &errorMsg);
 
   void connectionError(const QString &errorMsg);
   void connectionErrorPopup(const QString &errorMsg);
index 34cdc66..7910fb8 100644 (file)
@@ -40,7 +40,7 @@ CoreConnectionStatusWidget::CoreConnectionStatusWidget(CoreConnection *connectio
 
   connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState)));
   connect(coreConnection(), SIGNAL(connectionError(QString)), ui.messageLabel, SLOT(setText(QString)));
 
   connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState)));
   connect(coreConnection(), SIGNAL(connectionError(QString)), ui.messageLabel, SLOT(setText(QString)));
-  connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), SLOT(updateLag(int)));
+  connect(coreConnection(), SIGNAL(lagUpdated(int)), SLOT(updateLag(int)));
 }
 
 void CoreConnectionStatusWidget::update() {
 }
 
 void CoreConnectionStatusWidget::update() {
@@ -58,7 +58,8 @@ void CoreConnectionStatusWidget::update() {
 
 void CoreConnectionStatusWidget::updateLag(int msecs) {
   if(msecs >= 0) {
 
 void CoreConnectionStatusWidget::updateLag(int msecs) {
   if(msecs >= 0) {
-    ui.lagLabel->setText(tr("(Lag: %1 ms)").arg(msecs));
+    QString unit = msecs >= 100 ? tr("s", "seconds") : tr("ms", "milliseconds");
+    ui.lagLabel->setText(tr("(Lag: %1 %2)").arg(msecs >= 100 ? msecs / 1000. : msecs, 0, 'f', (int)(msecs >= 100)).arg(unit));
     if(!ui.lagLabel->isVisible())
       ui.lagLabel->show();
   } else {
     if(!ui.lagLabel->isVisible())
       ui.lagLabel->show();
   } else {