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

akonadi

  • 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 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "entityrightsfiltermodel.h"
23 
24 #include "entitytreemodel.h"
25 
26 #include <kdebug.h>
27 
28 using namespace Akonadi;
29 
30 namespace Akonadi {
31 
35 class EntityRightsFilterModelPrivate
36 {
37  public:
38  EntityRightsFilterModelPrivate( EntityRightsFilterModel *parent )
39  : q_ptr( parent ), mAccessRights( Collection::AllRights )
40  {
41  }
42 
43  bool rightsMatches( const QModelIndex &index ) const
44  {
45  if ( mAccessRights == Collection::AllRights ||
46  mAccessRights == Collection::ReadOnly ) {
47  return true;
48  }
49 
50  const Collection collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
51  if ( collection.isValid() ) {
52  return ( mAccessRights & collection.rights() );
53  } else {
54  const Item item = index.data( EntityTreeModel::ItemRole ).value<Item>();
55  if ( item.isValid() ) {
56  const Collection collection = index.data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
57  return ( mAccessRights & collection.rights() );
58  } else {
59  return false;
60  }
61  }
62  }
63 
64  Q_DECLARE_PUBLIC( EntityRightsFilterModel )
65  EntityRightsFilterModel *q_ptr;
66 
67  Collection::Rights mAccessRights;
68 };
69 
70 }
71 
72 EntityRightsFilterModel::EntityRightsFilterModel( QObject *parent )
73  : KRecursiveFilterProxyModel( parent ),
74  d_ptr( new EntityRightsFilterModelPrivate( this ) )
75 {
76 }
77 
78 EntityRightsFilterModel::~EntityRightsFilterModel()
79 {
80  delete d_ptr;
81 }
82 
83 void EntityRightsFilterModel::setAccessRights( Collection::Rights rights )
84 {
85  Q_D( EntityRightsFilterModel );
86  d->mAccessRights = rights;
87  invalidateFilter();
88 }
89 
90 Collection::Rights EntityRightsFilterModel::accessRights() const
91 {
92  Q_D( const EntityRightsFilterModel );
93  return d->mAccessRights;
94 }
95 
96 bool EntityRightsFilterModel::acceptRow( int sourceRow, const QModelIndex &sourceParent) const
97 {
98  Q_D( const EntityRightsFilterModel );
99 
100  const QModelIndex modelIndex = sourceModel()->index( sourceRow, 0, sourceParent );
101 
102  return d->rightsMatches( modelIndex );
103 }
104 
105 Qt::ItemFlags EntityRightsFilterModel::flags( const QModelIndex &index ) const
106 {
107  Q_D( const EntityRightsFilterModel );
108 
109  if ( d->rightsMatches( index ) ) {
110  return KRecursiveFilterProxyModel::flags( index );
111  } else {
112  return KRecursiveFilterProxyModel::flags( index ) & ~( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
113  }
114 }
115 
116 QModelIndexList EntityRightsFilterModel::match( const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags ) const
117 {
118  if ( role < Qt::UserRole ) {
119  return QSortFilterProxyModel::match( start, role, value, hits, flags );
120  }
121 
122  QModelIndexList list;
123  QModelIndex proxyIndex;
124  foreach ( const QModelIndex &idx, sourceModel()->match( mapToSource( start ), role, value, hits, flags ) ) {
125  proxyIndex = mapFromSource( idx );
126  if ( proxyIndex.isValid() )
127  list << proxyIndex;
128  }
129 
130  return list;
131 }
132 
Akonadi::EntityRightsFilterModel::setAccessRights
void setAccessRights(Collection::Rights rights)
Sets the access rights the entities shall be filtered against.
Definition: entityrightsfiltermodel.cpp:83
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:90
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:105
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:116
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:78
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:17 by doxygen 1.8.5 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-4.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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