X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fmessage.cpp;h=45517cff5ec69bb8e8c0d50322c96e6770972b12;hp=8b9f15849669107a13c63c384eb7a42950d4a92e;hb=0679f0aa992e4d0d0aab2ebe08e17544150fbc55;hpb=0ac9ce4d7cf768d13993d6aa1d6b791c4149a843 diff --git a/src/common/message.cpp b/src/common/message.cpp index 8b9f1584..45517cff 100644 --- a/src/common/message.cpp +++ b/src/common/message.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005/06 by The Quassel Team * + * Copyright (C) 2005-08 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) any later version. * + * (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 * @@ -19,30 +19,62 @@ ***************************************************************************/ #include "message.h" + +#include "util.h" + #include +Message::Message(const BufferInfo &bufferInfo, Type type, const QString &contents, const QString &sender, Flags flags) + : _timestamp(QDateTime::currentDateTime().toUTC()), + _bufferInfo(bufferInfo), + _contents(contents), + _sender(sender), + _type(type), + _flags(flags) +{ +} + +Message::Message(const QDateTime &ts, const BufferInfo &bufferInfo, Type type, const QString &contents, const QString &sender, Flags flags) + : _timestamp(ts), + _bufferInfo(bufferInfo), + _contents(contents), + _sender(sender), + _type(type), + _flags(flags) +{ +} + +void Message::setFlags(Flags flags) { + _flags = flags; +} + QDataStream &operator<<(QDataStream &out, const Message &msg) { - /* - out << (quint32)msg.timeStamp.toTime_t() << (quint8)msg.type << (quint8)msg.flags - << msg.target.toUtf8() << msg.sender.toUtf8() << msg.text.toUtf8(); - */ - out << (quint32)msg.timeStamp.toTime_t() << (quint8)msg.type << (quint8)msg.flags - << msg.buffer << msg.sender.toUtf8() << msg.text.toUtf8(); + out << msg.msgId() << (quint32)msg.timestamp().toTime_t() << (quint32)msg.type() << (quint8)msg.flags() + << msg.bufferInfo() << msg.sender().toUtf8() << msg.contents().toUtf8(); return out; } QDataStream &operator>>(QDataStream &in, Message &msg) { - quint8 t, f; + quint8 f; + quint32 t; quint32 ts; - QByteArray s, m, targ; - BufferId buf; - in >> ts >> t >> f >> buf >> s >> m; - msg.type = (Message::Type)t; - msg.flags = (quint8)f; - msg.timeStamp = QDateTime::fromTime_t(ts); - //msg.target = QString::fromUtf8(targ); - msg.sender = QString::fromUtf8(s); - msg.text = QString::fromUtf8(m); + QByteArray s, m; + BufferInfo buf; + in >> msg._msgId >> ts >> t >> f >> buf >> s >> m; + msg._type = (Message::Type)t; + msg._flags = (Message::Flags)f; + msg._bufferInfo = buf; + msg._timestamp = QDateTime::fromTime_t(ts); + msg._sender = QString::fromUtf8(s); + msg._contents = QString::fromUtf8(m); return in; } +QDebug operator<<(QDebug dbg, const Message &msg) { + dbg.nospace() << qPrintable(QString("Message(MsgId:")) << msg.msgId() + << qPrintable(QString(",")) << msg.timestamp() + << qPrintable(QString(", Type:")) << msg.type() + << qPrintable(QString(", Flags:")) << msg.flags() << qPrintable(QString(")")) + << msg.sender() << ":" << msg.contents(); + return dbg; +}