25#include <tdeabc/addresseelist.h>
27#include "searchmanager.h"
31SearchManager::SearchManager( TDEABC::AddressBook *ab,
32 TQObject *parent,
const char *name )
33 : TQObject( parent, name ), mAddressBook( ab )
37void SearchManager::search(
const TQString &pattern,
const TDEABC::Field::List &fields, Type type )
43 TDEABC::Addressee::List allContacts;
46 TDEABC::AddresseeList list( mAddressBook->allAddressees() );
47 if ( !fields.isEmpty() )
48 list.sortByField( fields.first() );
52#ifdef TDEPIM_NEW_DISTRLISTS
54 mDistributionLists.clear();
55 TDEABC::Addressee::List::Iterator rmIt( allContacts.begin() );
56 const TDEABC::Addressee::List::Iterator rmEndIt( allContacts.end() );
57 while ( rmIt != rmEndIt ) {
58 if ( KPIM::DistributionList::isDistributionList( *rmIt ) ) {
59 mDistributionLists.append(
static_cast<KPIM::DistributionList
>( *rmIt ) );
60 rmIt = allContacts.remove( rmIt );
65 typedef KPIM::DistributionList::Entry Entry;
66 if ( !mSelectedDistributionList.isNull() ) {
67 const KPIM::DistributionList dl = KPIM::DistributionList::findByName( mAddressBook, mSelectedDistributionList );
68 if ( !dl.isEmpty() ) {
70 const Entry::List entries = dl.entries( mAddressBook );
71 const Entry::List::ConstIterator end = entries.end();
72 for ( Entry::List::ConstIterator it = entries.begin(); it != end; ++it ) {
73 allContacts.append( (*it).addressee );
80 if ( mPattern.isEmpty() ) {
81 mContacts = allContacts;
83 emit contactsUpdated();
88 const TDEABC::Field::List fieldList = !mFields.isEmpty() ? mFields : TDEABC::Field::allFields();
90 TDEABC::Addressee::List::ConstIterator it( allContacts.begin() );
91 const TDEABC::Addressee::List::ConstIterator endIt( allContacts.end() );
92 for ( ; it != endIt; ++it ) {
93#ifdef TDEPIM_NEW_DISTRLISTS
94 if ( KPIM::DistributionList::isDistributionList( *it ) )
100 TDEABC::Field::List::ConstIterator fieldIt( fieldList.begin() );
101 const TDEABC::Field::List::ConstIterator fieldEndIt( fieldList.end() );
102 for ( ; fieldIt != fieldEndIt; ++fieldIt ) {
104 if ( type == StartsWith && (*fieldIt)->value( *it ).startsWith( pattern,
false ) ) {
105 mContacts.append( *it );
108 }
else if ( type == EndsWith && (*fieldIt)->value( *it ).endsWith( pattern,
false ) ) {
109 mContacts.append( *it );
112 }
else if ( type == Contains && (*fieldIt)->value( *it ).find( pattern, 0,
false ) != -1 ) {
113 mContacts.append( *it );
116 }
else if ( type == Equals && (*fieldIt)->value( *it ).localeAwareCompare( pattern ) == 0 ) {
117 mContacts.append( *it );
125 const TQStringList customs = (*it).customs();
127 TQStringList::ConstIterator customIt( customs.begin() );
128 const TQStringList::ConstIterator customEndIt( customs.end() );
129 for ( ; customIt != customEndIt; ++customIt ) {
130 int pos = (*customIt).find(
':' );
132 const TQString value = (*customIt).mid( pos + 1 );
133 if ( type == StartsWith && value.startsWith( pattern,
false ) ) {
134 mContacts.append( *it );
136 }
else if ( type == EndsWith && value.endsWith( pattern,
false ) ) {
137 mContacts.append( *it );
139 }
else if ( type == Contains && value.find( pattern, 0,
false ) != -1 ) {
140 mContacts.append( *it );
142 }
else if ( type == Equals && value.localeAwareCompare( pattern ) == 0 ) {
143 mContacts.append( *it );
151 emit contactsUpdated();
154TDEABC::Addressee::List SearchManager::contacts()
const
159void SearchManager::reload()
161 search( mPattern, mFields, mType );
164#ifdef TDEPIM_NEW_DISTRLISTS
166void KAB::SearchManager::setSelectedDistributionList(
const TQString &name )
168 if ( mSelectedDistributionList == name )
170 mSelectedDistributionList = name;
174KPIM::DistributionList::List KAB::SearchManager::distributionLists()
const
176 return mDistributionLists;
179TQStringList KAB::SearchManager::distributionListNames()
const
182 KPIM::DistributionList::List::ConstIterator it( mDistributionLists.begin() );
183 const KPIM::DistributionList::List::ConstIterator endIt( mDistributionLists.end() );
184 for ( ; it != endIt; ++it ) {
185 lst.append( (*it).formattedName() );
191#include "searchmanager.moc"