***************************************************************************/
#include "ctcpevent.h"
+
+Event *CtcpEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+ if(type == EventManager::CtcpEvent || type == EventManager::CtcpEventFlush)
+ return new CtcpEvent(type, map, network);
+
+ return 0;
+}
+
+
+CtcpEvent::CtcpEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : IrcEvent(type, map, network)
+{
+ _ctcpType = static_cast<CtcpType>(map.take("ctcpType").toInt());
+ _ctcpCmd = map.take("ctcpCmd").toString();
+ _target = map.take("target").toString();
+ _param = map.take("param").toString();
+ _reply = map.take("repy").toString();
+ _uuid = map.take("uuid").toString();
+}
+
+
+void CtcpEvent::toVariantMap(QVariantMap &map) const {
+ IrcEvent::toVariantMap(map);
+ map["ctcpType"] = ctcpType();
+ map["ctcpCmd"] = ctcpCmd();
+ map["target"] = target();
+ map["param"] = param();
+ map["reply"] = reply();
+ map["uuid"] = uuid().toString();
+}
inline QUuid uuid() const { return _uuid; }
inline void setUuid(const QUuid &uuid) { _uuid = uuid; }
+ static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
protected:
+ explicit CtcpEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "CtcpEvent"; }
virtual inline void debugInfo(QDebug &dbg) const {
NetworkEvent::debugInfo(dbg);
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#include "event.h"
+#include "ctcpevent.h"
+#include "ircevent.h"
+#include "networkevent.h"
+#include "messageevent.h"
Event::Event(EventManager::EventType type)
: _type(type)
+ , _valid(true)
{
}
+
+Event::Event(EventManager::EventType type, QVariantMap &map)
+ : _type(type)
+ , _valid(true)
+{
+ if(!map.contains("flags") || !map.contains("timestamp")) {
+ qWarning() << "Received invalid serialized event:" << map;
+ setValid(false);
+ return;
+ }
+
+ setFlags(static_cast<EventManager::EventFlags>(map.take("flags").toInt())); // TODO sanity check?
+ setTimestamp(QDateTime::fromTime_t(map.take("timestamp").toUInt()));
+}
+
+
+void Event::toVariantMap(QVariantMap &map) const {
+ map["type"] = static_cast<int>(type());
+ map["flags"] = static_cast<int>(flags());
+ map["timestamp"] = timestamp().toTime_t();
+}
+
+
+QVariantMap Event::toVariantMap() const {
+ QVariantMap map;
+ toVariantMap(map);
+ return map;
+}
+
+
+Event *Event::fromVariantMap(QVariantMap &map, Network *network) {
+ int inttype = map.take("type").toInt();
+ // sanity check if we have a valid enum value
+ if(EventManager::enumName(inttype).isEmpty()) {
+ qWarning() << "Received a serialized event with unknown type" << inttype;
+ return 0;
+ }
+
+ EventManager::EventType type = static_cast<EventManager::EventType>(inttype);
+ if(type == EventManager::Invalid || type == EventManager::GenericEvent)
+ return 0;
+
+ EventManager::EventType group = static_cast<EventManager::EventType>(type & EventManager::EventGroupMask);
+
+ Event *e = 0;
+
+ // we use static create() functions to keep group-specific special cases in the files they belong
+ // e.g. IrcEventRawMessage
+ switch(group) {
+ case EventManager::NetworkEvent:
+ e = NetworkEvent::create(type, map, network);
+ break;
+ case EventManager::IrcServerEvent:
+ // not in use!
+ break;
+ case EventManager::IrcEvent:
+ e = IrcEvent::create(type, map, network);
+ break;
+ case EventManager::MessageEvent:
+ e = MessageEvent::create(type, map, network);
+ break;
+ case EventManager::CtcpEvent:
+ e = CtcpEvent::create(type, map, network);
+ break;
+ default:
+ break;
+ }
+
+ if(!e) {
+ qWarning() << "Can't create event of type" << type;
+ return 0;
+ }
+
+ if(!map.isEmpty()) {
+ qWarning() << "Event creation from map did not consume all data:" << map;
+ }
+
+ return e;
+}
+
+
QDebug operator<<(QDebug dbg, Event *e) {
dbg.nospace() << qPrintable(e->className()) << "("
<< "type = 0x" << qPrintable(QString::number(e->type(), 16));
#include "eventmanager.h"
+class Network;
+
class Event {
public:
explicit Event(EventManager::EventType type = EventManager::Invalid);
- virtual ~Event() {};
+ virtual ~Event() {}
inline EventManager::EventType type() const { return _type; }
inline bool testFlag(EventManager::EventFlag flag) { return _flags.testFlag(flag); }
inline EventManager::EventFlags flags() const { return _flags; }
+ inline bool isValid() const { return _valid; }
inline void stop() { setFlag(EventManager::Stopped); }
inline bool isStopped() { return _flags.testFlag(EventManager::Stopped); }
//inline void setData(const QVariant &data) { _data = data; }
//inline QVariant data() const { return _data; }
+ // call EventManager::createEvent(map) instead!
+ static Event *fromVariantMap(QVariantMap &map, Network *network);
+ QVariantMap toVariantMap() const;
+
protected:
virtual inline QString className() const { return "Event"; }
virtual inline void debugInfo(QDebug &dbg) const { Q_UNUSED(dbg); }
+ explicit Event(EventManager::EventType type, QVariantMap &map);
+
+ // must only use primitive types: string, int, double, list, hash
+ // we want to convert this to JSON in the future!
+ virtual void toVariantMap(QVariantMap &map) const;
+
+ inline void setValid(bool valid) { _valid = valid; }
+
private:
EventManager::EventType _type;
EventManager::EventFlags _flags;
QDateTime _timestamp;
//QVariant _data;
+ bool _valid;
friend QDebug operator<<(QDebug dbg, Event *e);
};
return eventEnum().valueToKey(type);
}
+Event *EventManager::createEvent(const QVariantMap &map) {
+ QVariantMap m = map;
+
+ Network *net = networkById(m.take("network").toInt());
+ return Event::fromVariantMap(m, net);
+}
+
/* NOTE:
Registering and calling handlers works fine even if they specify a subclass of Event as their parameter.
However, this most probably is a result from a reinterpret_cast somewhere deep inside Qt, so there is *no*
#include <QMetaEnum>
+#include "types.h"
+
class Event;
+class Network;
class EventManager : public QObject {
Q_OBJECT
Silent = 0x40, ///< Don't generate a MessageEvent
Stopped = 0x80
};
- Q_DECLARE_FLAGS(EventFlags, EventFlag);
+ Q_DECLARE_FLAGS(EventFlags, EventFlag)
/*
MessageEvent = 0x00040000, ///< Stringified event suitable for converting to Message
CtcpEvent = 0x00050000,
- CtcpEventFlush,
+ CtcpEventFlush
};
EventManager(QObject *parent = 0);
static QString enumName(EventType type);
static QString enumName(int type); // for sanity tests
+ Event *createEvent(const QVariantMap &map);
+
public slots:
void registerObject(QObject *object, Priority priority = NormalPriority,
const QString &methodPrefix = "process",
void postEvent(Event *event);
protected:
+ virtual Network *networkById(NetworkId id) const = 0;
virtual void customEvent(QEvent *event);
private:
***************************************************************************/
#include "ircevent.h"
+
+Event *IrcEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+ if((type & EventManager::IrcEventNumericMask) == EventManager::IrcEventNumeric)
+ return new IrcEventNumeric(type, map, network);
+
+ if((type & EventManager::EventGroupMask) != EventManager::IrcEvent)
+ return 0;
+
+ switch(type) {
+ case EventManager::IrcEventRawPrivmsg:
+ case EventManager::IrcEventRawNotice:
+ return new IrcEventRawMessage(type, map, network);
+
+ default:
+ return new IrcEvent(type, map, network);
+ }
+}
+
+
+IrcEvent::IrcEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : NetworkEvent(type, map, network)
+{
+ _prefix = map.take("prefix").toString();
+ _params = map.take("params").toStringList();
+}
+
+
+void IrcEvent::toVariantMap(QVariantMap &map) const {
+ NetworkEvent::toVariantMap(map);
+ map["prefix"] = prefix();
+ map["params"] = params();
+}
+
+
+IrcEventNumeric::IrcEventNumeric(EventManager::EventType type, QVariantMap &map, Network *network)
+ : IrcEvent(type, map, network)
+{
+ _number = map.take("number").toUInt();
+ _target = map.take("target").toString();
+}
+
+
+void IrcEventNumeric::toVariantMap(QVariantMap &map) const {
+ IrcEvent::toVariantMap(map);
+ map["number"] = number();
+ map["target"] = target();
+}
+
+
+IrcEventRawMessage::IrcEventRawMessage(EventManager::EventType type, QVariantMap &map, Network *network)
+ : IrcEvent(type, map, network)
+{
+ _rawMessage = map.take("rawMessage").toByteArray();
+}
+
+
+void IrcEventRawMessage::toVariantMap(QVariantMap &map) const {
+ IrcEvent::toVariantMap(map);
+ map["rawMessage"] = rawMessage();
+}
inline QStringList params() const { return _params; }
inline void setParams(const QStringList ¶ms) { _params = params; }
+ static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
protected:
+ explicit IrcEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "IrcEvent"; }
virtual inline void debugInfo(QDebug &dbg) const {
NetworkEvent::debugInfo(dbg);
inline void setTarget(const QString &target) { _target = target; }
protected:
+ explicit IrcEventNumeric(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "IrcEventNumeric"; }
virtual inline void debugInfo(QDebug &dbg) const {
dbg << ", num = " << number();
uint _number;
QString _target;
+ friend class IrcEvent;
};
class IrcEventRawMessage : public IrcEvent {
inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; }
protected:
+ explicit IrcEventRawMessage(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "IrcEventRawMessage"; }
virtual inline void debugInfo(QDebug &dbg) const {
NetworkEvent::debugInfo(dbg);
private:
QByteArray _rawMessage;
+
+ friend class IrcEvent;
};
#endif
#include "messageevent.h"
+Event *MessageEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+ if(type == EventManager::MessageEvent)
+ return new MessageEvent(type, map, network);
+
+ return 0;
+}
+
MessageEvent::MessageEvent(Message::Type msgType, Network *net, const QString &msg, const QString &sender, const QString &target,
Message::Flags flags, const QDateTime ×tamp)
setTimestamp(QDateTime::currentDateTime());
}
+
+MessageEvent::MessageEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : NetworkEvent(type, map, network)
+{
+ _msgType = static_cast<Message::Type>(map.take("messageType").toInt());
+ _msgFlags = static_cast<Message::Flags>(map.take("messageFlags").toInt());
+ _bufferType = static_cast<BufferInfo::Type>(map.take("bufferType").toInt());
+ _text = map.take("text").toString();
+ _sender = map.take("sender").toString();
+ _target = map.take("target").toString();
+}
+
+
+void MessageEvent::toVariantMap(QVariantMap &map) const {
+ NetworkEvent::toVariantMap(map);
+ map["messageType"] = msgType();
+ map["messageFlags"] = (int)msgFlags();
+ map["bufferType"] = bufferType();
+ map["text"] = text();
+ map["sender"] = sender();
+ map["target"] = target();
+}
+
+
BufferInfo::Type MessageEvent::bufferTypeByTarget(const QString &target) const {
if(target.isEmpty())
return BufferInfo::StatusBuffer;
inline void setMsgFlag(Message::Flag flag) { _msgFlags |= flag; }
inline void setMsgFlags(Message::Flags flags) { _msgFlags = flags; }
+ static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
protected:
+ explicit MessageEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "MessageEvent"; }
virtual inline void debugInfo(QDebug &dbg) const {
NetworkEvent::debugInfo(dbg);
***************************************************************************/
#include "networkevent.h"
+
+Event *NetworkEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+ switch(type) {
+ case EventManager::NetworkIncoming:
+ return new NetworkDataEvent(type, map, network);
+
+ case EventManager::NetworkConnecting:
+ case EventManager::NetworkInitializing:
+ case EventManager::NetworkInitialized:
+ case EventManager::NetworkReconnecting:
+ case EventManager::NetworkDisconnecting:
+ case EventManager::NetworkDisconnected:
+ return new NetworkConnectionEvent(type, map, network);
+
+ case EventManager::NetworkSplitJoin:
+ case EventManager::NetworkSplitQuit:
+ return new NetworkSplitEvent(type, map, network);
+
+ default:
+ return 0;
+ }
+}
+
+
+NetworkEvent::NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : Event(type, map)
+ , _network(network)
+{
+
+}
+
+
+void NetworkEvent::toVariantMap(QVariantMap &map) const {
+ Event::toVariantMap(map);
+ map["network"] = networkId().toInt();
+}
+
+
+NetworkDataEvent::NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : NetworkEvent(type, map, network)
+{
+ _data = map.take("data").toByteArray();
+}
+
+
+void NetworkDataEvent::toVariantMap(QVariantMap &map) const {
+ NetworkEvent::toVariantMap(map);
+ map["data"] = data();
+}
+
+
+NetworkConnectionEvent::NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : NetworkEvent(type, map, network)
+{
+ _state = static_cast<Network::ConnectionState>(map.take("state").toInt()); // FIXME: check enum plausibility
+}
+
+
+void NetworkConnectionEvent::toVariantMap(QVariantMap &map) const {
+ NetworkEvent::toVariantMap(map);
+ map["state"] = connectionState();
+}
+
+
+NetworkSplitEvent::NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+ : NetworkEvent(type, map, network)
+{
+ _channel = map.take("channel").toString();
+ _users = map.take("users").toStringList();
+ _quitMsg = map.take("quitMessage").toString();
+}
+
+
+void NetworkSplitEvent::toVariantMap(QVariantMap &map) const
+{
+ NetworkEvent::toVariantMap(map);
+ map["channel"] = channel();
+ map["users"] = users();
+ map["quitMessage"] = quitMessage();
+}
inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); }
inline Network *network() const { return _network; }
+ static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
protected:
+ explicit NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "NetworkEvent"; }
virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); }
Network *_network;
};
+/*****************************************************************************/
+
class NetworkConnectionEvent : public NetworkEvent {
public:
inline void setConnectionState(Network::ConnectionState state) { _state = state; }
protected:
+ explicit NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "NetworkConnectionEvent"; }
virtual inline void debugInfo(QDebug &dbg) const {
NetworkEvent::debugInfo(dbg);
private:
Network::ConnectionState _state;
+
+ friend class NetworkEvent;
};
class NetworkDataEvent : public NetworkEvent {
inline void setData(const QByteArray &data) { _data = data; }
protected:
+ explicit NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
virtual inline QString className() const { return "NetworkDataEvent"; }
virtual inline void debugInfo(QDebug &dbg) const {
NetworkEvent::debugInfo(dbg);
private:
QByteArray _data;
+
+ friend class NetworkEvent;
};
class NetworkSplitEvent : public NetworkEvent {
inline QStringList users() const { return _users; }
inline QString quitMessage() const { return _quitMsg; }
+protected:
+ explicit NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+ void toVariantMap(QVariantMap &map) const;
+
+ virtual inline QString className() const { return "NetworkSplitEvent"; }
+ virtual inline void debugInfo(QDebug &dbg) const {
+ NetworkEvent::debugInfo(dbg);
+ dbg.nospace() << ", channel = " << qPrintable(channel())
+ << ", users = " << users()
+ << ", quitmsg = " << quitMessage();
+ }
+
private:
QString _channel;
QStringList _users;
QString _quitMsg;
+
+ friend class NetworkEvent;
};
corebufferviewconfig.h
corebufferviewmanager.h
corecoreinfo.h
+ coreeventmanager.h
coreidentity.h
coreignorelistmanager.h
coreircchannel.h
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-2012 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 COREEVENTMANAGER_H
+#define COREEVENTMANAGER_H
+
+#include "corenetwork.h"
+#include "coresession.h"
+#include "eventmanager.h"
+
+class CoreSession;
+
+class CoreEventManager : public EventManager
+{
+ Q_OBJECT
+
+public:
+ CoreEventManager(CoreSession *session)
+ : EventManager(session)
+ , _coreSession(session)
+ { }
+
+protected:
+ inline Network *networkById(NetworkId id) const { return _coreSession->network(id); }
+
+private:
+ CoreSession *_coreSession;
+};
+
+#endif
#include "corebuffersyncer.h"
#include "corebacklogmanager.h"
#include "corebufferviewmanager.h"
+#include "coreeventmanager.h"
#include "coreidentity.h"
#include "coreignorelistmanager.h"
#include "coreirclisthelper.h"
#include "coresessioneventprocessor.h"
#include "coreusersettings.h"
#include "ctcpparser.h"
-#include "eventmanager.h"
#include "eventstringifier.h"
#include "ircchannel.h"
#include "ircparser.h"
_ircListHelper(new CoreIrcListHelper(this)),
_networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this)),
_coreInfo(this),
- _eventManager(new EventManager(this)),
+ _eventManager(new CoreEventManager(this)),
_eventStringifier(new EventStringifier(this)),
_sessionEventProcessor(new CoreSessionEventProcessor(this)),
_ctcpParser(new CtcpParser(this)),