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