kmail

tdelistviewindexedsearchline.cpp
1 
2 /* This file is part of KMail
3  * Copyright (C) 2005 Luís Pedro Coelho <luis@luispedro.org>
4  *
5  * KMail is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License, version 2, as
7  * published by the Free Software Foundation.
8  *
9  * KMail is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * In addition, as a special exception, the copyright holders give
19  * permission to link the code of this program with any edition of
20  * the TQt library by Trolltech AS, Norway (or with modified versions
21  * of TQt that use the same license as TQt), and distribute linked
22  * combinations including the two. You must obey the GNU General
23  * Public License in all respects for all of the code used other than
24  * TQt. If you modify this file, you may extend this exception to
25  * your version of the file, but you are not obligated to do so. If
26  * you do not wish to do so, delete this exception statement from
27  * your version.
28  */
29 
30 #include "tdelistviewindexedsearchline.h"
31 #include <kdebug.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include "headeritem.h"
35 #include "kmheaders.h"
36 #include "kmfolder.h"
37 #include "index.h"
38 
39 using KMail::HeaderListQuickSearch;
40 
41 TDEListViewIndexedSearchLine::TDEListViewIndexedSearchLine( TQWidget* parent, TDEListView* listView, TDEActionCollection* actionCollection, const char* name ):
42  HeaderListQuickSearch( parent, listView, actionCollection, name ),
43  mFiltering( false )
44 {
45 }
46 
47 TDEListViewIndexedSearchLine::~TDEListViewIndexedSearchLine() {
48 }
49 
50 
51 void TDEListViewIndexedSearchLine::updateSearch( const TQString& s ) {
52  kdDebug( 5006 ) << "updateSearch( -" << s << "- )" << endl;
53  mFiltering = false;
54  if ( !s.isNull() && !s.isEmpty() ) {
55  bool ok = false;
56  KMMsgIndex* index = kmkernel->msgIndex();
57  if ( index ) {
58  mResults = index->simpleSearch( s, &ok );
59  std::sort( mResults.begin(), mResults.end() );
60  mFiltering = ok;
61  }
62  }
63  TDEListViewSearchLine::updateSearch( s );
64 }
65 
66 bool TDEListViewIndexedSearchLine::itemMatches( const TQListViewItem* item, const TQString& s ) const {
67  if ( mFiltering &&
68  std::binary_search( mResults.begin(), mResults.end(), static_cast<const KMail::HeaderItem*>( item )->msgSerNum() ) )
69  return true;
70  return KMail::HeaderListQuickSearch::itemMatches( item, s );
71 }
72 
73 #include "tdelistviewindexedsearchline.moc"
74 
Visual representation of a member of the set of displayables (mails in the current folder).
Definition: headeritem.h:164
virtual void updateSearch(const TQString &s=TQString())
Updates search to only make visible the items that match s.