22 #include <tdeglobal.h>
23 #include <kiconloader.h>
24 #include <tdelocale.h>
26 #include "recentaddresses.h"
28 #include "addresseeemailselection.h"
33 AddresseeEmailSelection::AddresseeEmailSelection()
38 uint AddresseeEmailSelection::fieldCount()
const
43 TQString AddresseeEmailSelection::fieldTitle( uint index )
const
60 TQStringList AddresseeEmailSelection::to()
const
65 TQStringList AddresseeEmailSelection::cc()
const
70 TQStringList AddresseeEmailSelection::bcc()
const
75 TDEABC::Addressee::List AddresseeEmailSelection::toAddresses()
const
77 return mToAddresseeList;
80 TDEABC::Addressee::List AddresseeEmailSelection::ccAddresses()
const
82 return mCcAddresseeList;
85 TDEABC::Addressee::List AddresseeEmailSelection::bccAddresses()
const
87 return mBccAddresseeList;
90 TQStringList AddresseeEmailSelection::toDistributionLists()
const
92 return mToDistributionList;
95 TQStringList AddresseeEmailSelection::ccDistributionLists()
const
97 return mCcDistributionList;
100 TQStringList AddresseeEmailSelection::bccDistributionLists()
const
102 return mBccDistributionList;
105 void AddresseeEmailSelection::setSelectedTo(
const TQStringList &emails )
107 setSelectedItem( 0, emails );
110 void AddresseeEmailSelection::setSelectedCC(
const TQStringList &emails )
112 setSelectedItem( 1, emails );
115 void AddresseeEmailSelection::setSelectedBCC(
const TQStringList &emails )
117 setSelectedItem( 2, emails );
121 uint AddresseeEmailSelection::itemCount(
const TDEABC::Addressee &addressee )
const
123 return addressee.emails().count();
126 TQString AddresseeEmailSelection::itemText(
const TDEABC::Addressee &addressee, uint index )
const
128 return addressee.formattedName() +
" " + email( addressee, index );
131 TQPixmap AddresseeEmailSelection::itemIcon(
const TDEABC::Addressee &addressee, uint )
const
133 if ( !addressee.photo().data().isNull() )
134 return addressee.photo().data().smoothScale( 16, 16 );
136 return TDEGlobal::iconLoader()->loadIcon(
"preferences-desktop-personal", TDEIcon::Small );
139 bool AddresseeEmailSelection::itemEnabled(
const TDEABC::Addressee &addressee, uint )
const
141 return addressee.emails().count() != 0;
144 bool AddresseeEmailSelection::itemMatches(
const TDEABC::Addressee &addressee, uint index,
const TQString &pattern )
const
146 return addressee.formattedName().startsWith( pattern,
false ) ||
147 email( addressee, index ).startsWith( pattern,
false );
150 bool AddresseeEmailSelection::itemEquals(
const TDEABC::Addressee &addressee, uint index,
const TQString &pattern )
const
152 return (pattern == addressee.formattedName() +
" " + email( addressee, index )) ||
153 (addressee.emails().contains( pattern ));
156 TQString AddresseeEmailSelection::distributionListText(
const TDEABC::DistributionList *distributionList )
const
158 return distributionList->name();
161 TQPixmap AddresseeEmailSelection::distributionListIcon(
const TDEABC::DistributionList* )
const
163 return TDEGlobal::iconLoader()->loadIcon(
"tdmconfig", TDEIcon::Small );
166 bool AddresseeEmailSelection::distributionListEnabled(
const TDEABC::DistributionList* )
const
171 bool AddresseeEmailSelection::distributionListMatches(
const TDEABC::DistributionList *distributionList,
172 const TQString &pattern )
const
175 bool ok = distributionList->name().startsWith( pattern,
false );
177 TDEABC::DistributionList::Entry::List entries = distributionList->entries();
178 TDEABC::DistributionList::Entry::List::ConstIterator it;
179 for ( it = entries.begin(); it != entries.end(); ++it ) {
180 ok = ok || (*it).addressee.formattedName().startsWith( pattern,
false ) ||
181 (*it).email.startsWith( pattern,
false );
187 uint AddresseeEmailSelection::addressBookCount()
const
193 TQString AddresseeEmailSelection::addressBookTitle( uint index )
const
196 return i18n(
"Recent Addresses" );
201 TDEABC::Addressee::List AddresseeEmailSelection::addressBookContent( uint index )
const
204 TDEConfig config(
"kmailrc" );
205 return RecentAddresses::self( &config )->tdeabcAddresses();
207 return TDEABC::Addressee::List();
211 TQString AddresseeEmailSelection::email(
const TDEABC::Addressee &addressee, uint index )
const
213 return addressee.emails()[ index ];
216 void AddresseeEmailSelection::setSelectedItem( uint fieldIndex,
const TQStringList &emails )
218 TQStringList::ConstIterator it;
219 for ( it = emails.begin(); it != emails.end(); ++it ) {
220 TDEABC::Addressee addr;
221 addr.insertEmail( *it,
true );
223 selector()->setItemSelected( fieldIndex, addr, 0, *it );
227 void AddresseeEmailSelection::addSelectedAddressees( uint fieldIndex,
const TDEABC::Addressee &addressee, uint itemIndex )
229 switch ( fieldIndex ) {
231 mToAddresseeList.append( addressee );
232 mToEmailList.append( email( addressee, itemIndex ) );
235 mCcAddresseeList.append( addressee );
236 mCcEmailList.append( email( addressee, itemIndex ) );
239 mBccAddresseeList.append( addressee );
240 mBccEmailList.append( email( addressee, itemIndex ) );
248 void AddresseeEmailSelection::addSelectedDistributionList( uint fieldIndex,
const TDEABC::DistributionList *list )
250 switch ( fieldIndex ) {
252 mToDistributionList.append( list->name() );
255 mCcDistributionList.append( list->name() );
258 mBccDistributionList.append( list->name() );
Handles a list of "recent email-addresses".
TDEPIM classes for drag and drop of mails.