25#include <tdeabc/addresseelist.h>
26#include <tdeversion.h>
28#include "searchmanager.h"
32SearchManager::SearchManager( TDEABC::AddressBook *ab,
33 TQObject *parent,
const char *name )
34 : TQObject( parent, name ), mAddressBook( ab )
38void SearchManager::search(
const TQString &pattern,
const TDEABC::Field::List &fields, Type type )
44 TDEABC::Addressee::List allContacts;
48 TDEABC::AddresseeList list( mAddressBook->allAddressees() );
49 if ( !fields.isEmpty() )
50 list.sortByField( fields.first() );
54 TDEABC::AddressBook::ConstIterator abIt( mAddressBook->begin() );
55 const TDEABC::AddressBook::ConstIterator abEndIt( mAddressBook->end() );
56 for ( ; abIt != abEndIt; ++abIt )
57 allContacts.append( *abIt );
60#ifdef TDEPIM_NEW_DISTRLISTS
62 mDistributionLists.clear();
63 TDEABC::Addressee::List::Iterator rmIt( allContacts.begin() );
64 const TDEABC::Addressee::List::Iterator rmEndIt( allContacts.end() );
65 while ( rmIt != rmEndIt ) {
66 if ( KPIM::DistributionList::isDistributionList( *rmIt ) ) {
67 mDistributionLists.append(
static_cast<KPIM::DistributionList
>( *rmIt ) );
68 rmIt = allContacts.remove( rmIt );
73 typedef KPIM::DistributionList::Entry Entry;
74 if ( !mSelectedDistributionList.isNull() ) {
75 const KPIM::DistributionList dl = KPIM::DistributionList::findByName( mAddressBook, mSelectedDistributionList );
76 if ( !dl.isEmpty() ) {
78 const Entry::List entries = dl.entries( mAddressBook );
79 const Entry::List::ConstIterator end = entries.end();
80 for ( Entry::List::ConstIterator it = entries.begin(); it != end; ++it ) {
81 allContacts.append( (*it).addressee );
88 if ( mPattern.isEmpty() ) {
89 mContacts = allContacts;
91 emit contactsUpdated();
96 const TDEABC::Field::List fieldList = !mFields.isEmpty() ? mFields : TDEABC::Field::allFields();
98 TDEABC::Addressee::List::ConstIterator it( allContacts.begin() );
99 const TDEABC::Addressee::List::ConstIterator endIt( allContacts.end() );
100 for ( ; it != endIt; ++it ) {
101#ifdef TDEPIM_NEW_DISTRLISTS
102 if ( KPIM::DistributionList::isDistributionList( *it ) )
108 TDEABC::Field::List::ConstIterator fieldIt( fieldList.begin() );
109 const TDEABC::Field::List::ConstIterator fieldEndIt( fieldList.end() );
110 for ( ; fieldIt != fieldEndIt; ++fieldIt ) {
112 if ( type == StartsWith && (*fieldIt)->value( *it ).startsWith( pattern,
false ) ) {
113 mContacts.append( *it );
116 }
else if ( type == EndsWith && (*fieldIt)->value( *it ).endsWith( pattern,
false ) ) {
117 mContacts.append( *it );
120 }
else if ( type == Contains && (*fieldIt)->value( *it ).find( pattern, 0,
false ) != -1 ) {
121 mContacts.append( *it );
124 }
else if ( type == Equals && (*fieldIt)->value( *it ).localeAwareCompare( pattern ) == 0 ) {
125 mContacts.append( *it );
133 const TQStringList customs = (*it).customs();
135 TQStringList::ConstIterator customIt( customs.begin() );
136 const TQStringList::ConstIterator customEndIt( customs.end() );
137 for ( ; customIt != customEndIt; ++customIt ) {
138 int pos = (*customIt).find(
':' );
140 const TQString value = (*customIt).mid( pos + 1 );
141 if ( type == StartsWith && value.startsWith( pattern,
false ) ) {
142 mContacts.append( *it );
144 }
else if ( type == EndsWith && value.endsWith( pattern,
false ) ) {
145 mContacts.append( *it );
147 }
else if ( type == Contains && value.find( pattern, 0,
false ) != -1 ) {
148 mContacts.append( *it );
150 }
else if ( type == Equals && value.localeAwareCompare( pattern ) == 0 ) {
151 mContacts.append( *it );
159 emit contactsUpdated();
162TDEABC::Addressee::List SearchManager::contacts()
const
167void SearchManager::reload()
169 search( mPattern, mFields, mType );
172#ifdef TDEPIM_NEW_DISTRLISTS
174void KAB::SearchManager::setSelectedDistributionList(
const TQString &name )
176 if ( mSelectedDistributionList == name )
178 mSelectedDistributionList = name;
182KPIM::DistributionList::List KAB::SearchManager::distributionLists()
const
184 return mDistributionLists;
187TQStringList KAB::SearchManager::distributionListNames()
const
190 KPIM::DistributionList::List::ConstIterator it( mDistributionLists.begin() );
191 const KPIM::DistributionList::List::ConstIterator endIt( mDistributionLists.end() );
192 for ( ; it != endIt; ++it ) {
193 lst.append( (*it).formattedName() );
199#include "searchmanager.moc"