1/*
2 Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef AKONADI_AGENTFILTERPROXYMODEL_H
21#define AKONADI_AGENTFILTERPROXYMODEL_H
22
23#include "akonadi_export.h"
24#include <QSortFilterProxyModel>
25
26namespace Akonadi {
27
28/**
29 * @short A proxy model for filtering AgentType or AgentInstance
30 *
31 * This filter proxy model works on top of a AgentTypeModel or AgentInstanceModel
32 * and can be used to show only AgentType or AgentInstance objects
33 * which provide a given mime type or capability.
34 *
35 * @code
36 *
37 * // Show only running agent instances that provide contacts
38 * Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this );
39 *
40 * Akonadi::AgentFilterProxyModel *proxy = new Akonadi::AgentFilterProxyModel( this );
41 * proxy->addMimeTypeFilter( "text/directory" );
42 *
43 * proxy->setSourceModel( model );
44 *
45 * QListView *view = new QListView( this );
46 * view->setModel( proxy );
47 *
48 * @endcode
49 *
50 * @author Volker Krause <vkrause@kde.org>
51 */
52class AKONADI_EXPORT AgentFilterProxyModel : public QSortFilterProxyModel
53{
54 Q_OBJECT
55public:
56 /**
57 * Create a new agent filter proxy model.
58 * By default no filtering is done.
59 * @param parent parent object
60 */
61 explicit AgentFilterProxyModel(QObject *parent = 0);
62
63 /**
64 * Destroys the agent filter proxy model.
65 */
66 ~AgentFilterProxyModel();
67
68 /**
69 * Accept agents supporting @p mimeType.
70 */
71 void addMimeTypeFilter(const QString &mimeType);
72
73 /**
74 * Accept agents with the given @p capability.
75 */
76 void addCapabilityFilter(const QString &capability);
77
78 /**
79 * Clear the filters ( mimeTypes & capabilities ).
80 */
81 void clearFilters();
82
83 /**
84 * Excludes agents with the given @p capability.
85 * @param capability undesired agent capability
86 * @since 4.6
87 */
88 void excludeCapabilities(const QString &capability);
89
90protected:
91 bool filterAcceptsRow(int row, const QModelIndex &parent) const;
92
93private:
94 //@cond PRIVATE
95 class Private;
96 Private *const d;
97 //@endcond
98};
99
100}
101
102#endif
103