From 0dfaab93892aee333f7b838658ef85b9ff270ba7 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 29 Jan 2014 20:27:48 +0100 Subject: [PATCH] Make CTCP PING report the correct millisecond round-trip time 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 | 7 +++++-- src/core/eventstringifier.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index e2968187..cc508cf8 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -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 diff --git a/src/core/eventstringifier.cpp b/src/core/eventstringifier.cpp index 5cb3fd9e..c9c35ae1 100644 --- a/src/core/eventstringifier.cpp +++ b/src/core/eventstringifier.cpp @@ -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 } } -- 2.20.1