e72ebb8a87b5a8c1479a1b94635348c53cfe6e66
[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
56   protected:
57
58   public slots:
59     void setBuffer(Buffer *);
60     void saveState();
61     void prependMessages(Buffer *, QList<Message>);  // for backlog processing
62
63   protected:
64     void resizeEvent ( QResizeEvent * event );
65
66   private slots:
67     void enterPressed();
68     void itemExpansionChanged(QTreeWidgetItem *);
69     void updateTitle();
70
71     //void displayMsg(Message);
72     void updateNickList(BufferState *state, VarMap nicks);
73     void updateNickList(VarMap nicks);
74     void setOwnNick(QString ownNick);
75     void setTopic(QString topic);
76     void setActive(bool act = true);
77
78     void messagesLayouted(LayoutTask);
79
80
81   private:
82     Ui::BufferWidget ui;
83     Buffer *curBuf;
84     QHash<Buffer *, BufferState *> states;
85     bool active;
86
87     ChatWidget *chatWidget;
88     QSplitter *splitter;
89     QTreeWidget *nickTree;
90
91     QString networkName;
92     QString bufferName;
93
94     LayoutThread *layoutThread;
95     QHash<Buffer *, QList<ChatLine*> > chatLineCache;
96     QHash<Buffer *, QList<Message> > msgCache;
97 };
98
99 struct BufferState {
100   ChatWidget *chatWidget;
101   QTreeWidget *nickTree;
102   QSplitter *splitter;
103   QWidget *page;
104   Buffer *buffer;
105   QByteArray splitterState;
106   QString topic, ownNick;
107   QString inputLine;
108   int currentLine;
109   int lineOffset;
110   bool opsExpanded, voicedExpanded, usersExpanded;
111 };
112
113 #endif