kabc Library: sortmode.cpp Source File (kabc Library)

| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# sortmode.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <kabc/field.h>
    00022
    00023 #include "sortmode.h"
    00024
    00025 using namespace KABC;
    00026
    00027 NameSortMode::NameSortMode()
    00028  : mNameType( FormattedName ), mAscendingOrder( true ), d( 0 )
    00029 {
    00030   mNameType = FormattedName;
    00031 }
    00032
    00033 NameSortMode::NameSortMode( NameType type, bool ascending )
    00034   : mNameType( type ), mAscendingOrder( ascending ), d( 0 )
    00035 {
    00036 }
    00037
    00038 bool NameSortMode::lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const
    00039 {
    00040   bool lesser = false;
    00041
    00042   switch ( mNameType ) {
    00043     case FormattedName:
    00044       lesser = QString::localeAwareCompare( first.formattedName(), second.formattedName() ) < 0;
    00045       break;
    00046     case FamilyName:
    00047       lesser = QString::localeAwareCompare( first.familyName(), second.familyName() ) < 0;
    00048       break;
    00049     case GivenName:
    00050       lesser = QString::localeAwareCompare( first.givenName(), second.givenName() ) < 0;
    00051       break;
    00052     default:
    00053       lesser = false;
    00054       break;
    00055   }
    00056
    00057   if ( !mAscendingOrder )
    00058     lesser = !lesser;
    00059
    00060   return lesser;
    00061 }
    00062
    00063 FieldSortMode::FieldSortMode( KABC::Field *field, bool ascending )
    00064   : mField( field ), mAscendingOrder( ascending ), d( 0 )
    00065 {
    00066 }
    00067
    00068 bool FieldSortMode::lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const
    00069 {
    00070   if ( !mField )
    00071     return false;
    00072   else {
    00073     bool lesser = QString::localeAwareCompare( mField->value( first ), mField->value( second ) ) < 0;
    00074     if ( !mAscendingOrder )
    00075       lesser = !lesser;
    00076
    00077     return lesser;
    00078   }
    00079 }

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:31 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003