From b5385b3ddf6f0e8df8f0af7275b59dcc1fcd0ed1 Mon Sep 17 00:00:00 2001 From: Alexander von Renteln Date: Tue, 8 Apr 2008 14:45:16 +0000 Subject: [PATCH] BR#138: prettifyed the whois output of the core --- src/client/networkmodel.cpp | 18 +------------- src/common/util.cpp | 24 +++++++++++++++++- src/common/util.h | 2 ++ src/core/ircserverhandler.cpp | 47 +++++++++++++++++++++++++++++------ src/core/ircserverhandler.h | 1 + version.inc | 4 +-- 6 files changed, 68 insertions(+), 28 deletions(-) diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 5b2f953e..9d463f64 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -596,23 +596,7 @@ QString IrcUserItem::toolTip(int column) const { QDateTime now = QDateTime::currentDateTime(); QDateTime idle = _ircUser->idleTime(); int idleTime = idle.secsTo(now); - - QList< QPair > timeUnit; - timeUnit.append(qMakePair(365*60*60, tr("year"))); - timeUnit.append(qMakePair(24*60*60, tr("day"))); - timeUnit.append(qMakePair(60*60, tr("h"))); - timeUnit.append(qMakePair(60, tr("min"))); - timeUnit.append(qMakePair(1, tr("sec"))); - - QString idleString(' '); - for(int i=0; i < timeUnit.size(); i++) { - int n = idleTime / timeUnit[i].first; - if(n > 0) { - idleString += QString("%1 %2 ").arg(QString::number(n), timeUnit[i].second); - } - idleTime = idleTime % timeUnit[i].first; - } - toolTip.append(tr("idling since %1").arg(idleString)); + toolTip.append(tr("idling since %1").arg(secondsToString(idleTime))); } if(_ircUser->loginTime().isValid()) { toolTip.append(tr("login time: %1").arg(_ircUser->loginTime().toString())); diff --git a/src/common/util.cpp b/src/common/util.cpp index 76a3e0c4..4c1a22f2 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -18,10 +18,12 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "util.h" +#include #include #include +#include "util.h" + class QMetaMethod; QString nickFromMask(QString mask) { @@ -156,3 +158,23 @@ QDir quasselDir() { return qDir; } + + +QString secondsToString(int timeInSeconds) { + QList< QPair > timeUnit; + timeUnit.append(qMakePair(365*60*60, QCoreApplication::translate("Quassel::secondsToString()", "year"))); + timeUnit.append(qMakePair(24*60*60, QCoreApplication::translate("Quassel::secondsToString()", "day"))); + timeUnit.append(qMakePair(60*60, QCoreApplication::translate("Quassel::secondsToString()", "h"))); + timeUnit.append(qMakePair(60, QCoreApplication::translate("Quassel::secondsToString()", "min"))); + timeUnit.append(qMakePair(1, QCoreApplication::translate("Quassel::secondsToString()", "sec"))); + + QString returnString; + for(int i=0; i < timeUnit.size(); i++) { + int n = timeInSeconds / timeUnit[i].first; + if(n > 0) { + returnString += QString("%1 %2 ").arg(QString::number(n), timeUnit[i].second); + } + timeInSeconds = timeInSeconds % timeUnit[i].first; + } + return returnString; +} diff --git a/src/common/util.h b/src/common/util.h index 0b372b6a..5c954b29 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -35,6 +35,8 @@ QString hostFromMask(QString mask); bool isChannelName(QString str); +QString secondsToString(int timeInSeconds); + //! Take a string and decode it using the specified text codec, recognizing utf8. /** This function takes a string and first checks if it is encoded in utf8, in which case it is * decoded appropriately. Otherwise, the specified text codec is used to transform the string. diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index d7eb114c..5af0c5ab 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -451,8 +451,10 @@ void IrcServerHandler::handle311(const QString &prefix, const QList ircuser->setUser(serverDecode(params[1])); ircuser->setHost(serverDecode(params[2])); ircuser->setRealName(serverDecode(params.last())); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is %2 (%3)") .arg(ircuser->nick()).arg(ircuser->hostmask()).arg(ircuser->realName())); + } else { + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is %2 (%3)") .arg(serverDecode(params[1])).arg(serverDecode(params[2])).arg(serverDecode(params.last()))); } - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1") .arg(serverDecode(params).join(" "))); } /* RPL_WHOISSERVER - " :" */ @@ -462,10 +464,12 @@ void IrcServerHandler::handle312(const QString &prefix, const QList if(ircuser) { ircuser->setServer(serverDecode(params[1])); } + + QString returnString = tr("%1 is online via %2 (%3)").arg(serverDecode(params[0])).arg(serverDecode(params[1])).arg(serverDecode(params.last())); if(_whois) { - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" "))); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(returnString)); } else { - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(serverDecode(params).join(" "))); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(returnString)); } } @@ -482,7 +486,10 @@ void IrcServerHandler::handle313(const QString &prefix, const QList /* RPL_WHOWASUSER - " * :" */ void IrcServerHandler::handle314(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix) - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(serverDecode(params).join(" "))); + QString nick = serverDecode(params[0]); + QString hostmask = QString("%1@%2").arg(serverDecode(params[1])).arg(serverDecode(params[2])); + QString realName = serverDecode(params.last()); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1 was %2 (%3)").arg(nick).arg(hostmask).arg(realName)); } /* RPL_ENDOFWHO: " :End of WHO list" */ @@ -495,7 +502,6 @@ void IrcServerHandler::handle315(const QString &prefix, const QList /* RPL_WHOISIDLE - " :seconds idle" (real life: " :seconds idle, signon time) */ - //TODO: parse real life message void IrcServerHandler::handle317(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix); QString nick = serverDecode(params[0]); @@ -508,9 +514,9 @@ void IrcServerHandler::handle317(const QString &prefix, const QList if(params.size()>3) { int loginTime = serverDecode(params[2]).toInt(); ircuser->setLoginTime(QDateTime::fromTime_t(loginTime)); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is logged in since %2 seconds").arg(ircuser->nick()).arg(ircuser->loginTime().toString())); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is logged in since %2").arg(ircuser->nick()).arg(ircuser->loginTime().toString())); } - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is idling for %2").arg(ircuser->nick()).arg(ircuser->idleTime().secsTo(now))); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is idling for %2 (%3)").arg(ircuser->nick()).arg(secondsToString(ircuser->idleTime().secsTo(now))).arg(ircuser->idleTime().toString())); } else { emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] idle message: %1").arg(userDecode(nick, params).join(" "))); @@ -521,12 +527,37 @@ void IrcServerHandler::handle317(const QString &prefix, const QList void IrcServerHandler::handle318(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix) _whois = false; - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" "))); + QStringList parameter = serverDecode(params); + parameter.removeFirst(); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(parameter.join(" "))); } /* RPL_WHOISCHANNELS - " :*( ( "@" / "+" ) " " )" */ void IrcServerHandler::handle319(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix) + QString nick = serverDecode(params.first()); + QStringList op; + QStringList voice; + QStringList user; + foreach (QString channel, serverDecode(params.last()).split(" ")) { + if(channel.startsWith("@")) + op.append(channel.remove(0,1)); + else if(channel.startsWith("+")) + voice.append(channel.remove(0,1)); + else + user.append(channel); + } + if(!user.isEmpty()) + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is a user on channels: %2").arg(nick).arg(user.join(" "))); + if(!voice.isEmpty()) + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 has voice on channels: %2").arg(nick).arg(voice.join(" "))); + if(!op.isEmpty()) + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is an operator on channels: %2").arg(nick).arg(op.join(" "))); +} + +/* RPL_WHOISVIRT - " is identified to services" */ +void IrcServerHandler::handle320(const QString &prefix, const QList ¶ms) { + Q_UNUSED(prefix); emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" "))); } diff --git a/src/core/ircserverhandler.h b/src/core/ircserverhandler.h index 89289fc0..562c422d 100644 --- a/src/core/ircserverhandler.h +++ b/src/core/ircserverhandler.h @@ -55,6 +55,7 @@ public slots: void handle317(const QString &prefix, const QList ¶ms); // RPL_WHOISIDLE void handle318(const QString &prefix, const QList ¶ms); // RPL_ENDOFWHOIS void handle319(const QString &prefix, const QList ¶ms); // RPL_WHOISCHANNELS + void handle320(const QString &prefix, const QList ¶ms); // RPL_WHOISVIRT (is identified to services) void handle331(const QString &prefix, const QList ¶ms); // RPL_NOTOPIC void handle332(const QString &prefix, const QList ¶ms); // RPL_TOPIC void handle333(const QString &prefix, const QList ¶ms); // Topic set by... diff --git a/version.inc b/version.inc index 6119edcf..1dd2a514 100644 --- a/version.inc +++ b/version.inc @@ -4,8 +4,8 @@ { using namespace Global; quasselVersion = "0.2.0-alpha5-pre"; - quasselDate = "2008-04-07"; - quasselBuild = 707; + quasselDate = "2008-04-08"; + quasselBuild = 711; //! Minimum client build number the core needs clientBuildNeeded = 642; -- 2.20.1