Switch some dirty hacking to using real infrastructure. A Chatline now contains three...
[quassel.git] / src / uisupport / abstractbuffercontainer.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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 ABSTRACTBUFFERCONTAINER_H_
22 #define ABSTRACTBUFFERCONTAINER_H_
23
24 #include "abstractitemview.h"
25 #include "buffermodel.h"
26
27 class AbstractChatView;
28 class AbstractUiMsg;
29 class Buffer;
30
31 class AbstractBufferContainer : public AbstractItemView {
32   Q_OBJECT
33
34   public:
35     AbstractBufferContainer(QWidget *parent);
36     virtual ~AbstractBufferContainer();
37
38     inline BufferId currentBuffer() const { return _currentBuffer; }
39
40   signals:
41     void currentChanged(BufferId);
42
43   protected:
44     //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary
45     virtual AbstractChatView *createChatView(BufferId) = 0;
46
47     //! Remove a chat view from the UI and delete it
48     /** This method shall remove the view from the UI (for example, from a QStackedWidget) if appropriate.
49      *  It also shall delete the object afterwards.
50      * \param view The chat view to be removed and deleted
51      */
52     virtual void removeChatView(BufferId) = 0;
53
54   protected slots:
55     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
56     virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
57
58     //! Show the given chat view
59     /** This method is called when the given chat view should be displayed. Use this e.g. for
60      *  selecting the appropriate page in a QStackedWidget.
61      * \param view The chat view to be displayed. May be 0 if no chat view is selected.
62      */
63     virtual void showChatView(BufferId) = 0;
64
65   private slots:
66     void appendMsg(AbstractUiMsg *);
67     void prependMsg(AbstractUiMsg *);
68     void removeBuffer(BufferId bufferId);
69     void setCurrentBuffer(BufferId bufferId);
70
71   private:
72     BufferId _currentBuffer;
73     QHash<BufferId, AbstractChatView *> _chatViews;
74 };
75
76 class AbstractChatView {
77
78   public:
79     virtual ~AbstractChatView() {};
80     virtual void appendMsg(AbstractUiMsg *msg) = 0;
81     virtual void prependMsg(AbstractUiMsg *msg) = 0;
82     virtual void setContents(const QList<AbstractUiMsg *> &contents) = 0;
83     //virtual BufferId bufferId() const = 0;
84
85 };
86
87 #endif