304d9ecb72c6e65af36d05c371650335a55ebfef
[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 <QDebug>
21
22 #include "buffer.h"
23
24 #include "client.h"
25 #include "ircchannel.h"
26 #include "util.h"
27
28
29 Buffer::Buffer(BufferInfo bufferid, QObject *parent)
30   : QObject(parent),
31     _bufferInfo(bufferid),
32     _active(false),
33     _ircChannel(0)
34 {
35   if(bufferid.buffer().isEmpty())
36     _type = StatusType;
37   else if(isChannelName(bufferid.buffer()))
38     _type = ChannelType;
39   else
40     _type = QueryType;
41
42 /*
43   QSettings s;
44   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(netname).arg(bufname));
45   state->splitterState = s.value("Splitter").toByteArray();
46   s.endGroup();
47   */
48   emit bufferUpdated(this);
49 }
50
51 Buffer::~Buffer() {
52   //delete widget;
53   /*
54   QSettings s;
55   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(networkName).arg(bufferName));
56   s.setValue("Splitter", state->splitterState);
57   s.endGroup();
58 */
59   //delete state;
60 }
61
62 Buffer::Type Buffer::bufferType() const {
63   return _type;
64 }
65
66 bool Buffer::isActive() const {
67   // FIXME determine status by checking for a networkInfo objekt
68   return true;
69 }
70
71 BufferInfo Buffer::bufferInfo() const {
72    return _bufferInfo;
73 }
74
75 void Buffer::updateBufferInfo(BufferInfo bufferid) {
76   _bufferInfo = bufferid;
77 }
78
79 uint Buffer::uid() const {
80   return bufferInfo().uid();
81 }
82
83 uint Buffer::networkId() const {
84   return bufferInfo().networkId();
85 }
86
87 QString Buffer::networkName() const {
88   return bufferInfo().network();
89 }
90
91 QString Buffer::name() const {
92   if(bufferType() == StatusType)
93     return tr("Status Buffer");
94   else
95     return bufferInfo().buffer();
96 }
97
98 QList<AbstractUiMsg *> Buffer::contents() const {
99   return layoutedMsgs;
100 }
101
102 QVariantMap Buffer::nickList() const {
103   // FIXME should return a Map or List of IrcUsers in the future
104   return QVariantMap();
105 }
106
107 QString Buffer::topic() const {
108   // FIXME check if we got a networkInfo() object
109   return QString();
110 }
111
112 QString Buffer::ownNick() const {
113   // FIXME check if we got a networkInfo() object
114   return QString();
115 }
116
117 bool Buffer::isStatusBuffer() const {
118    return bufferType() == StatusType;
119 }
120
121 void Buffer::setActive(bool a) {
122 //   if(a != active) {
123 //     active = a;
124 //     emit bufferUpdated(this);
125 //  }
126 }
127
128 void Buffer::appendMsg(const Message &msg) {
129   AbstractUiMsg *m = Client::layoutMsg(msg);
130   layoutedMsgs.append(m);
131   emit msgAppended(m);
132 }
133
134 void Buffer::prependMsg(const Message &msg) {
135   layoutQueue.append(msg);
136 }
137
138 bool Buffer::layoutMsg() {
139   if(layoutQueue.count()) {
140     AbstractUiMsg *m = Client::layoutMsg(layoutQueue.takeFirst());
141     layoutedMsgs.prepend(m);
142     emit msgPrepended(m);
143   }
144   return layoutQueue.count();
145 }
146
147 void Buffer::processUserInput(QString msg) {
148   // TODO User Input processing (plugins) -> well, this goes through MainWin into Core for processing... so...
149   emit userInput(_bufferInfo, msg);
150 }
151
152 IrcChannel *Buffer::ircChannel() const {
153   return _ircChannel;
154 }
155
156 void Buffer::setIrcChannel(IrcChannel *ircchan) {
157   if(_ircChannel) {
158     disconnect(_ircChannel, 0, this, 0);
159     // TODO: remove model etc
160   }
161   _ircChannel = ircchan;
162   if(_ircChannel) {
163     connect(_ircChannel, SIGNAL(destroyed()), this, SLOT(setIrcChannel()));
164   }
165 }
166
167 // no longer needed
168 // back reference:
169 // void Buffer::setTopic(QString t) {
170 //   _topic = t;
171 //   emit topicSet(t);
172 //   emit bufferUpdated(this);
173 // }
174
175 // void Buffer::addNick(QString nick, QVariantMap props) {
176 //   if(nick == ownNick()) setActive(true);
177 //   nicks[nick] = props;
178 //   emit nickListChanged(nicks);
179 // }
180
181 // void Buffer::updateNick(QString nick, QVariantMap props) {
182 //   nicks[nick] = props;
183 //   emit nickListChanged(nicks);
184 // }
185
186 // void Buffer::renameNick(QString oldnick, QString newnick) {
187 //   QVariant v = nicks.take(oldnick);
188 //   nicks[newnick] = v;
189 //   emit nickListChanged(nicks);
190 // }
191
192 // void Buffer::removeNick(QString nick) {
193 //   if(nick == ownNick()) setActive(false);
194 //   nicks.remove(nick);
195 //   emit nickListChanged(nicks);
196 // }
197
198 // void Buffer::setOwnNick(QString nick) {
199 //   _ownNick = nick;
200 //   emit ownNickSet(nick);
201 // }