22 #include "addresseelist.h"
28 #include <QtCore/QSharedData>
38 SortingTraits::Uid::Uid()
43 SortingTraits::Uid::~Uid()
50 return QString::compare( a1.
uid(), a2.
uid() ) == 0;
56 return QString::compare( a1.
uid(), a2.
uid() ) < 0;
59 SortingTraits::Name::Name()
64 SortingTraits::Name::~Name()
70 return QString::localeAwareCompare( a1.
name(), a2.
name() ) == 0;
75 return QString::localeAwareCompare( a1.
name(), a2.
name() ) < 0;
78 SortingTraits::FormattedName::FormattedName()
83 SortingTraits::FormattedName::~FormattedName()
97 SortingTraits::FamilyName::FamilyName()
102 SortingTraits::FamilyName::~FamilyName()
123 SortingTraits::GivenName::GivenName()
128 SortingTraits::GivenName::~GivenName()
155 static Field *sActiveField=0;
157 class AddresseeList::Private :
public QSharedData
161 : mReverseSorting( false ), mActiveSortingCriterion( FormattedName )
165 Private(
const Private &other )
166 : QSharedData( other )
168 mReverseSorting = other.mReverseSorting;
169 mActiveSortingCriterion = other.mActiveSortingCriterion;
172 bool mReverseSorting;
173 SortingCriterion mActiveSortingCriterion;
186 : QList<
Addressee>( other ), d( other.d )
191 : QList<
Addressee>( l ), d( new Private )
197 if (
this != &other ) {
198 QList<Addressee>::operator=( other );
209 str += QLatin1String(
"AddresseeList {\n" );
210 str += QString::fromLatin1(
" Reverse Order: %1\n" ).arg( d->mReverseSorting ?
211 QLatin1String(
"true" ) :
212 QLatin1String(
"false" ) );
215 if ( Uid == d->mActiveSortingCriterion ) {
216 crit = QLatin1String(
"Uid" );
217 }
else if ( Name == d->mActiveSortingCriterion ) {
218 crit = QLatin1String(
"Name" );
219 }
else if ( FormattedName == d->mActiveSortingCriterion ) {
220 crit = QLatin1String(
"FormattedName" );
221 }
else if ( FamilyName == d->mActiveSortingCriterion ) {
222 crit = QLatin1String(
"FamilyName" );
223 }
else if ( GivenName == d->mActiveSortingCriterion ) {
224 crit = QLatin1String(
"GivenName" );
226 crit = QLatin1String(
"unknown -- update dump method" );
229 str += QString::fromLatin1(
" Sorting criterion: %1\n" ).arg( crit );
230 #if 0 //code commented in loop => comment it too
231 for ( const_iterator it = begin(); it != end(); ++it ) {
236 str += QLatin1String(
"}\n" );
248 return d->mReverseSorting;
253 d->mActiveSortingCriterion = c;
255 sortByTrait<SortingTraits::Uid>();
256 }
else if ( Name == c ) {
257 sortByTrait<SortingTraits::Name>();
258 }
else if ( FormattedName == c ) {
259 sortByTrait<SortingTraits::FormattedName>();
260 }
else if ( FamilyName == c ) {
261 sortByTrait<SortingTraits::FamilyName>();
262 }
else if ( GivenName == c ) {
263 sortByTrait<SortingTraits::GivenName>();
265 kError( 5700 ) <<
"AddresseeList sorting criterion passed for which a trait is not known."
266 <<
"No sorting done.";
272 sortBy( d->mActiveSortingCriterion );
275 template<
class Trait>
287 iterator i1 = begin();
288 iterator endIt = end();
295 while ( i1 != endIt ) {
296 iterator j1 = begin();
300 if ( ( !d->mReverseSorting && Trait::lt( *j2, *j1 ) ) ||
301 ( d->mReverseSorting && Trait::lt( *j1, *j2 ) ) ) {
315 kWarning( 5700 ) <<
"sortByField called with no active sort field";
319 sActiveField = field;
321 if ( count() == 0 ) {
336 if ( count() == 0 ) {
347 return d->mActiveSortingCriterion;
void sortByField(Field *field=0)
Sorts this list by a specific field.
void sortByMode(SortMode *mode=0)
Sorts this list by a specific sorting mode.
QString name() const
Return name.
void setReverseSorting(bool reverseSorting=true)
Determines the direction of sorting.
a QValueList of Addressee, with sorting functionality
Sort method for sorting an addressee list.
void sortBy(SortingCriterion c)
Sorts this list by a specific criterion.
QString familyName() const
Return family name.
QString formattedName() const
Return formatted name.
static void setSortMode(KABC::SortMode *mode)
Sets the sort mode implementation.
void sortByTrait()
Templated sort function.
QString toString() const
Returns a string representation of the addressee list.
Field * sortingField() const
Returns the active sorting field, ie a pointer to the Field object which was used for the last sortBy...
SortingCriterion sortingCriterion() const
Returns the active sorting criterion, ie the sorting criterion that will be used by a sort call...
AddresseeList()
Creates a new addressee list.
QString givenName() const
Return given name.
Represents a field in the Addressbook.
void sort()
Sorts this list by its active sorting criterion.
~AddresseeList()
Destroys the addressee list.
QString uid() const
Return unique identifier.
AddresseeList & operator=(const AddresseeList &other)
Assignment operator.
Implements comparison by an arbitrary field.
bool reverseSorting() const
Returns the direction of sorting.