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