- Bug #20 (RPL_NICKNAMEINUSER)
[quassel.git] / gui / buffer.h
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 #ifndef _BUFFER_H_
22 #define _BUFFER_H_
23
24 #include <QtCore>
25 #include <QtGui>
26
27 #include "global.h"
28 #include "message.h"
29
30 class ChatWidget;
31 class ChatWidgetContents;
32 class BufferWidget;
33 struct BufferState;
34
35 //!\brief Encapsulates the contents of a single channel, query or server status context.
36 /** A Buffer maintains a list of existing nicks and their status. New messages can be appended using
37  * displayMsg(). A buffer displays its contents by way of a BufferWidget, which can be shown
38  * (and created on demand) by calling showWidget().
39  */
40 class Buffer : public QObject {
41   Q_OBJECT
42
43   public:
44     Buffer(QString network, QString buffer);
45     ~Buffer();
46     static void init();
47
48     enum Type { ServerBuffer, ChannelBuffer, QueryBuffer };
49     Type bufferType() { return type; }
50     bool isActive() { return active; }
51
52     QString networkName() { return _networkName; }
53     QString bufferName() { return _bufferName; }
54     QList<Message> *contents() { return &_contents; }
55     VarMap nickList() { return nicks; }
56     QString topic() { return _topic; }
57     QString ownNick() { return _ownNick; }
58
59   signals:
60     void userInput(QString, QString, QString);
61     void msgDisplayed(Message);
62     void nickListChanged(VarMap nicks);
63     void topicSet(QString topic);
64     void ownNickSet(QString ownNick);
65     void bufferUpdated(Buffer *);
66     void bufferDestroyed(Buffer *);
67
68   public slots:
69     void setActive(bool active = true);
70     void displayMsg(Message);
71     void prependMessages(QList<Message>); // for backlog
72     //void recvStatusMsg(QString msg);
73     void setTopic(QString);
74     //void setNicks(QStringList);
75     void addNick(QString nick, VarMap props);
76     void renameNick(QString oldnick, QString newnick);
77     void removeNick(QString nick);
78     void updateNick(QString nick, VarMap props);
79     void setOwnNick(QString nick);
80
81     void processUserInput(QString);
82
83   private:
84     bool active;
85     Type type;
86
87     VarMap nicks;
88     QString _topic;
89     QString _ownNick;
90     QString _networkName, _bufferName;
91     BufferState *state;
92
93     QList<Message> _contents;
94
95 };
96
97 #endif