forgot to add 6 files... -.-
[quassel.git] / src / client / buffertreemodel.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 _BUFFERTREEMODEL_H_
22 #define _BUFFERTREEMODEL_H_
23
24 #include <QtCore>
25
26 #include "treemodel.h"
27 #include "buffer.h"
28 #include "clientproxy.h"
29
30 /*****************************************
31  *  Fancy Buffer Items
32  *****************************************/
33 class BufferTreeItem : public TreeItem{
34   Q_OBJECT
35   
36 public:
37   BufferTreeItem(Buffer *, TreeItem *parent = 0);
38   QVariant data(int column, int role) const;
39   Buffer *buffer() const { return buf; }
40   void setActivity(const Buffer::ActivityLevel &);
41   
42 protected:
43   QString text(int column) const;
44   QColor foreground(int column) const;
45   
46   Buffer *buf;
47   Buffer::ActivityLevel activity;
48 };
49
50
51 /*****************************************
52  * BufferTreeModel
53  *****************************************/
54 class BufferTreeModel : public TreeModel {
55   Q_OBJECT
56   
57 public:
58   enum  myRoles {
59     BufferTypeRole = Qt::UserRole,
60     BufferActiveRole
61   };
62   
63   //BufferTreeModel(const QList<QVariant> &, QObject *parent = 0);
64   BufferTreeModel(QObject *parent = 0);
65   static QList<QVariant> defaultHeader();
66
67   virtual Qt::ItemFlags flags(const QModelIndex &index) const;
68   
69 //  void clearActivity(Buffer *buffer);
70   
71 public slots:
72   void bufferUpdated(Buffer *);    
73   void changeCurrent(const QModelIndex &, const QModelIndex &);
74   void selectBuffer(Buffer *buffer);
75   void doubleClickReceived(const QModelIndex &);
76   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
77   
78 signals:
79   void bufferSelected(Buffer *);
80   void invalidateFilter();
81   void fakeUserInput(BufferId, QString);
82   void updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags);
83     
84 private:
85   bool isBufferIndex(const QModelIndex &) const;
86   Buffer *getBufferByIndex(const QModelIndex &) const;
87   QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
88   QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
89
90   QStringList mimeTypes() const;
91   QMimeData *mimeData(const QModelIndexList &) const;
92   bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
93   
94   QHash<QString, TreeItem*> networkItem;
95   QHash<Buffer *, BufferTreeItem*> bufferItem;
96   Buffer *currentBuffer;
97 };
98
99 #endif