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