modernize: Use '= default' instead of empty ctor/dtor bodies
[quassel.git] / src / common / bufferinfo.cpp
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 #include <QString>
22 #include <QDataStream>
23 #include <QDebug>
24 #include <QByteArray>
25 #include <utility>
26
27 #include "bufferinfo.h"
28
29 #include "util.h"
30
31 BufferInfo::BufferInfo()
32     : _bufferId(0),
33     _netid(0),
34     _bufferName(QString())
35 {
36 }
37
38
39 BufferInfo::BufferInfo(BufferId id,  NetworkId networkid, Type type, uint gid, QString buf)
40     : _bufferId(id),
41     _netid(networkid),
42     _type(type),
43     _groupId(gid),
44     _bufferName(std::move(buf))
45 {
46 }
47
48
49 BufferInfo BufferInfo::fakeStatusBuffer(NetworkId networkId)
50 {
51     return BufferInfo(0, networkId, StatusBuffer);
52 }
53
54
55 QString BufferInfo::bufferName() const
56 {
57     if (isChannelName(_bufferName))
58         return _bufferName;
59     else
60         return nickFromMask(_bufferName);  // FIXME get rid of global functions and use the Network stuff instead!
61 }
62
63
64 bool BufferInfo::acceptsRegularMessages() const
65 {
66     if(_type == StatusBuffer || _type == InvalidBuffer)
67         return false;
68     return true;
69 }
70
71
72 QDebug operator<<(QDebug dbg, const BufferInfo &b)
73 {
74     dbg.nospace() << "(bufId: " << b.bufferId() << ", netId: " << b.networkId() << ", groupId: " << b.groupId() << ", buf: " << b.bufferName() << ")";
75     return dbg.space();
76 }
77
78
79 QDataStream &operator<<(QDataStream &out, const BufferInfo &bufferInfo)
80 {
81     out << bufferInfo._bufferId << bufferInfo._netid << (qint16)bufferInfo._type << bufferInfo._groupId << bufferInfo._bufferName.toUtf8();
82     return out;
83 }
84
85
86 QDataStream &operator>>(QDataStream &in, BufferInfo &bufferInfo)
87 {
88     QByteArray buffername;
89     qint16 bufferType;
90     in >> bufferInfo._bufferId >> bufferInfo._netid >> bufferType >> bufferInfo._groupId >> buffername;
91     bufferInfo._type = (BufferInfo::Type)bufferType;
92     bufferInfo._bufferName = QString::fromUtf8(buffername);
93     return in;
94 }
95
96
97 uint qHash(const BufferInfo &bufferid)
98 {
99     return qHash(bufferid._bufferId);
100 }