~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to mobile/notes/notesfilterproxymodel.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
 
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
 
 
20
#include "notesfilterproxymodel.h"
 
21
 
 
22
#include <akonadi/entitytreemodel.h>
 
23
#include <KMime/Message>
 
24
 
 
25
static bool noteMatchesFilter( const KMime::Message::Ptr &note, const QString &filterString );
 
26
 
 
27
using namespace Akonadi;
 
28
 
 
29
class NotesFilterProxyModel::Private
 
30
{
 
31
  public:
 
32
    QString mFilter;
 
33
};
 
34
 
 
35
NotesFilterProxyModel::NotesFilterProxyModel( QObject *parent )
 
36
  : QSortFilterProxyModel( parent ), d( new Private )
 
37
{
 
38
  setSortLocaleAware( true );
 
39
  setDynamicSortFilter( true );
 
40
}
 
41
 
 
42
NotesFilterProxyModel::~NotesFilterProxyModel()
 
43
{
 
44
  delete d;
 
45
}
 
46
 
 
47
void NotesFilterProxyModel::setFilterString( const QString &filter )
 
48
{
 
49
  d->mFilter = filter;
 
50
  invalidateFilter();
 
51
}
 
52
 
 
53
bool NotesFilterProxyModel::filterAcceptsRow( int row, const QModelIndex &parent ) const
 
54
{
 
55
  if ( d->mFilter.isEmpty() )
 
56
    return true;
 
57
 
 
58
  const QModelIndex index = sourceModel()->index( row, 0, parent );
 
59
 
 
60
  const Akonadi::Item item = index.data( Akonadi::EntityTreeModel::ItemRole ).value<Akonadi::Item>();
 
61
 
 
62
  if ( item.hasPayload<KMime::Message::Ptr>() ) {
 
63
    const KMime::Message::Ptr note = item.payload<KMime::Message::Ptr>();
 
64
    return noteMatchesFilter( note, d->mFilter );
 
65
  }
 
66
 
 
67
  return true;
 
68
}
 
69
 
 
70
static bool noteMatchesFilter( const KMime::Message::Ptr &note, const QString &filterString )
 
71
{
 
72
  if ( note->subject()->asUnicodeString().contains( filterString, Qt::CaseInsensitive ) )
 
73
    return true;
 
74
 
 
75
  if ( note->mainBodyPart()->decodedText().contains( filterString, Qt::CaseInsensitive ) )
 
76
    return true;
 
77
 
 
78
  return false;
 
79
}
 
80
 
 
81
#include "notesfilterproxymodel.moc"