f300d98626c6cf47a3bfbc71ae0fbeeedb0563e6
[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
29 #include <QItemSelectionModel>
30
31 class BufferInfo;
32 class SelectionModelSynchronizer;
33
34
35 /*****************************************
36  *  Fancy Buffer Items
37  *****************************************/
38 class BufferTreeItem : public TreeItem {
39   Q_OBJECT
40   
41 public:
42   BufferTreeItem(Buffer *, TreeItem *parent = 0);
43
44   virtual uint id() const;
45   QVariant data(int column, int role) const;
46   virtual Qt::ItemFlags flags() const;
47   
48   Buffer *buffer() const { return buf; }
49   void setActivity(const Buffer::ActivityLevel &);
50   
51 private:
52   QString text(int column) const;
53   QColor foreground(int column) const;
54   
55   Buffer *buf;
56   Buffer::ActivityLevel activity;
57 };
58
59 /*****************************************
60  *  Network Items
61  *****************************************/
62 class NetworkTreeItem : public TreeItem {
63   Q_OBJECT
64   
65 public:
66   NetworkTreeItem(const QString &, TreeItem *parent = 0);
67
68   virtual uint id() const;
69   virtual Qt::ItemFlags flags() const;
70   
71 private:
72   QString net;
73   
74 };
75
76 /*****************************************
77  * BufferTreeModel
78  *****************************************/
79 class BufferTreeModel : public TreeModel {
80   Q_OBJECT
81   
82 public:
83   enum myRoles {
84     BufferTypeRole = Qt::UserRole,
85     BufferActiveRole,
86     BufferNameRole,
87     BufferUidRole
88   };
89   
90   BufferTreeModel(QObject *parent = 0);
91   static QList<QVariant> defaultHeader();
92
93   inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
94
95 public slots:
96   void bufferUpdated(Buffer *);
97   void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
98   void selectBuffer(Buffer *buffer);
99   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
100   
101 signals:
102   void bufferSelected(Buffer *);
103   void invalidateFilter();
104   void selectionChanged(const QModelIndex &);
105     
106 private:
107   bool isBufferIndex(const QModelIndex &) const;
108   Buffer *getBufferByIndex(const QModelIndex &) const;
109   QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
110   QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
111
112   QStringList mimeTypes() const;
113   QMimeData *mimeData(const QModelIndexList &) const;
114   bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
115
116   SelectionModelSynchronizer *_selectionModelSynchronizer;
117   Buffer *currentBuffer;
118 };
119
120 #endif