Syncing my state before starting to reorganize the UI parts of the source...
[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 = ServerBuffer;
35   else if(isChannelName(bufferid.buffer()))
36     _type = ChannelBuffer;
37   else
38     _type = QueryBuffer;
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   emit bufferDestroyed(this);
59 }
60
61 Buffer::Type Buffer::bufferType() const {
62   return _type;
63 }
64
65 bool Buffer::isActive() const {
66   // FIXME determine status by checking for a networkInfo objekt
67   return true;
68 }
69
70 BufferInfo Buffer::bufferInfo() const {
71    return _bufferInfo;
72 }
73
74 void Buffer::updateBufferInfo(BufferInfo bufferid) {
75   _bufferInfo = bufferid;
76 }
77
78 uint Buffer::networkId() const {
79   return bufferInfo().networkId();
80 }
81
82 QString Buffer::networkName() const {
83   return bufferInfo().network();
84 }
85
86 QString Buffer::bufferName() const {
87   return bufferInfo().buffer();
88 }
89
90 QString Buffer::displayName() const {
91   if(bufferType() == ServerBuffer)
92     return tr("Status Buffer");
93   else
94     return bufferName();
95 }
96
97 QList<AbstractUiMsg *> Buffer::contents() const {
98   return layoutedMsgs;
99 }
100
101 QVariantMap Buffer::nickList() const {
102   // FIXME should return a Map or List of IrcUsers in the future
103   return QVariantMap();
104 }
105
106 QString Buffer::topic() const {
107   // FIXME check if we got a networkInfo() object
108   return QString();
109 }
110
111 QString Buffer::ownNick() const {
112   // FIXME check if we got a networkInfo() object
113   return QString();
114 }
115
116 bool Buffer::isStatusBuffer() const {
117    return bufferType() == ServerBuffer;
118 }
119
120 void Buffer::setActive(bool a) {
121 //   if(a != active) {
122 //     active = a;
123 //     emit bufferUpdated(this);
124 //  }
125 }
126
127 void Buffer::appendMsg(const Message &msg) {
128   AbstractUiMsg *m = Client::layoutMsg(msg);
129   layoutedMsgs.append(m);
130   emit msgAppended(m);
131 }
132
133 void Buffer::prependMsg(const Message &msg) {
134   layoutQueue.append(msg);
135 }
136
137 bool Buffer::layoutMsg() {
138   if(layoutQueue.count()) {
139     AbstractUiMsg *m = Client::layoutMsg(layoutQueue.takeFirst());
140     layoutedMsgs.prepend(m);
141     emit msgPrepended(m);
142   }
143   return layoutQueue.count();
144 }
145
146 void Buffer::processUserInput(QString msg) {
147   // TODO User Input processing (plugins) -> well, this goes through MainWin into Core for processing... so...
148   emit userInput(_bufferInfo, msg);
149 }
150
151 // no longer needed
152 // back reference:
153 // void Buffer::setTopic(QString t) {
154 //   _topic = t;
155 //   emit topicSet(t);
156 //   emit bufferUpdated(this);
157 // }
158
159 // void Buffer::addNick(QString nick, QVariantMap props) {
160 //   if(nick == ownNick()) setActive(true);
161 //   nicks[nick] = props;
162 //   emit nickListChanged(nicks);
163 // }
164
165 // void Buffer::updateNick(QString nick, QVariantMap props) {
166 //   nicks[nick] = props;
167 //   emit nickListChanged(nicks);
168 // }
169
170 // void Buffer::renameNick(QString oldnick, QString newnick) {
171 //   QVariant v = nicks.take(oldnick);
172 //   nicks[newnick] = v;
173 //   emit nickListChanged(nicks);
174 // }
175
176 // void Buffer::removeNick(QString nick) {
177 //   if(nick == ownNick()) setActive(false);
178 //   nicks.remove(nick);
179 //   emit nickListChanged(nicks);
180 // }
181
182 // void Buffer::setOwnNick(QString nick) {
183 //   _ownNick = nick;
184 //   emit ownNickSet(nick);
185 // }