94ff0bc32f9b536f00a8ef4230d8491ca53d95ae
[quassel.git] / gui / bufferwidget.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 _BUFFERWIDGET_H_
22 #define _BUFFERWIDGET_H_
23
24 #include "gui/ui_bufferwidget.h"
25
26 #include "global.h"
27 #include "message.h"
28 #include "chatwidget.h"
29
30 class Buffer;
31 struct BufferState;
32 class ChatWidget;
33 class LayoutThread;
34
35 //!\brief Displays the contents of a Buffer.
36 /** A BufferWidget usually includes a topic line, a nicklist, the chat itself, and an input line.
37  * For server buffers or queries, there is of course no nicklist.
38  * The contents of the chat is rendered by a ChatWidget.
39  */
40 class BufferWidget : public QWidget {
41   Q_OBJECT
42
43   public:
44     BufferWidget(QWidget *parent = 0);
45     ~BufferWidget();
46     void init();
47
48     QSize sizeHint() const;
49
50   signals:
51     void userInput(QString msg);
52     void aboutToClose();
53   
54     void layoutMessages(LayoutTask);
55     void nickListUpdated(QStringList l);
56       
57   protected:
58
59   public slots:
60     void setBuffer(Buffer *);
61     void saveState();
62     void prependMessages(Buffer *, QList<Message>);  // for backlog processing
63
64   protected:
65     void resizeEvent ( QResizeEvent * event );
66
67   private slots:
68     void enterPressed();
69     void itemExpansionChanged(QTreeWidgetItem *);
70     void updateTitle();
71
72     //void displayMsg(Message);
73     void updateNickList(BufferState *state, VarMap nicks);
74     void updateNickList(VarMap nicks);
75     void setOwnNick(QString ownNick);
76     void setTopic(QString topic);
77     void setActive(bool act = true);
78
79     void messagesLayouted(LayoutTask);
80
81
82   private:
83     Ui::BufferWidget ui;
84     Buffer *curBuf;
85     QHash<Buffer *, BufferState *> states;
86     bool active;
87
88     ChatWidget *chatWidget;
89     QSplitter *splitter;
90     QTreeWidget *nickTree;
91
92     QString networkName;
93     QString bufferName;
94
95     LayoutThread *layoutThread;
96     QHash<Buffer *, QList<ChatLine*> > chatLineCache;
97     QHash<Buffer *, QList<Message> > msgCache;
98 };
99
100 struct BufferState {
101   ChatWidget *chatWidget;
102   QTreeWidget *nickTree;
103   QSplitter *splitter;
104   QWidget *page;
105   Buffer *buffer;
106   QByteArray splitterState;
107   QString topic, ownNick;
108   QString inputLine;
109   int currentLine;
110   int lineOffset;
111   bool opsExpanded, voicedExpanded, usersExpanded;
112 };
113
114 #endif