2
Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
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.
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.
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
20
#include "notesfilterproxymodel.h"
22
#include <akonadi/entitytreemodel.h>
23
#include <KMime/Message>
25
static bool noteMatchesFilter( const KMime::Message::Ptr ¬e, const QString &filterString );
27
using namespace Akonadi;
29
class NotesFilterProxyModel::Private
35
NotesFilterProxyModel::NotesFilterProxyModel( QObject *parent )
36
: QSortFilterProxyModel( parent ), d( new Private )
38
setSortLocaleAware( true );
39
setDynamicSortFilter( true );
42
NotesFilterProxyModel::~NotesFilterProxyModel()
47
void NotesFilterProxyModel::setFilterString( const QString &filter )
53
bool NotesFilterProxyModel::filterAcceptsRow( int row, const QModelIndex &parent ) const
55
if ( d->mFilter.isEmpty() )
58
const QModelIndex index = sourceModel()->index( row, 0, parent );
60
const Akonadi::Item item = index.data( Akonadi::EntityTreeModel::ItemRole ).value<Akonadi::Item>();
62
if ( item.hasPayload<KMime::Message::Ptr>() ) {
63
const KMime::Message::Ptr note = item.payload<KMime::Message::Ptr>();
64
return noteMatchesFilter( note, d->mFilter );
70
static bool noteMatchesFilter( const KMime::Message::Ptr ¬e, const QString &filterString )
72
if ( note->subject()->asUnicodeString().contains( filterString, Qt::CaseInsensitive ) )
75
if ( note->mainBodyPart()->decodedText().contains( filterString, Qt::CaseInsensitive ) )
81
#include "notesfilterproxymodel.moc"