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

kmail

kmaddrbook.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002  * kmail: KDE mail client
00003  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #include "kmaddrbook.h"
00021 #include "kcursorsaver.h"
00022 
00023 #include <kabc/stdaddressbook.h>
00024 #include <kabc/vcardconverter.h>
00025 
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 
00030 #include <QRegExp>
00031 
00032 #include <unistd.h>
00033 
00034 void KabcBridge::addresses(QStringList& result) // includes lists
00035 {
00036   KCursorSaver busy(KBusyPtr::busy()); // loading might take a while
00037 
00038   KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00039   KABC::AddressBook::ConstIterator it;
00040   for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
00041     const QStringList emails = (*it).emails();
00042     QString n = (*it).prefix() + ' ' +
00043                 (*it).givenName() + ' ' +
00044                 (*it).additionalName() + ' ' +
00045                 (*it).familyName() + ' ' +
00046                 (*it).suffix();
00047     n = n.simplified();
00048 
00049     QRegExp needQuotes("[^ 0-9A-Za-z\\x0080-\\xFFFF]");
00050     QString endQuote = "\" ";
00051     QStringList::ConstIterator mit;
00052     QString addr, email;
00053 
00054     for ( mit = emails.begin(); mit != emails.end(); ++mit ) {
00055       email = *mit;
00056       if (!email.isEmpty()) {
00057         if (n.isEmpty() || (email.contains( '<' ) ))
00058           addr.clear();
00059         else { // do we really need quotes around this name ?
00060           if (n.contains(needQuotes) )
00061             addr = '"' + n + endQuote;
00062           else
00063             addr = n + ' ';
00064         }
00065 
00066         if (!addr.isEmpty() && !(email.contains( '<' ) )
00067             && !(email.contains( '>' ) )
00068             && !(email.contains( ',' ) ))
00069           addr += '<' + email + '>';
00070         else
00071           addr += email;
00072         addr = addr.trimmed();
00073         result.append( addr );
00074       }
00075     }
00076   }
00077 
00078   result += addressBook->allDistributionListNames();
00079 
00080   result.sort();
00081 }
00082 
00083 QStringList KabcBridge::addresses()
00084 {
00085     QStringList entries;
00086     KABC::AddressBook::ConstIterator it;
00087 
00088     const KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00089     for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
00090         entries += (*it).fullEmail();
00091     }
00092     return entries;
00093 }
00094 
00095 //-----------------------------------------------------------------------------
00096 QString KabcBridge::expandNickName( const QString& nickName )
00097 {
00098   if ( nickName.isEmpty() )
00099     return QString();
00100 
00101   const QString lowerNickName = nickName.toLower();
00102   const KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00103   for( KABC::AddressBook::ConstIterator it = addressBook->begin();
00104        it != addressBook->end(); ++it ) {
00105     if ( (*it).nickName().toLower() == lowerNickName )
00106       return (*it).fullEmail();
00107   }
00108   return QString();
00109 }
00110 
00111 
00112 //-----------------------------------------------------------------------------
00113 
00114 QStringList KabcBridge::categories()
00115 {
00116   KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00117   KABC::Addressee::List addresses = addressBook->allAddressees();
00118   QStringList allcategories, aux;
00119 
00120   for ( KABC::Addressee::List::Iterator it = addresses.begin();
00121         it != addresses.end(); ++it ) {
00122     aux = ( *it ).categories();
00123     for ( QStringList::ConstIterator itAux = aux.begin();
00124           itAux != aux.end(); ++itAux ) {
00125       // don't have duplicates in allcategories
00126       if ( !allcategories.contains( *itAux )  )
00127         allcategories += *itAux;
00128     }
00129   }
00130   return allcategories;
00131 }

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal