- Bug #20 (RPL_NICKNAMEINUSER)
[quassel.git] / gui / 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
21 #include "buffer.h"
22 #include "util.h"
23 #include "chatwidget.h"
24 #include "bufferwidget.h"
25
26 Buffer::Buffer(QString netname, QString bufname) {
27   _networkName = netname;
28   _bufferName = bufname;
29
30   if(bufname.isEmpty()) type = ServerBuffer;
31   else if(isChannelName(bufname)) type = ChannelBuffer;
32   else type = QueryBuffer;
33
34   active = false;
35 /*
36   QSettings s;
37   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(netname).arg(bufname));
38   state->splitterState = s.value("Splitter").toByteArray();
39   s.endGroup();
40   */
41   emit bufferUpdated(this);
42 }
43
44 Buffer::~Buffer() {
45   //delete widget;
46   /*
47   QSettings s;
48   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(networkName).arg(bufferName));
49   s.setValue("Splitter", state->splitterState);
50   s.endGroup();
51 */
52   //delete state;
53   emit bufferDestroyed(this);
54 }
55
56 void Buffer::init() {
57
58
59 }
60
61 void Buffer::setActive(bool a) {
62   if(a != active) {
63     active = a;
64     emit bufferUpdated(this);
65   }
66 }
67
68 void Buffer::displayMsg(Message msg) {
69   contents()->append(msg);
70   emit msgDisplayed(msg);
71 }
72
73 void Buffer::prependMessages(QList<Message> msgs) {
74   _contents = msgs + _contents;
75 }
76
77 void Buffer::processUserInput(QString msg) {
78   // TODO User Input processing (plugins) -> well, this goes through MainWin into Core for processing... so...
79   emit userInput(networkName(), bufferName(), msg);
80 }
81
82 void Buffer::setTopic(QString t) {
83   _topic = t;
84   emit topicSet(t);
85   emit bufferUpdated(this);
86 }
87
88 void Buffer::addNick(QString nick, VarMap props) {
89   if(nick == ownNick()) setActive(true);
90   nicks[nick] = props;
91   emit nickListChanged(nicks);
92 }
93
94 void Buffer::updateNick(QString nick, VarMap props) {
95   nicks[nick] = props;
96   emit nickListChanged(nicks);
97 }
98
99 void Buffer::renameNick(QString oldnick, QString newnick) {
100   QVariant v = nicks.take(oldnick);
101   nicks[newnick] = v;
102   emit nickListChanged(nicks);
103 }
104
105 void Buffer::removeNick(QString nick) {
106   if(nick == ownNick()) setActive(false);
107   nicks.remove(nick);
108   emit nickListChanged(nicks);
109 }
110
111 void Buffer::setOwnNick(QString nick) {
112   _ownNick = nick;
113   emit ownNickSet(nick);
114 }
115
116 /****************************************************************************************/
117
118
119 /****************************************************************************************/
120