author | eilers <eilers> | 2005-01-16 19:54:28 (UTC) |
---|---|---|
committer | eilers <eilers> | 2005-01-16 19:54:28 (UTC) |
commit | 37f290f048eeade1036cd1dc2239d2a98412c54b (patch) (unidiff) | |
tree | 04dea39ccf2725f4992d5b8bdbf12807e9a67ae2 /libopie2/opiepim/private/opimeventsortvector.cpp | |
parent | 07a4cf7e277aee7097c4da286a2559b717054362 (diff) | |
download | opie-37f290f048eeade1036cd1dc2239d2a98412c54b.zip opie-37f290f048eeade1036cd1dc2239d2a98412c54b.tar.gz opie-37f290f048eeade1036cd1dc2239d2a98412c54b.tar.bz2 |
Added new generic sorted for the databook backends. Needed an sortedvector
to do this job, which is now added to private classes..
Diffstat (limited to 'libopie2/opiepim/private/opimeventsortvector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/private/opimeventsortvector.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/libopie2/opiepim/private/opimeventsortvector.cpp b/libopie2/opiepim/private/opimeventsortvector.cpp new file mode 100644 index 0000000..4220c63 --- a/dev/null +++ b/libopie2/opiepim/private/opimeventsortvector.cpp | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net> | ||
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 "opimeventsortvector.h" | ||
31 | #include <opie2/ocontactaccess.h> | ||
32 | #include <opie2/opimnotifymanager.h> | ||
33 | #include <opie2/odatebookaccess.h> | ||
34 | |||
35 | #include <qvaluelist.h> | ||
36 | |||
37 | namespace Opie { | ||
38 | namespace Internal { | ||
39 | |||
40 | namespace{ | ||
41 | |||
42 | inline int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){ | ||
43 | OPimNotifyManager::Alarms left_alarms = leftnotifiers.alarms(); | ||
44 | OPimNotifyManager::Alarms right_alarms = rightnotifiers.alarms(); | ||
45 | |||
46 | // Well.. How could we compare two lists of alarms? I think we should find the most early datetimes | ||
47 | // and compare them.. (se) | ||
48 | // Find the first alarm of the left list | ||
49 | OPimNotifyManager::Alarms::Iterator it; | ||
50 | QDateTime left_earliest; // This datetime is initialized as invalid!! | ||
51 | for ( it = left_alarms.begin(); it != left_alarms.end(); ++it ){ | ||
52 | if ( !left_earliest.isValid() || left_earliest > (*it).dateTime() ){ | ||
53 | left_earliest = (*it).dateTime(); | ||
54 | } | ||
55 | } | ||
56 | QDateTime right_earliest; // This datetime is initialized as invalid!! | ||
57 | for ( it = right_alarms.begin(); it != right_alarms.end(); ++it ){ | ||
58 | if ( !right_earliest.isValid() || right_earliest > (*it).dateTime() ){ | ||
59 | right_earliest = (*it).dateTime(); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | int ret; | ||
64 | |||
65 | // Now compare this found alarms | ||
66 | if ( !left_earliest .isValid() ) ret++; | ||
67 | if ( !right_earliest.isValid() ) ret--; | ||
68 | |||
69 | if ( left_earliest.isValid() && right_earliest.isValid() ){ | ||
70 | ret += left_earliest < right_earliest ? -1 : 1; | ||
71 | } | ||
72 | |||
73 | return ret; | ||
74 | |||
75 | } | ||
76 | } | ||
77 | |||
78 | OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort ) | ||
79 | : OPimSortVector<OPimEvent>( size, asc, sort ) {} | ||
80 | |||
81 | int OPimEventSortVector::compareItems( const OPimEvent& left, | ||
82 | const OPimEvent& right ) { | ||
83 | if ( left.uid() == right.uid() ) | ||
84 | return 0; | ||
85 | |||
86 | int ret = 0; | ||
87 | bool asc = sortAscending(); | ||
88 | |||
89 | switch( sortOrder() ) { | ||
90 | case ODateBookAccess::SortDescription: | ||
91 | ret = testString( left.description(), right.description() ); | ||
92 | break; | ||
93 | case ODateBookAccess::SortLocation: | ||
94 | ret = testString( left.location(), right.location() ); | ||
95 | break; | ||
96 | case ODateBookAccess::SortNote: | ||
97 | ret = testString( left.note(),right.note() ); | ||
98 | break; | ||
99 | case ODateBookAccess::SortStartTime: | ||
100 | ret = testTime( left.startDateTime().time(), right.startDateTime().time() ); | ||
101 | break; | ||
102 | case ODateBookAccess::SortEndTime: | ||
103 | ret = testTime( left.endDateTime().time(), right.endDateTime().time() ); | ||
104 | break; | ||
105 | case ODateBookAccess::SortStartDate: | ||
106 | ret = testDate( left.startDateTime().date(), right.startDateTime().date() ); | ||
107 | break; | ||
108 | case ODateBookAccess::SortEndDate: | ||
109 | ret = testDate( left.endDateTime().date(), right.endDateTime().date() ); | ||
110 | break; | ||
111 | case ODateBookAccess::SortStartDateTime: | ||
112 | ret = testDateTime( left.startDateTime(), right.startDateTime() ); | ||
113 | break; | ||
114 | case ODateBookAccess::SortEndDateTime: | ||
115 | ret = testDateTime( left.endDateTime(), right.endDateTime() ); | ||
116 | break; | ||
117 | case ODateBookAccess::SortAlarmDateTime: | ||
118 | ret = testAlarmNotifiers( left.notifiers(), right.notifiers() ); | ||
119 | break; | ||
120 | default: | ||
121 | odebug << "OpimEventSortVector: Unknown sortOrder: " << sortOrder() << oendl; | ||
122 | } | ||
123 | |||
124 | /* twist to honor ascending/descending setting as QVector only sorts ascending */ | ||
125 | if ( !asc ) | ||
126 | ret *= -1; | ||
127 | |||
128 | // Maybe differentiate as in OPimTodoSortVector ### FIXME | ||
129 | // if( ret ) | ||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | } | ||
134 | } | ||