Now we have a sorted nicklist and hide unused categories \o/
[quassel.git] / src / client / buffertreemodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 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) 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
29 #include <QPointer>
30
31 #include <QItemSelectionModel>
32
33 class BufferInfo;
34
35 #include "selectionmodelsynchronizer.h"
36 #include "modelpropertymapper.h"
37 class MappedSelectionModel;
38 class QAbstractItemView;
39
40 /*****************************************
41  *  Fancy Buffer Items
42  *****************************************/
43 class BufferTreeItem : public TreeItem {
44   Q_OBJECT
45
46 public:
47   BufferTreeItem(Buffer *, TreeItem *parent = 0);
48
49   virtual uint id() const;
50   QVariant data(int column, int role) const;
51
52   Buffer *buffer() const { return buf; }
53   void setActivity(const Buffer::ActivityLevel &);
54
55 private:
56   QString text(int column) const;
57   QColor foreground(int column) const;
58
59   Buffer *buf;
60   Buffer::ActivityLevel activity;
61 };
62
63 /*****************************************
64  *  Network Items
65  *****************************************/
66 class NetworkTreeItem : public TreeItem {
67   Q_OBJECT
68
69 public:
70   NetworkTreeItem(const uint &netid, const QString &, TreeItem *parent = 0);
71
72   virtual QVariant data(int column, int row) const;
73   virtual uint id() const;
74
75 private:
76   uint _networkId;
77   QString net;
78 };
79
80 /*****************************************
81  * BufferTreeModel
82  *****************************************/
83 class BufferTreeModel : public TreeModel {
84   Q_OBJECT
85
86 public:
87   enum myRoles {
88     BufferTypeRole = Qt::UserRole,
89     BufferActiveRole,
90     BufferUidRole,
91     NetworkIdRole
92   };
93
94   BufferTreeModel(QObject *parent = 0);
95   static QList<QVariant> defaultHeader();
96
97   inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
98   inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
99
100   void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
101   void synchronizeView(QAbstractItemView *view);
102   void mapProperty(int column, int role, QObject *target, const QByteArray &property);
103
104   static bool mimeContainsBufferList(const QMimeData *mimeData);
105   static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
106
107   virtual QStringList mimeTypes() const;
108   virtual QMimeData *mimeData(const QModelIndexList &) const;
109   virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
110
111
112 public slots:
113   void bufferUpdated(Buffer *);
114   void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
115   void selectBuffer(Buffer *buffer);
116   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
117
118 signals:
119   void bufferSelected(Buffer *);
120   void invalidateFilter();
121   void selectionChanged(const QModelIndex &);
122
123 private:
124   bool isBufferIndex(const QModelIndex &) const;
125   Buffer *getBufferByIndex(const QModelIndex &) const;
126   QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
127   QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
128
129   QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
130   QPointer<ModelPropertyMapper> _propertyMapper;
131   Buffer *currentBuffer;
132 };
133
134 #endif