944b07cc07c7882a71f96d347eba5739d928a486
[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 "chatwidget.h"
28 #include "global.h"
29 #include "message.h"
30
31 class ChatWidget;
32 class ChatLine;
33 class ChatWidgetContents;
34 class BufferWidget;
35 struct BufferState;
36
37 //!\brief Encapsulates the contents of a single channel, query or server status context.
38 /** A Buffer maintains a list of existing nicks and their status. New messages can be appended using
39  * displayMsg(). A buffer displays its contents by way of a BufferWidget, which can be shown
40  * (and created on demand) by calling showWidget().
41  */
42 class Buffer : public QObject {
43   Q_OBJECT
44
45   public:
46     //Buffer(QString network, QString buffer);
47     Buffer(BufferId);
48     ~Buffer();
49     static void init();
50
51     enum Type { ServerBuffer, ChannelBuffer, QueryBuffer };
52
53     enum Activity {
54       NoActivity = 0x00,
55       OtherActivity = 0x01,
56       NewMessage = 0x02,
57       Highlight = 0x40
58     };
59     Q_DECLARE_FLAGS(ActivityLevel, Activity)
60     
61     Type bufferType() { return type; }
62     bool isActive() { return active; }
63
64     QString networkName() { return _networkName; }
65     QString bufferName() { return _bufferName; }
66     QString displayName();
67     BufferId bufferId() { return id; }
68     QList<ChatLine *> contents() { return lines; }
69     VarMap nickList() { return nicks; }
70     QString topic() { return _topic; }
71     QString ownNick() { return _ownNick; }
72     bool isStatusBuffer() { return bufferType() == ServerBuffer; }
73
74   signals:
75     void userInput(BufferId, QString);
76     //void msgDisplayed(Message);
77     void chatLineAppended(ChatLine *);
78     void chatLinePrepended(ChatLine *);
79     void nickListChanged(VarMap nicks);
80     void topicSet(QString topic);
81     void ownNickSet(QString ownNick);
82     void bufferUpdated(Buffer *);
83     void bufferDestroyed(Buffer *);
84
85   public slots:
86     void setActive(bool active = true);
87     //void displayMsg(Message);
88     //void prependMessages(QList<Message>); // for backlog
89     void appendChatLine(ChatLine *);
90     void prependChatLine(ChatLine *);
91     //void prependChatLines(QList<ChatLine *>);
92     //void recvStatusMsg(QString msg);
93     void setTopic(QString);
94     //void setNicks(QStringList);
95     void addNick(QString nick, VarMap props);
96     void renameNick(QString oldnick, QString newnick);
97     void removeNick(QString nick);
98     void updateNick(QString nick, VarMap props);
99     void setOwnNick(QString nick);
100
101     void processUserInput(QString);
102
103   private:
104     BufferId id;
105     bool active;
106     Type type;
107
108     VarMap nicks;
109     QString _topic;
110     QString _ownNick;
111     QString _networkName, _bufferName;
112     BufferState *state;
113
114     //QList<Message> _contents;
115     QList<ChatLine *> lines;
116
117 };
118 Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel)    
119
120 #endif