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