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