1/*
2 Copyright (c) 2009 Tobias Koenig <tokoe@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_ENTITYRIGHTSFILTERMODEL_H
21#define AKONADI_ENTITYRIGHTSFILTERMODEL_H
22
23#include "entitytreemodel.h"
24
25#include <krecursivefilterproxymodel.h>
26
27#include "akonadi_export.h"
28
29namespace Akonadi {
30
31class EntityRightsFilterModelPrivate;
32
33/**
34 * @short A proxy model that filters entities by access rights.
35 *
36 * This class can be used on top of an EntityTreeModel to exclude entities by access type
37 * or to include only certain entities with special access rights.
38 *
39 * @code
40 *
41 * using namespace Akonadi;
42 *
43 * EntityTreeModel *model = new EntityTreeModel( this );
44 *
45 * EntityRightsFilterModel *filter = new EntityRightsFilterModel();
46 * filter->setAccessRights( Collection::CanCreateItem | Collection::CanCreateCollection );
47 * filter->setSourceModel( model );
48 *
49 * EntityTreeView *view = new EntityTreeView( this );
50 * view->setModel( filter );
51 *
52 * @endcode
53 *
54 * @li For collections the access rights are checked against the collections own rights.
55 * @li For items the access rights are checked against the item's parent collection rights.
56 *
57 * @author Tobias Koenig <tokoe@kde.org>
58 * @since 4.6
59 */
60class AKONADI_EXPORT EntityRightsFilterModel : public KRecursiveFilterProxyModel
61{
62 Q_OBJECT
63
64public:
65 /**
66 * Creates a new entity rights filter model.
67 *
68 * @param parent The parent object.
69 */
70 explicit EntityRightsFilterModel(QObject *parent = 0);
71
72 /**
73 * Destroys the entity rights filter model.
74 */
75 virtual ~EntityRightsFilterModel();
76
77 /**
78 * Sets the access @p rights the entities shall be filtered
79 * against. If no rights are set explicitly, Collection::AllRights
80 * is assumed.
81 * @param rights the access rights filter values
82 */
83 void setAccessRights(Collection::Rights rights);
84
85 /**
86 * Returns the access rights that are used for filtering.
87 */
88 Collection::Rights accessRights() const;
89
90 /**
91 * @reimp
92 */
93 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
94
95 /**
96 * @reimp
97 */
98 virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1,
99 Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const;
100
101protected:
102 virtual bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const;
103
104private:
105 //@cond PRIVATE
106 Q_DECLARE_PRIVATE(EntityRightsFilterModel)
107 EntityRightsFilterModelPrivate *const d_ptr;
108 //@endcond
109};
110
111}
112
113#endif
114