91fe43d5e0e96b6907eff83cd759f0f2c8b9d410
[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 /*****************************************
30  *  Fancy Buffer Items
31  *****************************************/
32 class BufferTreeItem : public TreeItem {
33   Q_OBJECT
34   
35 public:
36   BufferTreeItem(Buffer *, TreeItem *parent = 0);
37   QVariant data(int column, int role) const;
38   Buffer *buffer() const { return buf; }
39   void setActivity(const Buffer::ActivityLevel &);
40   
41 protected:
42   QString text(int column) const;
43   QColor foreground(int column) const;
44   
45   Buffer *buf;
46   Buffer::ActivityLevel activity;
47 };
48
49
50 /*****************************************
51  * BufferTreeModel
52  *****************************************/
53 class BufferTreeModel : public TreeModel {
54   Q_OBJECT
55   
56 public:
57   enum  myRoles {
58     BufferTypeRole = Qt::UserRole,
59     BufferActiveRole,
60     BufferNameRole,
61     BufferIdRole
62   };
63   
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   void clear();  // EgS: check this
71   
72 public slots:
73   void bufferUpdated(Buffer *);    
74   void changeCurrent(const QModelIndex &, const QModelIndex &);
75   void selectBuffer(Buffer *buffer);
76   void doubleClickReceived(const QModelIndex &);
77   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
78   
79 signals:
80   void bufferSelected(Buffer *);
81   void invalidateFilter();
82   void fakeUserInput(BufferId, QString);
83   void selectionChanged(const QModelIndex &);
84     
85 private:
86   bool isBufferIndex(const QModelIndex &) const;
87   Buffer *getBufferByIndex(const QModelIndex &) const;
88   QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
89   QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
90
91   QStringList mimeTypes() const;
92   QMimeData *mimeData(const QModelIndexList &) const;
93   bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
94   
95   QHash<QString, TreeItem*> networkItem;
96   QHash<Buffer *, BufferTreeItem*> bufferItem;
97   Buffer *currentBuffer;
98 };
99
100 #endif