summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/private/opimcontactsortvector.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/private/opimcontactsortvector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/private/opimcontactsortvector.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/libopie2/opiepim/private/opimcontactsortvector.cpp b/libopie2/opiepim/private/opimcontactsortvector.cpp
new file mode 100644
index 0000000..9e186fe
--- a/dev/null
+++ b/libopie2/opiepim/private/opimcontactsortvector.cpp
@@ -0,0 +1,104 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimcontactsortvector.h"
31#include <opie2/ocontactaccess.h>
32
33namespace Opie {
34namespace Internal {
35OPimContactSortVector::OPimContactSortVector( uint size, bool asc, int sort )
36 : OPimSortVector<OPimContact>( size, asc, sort ) {}
37
38int OPimContactSortVector::compareItems( const OPimContact& left,
39 const OPimContact& right ) {
40 if ( left.uid() == right.uid() )
41 return 0;
42
43 bool soTitle, soSummary, soFirstName, soMiddleName, soSuffix, soEmail,
44 soNick, soAnni, soBirth, soGender;
45 soTitle = soSummary = soFirstName = soMiddleName = soSuffix = soEmail =
46 soNick = soAnni = soBirth = soGender = false;
47 int ret = 0;
48 bool asc = sortAscending();
49
50 switch( sortOrder() ) {
51 case OPimContactAccess::SortSummary:
52 ret = testString( left.fileAs(), right.fileAs() );
53 soSummary = true;
54 break;
55 case OPimContactAccess::SortTitle:
56 ret = testString( left.title(), right.title() );
57 soTitle = true;
58 break;
59 case OPimContactAccess::SortFirstName:
60 ret = testString( left.firstName(), right.firstName() );
61 soFirstName = true;
62 break;
63 case OPimContactAccess::SortMiddleName:
64 ret = testString( left.middleName(), right.middleName() );
65 soMiddleName = true;
66 break;
67 case OPimContactAccess::SortSuffix:
68 ret = testString( left.suffix(), right.suffix() );
69 soSuffix = true;
70 break;
71 case OPimContactAccess::SortEmail:
72 ret = testString( left.defaultEmail(), right.defaultEmail() );
73 soEmail = true;
74 break;
75 case OPimContactAccess::SortNickname:
76 ret = testString( left.nickname(), right.nickname() );
77 soNick = true;
78 break;
79 case OPimContactAccess::SortAnniversary:
80 ret = testDate( left.anniversary(), right.anniversary() );
81 soAnni = true;
82 break;
83 case OPimContactAccess::SortByDate:
84 case OPimContactAccess::SortBirthday:
85 ret = testDate( left.birthday(), right.birthday() );
86 soBirth = true;
87 break;
88 case OPimContactAccess::SortGender:
89 ret = testString( left.gender(), right.gender() );
90 soGender = true;
91 break;
92 }
93
94 /* twist to honor ascending/descending setting as QVector only sorts ascending*/
95 if ( !asc )
96 ret *= -1;
97
98 // Maybe differentiate as in OPimTodoSortVector ### FIXME
99 // if( ret )
100 return ret;
101}
102
103}
104}