kaddressbook
printsortmode.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <kabc/field.h>
00025
00026 #include "printsortmode.h"
00027
00028 #if KDE_IS_VERSION(3,3,91)
00029
00030 PrintSortMode::PrintSortMode( KABC::Field *field, bool ascending )
00031 : mSortField( field ), mAscending( ascending )
00032 {
00033 const KABC::Field::List fields = KABC::Field::allFields();
00034 KABC::Field::List::ConstIterator it;
00035 for ( it = fields.begin(); it != fields.end(); ++it ) {
00036 if ( (*it)->label() == KABC::Addressee::givenNameLabel() )
00037 mGivenNameField = *it;
00038 else if ( (*it)->label() == KABC::Addressee::familyNameLabel() )
00039 mFamilyNameField = *it;
00040 else if ( (*it)->label() == KABC::Addressee::formattedNameLabel() )
00041 mFormattedNameField = *it;
00042 }
00043 }
00044
00045 bool PrintSortMode::lesser( const KABC::Addressee &first,
00046 const KABC::Addressee &second ) const
00047 {
00048 if ( !mSortField )
00049 return false;
00050
00051 int result = QString::localeAwareCompare( mSortField->value( first ),
00052 mSortField->value( second ) );
00053 if ( result == 0 ) {
00054 int givenNameResult = QString::localeAwareCompare( mGivenNameField->value( first ),
00055 mGivenNameField->value( second ) );
00056 if ( givenNameResult == 0 ) {
00057 int familyNameResult = QString::localeAwareCompare( mFamilyNameField->value( first ),
00058 mFamilyNameField->value( second ) );
00059 if ( familyNameResult == 0 ) {
00060 result = QString::localeAwareCompare( mFormattedNameField->value( first ),
00061 mFormattedNameField->value( second ) );
00062 } else
00063 result = familyNameResult;
00064 } else
00065 result = givenNameResult;
00066 }
00067
00068 bool lesser = result < 0;
00069
00070 if ( !mAscending )
00071 lesser = !lesser;
00072
00073 return lesser;
00074 }
00075
00076 #endif
|