• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • addressline
kmailcompletion.cpp
Go to the documentation of this file.
1 /*
2  This file is part of libkdepim.
3 
4  Copyright (c) 2006 Christian Schaarschmidt <schaarsc@gmx.de>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "kmailcompletion.h"
23 #include <KDebug>
24 #include <QRegExp>
25 
26 using namespace KPIM;
27 
28 KMailCompletion::KMailCompletion()
29 {
30  setIgnoreCase( true );
31 }
32 
33 void KMailCompletion::clear()
34 {
35  m_keyMap.clear();
36  KCompletion::clear();
37 }
38 
39 QString KMailCompletion::makeCompletion( const QString &string )
40 {
41  QString match = KCompletion::makeCompletion( string );
42 
43  // this should be in postProcessMatch, but postProcessMatch is const and will not allow nextMatch
44  if ( !match.isEmpty() ){
45  const QString firstMatch( match );
46  while ( match.indexOf( QRegExp( QLatin1String("(@)|(<.*>)") ) ) == -1 ) {
47  /* local email do not require @domain part, if match is an address we'll
48  * find last+first <match> in m_keyMap and we'll know that match is
49  * already a valid email.
50  *
51  * Distribution list do not have last+first <match> entry, they will be
52  * in mailAddr
53  */
54  const QStringList &mailAddr = m_keyMap[ match ]; //get all mailAddr for this keyword
55  bool isEmail = false;
56  for ( QStringList::ConstIterator sit( mailAddr.begin() ), sEnd( mailAddr.end() );
57  sit != sEnd; ++sit ) {
58  if ( (*sit).indexOf( QLatin1Char('<') + match + QLatin1Char('>') ) != -1 || (*sit) == match ) {
59  isEmail = true;
60  break;
61  }
62  }
63 
64  if ( !isEmail ) {
65  // match is a keyword, skip it and try to find match <email@domain>
66  match = nextMatch();
67  if ( firstMatch == match ){
68  match.clear();
69  break;
70  }
71  } else {
72  break;
73  }
74  }
75  }
76  return match;
77 }
78 
79 void KMailCompletion::addItemWithKeys( const QString &email, int weight,
80  const QStringList *keyWords )
81 {
82  Q_ASSERT( keyWords != 0 );
83  QStringList::ConstIterator end = keyWords->constEnd();
84  for ( QStringList::ConstIterator it( keyWords->constBegin() ); it != end; ++it ) {
85  QStringList &emailList = m_keyMap[ (*it) ]; //lookup email-list for given keyword
86  if ( emailList.indexOf( email ) == -1 ) { //add email if not there
87  emailList.append( email );
88  }
89  addItem( (*it), weight ); //inform KCompletion about keyword
90  }
91 }
92 
93 void KMailCompletion::postProcessMatches( QStringList *pMatches ) const
94 {
95  Q_ASSERT( pMatches != 0 );
96  if ( pMatches->isEmpty() ) {
97  return;
98  }
99 
100  //KCompletion has found the keywords for us, we can now map them to mail-addr
101  QSet< QString > mailAddrDistinct;
102  for ( QStringList::ConstIterator sit( pMatches->begin() ), sEnd( pMatches->end() );
103  sit != sEnd; ++sit ) {
104  const QStringList &mailAddr = m_keyMap[ (*sit) ]; //get all mailAddr for this keyword
105  for ( QStringList::ConstIterator sit( mailAddr.begin() ), sEnd( mailAddr.end() );
106  sit != sEnd; ++sit ) {
107  mailAddrDistinct.insert( *sit ); //store mailAddr, QSet will make them unique
108  }
109  }
110  pMatches->clear(); //delete keywords
111  (*pMatches) += mailAddrDistinct.toList(); //add emailAddr
112 }
113 #include "kmailcompletion.moc"
kmailcompletion.h
KPIM::KMailCompletion::addItemWithKeys
void addItemWithKeys(const QString &email, int weight, const QStringList *keyWords)
specify keywords for email.
Definition: kmailcompletion.cpp:79
KPIM::KMailCompletion::clear
virtual void clear()
clears internal keyword map and calls KCompletion::clear.
Definition: kmailcompletion.cpp:33
KPIM::KMailCompletion::postProcessMatches
virtual void postProcessMatches(QStringList *pMatches) const
use internal map to replace all keywords in pMatches with corresponding email addresses.
Definition: kmailcompletion.cpp:93
KPIM::KMailCompletion::makeCompletion
QString makeCompletion(const QString &string)
uses KCompletion::makeCompletion to find email addresses which starts with string.
Definition: kmailcompletion.cpp:39
KPIM::KMailCompletion::KMailCompletion
KMailCompletion()
Definition: kmailcompletion.cpp:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal