1/*
2 Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
3 Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#ifndef AKONADI_ENTITYMIMETYPEFILTERMODEL_H
22#define AKONADI_ENTITYMIMETYPEFILTERMODEL_H
23
24#include "akonadi_export.h"
25#include "entitytreemodel.h"
26
27#include <QSortFilterProxyModel>
28
29namespace Akonadi {
30
31class EntityMimeTypeFilterModelPrivate;
32
33/**
34 * @short A proxy model that filters entities by mime type.
35 *
36 * This class can be used on top of an EntityTreeModel to exclude entities by mimetype
37 * or to include only certain mimetypes.
38 *
39 * @code
40 *
41 * Akonadi::EntityTreeModel *model = new Akonadi::EntityTreeModel( this );
42 *
43 * Akonadi::EntityMimeTypeFilterModel *proxy = new Akonadi::EntityMimeTypeFilterModel();
44 * proxy->addMimeTypeInclusionFilter( "message/rfc822" );
45 * proxy->setSourceModel( model );
46 *
47 * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView( this );
48 * view->setModel( proxy );
49 *
50 * @endcode
51 *
52 * @li If a mimetype is in both the exclusion list and the inclusion list, it is excluded.
53 * @li If the mimeTypeInclusionFilter is empty, all mimetypes are
54 * accepted (except if they are in the exclusion filter of course).
55 *
56 *
57 * @author Bruno Virlet <bruno.virlet@gmail.com>
58 * @author Stephen Kelly <steveire@gmail.com>
59 * @since 4.4
60 */
61class AKONADI_EXPORT EntityMimeTypeFilterModel : public QSortFilterProxyModel
62{
63 Q_OBJECT
64
65public:
66 /**
67 * Creates a new entity mime type filter model.
68 *
69 * @param parent The parent object.
70 */
71 explicit EntityMimeTypeFilterModel(QObject *parent = 0);
72
73 /**
74 * Destroys the entity mime type filter model.
75 */
76 virtual ~EntityMimeTypeFilterModel();
77
78 /**
79 * Add mime types to be shown by the filter.
80 *
81 * @param mimeTypes A list of mime types to be included.
82 */
83 void addMimeTypeInclusionFilters(const QStringList &mimeTypes);
84
85 /**
86 * Add mimetypes to filter out
87 *
88 * @param mimeTypes A list to exclude from the model.
89 */
90 void addMimeTypeExclusionFilters(const QStringList &mimeTypes);
91
92 /**
93 * Add mime type to be shown by the filter.
94 *
95 * @param mimeType A mime type to be shown.
96 */
97 void addMimeTypeInclusionFilter(const QString &mimeType);
98
99 /**
100 * Add mime type to be excluded by the filter.
101 *
102 * @param mimeType A mime type to be excluded.
103 */
104 void addMimeTypeExclusionFilter(const QString &mimeType);
105
106 /**
107 * Returns the list of mime type inclusion filters.
108 */
109 QStringList mimeTypeInclusionFilters() const;
110
111 /**
112 * Returns the list of mime type exclusion filters.
113 */
114 QStringList mimeTypeExclusionFilters() const;
115
116 /**
117 * Clear all mime type filters.
118 */
119 void clearFilters();
120
121 /**
122 * Sets the header @p set of the filter model.
123 * @param headerGroup the header to set.
124 * \sa EntityTreeModel::HeaderGroup
125 */
126 void setHeaderGroup(EntityTreeModel::HeaderGroup headerGroup);
127
128 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
129
130 virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
131
132 virtual bool canFetchMore(const QModelIndex &parent) const;
133
134 virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const;
135
136 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
137
138protected:
139 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
140 virtual bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const;
141
142private:
143 //@cond PRIVATE
144 Q_DECLARE_PRIVATE(EntityMimeTypeFilterModel)
145 EntityMimeTypeFilterModelPrivate *const d_ptr;
146 //@endcond
147};
148
149}
150
151#endif
152