kmaddrbook.cpp
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 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 */ 00020 #include <config.h> 00021 #include <unistd.h> 00022 00023 #include "kmaddrbook.h" 00024 #include "kcursorsaver.h" 00025 00026 #include <tdeapplication.h> 00027 #include <kdebug.h> 00028 #include <tdelocale.h> 00029 #include <tdemessagebox.h> 00030 #include <tdeabc/stdaddressbook.h> 00031 #include <tdeabc/distributionlist.h> 00032 #include <dcopref.h> 00033 00034 #include <tqregexp.h> 00035 00036 void KabcBridge::addresses(TQStringList& result) // includes lists 00037 { 00038 KCursorSaver busy(KBusyPtr::busy()); // loading might take a while 00039 00040 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true ); 00041 TDEABC::AddressBook::ConstIterator it; 00042 for( it = addressBook->begin(); it != addressBook->end(); ++it ) { 00043 const TQStringList emails = (*it).emails(); 00044 TQString n = (*it).prefix() + " " + 00045 (*it).givenName() + " " + 00046 (*it).additionalName() + " " + 00047 (*it).familyName() + " " + 00048 (*it).suffix(); 00049 n = n.simplifyWhiteSpace(); 00050 00051 TQRegExp needQuotes("[^ 0-9A-Za-z\\x0080-\\xFFFF]"); 00052 TQString endQuote = "\" "; 00053 TQStringList::ConstIterator mit; 00054 TQString addr, email; 00055 00056 for ( mit = emails.begin(); mit != emails.end(); ++mit ) { 00057 email = *mit; 00058 if (!email.isEmpty()) { 00059 if (n.isEmpty() || (email.find( '<' ) != -1)) 00060 addr = TQString(); 00061 else { // do we really need quotes around this name ? 00062 if (n.find(needQuotes) != -1) 00063 addr = '"' + n + endQuote; 00064 else 00065 addr = n + ' '; 00066 } 00067 00068 if (!addr.isEmpty() && (email.find( '<' ) == -1) 00069 && (email.find( '>' ) == -1) 00070 && (email.find( ',' ) == -1)) 00071 addr += '<' + email + '>'; 00072 else 00073 addr += email; 00074 addr = addr.stripWhiteSpace(); 00075 result.append( addr ); 00076 } 00077 } 00078 } 00079 TDEABC::DistributionListManager manager( addressBook ); 00080 manager.load(); 00081 result += manager.listNames(); 00082 00083 result.sort(); 00084 } 00085 00086 TQStringList KabcBridge::addresses() 00087 { 00088 TQStringList entries; 00089 TDEABC::AddressBook::ConstIterator it; 00090 00091 const TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true ); 00092 for( it = addressBook->begin(); it != addressBook->end(); ++it ) { 00093 entries += (*it).fullEmail(); 00094 } 00095 return entries; 00096 } 00097 00098 //----------------------------------------------------------------------------- 00099 TQString KabcBridge::expandNickName( const TQString& nickName ) 00100 { 00101 if ( nickName.isEmpty() ) 00102 return TQString(); 00103 00104 const TQString lowerNickName = nickName.lower(); 00105 const TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true ); 00106 for( TDEABC::AddressBook::ConstIterator it = addressBook->begin(); 00107 it != addressBook->end(); ++it ) { 00108 if ( (*it).nickName().lower() == lowerNickName ) 00109 return (*it).fullEmail(); 00110 } 00111 return TQString(); 00112 } 00113 00114 00115 //----------------------------------------------------------------------------- 00116 00117 TQStringList KabcBridge::categories() 00118 { 00119 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true ); 00120 TDEABC::Addressee::List addresses = addressBook->allAddressees(); 00121 TQStringList allcategories, aux; 00122 00123 for ( TDEABC::Addressee::List::Iterator it = addresses.begin(); 00124 it != addresses.end(); ++it ) { 00125 aux = ( *it ).categories(); 00126 for ( TQStringList::ConstIterator itAux = aux.begin(); 00127 itAux != aux.end(); ++itAux ) { 00128 // don't have duplicates in allcategories 00129 if ( allcategories.find( *itAux ) == allcategories.end() ) 00130 allcategories += *itAux; 00131 } 00132 } 00133 return allcategories; 00134 }