You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
265 lines
6.9 KiB
265 lines
6.9 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of libtdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <kglobal.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <klocale.h>
|
||
|
|
||
|
#include "recentaddresses.h"
|
||
|
|
||
|
#include "addresseeemailselection.h"
|
||
|
|
||
|
using namespace KPIM;
|
||
|
using KRecentAddress::RecentAddresses;
|
||
|
|
||
|
AddresseeEmailSelection::AddresseeEmailSelection()
|
||
|
: Selection()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
uint AddresseeEmailSelection::fieldCount() const
|
||
|
{
|
||
|
return 3;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeEmailSelection::fieldTitle( uint index ) const
|
||
15 years ago
|
{
|
||
|
switch ( index ) {
|
||
|
case 0:
|
||
|
return i18n( "To" );
|
||
|
break;
|
||
|
case 1:
|
||
|
return i18n( "Cc" );
|
||
|
break;
|
||
|
case 2:
|
||
|
return i18n( "Bcc" );
|
||
|
break;
|
||
|
default:
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddresseeEmailSelection::to() const
|
||
15 years ago
|
{
|
||
|
return mToEmailList;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddresseeEmailSelection::cc() const
|
||
15 years ago
|
{
|
||
|
return mCcEmailList;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddresseeEmailSelection::bcc() const
|
||
15 years ago
|
{
|
||
|
return mBccEmailList;
|
||
|
}
|
||
|
|
||
|
KABC::Addressee::List AddresseeEmailSelection::toAddresses() const
|
||
|
{
|
||
|
return mToAddresseeList;
|
||
|
}
|
||
|
|
||
|
KABC::Addressee::List AddresseeEmailSelection::ccAddresses() const
|
||
|
{
|
||
|
return mCcAddresseeList;
|
||
|
}
|
||
|
|
||
|
KABC::Addressee::List AddresseeEmailSelection::bccAddresses() const
|
||
|
{
|
||
|
return mBccAddresseeList;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddresseeEmailSelection::toDistributionLists() const
|
||
15 years ago
|
{
|
||
|
return mToDistributionList;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddresseeEmailSelection::ccDistributionLists() const
|
||
15 years ago
|
{
|
||
|
return mCcDistributionList;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddresseeEmailSelection::bccDistributionLists() const
|
||
15 years ago
|
{
|
||
|
return mBccDistributionList;
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeEmailSelection::setSelectedTo( const TQStringList &emails )
|
||
15 years ago
|
{
|
||
|
setSelectedItem( 0, emails );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeEmailSelection::setSelectedCC( const TQStringList &emails )
|
||
15 years ago
|
{
|
||
|
setSelectedItem( 1, emails );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeEmailSelection::setSelectedBCC( const TQStringList &emails )
|
||
15 years ago
|
{
|
||
|
setSelectedItem( 2, emails );
|
||
|
}
|
||
|
|
||
|
|
||
|
uint AddresseeEmailSelection::itemCount( const KABC::Addressee &addressee ) const
|
||
|
{
|
||
|
return addressee.emails().count();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeEmailSelection::itemText( const KABC::Addressee &addressee, uint index ) const
|
||
15 years ago
|
{
|
||
|
return addressee.formattedName() + " " + email( addressee, index );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPixmap AddresseeEmailSelection::itemIcon( const KABC::Addressee &addressee, uint ) const
|
||
15 years ago
|
{
|
||
|
if ( !addressee.photo().data().isNull() )
|
||
|
return addressee.photo().data().smoothScale( 16, 16 );
|
||
|
else
|
||
|
return KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small );
|
||
|
}
|
||
|
|
||
|
bool AddresseeEmailSelection::itemEnabled( const KABC::Addressee &addressee, uint ) const
|
||
|
{
|
||
|
return addressee.emails().count() != 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool AddresseeEmailSelection::itemMatches( const KABC::Addressee &addressee, uint index, const TQString &pattern ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
return addressee.formattedName().tqstartsWith( pattern, false ) ||
|
||
|
email( addressee, index ).tqstartsWith( pattern, false );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
bool AddresseeEmailSelection::itemEquals( const KABC::Addressee &addressee, uint index, const TQString &pattern ) const
|
||
15 years ago
|
{
|
||
|
return (pattern == addressee.formattedName() + " " + email( addressee, index )) ||
|
||
14 years ago
|
(addressee.emails().contains( pattern ));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeEmailSelection::distributionListText( const KABC::DistributionList *distributionList ) const
|
||
15 years ago
|
{
|
||
|
return distributionList->name();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPixmap AddresseeEmailSelection::distributionListIcon( const KABC::DistributionList* ) const
|
||
15 years ago
|
{
|
||
|
return KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small );
|
||
|
}
|
||
|
|
||
|
bool AddresseeEmailSelection::distributionListEnabled( const KABC::DistributionList* ) const
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool AddresseeEmailSelection::distributionListMatches( const KABC::DistributionList *distributionList,
|
||
15 years ago
|
const TQString &pattern ) const
|
||
15 years ago
|
{
|
||
|
// check whether the name of the distribution list matches the pattern or one of its entries.
|
||
14 years ago
|
bool ok = distributionList->name().tqstartsWith( pattern, false );
|
||
15 years ago
|
|
||
|
KABC::DistributionList::Entry::List entries = distributionList->entries();
|
||
|
KABC::DistributionList::Entry::List::ConstIterator it;
|
||
|
for ( it = entries.begin(); it != entries.end(); ++it ) {
|
||
14 years ago
|
ok = ok || (*it).addressee.formattedName().tqstartsWith( pattern, false ) ||
|
||
|
(*it).email.tqstartsWith( pattern, false );
|
||
15 years ago
|
}
|
||
|
|
||
|
return ok;
|
||
|
}
|
||
|
|
||
|
uint AddresseeEmailSelection::addressBookCount() const
|
||
|
{
|
||
|
// we provide the recent email addresses via the custom addressbooks
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeEmailSelection::addressBookTitle( uint index ) const
|
||
15 years ago
|
{
|
||
|
if ( index == 0 )
|
||
|
return i18n( "Recent Addresses" );
|
||
|
else
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
|
KABC::Addressee::List AddresseeEmailSelection::addressBookContent( uint index ) const
|
||
|
{
|
||
|
if ( index == 0 ) {
|
||
|
KConfig config( "kmailrc" );
|
||
|
return RecentAddresses::self( &config )->kabcAddresses();
|
||
|
} else {
|
||
|
return KABC::Addressee::List();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeEmailSelection::email( const KABC::Addressee &addressee, uint index ) const
|
||
15 years ago
|
{
|
||
|
return addressee.emails()[ index ];
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeEmailSelection::setSelectedItem( uint fieldIndex, const TQStringList &emails )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList::ConstIterator it;
|
||
15 years ago
|
for ( it = emails.begin(); it != emails.end(); ++it ) {
|
||
|
KABC::Addressee addr;
|
||
|
addr.insertEmail( *it, true );
|
||
|
|
||
|
selector()->setItemSelected( fieldIndex, addr, 0, *it );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AddresseeEmailSelection::addSelectedAddressees( uint fieldIndex, const KABC::Addressee &addressee, uint itemIndex )
|
||
|
{
|
||
|
switch ( fieldIndex ) {
|
||
|
case 0:
|
||
|
mToAddresseeList.append( addressee );
|
||
|
mToEmailList.append( email( addressee, itemIndex ) );
|
||
|
break;
|
||
|
case 1:
|
||
|
mCcAddresseeList.append( addressee );
|
||
|
mCcEmailList.append( email( addressee, itemIndex ) );
|
||
|
break;
|
||
|
case 2:
|
||
|
mBccAddresseeList.append( addressee );
|
||
|
mBccEmailList.append( email( addressee, itemIndex ) );
|
||
|
break;
|
||
|
default:
|
||
|
// oops
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AddresseeEmailSelection::addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList *list )
|
||
|
{
|
||
|
switch ( fieldIndex ) {
|
||
|
case 0:
|
||
|
mToDistributionList.append( list->name() );
|
||
|
break;
|
||
|
case 1:
|
||
|
mCcDistributionList.append( list->name() );
|
||
|
break;
|
||
|
case 2:
|
||
|
mBccDistributionList.append( list->name() );
|
||
|
break;
|
||
|
default:
|
||
|
// oops
|
||
|
break;
|
||
|
}
|
||
|
}
|