libkdepim
addresseeemailselection.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kglobal.h>
00023 #include <kiconloader.h>
00024 #include <klocale.h>
00025
00026 #include "recentaddresses.h"
00027
00028 #include "addresseeemailselection.h"
00029
00030 using namespace KPIM;
00031 using KRecentAddress::RecentAddresses;
00032
00033 AddresseeEmailSelection::AddresseeEmailSelection()
00034 : Selection()
00035 {
00036 }
00037
00038 uint AddresseeEmailSelection::fieldCount() const
00039 {
00040 return 3;
00041 }
00042
00043 QString AddresseeEmailSelection::fieldTitle( uint index ) const
00044 {
00045 switch ( index ) {
00046 case 0:
00047 return i18n( "To" );
00048 break;
00049 case 1:
00050 return i18n( "Cc" );
00051 break;
00052 case 2:
00053 return i18n( "Bcc" );
00054 break;
00055 default:
00056 return QString::null;
00057 }
00058 }
00059
00060 QStringList AddresseeEmailSelection::to() const
00061 {
00062 return mToEmailList;
00063 }
00064
00065 QStringList AddresseeEmailSelection::cc() const
00066 {
00067 return mCcEmailList;
00068 }
00069
00070 QStringList AddresseeEmailSelection::bcc() const
00071 {
00072 return mBccEmailList;
00073 }
00074
00075 KABC::Addressee::List AddresseeEmailSelection::toAddresses() const
00076 {
00077 return mToAddresseeList;
00078 }
00079
00080 KABC::Addressee::List AddresseeEmailSelection::ccAddresses() const
00081 {
00082 return mCcAddresseeList;
00083 }
00084
00085 KABC::Addressee::List AddresseeEmailSelection::bccAddresses() const
00086 {
00087 return mBccAddresseeList;
00088 }
00089
00090 QStringList AddresseeEmailSelection::toDistributionLists() const
00091 {
00092 return mToDistributionList;
00093 }
00094
00095 QStringList AddresseeEmailSelection::ccDistributionLists() const
00096 {
00097 return mCcDistributionList;
00098 }
00099
00100 QStringList AddresseeEmailSelection::bccDistributionLists() const
00101 {
00102 return mBccDistributionList;
00103 }
00104
00105 void AddresseeEmailSelection::setSelectedTo( const QStringList &emails )
00106 {
00107 setSelectedItem( 0, emails );
00108 }
00109
00110 void AddresseeEmailSelection::setSelectedCC( const QStringList &emails )
00111 {
00112 setSelectedItem( 1, emails );
00113 }
00114
00115 void AddresseeEmailSelection::setSelectedBCC( const QStringList &emails )
00116 {
00117 setSelectedItem( 2, emails );
00118 }
00119
00120
00121 uint AddresseeEmailSelection::itemCount( const KABC::Addressee &addressee ) const
00122 {
00123 return addressee.emails().count();
00124 }
00125
00126 QString AddresseeEmailSelection::itemText( const KABC::Addressee &addressee, uint index ) const
00127 {
00128 return addressee.formattedName() + " " + email( addressee, index );
00129 }
00130
00131 QPixmap AddresseeEmailSelection::itemIcon( const KABC::Addressee &addressee, uint ) const
00132 {
00133 if ( !addressee.photo().data().isNull() )
00134 return addressee.photo().data().smoothScale( 16, 16 );
00135 else
00136 return KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small );
00137 }
00138
00139 bool AddresseeEmailSelection::itemEnabled( const KABC::Addressee &addressee, uint ) const
00140 {
00141 return addressee.emails().count() != 0;
00142 }
00143
00144 bool AddresseeEmailSelection::itemMatches( const KABC::Addressee &addressee, uint index, const QString &pattern ) const
00145 {
00146 return addressee.formattedName().startsWith( pattern, false ) ||
00147 email( addressee, index ).startsWith( pattern, false );
00148 }
00149
00150 bool AddresseeEmailSelection::itemEquals( const KABC::Addressee &addressee, uint index, const QString &pattern ) const
00151 {
00152 return (pattern == addressee.formattedName() + " " + email( addressee, index )) ||
00153 (addressee.emails().contains( pattern ));
00154 }
00155
00156 QString AddresseeEmailSelection::distributionListText( const KABC::DistributionList *distributionList ) const
00157 {
00158 return distributionList->name();
00159 }
00160
00161 QPixmap AddresseeEmailSelection::distributionListIcon( const KABC::DistributionList* ) const
00162 {
00163 return KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small );
00164 }
00165
00166 bool AddresseeEmailSelection::distributionListEnabled( const KABC::DistributionList* ) const
00167 {
00168 return true;
00169 }
00170
00171 bool AddresseeEmailSelection::distributionListMatches( const KABC::DistributionList *distributionList,
00172 const QString &pattern ) const
00173 {
00174
00175 bool ok = distributionList->name().startsWith( pattern, false );
00176
00177 KABC::DistributionList::Entry::List entries = distributionList->entries();
00178 KABC::DistributionList::Entry::List::ConstIterator it;
00179 for ( it = entries.begin(); it != entries.end(); ++it ) {
00180 ok = ok || (*it).addressee.formattedName().startsWith( pattern, false ) ||
00181 (*it).email.startsWith( pattern, false );
00182 }
00183
00184 return ok;
00185 }
00186
00187 uint AddresseeEmailSelection::addressBookCount() const
00188 {
00189
00190 return 1;
00191 }
00192
00193 QString AddresseeEmailSelection::addressBookTitle( uint index ) const
00194 {
00195 if ( index == 0 )
00196 return i18n( "Recent Addresses" );
00197 else
00198 return QString::null;
00199 }
00200
00201 KABC::Addressee::List AddresseeEmailSelection::addressBookContent( uint index ) const
00202 {
00203 if ( index == 0 ) {
00204 KConfig config( "kmailrc" );
00205 return RecentAddresses::self( &config )->kabcAddresses();
00206 } else {
00207 return KABC::Addressee::List();
00208 }
00209 }
00210
00211 QString AddresseeEmailSelection::email( const KABC::Addressee &addressee, uint index ) const
00212 {
00213 return addressee.emails()[ index ];
00214 }
00215
00216 void AddresseeEmailSelection::setSelectedItem( uint fieldIndex, const QStringList &emails )
00217 {
00218 QStringList::ConstIterator it;
00219 for ( it = emails.begin(); it != emails.end(); ++it ) {
00220 KABC::Addressee addr;
00221 addr.insertEmail( *it, true );
00222
00223 selector()->setItemSelected( fieldIndex, addr, 0, *it );
00224 }
00225 }
00226
00227 void AddresseeEmailSelection::addSelectedAddressees( uint fieldIndex, const KABC::Addressee &addressee, uint itemIndex )
00228 {
00229 switch ( fieldIndex ) {
00230 case 0:
00231 mToAddresseeList.append( addressee );
00232 mToEmailList.append( email( addressee, itemIndex ) );
00233 break;
00234 case 1:
00235 mCcAddresseeList.append( addressee );
00236 mCcEmailList.append( email( addressee, itemIndex ) );
00237 break;
00238 case 2:
00239 mBccAddresseeList.append( addressee );
00240 mBccEmailList.append( email( addressee, itemIndex ) );
00241 break;
00242 default:
00243
00244 break;
00245 }
00246 }
00247
00248 void AddresseeEmailSelection::addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList *list )
00249 {
00250 switch ( fieldIndex ) {
00251 case 0:
00252 mToDistributionList.append( list->name() );
00253 break;
00254 case 1:
00255 mCcDistributionList.append( list->name() );
00256 break;
00257 case 2:
00258 mBccDistributionList.append( list->name() );
00259 break;
00260 default:
00261
00262 break;
00263 }
00264 }
|