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