Make CTCP PING report the correct millisecond round-trip time
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 29 Jan 2014 19:27:48 +0000 (20:27 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 29 Jan 2014 19:30:37 +0000 (20:30 +0100)
If we want to display latency in milliseconds, we should also make sure
our payload is set in milliseconds.

Unfortunately, millisecond resolution for QDateTime appeared only in
Qt 4.7, so it'll stay in seconds for cores built against older Qt versions.

src/core/coreuserinputhandler.cpp
src/core/eventstringifier.cpp

index e296818..cc508cf 100644 (file)
@@ -169,8 +169,11 @@ void CoreUserInputHandler::handleCtcp(const BufferInfo &bufferInfo, const QStrin
     QString verboseMessage = tr("sending CTCP-%1 request to %2").arg(ctcpTag).arg(nick);
 
     if (ctcpTag == "PING") {
-        uint now = QDateTime::currentDateTime().toTime_t();
-        message = QString::number(now);
+#if QT_VERSION >= 0x040700
+        message = QString::number(QDateTime::currentMSecsSinceEpoch());
+#else
+        message = QString::number(QDateTime::currentDateTime().toTime_t());
+#endif
     }
 
     // FIXME make this a proper event
index 5cb3fd9..c9c35ae 100644 (file)
@@ -733,7 +733,12 @@ void EventStringifier::handleCtcpPing(CtcpEvent *e)
     if (e->ctcpType() == CtcpEvent::Query)
         defaultHandler(e->ctcpCmd(), e);
     else {
+#if QT_VERSION >= 0x040700
         displayMsg(e, Message::Server, tr("Received CTCP-PING answer from %1 with %2 milliseconds round trip time")
-            .arg(nickFromMask(e->prefix())).arg(QDateTime::fromTime_t(e->param().toInt()).msecsTo(e->timestamp())));
+            .arg(nickFromMask(e->prefix())).arg(QDateTime::fromMSecsSinceEpoch(e->param().toULongLong()).msecsTo(e->timestamp())));
+#else
+        displayMsg(e, Message::Server, tr("Received CTCP-PING answer from %1 with %2 seconds round trip time")
+            .arg(nickFromMask(e->prefix())).arg(QDateTime::fromTime_t(e->param().toInt()).secsTo(e->timestamp())));
+#endif
     }
 }