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

akonadi

trashfilterproxymodel.cpp
00001 /*
00002  Copyright (c) 2011 Christian Mollekopf <chrigi_1@fastmail.fm>
00003 
00004  This library is free software; you can redistribute it and/or modify it
00005  under the terms of the GNU Library General Public License as published by
00006  the Free Software Foundation; either version 2 of the License, or (at your
00007  option) any later version.
00008 
00009  This library is distributed in the hope that it will be useful, but WITHOUT
00010  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012  License for more details.
00013 
00014  You should have received a copy of the GNU Library General Public License
00015  along with this library; see the file COPYING.LIB.  If not, write to the
00016  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  02110-1301, USA.
00018 */
00019 #include "trashfilterproxymodel.h"
00020 
00021 #include <akonadi/entity.h>
00022 #include <akonadi/entitydeletedattribute.h>
00023 #include <akonadi/item.h>
00024 #include <akonadi/entitytreemodel.h>
00025 #include <akonadi/resourcesettings.h>
00026 
00027 using namespace Akonadi;
00028 
00029 class TrashFilterProxyModel::TrashFilterProxyModelPrivate
00030 {
00031   public:
00032     TrashFilterProxyModelPrivate() : mTrashIsShown( false ) {};
00033     bool showEntity( const Entity & ) const;
00034     bool mTrashIsShown;
00035 };
00036 
00037 bool TrashFilterProxyModel::TrashFilterProxyModelPrivate::showEntity( const Akonadi::Entity &entity ) const
00038 {
00039   if ( entity.hasAttribute<EntityDeletedAttribute>() ) {
00040     return true;
00041   }
00042   if ( entity.id() == Collection::root().id() ) {
00043     return false;
00044   }
00045   return showEntity( entity.parentCollection() );
00046 }
00047 
00048 
00049 TrashFilterProxyModel::TrashFilterProxyModel( QObject* parent )
00050     : KRecursiveFilterProxyModel( parent ),
00051     d_ptr( new TrashFilterProxyModelPrivate() )
00052 {
00053 
00054 }
00055 
00056 TrashFilterProxyModel::~TrashFilterProxyModel()
00057 {
00058   delete d_ptr;
00059 }
00060 
00061 
00062 void TrashFilterProxyModel::showTrash( bool enable )
00063 {
00064   Q_D( TrashFilterProxyModel );
00065   d->mTrashIsShown = enable;
00066   invalidateFilter();
00067 }
00068 
00069 bool TrashFilterProxyModel::trashIsShown() const
00070 {
00071   Q_D( const TrashFilterProxyModel );
00072   return d->mTrashIsShown;
00073 }
00074 
00075 
00076 bool TrashFilterProxyModel::acceptRow( int sourceRow, const QModelIndex& sourceParent ) const
00077 {
00078   Q_D( const TrashFilterProxyModel );
00079   const QModelIndex &index = sourceModel()->index( sourceRow, 0, sourceParent );
00080   const Item &item = index.data( EntityTreeModel::ItemRole ).value<Item>();
00081   //kDebug() << item.id();
00082   if ( item.isValid() ) {
00083     if ( item.hasAttribute<EntityDeletedAttribute>()/* d->showEntity(item)*/ ) {
00084       return d->mTrashIsShown;
00085     }
00086   }
00087   const Collection &collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
00088   if ( collection.isValid() ) {
00089     if ( collection.hasAttribute<EntityDeletedAttribute>()/*d->showEntity(collection) */ ) {
00090       return d->mTrashIsShown;
00091     }
00092   }
00093   return !d->mTrashIsShown;
00094 }
00095 
00096 #include "trashfilterproxymodel.moc"
00097 
00098 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:37 by doxygen 1.8.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
  • Modules
  • Related Pages

kdepimlibs-4.8.3 API Reference

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