Added a function decodeString() to util.{h|cpp} that takes a QByteArray with raw...
[quassel.git] / src / client / buffer.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel Team                             *
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) any later version.                                   *
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 #include "buffer.h"
21
22 #include "client.h"
23 #include "util.h"
24
25
26 Buffer::Buffer(BufferId bufid) {
27   id = bufid;
28   _networkName = bufid.network();
29   _bufferName = bufid.buffer();
30
31   if(_bufferName.isEmpty()) type = ServerBuffer;
32   else if(isChannelName(_bufferName)) type = ChannelBuffer;
33   else type = QueryBuffer;
34
35   active = false;
36 /*
37   QSettings s;
38   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(netname).arg(bufname));
39   state->splitterState = s.value("Splitter").toByteArray();
40   s.endGroup();
41   */
42   emit bufferUpdated(this);
43 }
44
45 Buffer::~Buffer() {
46   //delete widget;
47   /*
48   QSettings s;
49   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(networkName).arg(bufferName));
50   s.setValue("Splitter", state->splitterState);
51   s.endGroup();
52 */
53   //delete state;
54   emit bufferDestroyed(this);
55 }
56
57 Buffer::Type Buffer::bufferType() const {
58    return type;
59 }
60
61 bool Buffer::isActive() const {
62    return active;
63 }
64
65 QString Buffer::networkName() const {
66    return _networkName;
67 }
68
69 QString Buffer::bufferName() const {
70    return _bufferName;
71 }
72
73 QString Buffer::displayName() const {
74   if(bufferType() == ServerBuffer)
75     return tr("Status Buffer");
76   else
77     return bufferName();
78 }
79
80 BufferId Buffer::bufferId() const {
81    return id;
82 }
83
84 QList<AbstractUiMsg *> Buffer::contents() const {
85    return layoutedMsgs;
86 }
87
88 VarMap Buffer::nickList() const {
89    return nicks;
90 }
91
92 QString Buffer::topic() const {
93    return _topic;
94 }
95
96 QString Buffer::ownNick() const {
97    return _ownNick;
98 }
99
100 bool Buffer::isStatusBuffer() const {
101    return bufferType() == ServerBuffer;
102 }
103
104 void Buffer::setActive(bool a) {
105   if(a != active) {
106     active = a;
107     emit bufferUpdated(this);
108   }
109 }
110
111 void Buffer::appendMsg(const Message &msg) {
112   AbstractUiMsg *m = Client::layoutMsg(msg);
113   layoutedMsgs.append(m);
114   emit msgAppended(m);
115 }
116
117 void Buffer::prependMsg(const Message &msg) {
118   layoutQueue.append(msg);
119 }
120
121 bool Buffer::layoutMsg() {
122   if(layoutQueue.count()) {
123     AbstractUiMsg *m = Client::layoutMsg(layoutQueue.takeFirst());
124     layoutedMsgs.prepend(m);
125     emit msgPrepended(m);
126   }
127   return layoutQueue.count();
128 }
129
130 void Buffer::processUserInput(QString msg) {
131   // TODO User Input processing (plugins) -> well, this goes through MainWin into Core for processing... so...
132   emit userInput(id, msg);
133 }
134
135 void Buffer::setTopic(QString t) {
136   _topic = t;
137   emit topicSet(t);
138   emit bufferUpdated(this);
139 }
140
141 void Buffer::addNick(QString nick, VarMap props) {
142   if(nick == ownNick()) setActive(true);
143   nicks[nick] = props;
144   emit nickListChanged(nicks);
145 }
146
147 void Buffer::updateNick(QString nick, VarMap props) {
148   nicks[nick] = props;
149   emit nickListChanged(nicks);
150 }
151
152 void Buffer::renameNick(QString oldnick, QString newnick) {
153   QVariant v = nicks.take(oldnick);
154   nicks[newnick] = v;
155   emit nickListChanged(nicks);
156 }
157
158 void Buffer::removeNick(QString nick) {
159   if(nick == ownNick()) setActive(false);
160   nicks.remove(nick);
161   emit nickListChanged(nicks);
162 }
163
164 void Buffer::setOwnNick(QString nick) {
165   _ownNick = nick;
166   emit ownNickSet(nick);
167 }