kmail
kmaddrbook.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <unistd.h>
00022
00023 #include "kmaddrbook.h"
00024 #include "kcursorsaver.h"
00025
00026 #include <kapplication.h>
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <kabc/stdaddressbook.h>
00031 #include <kabc/distributionlist.h>
00032 #include <kabc/vcardconverter.h>
00033 #include <dcopref.h>
00034
00035 #include <qregexp.h>
00036
00037 void KabcBridge::addresses(QStringList& result)
00038 {
00039 KCursorSaver busy(KBusyPtr::busy());
00040
00041 KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00042 KABC::AddressBook::ConstIterator it;
00043 for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
00044 const QStringList emails = (*it).emails();
00045 QString n = (*it).prefix() + " " +
00046 (*it).givenName() + " " +
00047 (*it).additionalName() + " " +
00048 (*it).familyName() + " " +
00049 (*it).suffix();
00050 n = n.simplifyWhiteSpace();
00051
00052 QRegExp needQuotes("[^ 0-9A-Za-z\\x0080-\\xFFFF]");
00053 QString endQuote = "\" ";
00054 QStringList::ConstIterator mit;
00055 QString addr, email;
00056
00057 for ( mit = emails.begin(); mit != emails.end(); ++mit ) {
00058 email = *mit;
00059 if (!email.isEmpty()) {
00060 if (n.isEmpty() || (email.find( '<' ) != -1))
00061 addr = QString::null;
00062 else {
00063 if (n.find(needQuotes) != -1)
00064 addr = '"' + n + endQuote;
00065 else
00066 addr = n + ' ';
00067 }
00068
00069 if (!addr.isEmpty() && (email.find( '<' ) == -1)
00070 && (email.find( '>' ) == -1)
00071 && (email.find( ',' ) == -1))
00072 addr += '<' + email + '>';
00073 else
00074 addr += email;
00075 addr = addr.stripWhiteSpace();
00076 result.append( addr );
00077 }
00078 }
00079 }
00080 KABC::DistributionListManager manager( addressBook );
00081 manager.load();
00082 result += manager.listNames();
00083
00084 result.sort();
00085 }
00086
00087 QStringList KabcBridge::addresses()
00088 {
00089 QStringList entries;
00090 KABC::AddressBook::ConstIterator it;
00091
00092 const KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00093 for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
00094 entries += (*it).fullEmail();
00095 }
00096 return entries;
00097 }
00098
00099
00100 QString KabcBridge::expandNickName( const QString& nickName )
00101 {
00102 if ( nickName.isEmpty() )
00103 return QString::null;
00104
00105 const QString lowerNickName = nickName.lower();
00106 const KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00107 for( KABC::AddressBook::ConstIterator it = addressBook->begin();
00108 it != addressBook->end(); ++it ) {
00109 if ( (*it).nickName().lower() == lowerNickName )
00110 return (*it).fullEmail();
00111 }
00112 return QString::null;
00113 }
00114
00115
00116
00117
00118 QStringList KabcBridge::categories()
00119 {
00120 KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
00121 KABC::Addressee::List addresses = addressBook->allAddressees();
00122 QStringList allcategories, aux;
00123
00124 for ( KABC::Addressee::List::Iterator it = addresses.begin();
00125 it != addresses.end(); ++it ) {
00126 aux = ( *it ).categories();
00127 for ( QStringList::ConstIterator itAux = aux.begin();
00128 itAux != aux.end(); ++itAux ) {
00129
00130 if ( allcategories.find( *itAux ) == allcategories.end() )
00131 allcategories += *itAux;
00132 }
00133 }
00134 return allcategories;
00135 }
|