Making Quassel slowly ready for its first release...
[quassel.git] / src / uisupport / bufferviewfilter.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) version 3.                                           *
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 _BUFFERVIEWFILTER_H_
22 #define _BUFFERVIEWFILTER_H_
23
24 #include <QFlags>
25 #include <QDropEvent>
26 #include <QSortFilterProxyModel>
27 #include <QSet>
28 #include "buffer.h"
29 #include "buffertreemodel.h"
30
31 /*****************************************
32  * Buffer View Filter
33  *****************************************/
34 class BufferViewFilter : public QSortFilterProxyModel {
35   Q_OBJECT
36   
37 public:
38   enum Mode {
39     NoActive = 0x01,
40     NoInactive = 0x02,
41     SomeNets = 0x04,
42     AllNets = 0x08,
43     NoChannels = 0x10,
44     NoQueries = 0x20,
45     NoServers = 0x40,
46     FullCustom = 0x80
47   };
48   Q_DECLARE_FLAGS(Modes, Mode);
49
50   BufferViewFilter(QAbstractItemModel *model, const Modes &mode, const QList<uint> &nets);
51   
52   virtual Qt::ItemFlags flags(const QModelIndex &index) const;
53   virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
54   
55 public slots:
56   void removeBuffer(const QModelIndex &);
57   void invalidateFilter_();
58   
59 protected:
60   bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
61   bool lessThan(const QModelIndex &, const QModelIndex &) const;
62   
63 private:
64   Modes mode;
65   QSet<uint> networks;
66   QSet<uint> buffers;
67
68   bool filterAcceptBuffer(const QModelIndex &) const;
69   bool filterAcceptNetwork(const QModelIndex &) const;
70   void addBuffer(const uint &);
71
72 };
73 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferViewFilter::Modes)    
74
75 #endif
76