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