• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.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 || mAccessRights == Collection::ReadOnly )
46  return true;
47 
48  const Collection collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
49  if ( collection.isValid() ) {
50  return (mAccessRights & collection.rights());
51  } else {
52  const Item item = index.data( EntityTreeModel::ItemRole ).value<Item>();
53  if ( item.isValid() ) {
54  const Collection collection = index.data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
55  return (mAccessRights & collection.rights());
56  } else {
57  return false;
58  }
59  }
60  }
61 
62  Q_DECLARE_PUBLIC(EntityRightsFilterModel)
63  EntityRightsFilterModel *q_ptr;
64 
65  Collection::Rights mAccessRights;
66 };
67 
68 }
69 
70 EntityRightsFilterModel::EntityRightsFilterModel( QObject *parent )
71  : KRecursiveFilterProxyModel( parent ),
72  d_ptr( new EntityRightsFilterModelPrivate( this ) )
73 {
74 }
75 
76 EntityRightsFilterModel::~EntityRightsFilterModel()
77 {
78  delete d_ptr;
79 }
80 
81 void EntityRightsFilterModel::setAccessRights( Collection::Rights rights )
82 {
83  Q_D(EntityRightsFilterModel);
84  d->mAccessRights = rights;
85  invalidateFilter();
86 }
87 
88 Collection::Rights EntityRightsFilterModel::accessRights() const
89 {
90  Q_D(const EntityRightsFilterModel);
91  return d->mAccessRights;
92 }
93 
94 bool EntityRightsFilterModel::acceptRow( int sourceRow, const QModelIndex &sourceParent) const
95 {
96  Q_D(const EntityRightsFilterModel);
97 
98  const QModelIndex modelIndex = sourceModel()->index( sourceRow, 0, sourceParent );
99 
100  return d->rightsMatches( modelIndex );
101 }
102 
103 Qt::ItemFlags EntityRightsFilterModel::flags( const QModelIndex &index ) const
104 {
105  Q_D(const EntityRightsFilterModel);
106 
107  if ( d->rightsMatches( index ) )
108  return KRecursiveFilterProxyModel::flags( index );
109  else
110  return KRecursiveFilterProxyModel::flags( index ) & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
111 }
112 
113 QModelIndexList EntityRightsFilterModel::match( const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags ) const
114 {
115  if ( role < Qt::UserRole )
116  return QSortFilterProxyModel::match( start, role, value, hits, flags );
117 
118  QModelIndexList list;
119  QModelIndex proxyIndex;
120  foreach ( const QModelIndex &idx, sourceModel()->match( mapToSource( start ), role, value, hits, flags ) ) {
121  proxyIndex = mapFromSource( idx );
122  if ( proxyIndex.isValid() )
123  list << proxyIndex;
124  }
125 
126  return list;
127 }
128 
129 #include "entityrightsfiltermodel.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed Nov 28 2012 21:51:31 by doxygen 1.8.1.2 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.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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