Add more Event specializations (IrcEvent*, MessageEvent)
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 23 Sep 2010 09:03:04 +0000 (11:03 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:31 +0000 (01:06 +0200)
src/common/CMakeLists.txt
src/common/ircevent.cpp [new file with mode: 0644]
src/common/ircevent.h [new file with mode: 0644]
src/common/messageevent.cpp [new file with mode: 0644]
src/common/messageevent.h [new file with mode: 0644]

index c5da750..eb48554 100644 (file)
@@ -17,10 +17,12 @@ set(SOURCES
     identity.cpp
     ignorelistmanager.cpp
     ircchannel.cpp
+    ircevent.cpp
     irclisthelper.cpp
     ircuser.cpp
     logger.cpp
     message.cpp
+    messageevent.cpp
     network.cpp
     networkconfig.cpp
     networkevent.cpp
@@ -55,7 +57,9 @@ set(HEADERS ${MOC_HDRS}
     bufferinfo.h
     cliparser.h
     event.h
+    ircevent.h
     networkevent.h
+    messageevent.h
     logger.h
     message.h
     types.h
diff --git a/src/common/ircevent.cpp b/src/common/ircevent.cpp
new file mode 100644 (file)
index 0000000..2da406c
--- /dev/null
@@ -0,0 +1,21 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2010 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "ircevent.h"
diff --git a/src/common/ircevent.h b/src/common/ircevent.h
new file mode 100644 (file)
index 0000000..6704013
--- /dev/null
@@ -0,0 +1,82 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2010 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef IRCEVENT_H
+#define IRCEVENT_H
+
+#include "networkevent.h"
+
+class IrcEvent : public NetworkEvent {
+public:
+  explicit IrcEvent(EventManager::EventType type, Network *network, const QString &prefix, const QStringList &params = QStringList())
+    : NetworkEvent(type, network),
+      _prefix(prefix),
+      _params(params)
+  {}
+
+  inline QString prefix() const { return _prefix; }
+  inline void setPrefix(const QString &prefix) { _prefix = prefix; }
+
+  inline QStringList params() const { return _params; }
+  inline void setParams(const QStringList &params) { _params = params; }
+
+private:
+  QString _prefix;
+  QStringList _params;
+
+};
+
+class IrcEventNumeric : public IrcEvent {
+public:
+  explicit IrcEventNumeric(uint number, Network *network, const QString &prefix, const QString &target, const QStringList &params = QStringList())
+    : IrcEvent(EventManager::IrcEventNumeric, network, prefix, params),
+      _number(number),
+      _target(target)
+  {}
+
+  inline uint number() const { return _number; }
+
+  inline QString target() const { return _target; }
+  inline void setTarget(const QString &target) { _target = target; }
+
+private:
+  uint _number;
+  QString _target;
+
+};
+
+class IrcEventRawMessage : public IrcEvent {
+public:
+  explicit IrcEventRawMessage(EventManager::EventType type, Network *network, const QString &prefix, const QString &target, const QByteArray &rawMessage)
+    : IrcEvent(type, network, prefix, QStringList() << target),
+      _rawMessage(rawMessage)
+  {}
+
+  inline QString target() const { return params().at(0); }
+  inline void setTarget(const QString &target) { setParams(QStringList() << target); }
+
+  inline QByteArray rawMessage() const { return _rawMessage; }
+  inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; }
+
+private:
+  QByteArray _rawMessage;
+};
+
+#endif
diff --git a/src/common/messageevent.cpp b/src/common/messageevent.cpp
new file mode 100644 (file)
index 0000000..d7f3b7c
--- /dev/null
@@ -0,0 +1,53 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2010 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "messageevent.h"
+
+
+MessageEvent::MessageEvent(Message::Type msgType, Network *net, const QString &msg, const QString &target, const QString &sender, Message::Flags flags)
+    : NetworkEvent(EventManager::MessageEvent, net),
+      _msgType(msgType),
+      _text(msg),
+      _target(target),
+      _sender(sender),
+      _msgFlags(flags)
+{
+  IrcChannel *channel = network()->ircChannel(_target);
+  if(!channel) {
+    if(!_target.isEmpty() && network()->prefixes().contains(_target.at(0)))
+      _target = _target.mid(1);
+
+    if(_target.startsWith('$') || _target.startsWith('#'))
+      _target = nickFromMask(sender);
+  }
+
+  _bufferType = bufferTypeByTarget(_target);
+}
+
+BufferInfo::Type MessageEvent::bufferTypeByTarget(const QString &target) const {
+  if(target.isEmpty())
+    return BufferInfo::StatusBuffer;
+
+  if(network()->isChannelName(target))
+    return BufferInfo::ChannelBuffer;
+
+  return BufferInfo::QueryBuffer;
+}
+
diff --git a/src/common/messageevent.h b/src/common/messageevent.h
new file mode 100644 (file)
index 0000000..10803cb
--- /dev/null
@@ -0,0 +1,64 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2010 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef MESSAGEEVENT_H
+#define MESSAGEEVENT_H
+
+#include "message.h"
+#include "networkevent.h"
+
+// this corresponds to CoreSession::RawMessage for now and should contain the information we need to convert events
+// into messages for the legacy code to work with
+
+class MessageEvent : public NetworkEvent {
+
+public:
+  explicit MessageEvent(Message::Type msgType,
+                        Network *network,
+                        const QString &msg,
+                        const QString &target = QString(),
+                        const QString &sender = QString(),
+                        Message::Flags msgFlags = Message::None
+                        );
+
+  inline Message::Type msgType() const { return _msgType; }
+  inline void setMsgType(Message::Type type) { _msgType = type; }
+
+  inline BufferInfo::Type bufferType() const { return _bufferType; }
+  inline void setBufferType(BufferInfo::Type type) { _bufferType = type; }
+
+  inline QString target() const { return _target; }
+  inline QString text() const { return _text; }
+  inline QString sender() const { return _sender; }
+
+  inline Message::Flags msgFlags() const { return _msgFlags; }
+  inline void setMsgFlag(Message::Flag flag) { _msgFlags |= flag; }
+  inline void setMsgFlags(Message::Flags flags) { _msgFlags = flags; }
+
+private:
+  BufferInfo::Type bufferTypeByTarget(const QString &target) const;
+
+  Message::Type _msgType;
+  BufferInfo::Type _bufferType;
+  QString _text, _target, _sender;
+  Message::Flags _msgFlags;
+};
+
+#endif