Merged changes from branch "sput" r50:55 back into trunk.
[quassel.git] / gui / buffer.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 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 <QtCore>
25 #include <QtGui>
26
27 #include "ui_bufferwidget.h"
28
29 #include "global.h"
30 #include "message.h"
31
32 class ChatWidget;
33 class ChatWidgetContents;
34 class BufferWidget;
35
36 //!\brief Encapsulates the contents of a single channel, query or server status context.
37 /** A Buffer maintains a list of existing nicks and their status. New messages can be appended using
38  * displayMsg(). A buffer displays its contents by way of a BufferWidget, which can be shown
39  * (and created on demand) by calling showWidget().
40  */
41 class Buffer : public QObject {
42   Q_OBJECT
43
44   public:
45     Buffer(QString network, QString buffer);
46     ~Buffer();
47
48     bool isActive() { return active; }
49   public:
50     QWidget *getWidget();
51
52   signals:
53     void userInput(QString, QString, QString);
54     void nickListChanged(QStringList);
55
56   public slots:
57     void setActive(bool active = true);
58     void displayMsg(Message);
59     //void recvStatusMsg(QString msg);
60     void setTopic(QString);
61     //void setNicks(QStringList);
62     void addNick(QString nick, VarMap props);
63     void renameNick(QString oldnick, QString newnick);
64     void removeNick(QString nick);
65     void updateNick(QString nick, VarMap props);
66     void setOwnNick(QString nick);
67
68     QWidget * showWidget(QWidget *parent = 0);
69     void hideWidget();
70     void deleteWidget();
71
72     void scrollToEnd();
73
74   private slots:
75     void userInput(QString);
76
77   private:
78     bool active;
79     BufferWidget *widget;
80     ChatWidget *chatWidget;
81     ChatWidgetContents *contentsWidget;
82     VarMap nicks;
83     QString topic;
84     QString ownNick;
85     QString networkName, bufferName;
86
87     QList<Message> contents;
88 };
89
90 //!\brief Displays the contents of a Buffer.
91 /** A BufferWidget usually includes a topic line, a nicklist, the chat itself, and an input line.
92  * For server buffers or queries, there is of course no nicklist.
93  * The contents of the chat is rendered by a ChatWidget.
94  */
95 class BufferWidget : public QWidget {
96   Q_OBJECT
97
98   public:
99     BufferWidget(QString netname, QString bufname, bool active, QString ownNick, ChatWidgetContents *contents, Buffer *parentBuffer, QWidget *parent = 0);
100     ~BufferWidget();
101
102     void setActive(bool act = true);
103
104   signals:
105     void userInput(QString);
106
107   protected:
108
109   public slots:
110     void displayMsg(Message);
111     void updateNickList(VarMap nicks);
112     void setOwnNick(QString ownNick);
113     void setTopic(QString topic);
114
115   private slots:
116     void enterPressed();
117     void itemExpansionChanged(QTreeWidgetItem *);
118     void updateTitle();
119
120   private:
121     Ui::BufferWidget ui;
122     Buffer *parentBuffer;
123     bool active;
124
125     QString networkName;
126     QString bufferName;
127
128     bool opsExpanded, voicedExpanded, usersExpanded;
129
130 };
131
132 #endif