tdelistviewindexedsearchline.cpp
00001 00002 /* This file is part of KMail 00003 * Copyright (C) 2005 Luís Pedro Coelho <luis@luispedro.org> 00004 * 00005 * KMail is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU General Public License, version 2, as 00007 * published by the Free Software Foundation. 00008 * 00009 * KMail is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 * 00018 * In addition, as a special exception, the copyright holders give 00019 * permission to link the code of this program with any edition of 00020 * the TQt library by Trolltech AS, Norway (or with modified versions 00021 * of TQt that use the same license as TQt), and distribute linked 00022 * combinations including the two. You must obey the GNU General 00023 * Public License in all respects for all of the code used other than 00024 * TQt. If you modify this file, you may extend this exception to 00025 * your version of the file, but you are not obligated to do so. If 00026 * you do not wish to do so, delete this exception statement from 00027 * your version. 00028 */ 00029 00030 #include "tdelistviewindexedsearchline.h" 00031 #include <kdebug.h> 00032 #include <sys/types.h> 00033 #include <sys/stat.h> 00034 #include "headeritem.h" 00035 #include "kmheaders.h" 00036 #include "kmfolder.h" 00037 #include "index.h" 00038 00039 using KMail::HeaderListQuickSearch; 00040 00041 TDEListViewIndexedSearchLine::TDEListViewIndexedSearchLine( TQWidget* parent, TDEListView* listView, TDEActionCollection* actionCollection, const char* name ): 00042 HeaderListQuickSearch( parent, listView, actionCollection, name ), 00043 mFiltering( false ) 00044 { 00045 } 00046 00047 TDEListViewIndexedSearchLine::~TDEListViewIndexedSearchLine() { 00048 } 00049 00050 00051 void TDEListViewIndexedSearchLine::updateSearch( const TQString& s ) { 00052 kdDebug( 5006 ) << "updateSearch( -" << s << "- )" << endl; 00053 mFiltering = false; 00054 if ( !s.isNull() && !s.isEmpty() ) { 00055 bool ok = false; 00056 KMMsgIndex* index = kmkernel->msgIndex(); 00057 if ( index ) { 00058 mResults = index->simpleSearch( s, &ok ); 00059 std::sort( mResults.begin(), mResults.end() ); 00060 mFiltering = ok; 00061 } 00062 } 00063 TDEListViewSearchLine::updateSearch( s ); 00064 } 00065 00066 bool TDEListViewIndexedSearchLine::itemMatches( const TQListViewItem* item, const TQString& s ) const { 00067 if ( mFiltering && 00068 std::binary_search( mResults.begin(), mResults.end(), static_cast<const KMail::HeaderItem*>( item )->msgSerNum() ) ) 00069 return true; 00070 return KMail::HeaderListQuickSearch::itemMatches( item, s ); 00071 } 00072 00073 #include "tdelistviewindexedsearchline.moc" 00074