24#include <tdeabc/field.h>
26#include "printsortmode.h"
28PrintSortMode::PrintSortMode( TDEABC::Field *field,
bool ascending )
29 : mSortField( field ), mAscending( ascending )
31 const TDEABC::Field::List fields = TDEABC::Field::allFields();
32 TDEABC::Field::List::ConstIterator it;
33 for ( it = fields.begin(); it != fields.end(); ++it ) {
34 if ( (*it)->label() == TDEABC::Addressee::givenNameLabel() )
35 mGivenNameField = *it;
36 else if ( (*it)->label() == TDEABC::Addressee::familyNameLabel() )
37 mFamilyNameField = *it;
38 else if ( (*it)->label() == TDEABC::Addressee::formattedNameLabel() )
39 mFormattedNameField = *it;
43bool PrintSortMode::lesser(
const TDEABC::Addressee &first,
44 const TDEABC::Addressee &second )
const
49 int result = TQString::localeAwareCompare( mSortField->value( first ),
50 mSortField->value( second ) );
52 int givenNameResult = TQString::localeAwareCompare( mGivenNameField->value( first ),
53 mGivenNameField->value( second ) );
54 if ( givenNameResult == 0 ) {
55 int familyNameResult = TQString::localeAwareCompare( mFamilyNameField->value( first ),
56 mFamilyNameField->value( second ) );
57 if ( familyNameResult == 0 ) {
58 result = TQString::localeAwareCompare( mFormattedNameField->value( first ),
59 mFormattedNameField->value( second ) );
61 result = familyNameResult;
63 result = givenNameResult;
66 bool lesser = result < 0;