1 #include "distributionlist.h"
2 #include <tdeabc/addressbook.h>
4 static const char* s_customFieldName =
"DistributionList";
13 : TDEABC::Addressee( addr )
20 Addressee::setFormattedName( name );
22 Addressee::setFamilyName( name );
25 if ( custom(
"KADDRESSBOOK", s_customFieldName ).isEmpty() )
26 insertCustom(
"KADDRESSBOOK", s_customFieldName,
";" );
31 typedef TQValueList<TQPair<TQString, TQString> > ParseList;
32 static ParseList parseCustom(
const TQString& str )
35 const TQStringList lst = TQStringList::split(
';', str );
36 for( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
37 if ( (*it).isEmpty() )
40 TQStringList helpList = TQStringList::split(
',', (*it),
true );
41 Q_ASSERT( !helpList.isEmpty() );
42 if ( helpList.isEmpty() )
44 Q_ASSERT( helpList.count() < 3 );
45 const TQString uid = helpList.first();
46 const TQString email = helpList.last();
47 res.append( qMakePair( uid, email ) );
55 removeEntry( addr.formattedName(), email );
56 insertEntry( addr.uid(), email );
61 Q_ASSERT( !email.isEmpty() || email.isNull() );
62 removeEntry( uid, email );
63 TQString str = custom(
"KADDRESSBOOK", s_customFieldName );
65 str +=
";" + uid +
"," + email;
66 insertCustom(
"KADDRESSBOOK", s_customFieldName, str );
71 removeEntry( addr.uid(), email );
73 removeEntry( addr.formattedName(), email );
78 Q_ASSERT( !email.isEmpty() || email.isNull() );
79 ParseList parseList = parseCustom( custom(
"KADDRESSBOOK", s_customFieldName ) );
81 for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) {
82 const TQString thisUid = (*it).first;
83 const TQString thisEmail = (*it).second;
84 if ( thisUid == uid && thisEmail == email ) {
87 str +=
";" + thisUid +
"," + thisEmail;
91 insertCustom(
"KADDRESSBOOK", s_customFieldName, str );
94 bool KPIM::DistributionList::isDistributionList(
const TDEABC::Addressee& addr )
96 const TQString str = addr.custom(
"KADDRESSBOOK", s_customFieldName );
97 return !str.isEmpty();
101 static TDEABC::Addressee::List findByFormattedName( TDEABC::AddressBook* book,
102 const TQString& name,
103 bool caseSensitive =
true )
105 TDEABC::Addressee::List res;
106 TDEABC::AddressBook::Iterator abIt;
107 for ( abIt = book->begin(); abIt != book->end(); ++abIt )
109 if ( caseSensitive && (*abIt).formattedName() == name )
111 if ( !caseSensitive && (*abIt).formattedName().lower() == name.lower() )
118 const TQString& name,
121 TDEABC::AddressBook::Iterator abIt;
122 for ( abIt = book->begin(); abIt != book->end(); ++abIt )
124 if ( isDistributionList( *abIt ) ) {
125 if ( caseSensitive && (*abIt).formattedName() == name )
127 if ( !caseSensitive && (*abIt).formattedName().lower() == name.lower() )
131 return DistributionList();
134 static TDEABC::Addressee findByUidOrName( TDEABC::AddressBook* book,
const TQString& uidOrName,
const TQString& email )
136 TDEABC::Addressee a = book->findByUid( uidOrName );
141 if ( !email.isEmpty() ) {
142 TDEABC::Addressee::List lst = book->findByEmail( email );
143 TDEABC::Addressee::List::ConstIterator listit = lst.begin();
144 for ( ; listit != lst.end(); ++listit )
145 if ( (*listit).formattedName() == uidOrName ) {
149 if ( !lst.isEmpty() && a.isEmpty() ) {
156 TDEABC::Addressee::List lst = findByFormattedName( book, uidOrName );
157 if ( !lst.isEmpty() )
167 const TQString str = custom(
"KADDRESSBOOK", s_customFieldName );
168 const ParseList parseList = parseCustom( str );
169 for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) {
170 const TQString uid = (*it).first;
171 const TQString email = (*it).second;
173 TDEABC::Addressee a = findByUidOrName( book, uid, email );
176 kdWarning() <<
"Addressee not found: " << uid << endl;
178 res.append(
Entry( a, email ) );
188 const TQString str = custom(
"KADDRESSBOOK", s_customFieldName );
189 ParseList parseList = parseCustom( str );
190 for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) {
191 const TQString thisUid = (*it).first;
192 const TQString thisEmail = (*it).second;
195 TDEABC::Addressee a = findByUidOrName( book, thisUid, thisEmail );
201 const TQString email = thisEmail.isEmpty() ? a.fullEmail() :
202 a.fullEmail( thisEmail );
203 if ( !email.isEmpty() ) {
204 emails.append( email );
211 TQValueList<KPIM::DistributionList>
212 KPIM::DistributionList::allDistributionLists( TDEABC::AddressBook* book )
214 TQValueList<KPIM::DistributionList> lst;
215 TDEABC::AddressBook::Iterator abIt;
216 for ( abIt = book->begin(); abIt != book->end(); ++abIt )
218 if ( isDistributionList( *abIt ) ) {
Distribution list of email addresses.
void insertEntry(const Addressee &, const TQString &email=TQString())
Insert an entry into this distribution list.
void setName(const TQString &name)
HACK: reimplemented from Addressee, but it's NOT virtual there.
void removeEntry(const Addressee &, const TQString &email=TQString())
Remove an entry from this distribution list.
DistributionList()
Create a distribution list.
Entry::List entries(TDEABC::AddressBook *book) const
Return list of entries belonging to this distribution list.
TQStringList emails(TDEABC::AddressBook *book) const
Return list of email addresses, which belong to this distributon list.