Event backend porting
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 6 Oct 2010 09:08:14 +0000 (11:08 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:32 +0000 (01:06 +0200)
RPL_AWAY (301), RPL_UNAWAY (305), RPL_NOWAWAY (306)

Also replacing the fixed strings from the ircd by a translateable version.

src/core/coresessioneventprocessor.cpp
src/core/coresessioneventprocessor.h
src/core/eventstringifier.cpp
src/core/eventstringifier.h
src/core/ircserverhandler.cpp
src/core/ircserverhandler.h

index e3eca41..fb9f903 100644 (file)
@@ -190,6 +190,49 @@ void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *) {
   // TODO: save information in network object
 }
 
   // TODO: save information in network object
 }
 
+/*
+WHOIS-Message:
+   Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
+  and 301 (RPL_AWAY)
+              "<nick> :<away message>"
+WHO-Message:
+   Replies 352 and 315 paired are used to answer a WHO message.
+
+WHOWAS-Message:
+   Replies 314 and 369 are responses to a WHOWAS message.
+
+*/
+
+/* RPL_AWAY - "<nick> :<away message>" */
+void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e) {
+  if(!checkParamCount(e, 2))
+    return;
+
+  IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
+  if(ircuser) {
+    ircuser->setAway(true);
+    ircuser->setAwayMessage(e->params().at(1));
+    //ircuser->setLastAwayMessage(now);
+  }
+}
+
+/* RPL_UNAWAY - ":You are no longer marked as being away" */
+void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e) {
+  IrcUser *me = e->network()->me();
+  if(me)
+    me->setAway(false);
+
+  if(e->network()->autoAwayActive())
+    e->network()->setAutoAwayActive(false);
+}
+
+/* RPL_NOWAWAY - ":You have been marked as being away" */
+void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e) {
+  IrcUser *me = e->network()->me();
+  if(me)
+    me->setAway(true);
+}
+
 /* template
 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
   if(!checkParamCount(e, 1))
 /* template
 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
   if(!checkParamCount(e, 1))
index 1361205..e164ca8 100644 (file)
@@ -52,6 +52,9 @@ public:
   Q_INVOKABLE void processIrcEvent250(IrcEvent *event);            // RPL_STATSCONN
   Q_INVOKABLE void processIrcEvent265(IrcEvent *event);            // RPL_LOCALUSERS
   Q_INVOKABLE void processIrcEvent266(IrcEvent *event);            // RPL_GLOBALUSERS
   Q_INVOKABLE void processIrcEvent250(IrcEvent *event);            // RPL_STATSCONN
   Q_INVOKABLE void processIrcEvent265(IrcEvent *event);            // RPL_LOCALUSERS
   Q_INVOKABLE void processIrcEvent266(IrcEvent *event);            // RPL_GLOBALUSERS
+  Q_INVOKABLE void processIrcEvent301(IrcEvent *event);            // RPL_AWAY
+  Q_INVOKABLE void processIrcEvent305(IrcEvent *event);            // RPL_UNAWAY
+  Q_INVOKABLE void processIrcEvent306(IrcEvent *event);            // RPL_NOWAWAY
 
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
 
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
index 8b92da0..64e7003 100644 (file)
@@ -53,7 +53,7 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
   case 1: case 2: case 3: case 4: case 5:
   case 221: case 250: case 251: case 252: case 253: case 254: case 255: case 265: case 266:
   case 372: case 375:
   case 1: case 2: case 3: case 4: case 5:
   case 221: case 250: case 251: case 252: case 253: case 254: case 255: case 265: case 266:
   case 372: case 375:
-    displayMsg(e, Message::Server, e->params().join(" "), e->prefix()); qDebug () << e;
+    displayMsg(e, Message::Server, e->params().join(" "), e->prefix());
     break;
 
   // Server error messages without param, just display them
     break;
 
   // Server error messages without param, just display them
@@ -101,7 +101,7 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
   default:
     if(_whois) {
       // many nets define their own WHOIS fields. we fetch those not in need of special attention here:
   default:
     if(_whois) {
       // many nets define their own WHOIS fields. we fetch those not in need of special attention here:
-      displayMsg(e, Message::Server, "[Whois] " + e->params().join(" "), e->prefix());
+      displayMsg(e, Message::Server, tr("[Whois] ") + e->params().join(" "), e->prefix());
     } else {
       // FIXME figure out how/where to do this in the future
       //if(coreSession()->ircListHelper()->requestInProgress(network()->networkId()))
     } else {
       // FIXME figure out how/where to do this in the future
       //if(coreSession()->ircListHelper()->requestInProgress(network()->networkId()))
@@ -168,3 +168,40 @@ void EventStringifier::processIrcEventTopic(IrcEvent *e) {
   displayMsg(e, Message::Topic, tr("%1 has changed topic for %2 to: \"%3\"")
              .arg(e->nick(), e->params().at(0), e->params().at(1)), QString(), e->params().at(0));
 }
   displayMsg(e, Message::Topic, tr("%1 has changed topic for %2 to: \"%3\"")
              .arg(e->nick(), e->params().at(0), e->params().at(1)), QString(), e->params().at(0));
 }
+
+void EventStringifier::processIrcEvent301(IrcEvent *e) {
+  QString nick = e->params().at(0);
+  QString awayMsg = e->params().at(1);
+  QString msg, target;
+  bool send = true;
+
+  // FIXME: proper redirection needed
+  if(_whois) {
+    msg = tr("[Whois] ");
+  } else {
+    target = nick;
+    IrcUser *ircuser = e->network()->ircUser(nick);
+    if(ircuser) {
+      int now = QDateTime::currentDateTime().toTime_t();
+      const int silenceTime = 60;
+      if(ircuser->lastAwayMessage() + silenceTime >= now)
+        send = false;
+      ircuser->setLastAwayMessage(now);
+    }
+  }
+  if(send)
+    displayMsg(e, Message::Server, msg + tr("%1 is away: \"%2\"").arg(nick, awayMsg), QString(), target);
+}
+
+/* RPL_UNAWAY */
+void EventStringifier::earlyProcessIrcEvent305(IrcEvent *e) {
+  // needs to be called early so we still get the old autoAwayActive state!
+  if(!e->network()->autoAwayActive())
+    displayMsg(e, Message::Server, tr("You are no longer marked as being away"));
+}
+
+/* RPL_NOWAWAY */
+void EventStringifier::processIrcEvent306(IrcEvent *e) {
+  if(!e->network()->autoAwayActive())
+    displayMsg(e, Message::Server, tr("You have been marked as being away"));
+}
index 4bc7f1a..6dbfc0f 100644 (file)
@@ -57,6 +57,10 @@ public:
   Q_INVOKABLE void processIrcEventPong(IrcEvent *event);
   Q_INVOKABLE void processIrcEventTopic(IrcEvent *event);
 
   Q_INVOKABLE void processIrcEventPong(IrcEvent *event);
   Q_INVOKABLE void processIrcEventTopic(IrcEvent *event);
 
+  Q_INVOKABLE void processIrcEvent301(IrcEvent *event);      // RPL_AWAY
+  Q_INVOKABLE void earlyProcessIrcEvent305(IrcEvent *event); // RPL_UNAWAY
+  Q_INVOKABLE void processIrcEvent306(IrcEvent *event);      // RPL_NOWAWAY
+
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
 public slots:
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
 public slots:
index 523b215..debe2ef 100644 (file)
@@ -442,69 +442,6 @@ WHOWAS-Message:
 
 */
 
 
 */
 
-
-/*   RPL_AWAY - "<nick> :<away message>" */
-void IrcServerHandler::handle301(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle301()", params, 2))
-    return;
-
-
-  QString nickName = serverDecode(params[0]);
-  QString awayMessage = userDecode(nickName, params[1]);
-
-  IrcUser *ircuser = network()->ircUser(nickName);
-  if(ircuser) {
-    ircuser->setAwayMessage(awayMessage);
-    ircuser->setAway(true);
-  }
-
-  // FIXME: proper redirection needed
-  if(_whois) {
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is away: \"%2\"").arg(nickName).arg(awayMessage));
-  } else {
-    if(ircuser) {
-      int now = QDateTime::currentDateTime().toTime_t();
-      int silenceTime = 60;
-      if(ircuser->lastAwayMessage() + silenceTime < now) {
-        emit displayMsg(Message::Server, BufferInfo::QueryBuffer, params[0], tr("%1 is away: \"%2\"").arg(nickName).arg(awayMessage));
-      }
-      ircuser->setLastAwayMessage(now);
-    } else {
-      // probably should not happen
-      emit displayMsg(Message::Server, BufferInfo::QueryBuffer, params[0], tr("%1 is away: \"%2\"").arg(nickName).arg(awayMessage));
-    }
-  }
-}
-
-// 305  RPL_UNAWAY
-//      ":You are no longer marked as being away"
-void IrcServerHandler::handle305(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  IrcUser *me = network()->me();
-  if(me)
-    me->setAway(false);
-
-  if(!network()->autoAwayActive()) {
-    if(!params.isEmpty())
-      emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params[0]));
-  } else {
-    network()->setAutoAwayActive(false);
-  }
-}
-
-// 306  RPL_NOWAWAY
-//      ":You have been marked as being away"
-void IrcServerHandler::handle306(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  IrcUser *me = network()->me();
-  if(me)
-    me->setAway(true);
-
-  if(!params.isEmpty() && !network()->autoAwayActive())
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params[0]));
-}
-
 /* RPL_WHOISSERVICE - "<user> is registered nick" */
 void IrcServerHandler::handle307(const QString &prefix, const QList<QByteArray> &params) {
   Q_UNUSED(prefix)
 /* RPL_WHOISSERVICE - "<user> is registered nick" */
 void IrcServerHandler::handle307(const QString &prefix, const QList<QByteArray> &params) {
   Q_UNUSED(prefix)
index 9854396..d7b8750 100644 (file)
@@ -41,9 +41,6 @@ public slots:
   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
   void handle005(const QString &prefix, const QList<QByteArray> &params);   // RPL_ISUPPORT
   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
   void handle005(const QString &prefix, const QList<QByteArray> &params);   // RPL_ISUPPORT
-  void handle301(const QString &prefix, const QList<QByteArray> &params);   // RPL_AWAY
-  void handle305(const QString &prefix, const QList<QByteArray> &params);   // RPL_UNAWAY
-  void handle306(const QString &prefix, const QList<QByteArray> &params);   // RPL_NOWAWAY
   void handle307(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISSERVICE
   void handle310(const QString &prefix, const QList<QByteArray> &params);   // RPL_SUSERHOST
   void handle311(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISUSER
   void handle307(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISSERVICE
   void handle310(const QString &prefix, const QList<QByteArray> &params);   // RPL_SUSERHOST
   void handle311(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISUSER