Various stuff, cosmetic fixes, fiddling with IrcUsers and NetworkInfos in Buffers.
[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 class AbstractUiMsg;
25 class IrcChannel;
26
27 struct BufferState;
28
29 #include "message.h"
30 #include "bufferinfo.h"
31
32 #include <QVariantMap>
33
34 //!\brief Encapsulates the contents of a single channel, query or server status context.
35 /** A Buffer maintains a list of existing nicks and their status.
36  */
37 class Buffer : public QObject {
38   Q_OBJECT
39
40 public:
41   Buffer(BufferInfo, QObject *parent = 0);
42   virtual ~Buffer();
43
44   enum Type {
45     StatusType,
46     ChannelType,
47     QueryType
48   };
49
50   enum Activity {
51     NoActivity = 0x00,
52     OtherActivity = 0x01,
53     NewMessage = 0x02,
54     Highlight = 0x40
55   };
56   Q_DECLARE_FLAGS(ActivityLevel, Activity)
57
58   bool isStatusBuffer() const;
59   Type bufferType() const;
60   bool isActive() const;
61
62   BufferInfo bufferInfo() const;
63   void updateBufferInfo(BufferInfo bufferid);
64
65   BufferId uid() const;
66   NetworkId networkId() const;
67   
68   QString networkName() const;
69   QString name() const;
70   
71   QList<AbstractUiMsg *> contents() const;
72   
73   QVariantMap nickList() const;
74   QString topic() const;
75   QString ownNick() const;
76
77   //! Returns a pointer to the associated IrcChannel object for the buffer.
78   /** A buffer has an IrcChannel object only if it is a channel buffer
79    * (i.e. bufferType() == ChannelType), and if it is active at the moment.
80    * \returns A pointer to the associated IrcChannel object, if the buffer is a channel and online; 0 else.
81    */
82   IrcChannel *ircChannel() const;
83
84 signals:
85   void userInput(const BufferInfo &, QString);
86   void nickListChanged(QVariantMap nicks);
87   void topicSet(QString topic);
88   void ownNickSet(QString ownNick);
89   void bufferUpdated(Buffer *);
90
91   void msgAppended(AbstractUiMsg *);
92   void msgPrepended(AbstractUiMsg *);
93   void layoutQueueEmpty();
94
95 public slots:
96   void setActive(bool active = true);
97   void appendMsg(const Message &);
98   void prependMsg(const Message &);
99   bool layoutMsg();
100   void setIrcChannel(IrcChannel *chan = 0);
101
102   // no longer needed
103 //   void setTopic(QString);
104 //   //void setNicks(QStringList);
105 //   void addNick(QString nick, QVariantMap props);
106 //   void renameNick(QString oldnick, QString newnick);
107 //   void removeNick(QString nick);
108 //   void updateNick(QString nick, QVariantMap props);
109 //  void setOwnNick(QString nick);
110
111   void processUserInput(QString);
112
113 private:
114   BufferInfo _bufferInfo;
115   bool _active;
116   Type _type;
117   BufferState *state;
118   IrcChannel *_ircChannel;
119
120   QList<Message> layoutQueue;
121   QList<AbstractUiMsg *> layoutedMsgs;
122
123 };
124 Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel)
125
126 #endif