X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fevent.cpp;h=4d9a6def1d09b06f7a905511bf63e291b9970878;hp=2306adc97f7a9c66ab451342236c62631e41ce9f;hb=3a3e844f9fcfd12235a0086af75ecd503b621ef4;hpb=b65b9f7615165e8700a44d59b7275a55558dd45b diff --git a/src/common/event.cpp b/src/common/event.cpp index 2306adc9..4d9a6def 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -22,6 +22,8 @@ #include "ircevent.h" #include "networkevent.h" #include "messageevent.h" +#include "peer.h" +#include "signalproxy.h" Event::Event(EventManager::EventType type) : _type(type) @@ -40,16 +42,33 @@ Event::Event(EventManager::EventType type, QVariantMap &map) return; } + Q_ASSERT(SignalProxy::current()); + Q_ASSERT(SignalProxy::current()->sourcePeer()); + setFlags(static_cast(map.take("flags").toInt())); // TODO sanity check? - setTimestamp(QDateTime::fromTime_t(map.take("timestamp").toUInt())); + + if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::LongTime)) { + // timestamp is a qint64, signed rather than unsigned + setTimestamp(QDateTime::fromMSecsSinceEpoch(map.take("timestamp").toLongLong())); + } else { + setTimestamp(QDateTime::fromTime_t(map.take("timestamp").toUInt())); + } } void Event::toVariantMap(QVariantMap &map) const { + Q_ASSERT(SignalProxy::current()); + Q_ASSERT(SignalProxy::current()->targetPeer()); + map["type"] = static_cast(type()); map["flags"] = static_cast(flags()); - map["timestamp"] = timestamp().toTime_t(); + if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::LongTime)) { + // toMSecs returns a qint64, signed rather than unsigned + map["timestamp"] = timestamp().toMSecsSinceEpoch(); + } else { + map["timestamp"] = timestamp().toTime_t(); + } } @@ -67,16 +86,16 @@ Event *Event::fromVariantMap(QVariantMap &map, Network *network) // 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; + return nullptr; } EventManager::EventType type = static_cast(inttype); if (type == EventManager::Invalid || type == EventManager::GenericEvent) - return 0; + return nullptr; EventManager::EventType group = static_cast(type & EventManager::EventGroupMask); - Event *e = 0; + Event *e = nullptr; // we use static create() functions to keep group-specific special cases in the files they belong // e.g. IrcEventRawMessage @@ -102,7 +121,7 @@ Event *Event::fromVariantMap(QVariantMap &map, Network *network) if (!e) { qWarning() << "Can't create event of type" << type; - return 0; + return nullptr; } if (!map.isEmpty()) {