fixing a bug where quit messages from different networks were shown if the user has...
[quassel.git] / src / common / bufferinfo.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, 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
30 BufferInfo::BufferInfo()
31   : _bufferId(0),
32     _netid(0),
33     _type(InvalidBuffer),
34     _groupId(0),
35     _bufferName(QString())
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(buf)
45 {
46 }
47
48 BufferInfo BufferInfo::fakeStatusBuffer(NetworkId networkId) {
49   return BufferInfo(0, networkId, StatusBuffer);
50 }
51
52 QString BufferInfo::bufferName() const {
53   if(isChannelName(_bufferName))
54     return _bufferName;
55   else
56     return nickFromMask(_bufferName);  // FIXME get rid of global functions and use the Network stuff instead!
57 }
58
59 QDebug operator<<(QDebug dbg, const BufferInfo &b) {
60   dbg.nospace() << "(bufId: " << b.bufferId() << ", netId: " << b.networkId() << ", groupId: " << b.groupId() << ", buf: " << b.bufferName() << ")";
61   return dbg.space();
62 }
63
64 QDataStream &operator<<(QDataStream &out, const BufferInfo &bufferInfo) {
65   out << bufferInfo._bufferId << bufferInfo._netid << (qint16)bufferInfo._type << bufferInfo._groupId << bufferInfo._bufferName.toUtf8();
66   return out;
67 }
68
69 QDataStream &operator>>(QDataStream &in, BufferInfo &bufferInfo) {
70   QByteArray buffername;
71   qint16 bufferType;
72   in >> bufferInfo._bufferId >> bufferInfo._netid >> bufferType >> bufferInfo._groupId >> buffername;
73   bufferInfo._type = (BufferInfo::Type)bufferType;
74   bufferInfo._bufferName = QString::fromUtf8(buffername);
75   return in;
76 }
77
78 uint qHash(const BufferInfo &bufferid) {
79   return qHash(bufferid._bufferId);
80 }
81