libkdepim
kmailcompletion.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kmailcompletion.h"
00023 #include <kdebug.h>
00024
00025 #include <qregexp.h>
00026
00027 using namespace KPIM;
00028
00029 KMailCompletion::KMailCompletion()
00030 {
00031 setIgnoreCase( true );
00032 }
00033
00034 void KMailCompletion::clear()
00035 {
00036 m_keyMap.clear();
00037 KCompletion::clear();
00038 }
00039
00040 QString KMailCompletion::makeCompletion( const QString &string )
00041 {
00042 QString match = KCompletion::makeCompletion( string );
00043
00044
00045 if ( !match.isEmpty() ){
00046 const QString firstMatch( match );
00047 while ( match.find( QRegExp( "(@)|(<.*>)" ) ) == -1 ) {
00048
00049
00050
00051
00052
00053 const QStringList &mailAddr = m_keyMap[ match ];
00054 bool isEmail = false;
00055 for ( QStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit )
00056 if ( (*sit).find( "<" + match + ">" ) != -1 || (*sit) == match ) {
00057 isEmail = true;
00058 break;
00059 }
00060
00061 if ( !isEmail ) {
00062
00063 match = nextMatch();
00064 if ( firstMatch == match ){
00065 match = QString::null;
00066 break;
00067 }
00068 } else
00069 break;
00070 }
00071 }
00072 return match;
00073 }
00074
00075 void KMailCompletion::addItemWithKeys( const QString& email, int weight, const QStringList* keyWords)
00076 {
00077 Q_ASSERT( keyWords != 0 );
00078 for ( QStringList::ConstIterator it( keyWords->begin() ); it != keyWords->end(); ++it ) {
00079 QStringList &emailList = m_keyMap[ (*it) ];
00080 if ( emailList.find( email ) == emailList.end() )
00081 emailList.append( email );
00082 addItem( (*it),weight );
00083 }
00084 }
00085
00086 void KMailCompletion::postProcessMatches( QStringList * pMatches )const
00087 {
00088 Q_ASSERT( pMatches != 0 );
00089 if ( pMatches->isEmpty() )
00090 return;
00091
00092
00093 QMap< QString, bool > mailAddrDistinct;
00094 for ( QStringList::ConstIterator sit ( pMatches->begin() ), sEnd( pMatches->end() ); sit != sEnd; ++sit ) {
00095 const QStringList &mailAddr = m_keyMap[ (*sit) ];
00096 for ( QStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit ) {
00097 mailAddrDistinct[ (*sit) ] = true;
00098 }
00099 }
00100 pMatches->clear();
00101 (*pMatches) += mailAddrDistinct.keys();
00102 }
00103 #include "kmailcompletion.moc"
|