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