7e6df2667d80fc0d6ce3593cd51db5194a69c76e
[quassel.git] / src / common / messageevent.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "common-export.h"
24
25 #include "message.h"
26 #include "networkevent.h"
27
28 // this corresponds to CoreSession::RawMessage for now and should contain the information we need to convert events
29 // into messages for the legacy code to work with
30
31 class COMMON_EXPORT MessageEvent : public NetworkEvent
32 {
33 public:
34     explicit MessageEvent(Message::Type msgType,
35         Network *network,
36         QString msg,
37         const QString &sender = QString(),
38         QString target = QString(),
39         Message::Flags msgFlags = Message::None,
40         const QDateTime &timestamp = QDateTime()
41         );
42
43     inline Message::Type msgType() const { return _msgType; }
44     inline void setMsgType(Message::Type type) { _msgType = type; }
45
46     inline BufferInfo::Type bufferType() const { return _bufferType; }
47     inline void setBufferType(BufferInfo::Type type) { _bufferType = type; }
48
49     inline QString target() const { return _target; }
50     inline QString text() const { return _text; }
51     inline QString sender() const { return _sender; }
52
53     inline Message::Flags msgFlags() const { return _msgFlags; }
54     inline void setMsgFlag(Message::Flag flag) { _msgFlags |= flag; }
55     inline void setMsgFlags(Message::Flags flags) { _msgFlags = flags; }
56
57     static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
58
59 protected:
60     explicit MessageEvent(EventManager::EventType type, QVariantMap &map, Network *network);
61     void toVariantMap(QVariantMap &map) const override;
62
63     inline QString className() const override { return "MessageEvent"; }
64     inline void debugInfo(QDebug &dbg) const override
65     {
66         NetworkEvent::debugInfo(dbg);
67         dbg.nospace() << ", sender = " << qPrintable(sender())
68                       << ", target = " << qPrintable(target())
69                       << ", text = " << text()
70                       << ", msgtype = " << qPrintable(QString::number(msgType(), 16))
71                       << ", buffertype = " << qPrintable(QString::number(bufferType(), 16))
72                       << ", msgflags = " << qPrintable(QString::number(msgFlags(), 16));
73     }
74
75
76 private:
77     BufferInfo::Type bufferTypeByTarget(const QString &target) const;
78
79     Message::Type _msgType;
80     BufferInfo::Type _bufferType;
81     QString _text, _sender, _target;
82     Message::Flags _msgFlags;
83 };