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

akonadi

  • akonadi
trashfilterproxymodel.cpp
1 /*
2  Copyright (c) 2011 Christian Mollekopf <chrigi_1@fastmail.fm>
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 #include "trashfilterproxymodel.h"
20 
21 #include <akonadi/entity.h>
22 #include <akonadi/entitydeletedattribute.h>
23 #include <akonadi/item.h>
24 #include <akonadi/entitytreemodel.h>
25 #include <akonadi/resourcesettings.h>
26 
27 using namespace Akonadi;
28 
29 class TrashFilterProxyModel::TrashFilterProxyModelPrivate
30 {
31  public:
32  TrashFilterProxyModelPrivate() : mTrashIsShown( false ) {};
33  bool showEntity( const Entity & ) const;
34  bool mTrashIsShown;
35 };
36 
37 bool TrashFilterProxyModel::TrashFilterProxyModelPrivate::showEntity( const Akonadi::Entity &entity ) const
38 {
39  if ( entity.hasAttribute<EntityDeletedAttribute>() ) {
40  return true;
41  }
42  if ( entity.id() == Collection::root().id() ) {
43  return false;
44  }
45  return showEntity( entity.parentCollection() );
46 }
47 
48 
49 TrashFilterProxyModel::TrashFilterProxyModel( QObject* parent )
50  : KRecursiveFilterProxyModel( parent ),
51  d_ptr( new TrashFilterProxyModelPrivate() )
52 {
53 
54 }
55 
56 TrashFilterProxyModel::~TrashFilterProxyModel()
57 {
58  delete d_ptr;
59 }
60 
61 
62 void TrashFilterProxyModel::showTrash( bool enable )
63 {
64  Q_D( TrashFilterProxyModel );
65  d->mTrashIsShown = enable;
66  invalidateFilter();
67 }
68 
69 bool TrashFilterProxyModel::trashIsShown() const
70 {
71  Q_D( const TrashFilterProxyModel );
72  return d->mTrashIsShown;
73 }
74 
75 
76 bool TrashFilterProxyModel::acceptRow( int sourceRow, const QModelIndex& sourceParent ) const
77 {
78  Q_D( const TrashFilterProxyModel );
79  const QModelIndex &index = sourceModel()->index( sourceRow, 0, sourceParent );
80  const Item &item = index.data( EntityTreeModel::ItemRole ).value<Item>();
81  //kDebug() << item.id();
82  if ( item.isValid() ) {
83  if ( item.hasAttribute<EntityDeletedAttribute>()/* d->showEntity(item)*/ ) {
84  return d->mTrashIsShown;
85  }
86  }
87  const Collection &collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
88  if ( collection.isValid() ) {
89  if ( collection.hasAttribute<EntityDeletedAttribute>()/*d->showEntity(collection) */ ) {
90  return d->mTrashIsShown;
91  }
92  }
93  return !d->mTrashIsShown;
94 }
95 
96 
97 
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:186
Akonadi::TrashFilterProxyModel::acceptRow
virtual bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const
Sort filter criterias, according to how expensive the operation is.
Definition: trashfilterproxymodel.cpp:76
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:58
Akonadi::EntityDeletedAttribute
An Attribute that marks that an entity was marked as deleted.
Definition: entitydeletedattribute.h:51
Akonadi::EntityTreeModel::ItemRole
The Item.
Definition: entitytreemodel.h:331
Akonadi::Entity::hasAttribute
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Definition: entity.cpp:146
Akonadi::TrashFilterProxyModel
Filter model which hides/shows entites marked as trash.
Definition: trashfilterproxymodel.h:56
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:19 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