• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

collectionfilterproxymodel.cpp

00001 /*
00002     Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
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 
00020 #include "collectionfilterproxymodel.h"
00021 
00022 #include "collectionmodel.h"
00023 
00024 #include <kmimetype.h>
00025 
00026 #include <QtCore/QString>
00027 #include <QtCore/QStringList>
00028 
00029 using namespace Akonadi;
00030 
00034 class CollectionFilterProxyModel::Private
00035 {
00036   public:
00037     Private( CollectionFilterProxyModel *parent )
00038       : mParent( parent )
00039     {
00040       mimeTypes << QLatin1String( "text/uri-list" );
00041     }
00042 
00043     bool collectionAccepted( const QModelIndex &index );
00044 
00045     CollectionFilterProxyModel *mParent;
00046     QStringList mimeTypes;
00047 };
00048 
00049 bool CollectionFilterProxyModel::Private::collectionAccepted( const QModelIndex &index )
00050 {
00051   // Retrieve supported mimetypes
00052   QStringList collectionMimeTypes = mParent->sourceModel()->data( index, CollectionModel::CollectionRole ).value<Collection>().contentMimeTypes();
00053 
00054   // If this collection directly contains one valid mimetype, it is accepted
00055   foreach ( const QString &type, collectionMimeTypes ) {
00056     if ( mimeTypes.contains( type ) )
00057       return true;
00058 
00059     KMimeType::Ptr mimeType = KMimeType::mimeType( type, KMimeType::ResolveAliases );
00060     if ( !mimeType.isNull() ) {
00061       foreach ( const QString &mt, mimeTypes ) {
00062         if ( mimeType->is( mt ) )
00063           return true;
00064       }
00065     }
00066   }
00067   // If this collection has a child which contains valid mimetypes, it is accepted
00068   QModelIndex childIndex = index.child( 0, 0 );
00069   while ( childIndex.isValid() ) {
00070     if ( collectionAccepted( childIndex ) )
00071       return true;
00072 
00073     childIndex = childIndex.sibling( childIndex.row() + 1, 0 );
00074   }
00075 
00076   // Or else, no reason to keep this collection.
00077   return false;
00078 }
00079 
00080 
00081 CollectionFilterProxyModel::CollectionFilterProxyModel( QObject *parent )
00082   : QSortFilterProxyModel( parent ),
00083     d( new Private( this ) )
00084 {
00085   setSupportedDragActions( Qt::CopyAction | Qt::MoveAction );
00086 }
00087 
00088 CollectionFilterProxyModel::~CollectionFilterProxyModel()
00089 {
00090   delete d;
00091 }
00092 
00093 void CollectionFilterProxyModel::addMimeTypeFilters(const QStringList &typeList)
00094 {
00095   d->mimeTypes << typeList;
00096   invalidateFilter();
00097 }
00098 
00099 void CollectionFilterProxyModel::addMimeTypeFilter(const QString &type)
00100 {
00101   d->mimeTypes << type;
00102   invalidateFilter();
00103 }
00104 
00105 bool CollectionFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent) const
00106 {
00107   return d->collectionAccepted( sourceModel()->index( sourceRow, 0, sourceParent ) );
00108 }
00109 
00110 QStringList CollectionFilterProxyModel::mimeTypeFilters() const
00111 {
00112   return d->mimeTypes;
00113 }
00114 
00115 void CollectionFilterProxyModel::clearFilters()
00116 {
00117   d->mimeTypes.clear();
00118   invalidateFilter();
00119 }
00120 
00121 #include "collectionfilterproxymodel.moc"

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal