Event backend porting
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 3 Oct 2010 22:02:58 +0000 (00:02 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:32 +0000 (01:06 +0200)
INVITE, KICK, NICK, PART are using the event backend now.

src/core/coresession.cpp
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 9f24007..2ed950c 100644 (file)
@@ -96,6 +96,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
   initScriptEngine();
 
   eventManager()->registerObject(ircParser(), EventManager::NormalPriority);
+  eventManager()->registerObject(eventStringifier(), EventManager::HighPriority, "earlyProcess"); // some need to be sent before statechange
   eventManager()->registerObject(eventProcessor(), EventManager::HighPriority); // needs to process events *before* the stringifier!
   eventManager()->registerObject(eventStringifier(), EventManager::NormalPriority);
   eventManager()->registerObject(this, EventManager::LowPriority); // for sending MessageEvents to the client
index 8599524..2147071 100644 (file)
@@ -57,3 +57,52 @@ void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
     break;
   }
 }
+
+void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e) {
+  if(checkParamCount(e, 2)) {
+    e->network()->updateNickFromMask(e->prefix());
+  }
+}
+
+void CoreSessionEventProcessor::processIrcEventKick(IrcEvent *e) {
+  if(checkParamCount(e, 2)) {
+    e->network()->updateNickFromMask(e->prefix());
+    IrcUser *victim = e->network()->ircUser(e->params().at(1));
+    if(victim) {
+      victim->partChannel(e->params().at(0));
+      //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
+    }
+  }
+}
+
+void CoreSessionEventProcessor::processIrcEventNick(IrcEvent *e) {
+  if(checkParamCount(e, 1)) {
+    IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
+    if(!ircuser) {
+      qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
+      return;
+    }
+    QString newnick = e->params().at(0);
+    QString oldnick = ircuser->nick();
+
+    // the order is cruicial
+    // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
+    // and remove the ircuser from the querybuffer leading to a wrong on/offline state
+    ircuser->setNick(newnick);
+    coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
+  }
+}
+
+void CoreSessionEventProcessor::processIrcEventPart(IrcEvent *e) {
+  if(checkParamCount(e, 1)) {
+    IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
+    if(!ircuser) {
+      qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
+      return;
+    }
+    QString channel = e->params().at(0);
+    ircuser->partChannel(channel);
+    if(e->network()->isMe(ircuser))
+      qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
+  }
+}
index 4d7559d..98274fa 100644 (file)
@@ -37,6 +37,11 @@ public:
 
   Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event);
 
+  Q_INVOKABLE void processIrcEventInvite(IrcEvent *event);
+  Q_INVOKABLE void processIrcEventKick(IrcEvent *event);
+  Q_INVOKABLE void processIrcEventNick(IrcEvent *event);
+  Q_INVOKABLE void processIrcEventPart(IrcEvent *event);
+
 protected:
   bool checkParamCount(IrcEvent *event, int minParams);
 
index 44528e5..304e36c 100644 (file)
@@ -109,3 +109,48 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
     }
   }
 }
+
+void EventStringifier::processIrcEventInvite(IrcEvent *e) {
+  displayMsg(e, Message::Invite, tr("%1 invited you to channel %2").arg(e->nick(), e->params().at(1)));
+}
+
+void EventStringifier::earlyProcessIrcEventKick(IrcEvent *e) {
+  IrcUser *victim = e->network()->ircUser(e->params().at(1));
+  if(victim) {
+    QString channel = e->params().at(0);
+    QString msg = victim->nick();
+    if(e->params().count() > 2)
+      msg += " " + e->params().at(2);
+
+    displayMsg(e, Message::Kick, msg, e->prefix(), channel);
+  }
+}
+
+// this needs to be called before the ircuser is renamed!
+void EventStringifier::earlyProcessIrcEventNick(IrcEvent *e) {
+  if(e->params().count() < 1)
+    return;
+
+  IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
+  if(!ircuser) {
+    qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
+    return;
+  }
+
+  QString newnick = e->params().at(0);
+  QString oldnick = ircuser->nick();
+
+  QString sender = e->network()->isMyNick(oldnick) ? newnick : e->prefix();
+  foreach(const QString &channel, ircuser->channels())
+    displayMsg(e, Message::Nick, newnick, sender, channel);
+}
+
+void EventStringifier::earlyProcessIrcEventPart(IrcEvent *e) {
+  if(e->params().count() < 1)
+    return;
+
+  QString channel = e->params().at(0);
+  QString msg = e->params().count() > 1? e->params().at(1) : QString();
+
+  displayMsg(e, Message::Part, msg, e->prefix(), channel);
+}
index 2e1074a..0ff417d 100644 (file)
@@ -50,6 +50,11 @@ public:
   //! Handle generic numeric events
   Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event);
 
+  Q_INVOKABLE void processIrcEventInvite(IrcEvent *event);
+  Q_INVOKABLE void earlyProcessIrcEventKick(IrcEvent *event);
+  Q_INVOKABLE void earlyProcessIrcEventNick(IrcEvent *event);
+  Q_INVOKABLE void earlyProcessIrcEventPart(IrcEvent *event);
+
 public slots:
   //! Creates and sends a MessageEvent
   void displayMsg(NetworkEvent *event,
index 341dd00..fe9f250 100644 (file)
@@ -138,20 +138,6 @@ void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const
 //******************************/
 // IRC SERVER HANDLER
 //******************************/
-void IrcServerHandler::handleInvite(const QString &prefix, const QList<QByteArray> &params) {
-  if(!checkParamCount("IrcServerHandler::handleInvite()", params, 2))
-    return;
-//   qDebug() << "IrcServerHandler::handleInvite()" << prefix << params;
-
-  IrcUser *ircuser = network()->updateNickFromMask(prefix);
-  if(!ircuser) {
-    return;
-  }
-
-  QString channel = serverDecode(params[1]);
-
-  emit displayMsg(Message::Invite, BufferInfo::StatusBuffer, "", tr("%1 invited you to channel %2").arg(ircuser->nick()).arg(channel));
-}
 
 void IrcServerHandler::handleJoin(const QString &prefix, const QList<QByteArray> &params) {
   if(!checkParamCount("IrcServerHandler::handleJoin()", params, 1))
@@ -182,28 +168,6 @@ void IrcServerHandler::handleJoin(const QString &prefix, const QList<QByteArray>
   }
 }
 
-void IrcServerHandler::handleKick(const QString &prefix, const QList<QByteArray> &params) {
-  if(!checkParamCount("IrcServerHandler::handleKick()", params, 2))
-    return;
-
-  network()->updateNickFromMask(prefix);
-  IrcUser *victim = network()->ircUser(params[1]);
-  if(!victim)
-    return;
-
-  QString channel = serverDecode(params[0]);
-  victim->partChannel(channel);
-
-  QString msg;
-  if(params.count() > 2) // someone got a reason!
-    msg = QString("%1 %2").arg(victim->nick()).arg(channelDecode(channel, params[2]));
-  else
-    msg = victim->nick();
-
-  emit displayMsg(Message::Kick, BufferInfo::ChannelBuffer, channel, msg, prefix);
-  //if(network()->isMe(victim)) network()->setKickedFromChannel(channel);
-}
-
 void IrcServerHandler::handleMode(const QString &prefix, const QList<QByteArray> &params) {
   if(!checkParamCount("IrcServerHandler::handleMode()", params, 2))
     return;
@@ -315,33 +279,6 @@ void IrcServerHandler::handleMode(const QString &prefix, const QList<QByteArray>
   }
 }
 
-void IrcServerHandler::handleNick(const QString &prefix, const QList<QByteArray> &params) {
-  if(!checkParamCount("IrcServerHandler::handleNick()", params, 1))
-    return;
-
-  IrcUser *ircuser = network()->updateNickFromMask(prefix);
-  if(!ircuser) {
-    qWarning() << "IrcServerHandler::handleNick(): Unknown IrcUser!";
-    return;
-  }
-  QString newnick = serverDecode(params[0]);
-  QString oldnick = ircuser->nick();
-
-  QString sender = network()->isMyNick(oldnick)
-    ? newnick
-    : prefix;
-
-
-  // the order is cruicial
-  // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
-  // and remove the ircuser from the querybuffer leading to a wrong on/offline state
-  ircuser->setNick(newnick);
-  coreSession()->renameBuffer(network()->networkId(), newnick, oldnick);
-
-  foreach(QString channel, ircuser->channels())
-    emit displayMsg(Message::Nick, BufferInfo::ChannelBuffer, channel, newnick, sender);
-}
-
 void IrcServerHandler::handleNotice(const QString &prefix, const QList<QByteArray> &params) {
   if(!checkParamCount("IrcServerHandler::handleNotice()", params, 2))
     return;
@@ -383,27 +320,6 @@ void IrcServerHandler::handleNotice(const QString &prefix, const QList<QByteArra
 
 }
 
-void IrcServerHandler::handlePart(const QString &prefix, const QList<QByteArray> &params) {
-  if(!checkParamCount("IrcServerHandler::handlePart()", params, 1))
-    return;
-
-  IrcUser *ircuser = network()->updateNickFromMask(prefix);
-  QString channel = serverDecode(params[0]);
-  if(!ircuser) {
-    qWarning() << "IrcServerHandler::handlePart(): Unknown IrcUser!";
-    return;
-  }
-
-  ircuser->partChannel(channel);
-
-  QString msg;
-  if(params.count() > 1)
-    msg = userDecode(ircuser->nick(), params[1]);
-
-  emit displayMsg(Message::Part, BufferInfo::ChannelBuffer, channel, msg, prefix);
-  if(network()->isMe(ircuser)) network()->setChannelParted(channel);
-}
-
 void IrcServerHandler::handlePing(const QString &prefix, const QList<QByteArray> &params) {
   Q_UNUSED(prefix);
   putCmd("PONG", params);
index 2f9623c..96ededf 100644 (file)
@@ -34,13 +34,9 @@ public:
   void handleServerMsg(QByteArray rawMsg);
 
 public slots:
-  void handleInvite(const QString &prefix, const QList<QByteArray> &params);
   void handleJoin(const QString &prefix, const QList<QByteArray> &params);
-  void handleKick(const QString &prefix, const QList<QByteArray> &params);
   void handleMode(const QString &prefix, const QList<QByteArray> &params);
-  void handleNick(const QString &prefix, const QList<QByteArray> &params);
   void handleNotice(const QString &prefix, const QList<QByteArray> &params);
-  void handlePart(const QString &prefix, const QList<QByteArray> &params);
   void handlePing(const QString &prefix, const QList<QByteArray> &params);
   void handlePong(const QString &prefix, const QList<QByteArray> &params);
   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);