• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
27using namespace Akonadi;
28
29class TrashFilterProxyModel::TrashFilterProxyModelPrivate
30{
31public:
32 TrashFilterProxyModelPrivate()
33 : mTrashIsShown(false)
34 {
35 };
36 bool showEntity(const Entity &) const;
37 bool mTrashIsShown;
38};
39
40bool TrashFilterProxyModel::TrashFilterProxyModelPrivate::showEntity(const Akonadi::Entity &entity) const
41{
42 if (entity.hasAttribute<EntityDeletedAttribute>()) {
43 return true;
44 }
45 if (entity.id() == Collection::root().id()) {
46 return false;
47 }
48 return showEntity(entity.parentCollection());
49}
50
51TrashFilterProxyModel::TrashFilterProxyModel(QObject *parent)
52 : KRecursiveFilterProxyModel(parent)
53 , d_ptr(new TrashFilterProxyModelPrivate())
54{
55
56}
57
58TrashFilterProxyModel::~TrashFilterProxyModel()
59{
60 delete d_ptr;
61}
62
63void TrashFilterProxyModel::showTrash(bool enable)
64{
65 Q_D(TrashFilterProxyModel);
66 d->mTrashIsShown = enable;
67 invalidateFilter();
68}
69
70bool TrashFilterProxyModel::trashIsShown() const
71{
72 Q_D(const TrashFilterProxyModel);
73 return d->mTrashIsShown;
74}
75
76bool 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}
Akonadi::Collection
Represents a collection of PIM items.
Definition collection.h:76
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition collection.cpp:192
Akonadi::EntityDeletedAttribute
An Attribute that marks that an entity was marked as deleted.
Definition entitydeletedattribute.h:50
Akonadi::EntityTreeModel::ItemRole
@ ItemRole
The Item.
Definition entitytreemodel.h:332
Akonadi::EntityTreeModel::CollectionRole
@ CollectionRole
The collection.
Definition entitytreemodel.h:336
Akonadi::Entity
The base class for Item and Collection.
Definition entity.h:60
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition entity.cpp:185
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:148
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition entity.cpp:72
Akonadi::TrashFilterProxyModel
Filter model which hides/shows entites marked as trash.
Definition trashfilterproxymodel.h:57
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
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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