• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
entityrightsfiltermodel.cpp
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 #include "entityrightsfiltermodel.h"
22 
23 #include "entitytreemodel.h"
24 
25 #include <kdebug.h>
26 
27 using namespace Akonadi;
28 
29 namespace Akonadi {
30 
34 class EntityRightsFilterModelPrivate
35 {
36  public:
37  EntityRightsFilterModelPrivate( EntityRightsFilterModel *parent )
38  : q_ptr( parent ), mAccessRights( Collection::AllRights )
39  {
40  }
41 
42  bool rightsMatches( const QModelIndex &index ) const
43  {
44  if ( mAccessRights == Collection::AllRights ||
45  mAccessRights == Collection::ReadOnly ) {
46  return true;
47  }
48 
49  const Collection collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
50  if ( collection.isValid() ) {
51  return ( mAccessRights & collection.rights() );
52  } else {
53  const Item item = index.data( EntityTreeModel::ItemRole ).value<Item>();
54  if ( item.isValid() ) {
55  const Collection collection = index.data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
56  return ( mAccessRights & collection.rights() );
57  } else {
58  return false;
59  }
60  }
61  }
62 
63  Q_DECLARE_PUBLIC( EntityRightsFilterModel )
64  EntityRightsFilterModel *q_ptr;
65 
66  Collection::Rights mAccessRights;
67 };
68 
69 }
70 
71 EntityRightsFilterModel::EntityRightsFilterModel( QObject *parent )
72  : KRecursiveFilterProxyModel( parent ),
73  d_ptr( new EntityRightsFilterModelPrivate( this ) )
74 {
75 }
76 
77 EntityRightsFilterModel::~EntityRightsFilterModel()
78 {
79  delete d_ptr;
80 }
81 
82 void EntityRightsFilterModel::setAccessRights( Collection::Rights rights )
83 {
84  Q_D( EntityRightsFilterModel );
85  d->mAccessRights = rights;
86  invalidateFilter();
87 }
88 
89 Collection::Rights EntityRightsFilterModel::accessRights() const
90 {
91  Q_D( const EntityRightsFilterModel );
92  return d->mAccessRights;
93 }
94 
95 bool EntityRightsFilterModel::acceptRow( int sourceRow, const QModelIndex &sourceParent) const
96 {
97  Q_D( const EntityRightsFilterModel );
98 
99  const QModelIndex modelIndex = sourceModel()->index( sourceRow, 0, sourceParent );
100 
101  return d->rightsMatches( modelIndex );
102 }
103 
104 Qt::ItemFlags EntityRightsFilterModel::flags( const QModelIndex &index ) const
105 {
106  Q_D( const EntityRightsFilterModel );
107 
108  if ( d->rightsMatches( index ) ) {
109  return KRecursiveFilterProxyModel::flags( index );
110  } else {
111  return KRecursiveFilterProxyModel::flags( index ) & ~( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
112  }
113 }
114 
115 QModelIndexList EntityRightsFilterModel::match( const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags ) const
116 {
117  if ( role < Qt::UserRole ) {
118  return QSortFilterProxyModel::match( start, role, value, hits, flags );
119  }
120 
121  QModelIndexList list;
122  QModelIndex proxyIndex;
123  foreach ( const QModelIndex &idx, sourceModel()->match( mapToSource( start ), role, value, hits, flags ) ) {
124  proxyIndex = mapFromSource( idx );
125  if ( proxyIndex.isValid() )
126  list << proxyIndex;
127  }
128 
129  return list;
130 }
131 
Akonadi::EntityRightsFilterModel::setAccessRights
void setAccessRights(Collection::Rights rights)
Sets the access rights the entities shall be filtered against.
Definition: entityrightsfiltermodel.cpp:82
Akonadi::Collection::AllRights
Has all rights on this storage collection.
Definition: collection.h:96
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityRightsFilterModel::accessRights
Collection::Rights accessRights() const
Returns the access rights that are used for filtering.
Definition: entityrightsfiltermodel.cpp:89
Akonadi::EntityRightsFilterModel
A proxy model that filters entities by access rights.
Definition: entityrightsfiltermodel.h:60
Akonadi::Collection::ReadOnly
Can only read items or subcollection of this collection.
Definition: collection.h:87
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::EntityTreeModel::ParentCollectionRole
The parent collection of the entity.
Definition: entitytreemodel.h:340
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:99
Akonadi::EntityRightsFilterModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: entityrightsfiltermodel.cpp:104
Akonadi::EntityTreeModel::ItemRole
The Item.
Definition: entitytreemodel.h:331
Akonadi::EntityRightsFilterModel::match
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Definition: entityrightsfiltermodel.cpp:115
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::EntityRightsFilterModel::~EntityRightsFilterModel
virtual ~EntityRightsFilterModel()
Destroys the entity rights filter model.
Definition: entityrightsfiltermodel.cpp:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal