Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opimcontactsortvector.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) 2004 Holger Freyther <freyther@handhelds.org>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include "opimcontactsortvector.h"
00031 #include <opie2/ocontactaccess.h>
00032 
00033 namespace Opie {
00034 namespace Internal {
00035 OPimContactSortVector::OPimContactSortVector( uint size, bool asc, int sort )
00036     : OPimSortVector<OPimContact>( size, asc, sort ) {}
00037 
00038 int OPimContactSortVector::compareItems( const OPimContact& left,
00039                                          const OPimContact& right ) {
00040     if ( left.uid() == right.uid() )
00041         return 0;
00042 
00043     bool soTitle, soSummary, soFirstName, soMiddleName, soSuffix, soEmail,
00044         soNick, soFileAs, soAnni, soBirth, soGender;
00045     soTitle = soSummary = soFirstName = soMiddleName = soSuffix = soEmail =
00046      soNick = soFileAs = soAnni = soBirth = soGender = false;
00047     int ret = 0;
00048     bool asc = sortAscending();
00049 
00050     switch( sortOrder() ) {
00051     case OPimContactAccess::SortSummary:
00052         ret = testString( left.fileAs(), right.fileAs() );
00053         soSummary = true;
00054         break;
00055     case OPimContactAccess::SortTitle:
00056         ret = testString( left.title(), right.title() );
00057         soTitle = true;
00058         break;
00059     case OPimContactAccess::SortFirstName:
00060         ret = testString( left.firstName(), right.firstName() );
00061         soFirstName = true;
00062         break;
00063     case OPimContactAccess::SortMiddleName:
00064         ret = testString( left.middleName(), right.middleName() );
00065         soMiddleName = true;
00066         break;
00067     case OPimContactAccess::SortSuffix:
00068         ret = testString( left.suffix(), right.suffix() );
00069         soSuffix = true;
00070         break;
00071     case OPimContactAccess::SortEmail:
00072         ret = testString( left.defaultEmail(), right.defaultEmail() );
00073         soEmail = true;
00074         break;
00075     case OPimContactAccess::SortNickname:
00076         ret = testString( left.nickname(), right.nickname() );
00077         soNick = true;
00078         break;
00079     case OPimContactAccess::SortFileAsName:
00080         ret = testString( left.fileAs(), right.fileAs() );
00081         soFileAs = true;
00082         break;
00083     case OPimContactAccess::SortAnniversary:
00084         ret = testDate( left.anniversary(), right.anniversary() );
00085         soAnni = true;
00086         break;
00087     case OPimContactAccess::SortByDate:
00088     case OPimContactAccess::SortBirthday:
00089         ret = testDate( left.birthday(), right.birthday() );
00090         soBirth = true;
00091         break;
00092     case OPimContactAccess::SortGender:
00093         ret = testString( left.gender(), right.gender() );
00094         soGender = true;
00095         break;
00096     }
00097 
00098     /* twist to honor ascending/descending setting as QVector only sorts ascending*/
00099     if ( !asc )
00100         ret *= -1;
00101 
00102     //  Maybe differentiate as in OPimTodoSortVector ### FIXME
00103     //  if( ret )
00104     return ret;
00105 }
00106 
00107 }
00108 }

Generated on Sat Nov 5 16:16:23 2005 for OPIE by  doxygen 1.4.2