Merge pull request #2 from sandsmark/wii
[quassel.git] / src / common / message.cpp
index 9875473..f4016f5 100644 (file)
@@ -1,11 +1,11 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2005/06 by The Quassel Team                             *
+ *   Copyright (C) 2005-2013 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     *
  *   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        *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  *   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.,                                       *
  *   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.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
 #include "message.h"
  ***************************************************************************/
 
 #include "message.h"
-#include <QDataStream>
 
 
-Message::Message(BufferId __buffer, Type __type, QString __text, QString __sender, quint8 __flags)
-  : _buffer(__buffer), _text(__text), _sender(__sender), _type(__type), _flags(__flags) {
-  _timeStamp = QDateTime::currentDateTime().toUTC();
-}
+#include "util.h"
 
 
-Message::Message(QDateTime __ts, BufferId __buffer, Type __type, QString __text, QString __sender, quint8 __flags)
-  : _timeStamp(__ts), _buffer(__buffer), _text(__text), _sender(__sender), _type(__type), _flags(__flags) {
+#include <QDataStream>
 
 
+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)
+{
 }
 
 }
 
-MsgId Message::msgId() const {
-  return _msgId;
-}
 
 
-void Message::setMsgId(MsgId _id) {
-  _msgId = _id;
+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)
+{
 }
 
 }
 
-BufferId Message::buffer() const {
-  return _buffer;
-}
 
 
-QString Message::text() const {
-  return _text;
+QDataStream &operator<<(QDataStream &out, const Message &msg)
+{
+    out << msg.msgId() << (quint32)msg.timestamp().toTime_t() << (quint32)msg.type() << (quint8)msg.flags()
+    << msg.bufferInfo() << msg.sender().toUtf8() << msg.contents().toUtf8();
+    return out;
 }
 
 }
 
-QString Message::sender() const {
-  return _sender;
-}
 
 
-Message::Type Message::type() const {
-   return _type;
+QDataStream &operator>>(QDataStream &in, Message &msg)
+{
+    quint8 f;
+    quint32 t;
+    quint32 ts;
+    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;
 }
 
 }
 
-quint8 Message::flags() const {
-   return _flags;
-}
 
 
-QDateTime Message::timeStamp() const {
-  return _timeStamp;
+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;
 }
 }
-
-
-QDataStream &operator<<(QDataStream &out, const Message &msg) {
-  out << (quint32)msg.timeStamp().toTime_t() << (quint8)msg.type() << (quint8)msg.flags()
-      << msg.buffer() << msg.sender().toUtf8() << msg.text().toUtf8();
-  return out;
-}
-
-QDataStream &operator>>(QDataStream &in, Message &msg) {
-  quint8 t, f;
-  quint32 ts;
-  QByteArray s, m;
-  BufferId buf;
-  in >> ts >> t >> f >> buf >> s >> m;
-  msg._type = (Message::Type)t;
-  msg._flags = (quint8)f;
-  msg._buffer = buf;
-  msg._timeStamp = QDateTime::fromTime_t(ts);
-  msg._sender = QString::fromUtf8(s);
-  msg._text = QString::fromUtf8(m);
-  return in;
-}
-