• 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
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 TrashFilterProxyModel::TrashFilterProxyModel( QObject* parent )
49  : KRecursiveFilterProxyModel( parent ),
50  d_ptr( new TrashFilterProxyModelPrivate() )
51 {
52 
53 }
54 
55 TrashFilterProxyModel::~TrashFilterProxyModel()
56 {
57  delete d_ptr;
58 }
59 
60 void TrashFilterProxyModel::showTrash( bool enable )
61 {
62  Q_D( TrashFilterProxyModel );
63  d->mTrashIsShown = enable;
64  invalidateFilter();
65 }
66 
67 bool TrashFilterProxyModel::trashIsShown() const
68 {
69  Q_D( const TrashFilterProxyModel );
70  return d->mTrashIsShown;
71 }
72 
73 bool TrashFilterProxyModel::acceptRow( int sourceRow, const QModelIndex& sourceParent ) const
74 {
75  Q_D( const TrashFilterProxyModel );
76  const QModelIndex &index = sourceModel()->index( sourceRow, 0, sourceParent );
77  const Item &item = index.data( EntityTreeModel::ItemRole ).value<Item>();
78  //kDebug() << item.id();
79  if ( item.isValid() ) {
80  if ( item.hasAttribute<EntityDeletedAttribute>()/* d->showEntity(item)*/ ) {
81  return d->mTrashIsShown;
82  }
83  }
84  const Collection &collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
85  if ( collection.isValid() ) {
86  if ( collection.hasAttribute<EntityDeletedAttribute>()/*d->showEntity(collection) */ ) {
87  return d->mTrashIsShown;
88  }
89  }
90  return !d->mTrashIsShown;
91 }
92 
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:73
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:59
Akonadi::EntityDeletedAttribute
An Attribute that marks that an entity was marked as deleted.
Definition: entitydeletedattribute.h:49
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:28 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