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