19 #include "trashfilterproxymodel.h"
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>
27 using namespace Akonadi;
29 class TrashFilterProxyModel::TrashFilterProxyModelPrivate
32 TrashFilterProxyModelPrivate() : mTrashIsShown( false ) {};
33 bool showEntity(
const Entity & )
const;
37 bool TrashFilterProxyModel::TrashFilterProxyModelPrivate::showEntity(
const Akonadi::Entity &entity )
const
39 if ( entity.hasAttribute<EntityDeletedAttribute>() ) {
42 if ( entity.id() == Collection::root().id() ) {
45 return showEntity( entity.parentCollection() );
49 TrashFilterProxyModel::TrashFilterProxyModel( QObject* parent )
50 : KRecursiveFilterProxyModel( parent ),
51 d_ptr( new TrashFilterProxyModelPrivate() )
56 TrashFilterProxyModel::~TrashFilterProxyModel()
62 void TrashFilterProxyModel::showTrash(
bool enable )
64 Q_D( TrashFilterProxyModel );
65 d->mTrashIsShown = enable;
69 bool TrashFilterProxyModel::trashIsShown()
const
71 Q_D(
const TrashFilterProxyModel );
72 return d->mTrashIsShown;
76 bool TrashFilterProxyModel::acceptRow(
int sourceRow,
const QModelIndex& sourceParent )
const
78 Q_D(
const TrashFilterProxyModel );
79 const QModelIndex &index = sourceModel()->index( sourceRow, 0, sourceParent );
80 const Item &item = index.data( EntityTreeModel::ItemRole ).value<Item>();
82 if ( item.isValid() ) {
83 if ( item.hasAttribute<EntityDeletedAttribute>() ) {
84 return d->mTrashIsShown;
87 const Collection &collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
88 if ( collection.isValid() ) {
89 if ( collection.hasAttribute<EntityDeletedAttribute>() ) {
90 return d->mTrashIsShown;
93 return !d->mTrashIsShown;
96 #include "trashfilterproxymodel.moc"