summaryrefslogtreecommitdiffstats
path: root/libkdepim/kmailcompletion.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /libkdepim/kmailcompletion.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkdepim/kmailcompletion.cpp')
-rw-r--r--libkdepim/kmailcompletion.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/libkdepim/kmailcompletion.cpp b/libkdepim/kmailcompletion.cpp
new file mode 100644
index 000000000..41d2f2ce8
--- /dev/null
+++ b/libkdepim/kmailcompletion.cpp
@@ -0,0 +1,103 @@
+/*
+ This file is part of libkdepim.
+
+ Copyright (c) 2006 Christian Schaarschmidt <schaarsc@gmx.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kmailcompletion.h"
+#include <kdebug.h>
+
+#include <qregexp.h>
+
+using namespace KPIM;
+
+KMailCompletion::KMailCompletion()
+{
+ setIgnoreCase( true );
+}
+
+void KMailCompletion::clear()
+{
+ m_keyMap.clear();
+ KCompletion::clear();
+}
+
+QString KMailCompletion::makeCompletion( const QString &string )
+{
+ QString match = KCompletion::makeCompletion( string );
+
+ // this should be in postProcessMatch, but postProcessMatch is const and will not allow nextMatch
+ if ( !match.isEmpty() ){
+ const QString firstMatch( match );
+ while ( match.find( QRegExp( "(@)|(<.*>)" ) ) == -1 ) {
+ /* local email do not require @domain part, if match is an address we'll find
+ * last+first <match> in m_keyMap and we'll know that match is already a valid email.
+ *
+ * Distribution list do not have last+first <match> entry, they will be in mailAddr
+ */
+ const QStringList &mailAddr = m_keyMap[ match ]; //get all mailAddr for this keyword
+ bool isEmail = false;
+ for ( QStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit )
+ if ( (*sit).find( "<" + match + ">" ) != -1 || (*sit) == match ) {
+ isEmail = true;
+ break;
+ }
+
+ if ( !isEmail ) {
+ // match is a keyword, skip it and try to find match <email@domain>
+ match = nextMatch();
+ if ( firstMatch == match ){
+ match = QString::null;
+ break;
+ }
+ } else
+ break;
+ }
+ }
+ return match;
+}
+
+void KMailCompletion::addItemWithKeys( const QString& email, int weight, const QStringList* keyWords)
+{
+ Q_ASSERT( keyWords != 0 );
+ for ( QStringList::ConstIterator it( keyWords->begin() ); it != keyWords->end(); ++it ) {
+ QStringList &emailList = m_keyMap[ (*it) ]; //lookup email-list for given keyword
+ if ( emailList.find( email ) == emailList.end() ) //add email if not there
+ emailList.append( email );
+ addItem( (*it),weight ); //inform KCompletion about keyword
+ }
+}
+
+void KMailCompletion::postProcessMatches( QStringList * pMatches )const
+{
+ Q_ASSERT( pMatches != 0 );
+ if ( pMatches->isEmpty() )
+ return;
+
+ //KCompletion has found the keywords for us, we can now map them to mail-addr
+ QMap< QString, bool > mailAddrDistinct; //TODO replace with QSet in KDE4
+ for ( QStringList::ConstIterator sit ( pMatches->begin() ), sEnd( pMatches->end() ); sit != sEnd; ++sit ) {
+ const QStringList &mailAddr = m_keyMap[ (*sit) ]; //get all mailAddr for this keyword
+ for ( QStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit ) {
+ mailAddrDistinct[ (*sit) ] = true; //store mailAddr, QMap will make them unique
+ }
+ }
+ pMatches->clear(); //delete keywords
+ (*pMatches) += mailAddrDistinct.keys(); //add emailAddr
+}
+#include "kmailcompletion.moc"