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