summaryrefslogtreecommitdiff
authoreilers <eilers>2005-01-16 19:54:28 (UTC)
committer eilers <eilers>2005-01-16 19:54:28 (UTC)
commit37f290f048eeade1036cd1dc2239d2a98412c54b (patch) (unidiff)
tree04dea39ccf2725f4992d5b8bdbf12807e9a67ae2
parent07a4cf7e277aee7097c4da286a2559b717054362 (diff)
downloadopie-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 (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ChangeLog3
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.cpp5
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h3
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp58
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h25
-rw-r--r--libopie2/opiepim/private/opimeventsortvector.cpp134
-rw-r--r--libopie2/opiepim/private/opimeventsortvector.h48
-rw-r--r--libopie2/opiepim/private/opimsortvector.h34
-rw-r--r--libopie2/opiepim/private/opimtodosortvector.cpp2
-rw-r--r--libopie2/opiepim/private/private.pro2
10 files changed, 308 insertions, 6 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog
index 320b189..e94fa59 100644
--- a/libopie2/opiepim/ChangeLog
+++ b/libopie2/opiepim/ChangeLog
@@ -1,26 +1,29 @@
12005-01-16 Stefan Eilers <stefan@eilers-online.net>
2 * Added new OPimEventSortVector class, improved OPimSortVector
3 * OPimAccessBackend now supports generic sorting.
12005-01-03 Stefan Eilers <stefan@eilers-online.net> 42005-01-03 Stefan Eilers <stefan@eilers-online.net>
2 * Fixing bug in API documentation 5 * Fixing bug in API documentation
3 * Moving hasQuerySettings() and querySettings() to OPimAccessTemplate to be available for all frontends 6 * Moving hasQuerySettings() and querySettings() to OPimAccessTemplate to be available for all frontends
42004-12-28 Stefan Eilers <stefan@eilers-online.net> 72004-12-28 Stefan Eilers <stefan@eilers-online.net>
5 * Make improved query by example accessable via frontend 8 * Make improved query by example accessable via frontend
6 * Some API documentation improvement 9 * Some API documentation improvement
7 * Cleanup of backend api.. 10 * Cleanup of backend api..
8 * Fixing bug #1501 11 * Fixing bug #1501
92004-11-23 Stefan Eilers <stefan@eilers-online.net> 122004-11-23 Stefan Eilers <stefan@eilers-online.net>
10 * Implement fast and full featured version of sorted() for addressbook 13 * Implement fast and full featured version of sorted() for addressbook
11 * Implement generic queryByExample for all Addressboook backends. It allows incremental search. 14 * Implement generic queryByExample for all Addressboook backends. It allows incremental search.
12 * Update of API Documentation 15 * Update of API Documentation
132004-11-18 Holger Freyther <freyther@handhelds.org> 162004-11-18 Holger Freyther <freyther@handhelds.org>
14 * Every Access can give a set of Occurrences for a period or a datetime 17 * Every Access can give a set of Occurrences for a period or a datetime
15 * QueryByExample, Find, Sort can be generically accessed by OPimBase 18 * QueryByExample, Find, Sort can be generically accessed by OPimBase
16 pointer interface 19 pointer interface
17 * OPimBackendOccurrence gets split up to OPimOccurrences by 20 * OPimBackendOccurrence gets split up to OPimOccurrences by
18 OPimTemplateBase 21 OPimTemplateBase
19 * Add safeCast to various OPimRecords 22 * Add safeCast to various OPimRecords
20 * Kill memleak in OPimTodo 23 * Kill memleak in OPimTodo
21 * Add SortVector implementations for OPimTodo and OPimContact 24 * Add SortVector implementations for OPimTodo and OPimContact
22 25
23 2004-??-??The Opie Team <opie@handhelds.org> 26 2004-??-??The Opie Team <opie@handhelds.org>
24 * Implemented some important modifications to allow to use OPimRecords as it is, without 27 * Implemented some important modifications to allow to use OPimRecords as it is, without
25 have to cast them. This makes it possible to write applications which handling pim 28 have to cast them. This makes it possible to write applications which handling pim
26 data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file 29 data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.cpp b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
index b4fdd46..c09427c 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
@@ -1,314 +1,315 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org> 3 Copyright (C) Holger Freyther <freyther@handhelds.org>
4 Copyright (C) Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 14 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 21++= -. .` .: details.
21 : = ...= . :.=- 22 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
28*/ 29*/
29 30
30#include "ocontactaccessbackend.h" 31#include "ocontactaccessbackend.h"
31#include <opie2/private/opimcontactsortvector.h> 32#include <opie2/private/opimcontactsortvector.h>
32#include <opie2/ocontactaccess.h> 33#include <opie2/ocontactaccess.h>
33 34
34#include <opie2/odebug.h> 35#include <opie2/odebug.h>
35 36
36#include <qdatetime.h> 37#include <qdatetime.h>
37 38
38namespace Opie { 39namespace Opie {
39OPimContactAccessBackend::OPimContactAccessBackend() {} 40OPimContactAccessBackend::OPimContactAccessBackend() {}
40 41
41UIDArray OPimContactAccessBackend::queryByExample( const UIDArray& uid_array, const OPimContact& query, int settings, 42UIDArray OPimContactAccessBackend::queryByExample( const UIDArray& uid_array, const OPimContact& query, int settings,
42 const QDateTime& d )const { 43 const QDateTime& d )const {
43 odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl; 44 odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl;
44 45
45 UIDArray m_currentQuery( uid_array.count() ); 46 UIDArray m_currentQuery( uid_array.count() );
46 uint arraycounter = 0; 47 uint arraycounter = 0;
47 48
48 for( uint it = 0; it < uid_array.count(); ++it ){ 49 for( uint it = 0; it < uid_array.count(); ++it ){
49 /* Search all fields and compare them with query object. Store them into list 50 /* Search all fields and compare them with query object. Store them into list
50 * if all fields matches. 51 * if all fields matches.
51 */ 52 */
52 QDate* queryDate = 0l; 53 QDate* queryDate = 0l;
53 QDate* checkDate = 0l; 54 QDate* checkDate = 0l;
54 bool allcorrect = true; 55 bool allcorrect = true;
55 for ( int i = 0; i < Qtopia::Groups; i++ ) { 56 for ( int i = 0; i < Qtopia::Groups; i++ ) {
56 // Birthday and anniversary are special nonstring fields and should 57 // Birthday and anniversary are special nonstring fields and should
57 // be handled specially 58 // be handled specially
58 switch ( i ){ 59 switch ( i ){
59 case Qtopia::Birthday: 60 case Qtopia::Birthday:
60 queryDate = new QDate( query.birthday() ); 61 queryDate = new QDate( query.birthday() );
61 checkDate = new QDate( find( uid_array[it] ).birthday() ); 62 checkDate = new QDate( find( uid_array[it] ).birthday() );
62 // fall through 63 // fall through
63 case Qtopia::Anniversary: 64 case Qtopia::Anniversary:
64 if ( queryDate == 0l ){ 65 if ( queryDate == 0l ){
65 queryDate = new QDate( query.anniversary() ); 66 queryDate = new QDate( query.anniversary() );
66 checkDate = new QDate( find( uid_array[it] ).anniversary() ); 67 checkDate = new QDate( find( uid_array[it] ).anniversary() );
67 } 68 }
68 69
69 if ( queryDate->isValid() ){ 70 if ( queryDate->isValid() ){
70 if( checkDate->isValid() ){ 71 if( checkDate->isValid() ){
71 if ( settings & OPimContactAccess::DateYear ){ 72 if ( settings & OPimContactAccess::DateYear ){
72 if ( queryDate->year() != checkDate->year() ) 73 if ( queryDate->year() != checkDate->year() )
73 allcorrect = false; 74 allcorrect = false;
74 } 75 }
75 if ( settings & OPimContactAccess::DateMonth ){ 76 if ( settings & OPimContactAccess::DateMonth ){
76 if ( queryDate->month() != checkDate->month() ) 77 if ( queryDate->month() != checkDate->month() )
77 allcorrect = false; 78 allcorrect = false;
78 } 79 }
79 if ( settings & OPimContactAccess::DateDay ){ 80 if ( settings & OPimContactAccess::DateDay ){
80 if ( queryDate->day() != checkDate->day() ) 81 if ( queryDate->day() != checkDate->day() )
81 allcorrect = false; 82 allcorrect = false;
82 } 83 }
83 if ( settings & OPimContactAccess::DateDiff ) { 84 if ( settings & OPimContactAccess::DateDiff ) {
84 QDate current; 85 QDate current;
85 // If we get an additional date, we 86 // If we get an additional date, we
86 // will take this date instead of 87 // will take this date instead of
87 // the current one.. 88 // the current one..
88 if ( !d.date().isValid() ) 89 if ( !d.date().isValid() )
89 current = QDate::currentDate(); 90 current = QDate::currentDate();
90 else 91 else
91 current = d.date(); 92 current = d.date();
92 93
93 // We have to equalize the year, otherwise 94 // We have to equalize the year, otherwise
94 // the search will fail.. 95 // the search will fail..
95 checkDate->setYMD( current.year(), 96 checkDate->setYMD( current.year(),
96 checkDate->month(), 97 checkDate->month(),
97 checkDate->day() ); 98 checkDate->day() );
98 if ( *checkDate < current ) 99 if ( *checkDate < current )
99 checkDate->setYMD( current.year()+1, 100 checkDate->setYMD( current.year()+1,
100 checkDate->month(), 101 checkDate->month(),
101 checkDate->day() ); 102 checkDate->day() );
102 103
103 // Check whether the birthday/anniversary date is between 104 // Check whether the birthday/anniversary date is between
104 // the current/given date and the maximum date 105 // the current/given date and the maximum date
105 // ( maximum time range ) ! 106 // ( maximum time range ) !
106 if ( current.daysTo( *queryDate ) >= 0 ){ 107 if ( current.daysTo( *queryDate ) >= 0 ){
107 if ( !( ( *checkDate >= current ) && 108 if ( !( ( *checkDate >= current ) &&
108 ( *checkDate <= *queryDate ) ) ){ 109 ( *checkDate <= *queryDate ) ) ){
109 allcorrect = false; 110 allcorrect = false;
110 } 111 }
111 } 112 }
112 } 113 }
113 } else{ 114 } else{
114 // checkDate is invalid. Therefore this entry is always rejected 115 // checkDate is invalid. Therefore this entry is always rejected
115 allcorrect = false; 116 allcorrect = false;
116 } 117 }
117 } 118 }
118 119
119 delete queryDate; 120 delete queryDate;
120 queryDate = 0l; 121 queryDate = 0l;
121 delete checkDate; 122 delete checkDate;
122 checkDate = 0l; 123 checkDate = 0l;
123 break; 124 break;
124 default: 125 default:
125 /* Just compare fields which are not empty in the query object */ 126 /* Just compare fields which are not empty in the query object */
126 if ( !query.field(i).isEmpty() ){ 127 if ( !query.field(i).isEmpty() ){
127 switch ( settings & ~( OPimContactAccess::IgnoreCase 128 switch ( settings & ~( OPimContactAccess::IgnoreCase
128 | OPimContactAccess::DateDiff 129 | OPimContactAccess::DateDiff
129 | OPimContactAccess::DateYear 130 | OPimContactAccess::DateYear
130 | OPimContactAccess::DateMonth 131 | OPimContactAccess::DateMonth
131 | OPimContactAccess::DateDay 132 | OPimContactAccess::DateDay
132 | OPimContactAccess::MatchOne 133 | OPimContactAccess::MatchOne
133 ) ){ 134 ) ){
134 135
135 case OPimContactAccess::RegExp:{ 136 case OPimContactAccess::RegExp:{
136 QRegExp expr ( query.field(i), 137 QRegExp expr ( query.field(i),
137 !(settings & OPimContactAccess::IgnoreCase), 138 !(settings & OPimContactAccess::IgnoreCase),
138 false ); 139 false );
139 if ( expr.find ( find( uid_array[it] ).field(i), 0 ) == -1 ) 140 if ( expr.find ( find( uid_array[it] ).field(i), 0 ) == -1 )
140 allcorrect = false; 141 allcorrect = false;
141 } 142 }
142 break; 143 break;
143 case OPimContactAccess::WildCards:{ 144 case OPimContactAccess::WildCards:{
144 QRegExp expr ( query.field(i), 145 QRegExp expr ( query.field(i),
145 !(settings & OPimContactAccess::IgnoreCase), 146 !(settings & OPimContactAccess::IgnoreCase),
146 true ); 147 true );
147 if ( expr.find ( find( uid_array[it] ).field(i), 0 ) == -1 ) 148 if ( expr.find ( find( uid_array[it] ).field(i), 0 ) == -1 )
148 allcorrect = false; 149 allcorrect = false;
149 } 150 }
150 break; 151 break;
151 case OPimContactAccess::ExactMatch:{ 152 case OPimContactAccess::ExactMatch:{
152 if (settings & OPimContactAccess::IgnoreCase){ 153 if (settings & OPimContactAccess::IgnoreCase){
153 if ( query.field(i).upper() != 154 if ( query.field(i).upper() !=
154 find( uid_array[it] ).field(i).upper() ) 155 find( uid_array[it] ).field(i).upper() )
155 allcorrect = false; 156 allcorrect = false;
156 }else{ 157 }else{
157 if ( query.field(i) != find( uid_array[it] ).field(i) ) 158 if ( query.field(i) != find( uid_array[it] ).field(i) )
158 allcorrect = false; 159 allcorrect = false;
159 } 160 }
160 } 161 }
161 break; 162 break;
162 } 163 }
163 } 164 }
164 } 165 }
165 } 166 }
166 if ( allcorrect ){ 167 if ( allcorrect ){
167 m_currentQuery[arraycounter++] = uid_array[it]; 168 m_currentQuery[arraycounter++] = uid_array[it];
168 } 169 }
169 } 170 }
170 171
171 // Shrink to fit.. 172 // Shrink to fit..
172 m_currentQuery.resize(arraycounter); 173 m_currentQuery.resize(arraycounter);
173 174
174 return m_currentQuery; 175 return m_currentQuery;
175 176
176} 177}
177 178
178const uint OPimContactAccessBackend::querySettings() const 179const uint OPimContactAccessBackend::querySettings() const
179{ 180{
180 return ( OPimContactAccess::WildCards 181 return ( OPimContactAccess::WildCards
181 | OPimContactAccess::IgnoreCase 182 | OPimContactAccess::IgnoreCase
182 | OPimContactAccess::RegExp 183 | OPimContactAccess::RegExp
183 | OPimContactAccess::ExactMatch 184 | OPimContactAccess::ExactMatch
184 | OPimContactAccess::DateDiff 185 | OPimContactAccess::DateDiff
185 | OPimContactAccess::DateYear 186 | OPimContactAccess::DateYear
186 | OPimContactAccess::DateMonth 187 | OPimContactAccess::DateMonth
187 | OPimContactAccess::DateDay 188 | OPimContactAccess::DateDay
188 ); 189 );
189} 190}
190 191
191bool OPimContactAccessBackend::hasQuerySettings (uint querySettings) const 192bool OPimContactAccessBackend::hasQuerySettings (uint querySettings) const
192{ 193{
193 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 194 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
194 * may be added with any of the other settings. IgnoreCase should never used alone. 195 * may be added with any of the other settings. IgnoreCase should never used alone.
195 * Wildcards, RegExp, ExactMatch should never used at the same time... 196 * Wildcards, RegExp, ExactMatch should never used at the same time...
196 */ 197 */
197 198
198 // Step 1: Check whether the given settings are supported by this backend 199 // Step 1: Check whether the given settings are supported by this backend
199 if ( ( querySettings & ( 200 if ( ( querySettings & (
200 OPimContactAccess::IgnoreCase 201 OPimContactAccess::IgnoreCase
201 | OPimContactAccess::WildCards 202 | OPimContactAccess::WildCards
202 | OPimContactAccess::DateDiff 203 | OPimContactAccess::DateDiff
203 | OPimContactAccess::DateYear 204 | OPimContactAccess::DateYear
204 | OPimContactAccess::DateMonth 205 | OPimContactAccess::DateMonth
205 | OPimContactAccess::DateDay 206 | OPimContactAccess::DateDay
206 | OPimContactAccess::RegExp 207 | OPimContactAccess::RegExp
207 | OPimContactAccess::ExactMatch 208 | OPimContactAccess::ExactMatch
208 ) ) != querySettings ) 209 ) ) != querySettings )
209 return false; 210 return false;
210 211
211 // Step 2: Check whether the given combinations are ok.. 212 // Step 2: Check whether the given combinations are ok..
212 213
213 // IngoreCase alone is invalid 214 // IngoreCase alone is invalid
214 if ( querySettings == OPimContactAccess::IgnoreCase ) 215 if ( querySettings == OPimContactAccess::IgnoreCase )
215 return false; 216 return false;
216 217
217 // WildCards, RegExp and ExactMatch should never used at the same time 218 // WildCards, RegExp and ExactMatch should never used at the same time
218 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 219 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
219 | OPimContactAccess::DateDiff 220 | OPimContactAccess::DateDiff
220 | OPimContactAccess::DateYear 221 | OPimContactAccess::DateYear
221 | OPimContactAccess::DateMonth 222 | OPimContactAccess::DateMonth
222 | OPimContactAccess::DateDay 223 | OPimContactAccess::DateDay
223 ) 224 )
224 ){ 225 ){
225 case OPimContactAccess::RegExp: 226 case OPimContactAccess::RegExp:
226 return ( true ); 227 return ( true );
227 case OPimContactAccess::WildCards: 228 case OPimContactAccess::WildCards:
228 return ( true ); 229 return ( true );
229 case OPimContactAccess::ExactMatch: 230 case OPimContactAccess::ExactMatch:
230 return ( true ); 231 return ( true );
231 case 0: // one of the upper removed bits were set.. 232 case 0: // one of the upper removed bits were set..
232 return ( true ); 233 return ( true );
233 default: 234 default:
234 return ( false ); 235 return ( false );
235 } 236 }
236} 237}
237 238
238 239
239UIDArray OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, 240UIDArray OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder,
240 int filter, const QArray<int>& categories)const { 241 int filter, const QArray<int>& categories )const {
241 odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl; 242 odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl;
242 243
243 Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder ); 244 Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder );
244 245
245 int item = 0; 246 int item = 0;
246 uint cat_count = categories.count(); 247 uint cat_count = categories.count();
247 uint eve_count = ar.count(); 248 uint eve_count = ar.count();
248 bool bCat = filter & OPimContactAccess::FilterCategory ? true : false; 249 bool bCat = filter & OPimContactAccess::FilterCategory ? true : false;
249 bool catPassed = false; 250 bool catPassed = false;
250 int cat; 251 int cat;
251 252
252 for ( uint i = 0; i < eve_count; ++i ) { 253 for ( uint i = 0; i < eve_count; ++i ) {
253 OPimContact contact = find( ar[i], ar, i, Frontend::Forward ); 254 OPimContact contact = find( ar[i], ar, i, Frontend::Forward );
254 if ( contact.isEmpty() ) 255 if ( contact.isEmpty() )
255 continue; 256 continue;
256 257
257 /* show category */ 258 /* show category */
258 /* -1 == unfiled */ 259 /* -1 == unfiled */
259 catPassed = false; 260 catPassed = false;
260 for ( uint cat_nu = 0; cat_nu < cat_count; ++cat_nu ) { 261 for ( uint cat_nu = 0; cat_nu < cat_count; ++cat_nu ) {
261 cat = categories[cat_nu]; 262 cat = categories[cat_nu];
262 if ( bCat && cat == -1 ) { 263 if ( bCat && cat == -1 ) {
263 if(!contact.categories().isEmpty() ) 264 if(!contact.categories().isEmpty() )
264 continue; 265 continue;
265 } else if ( bCat && cat != 0) 266 } else if ( bCat && cat != 0)
266 if (!contact.categories().contains( cat ) ) 267 if (!contact.categories().contains( cat ) )
267 continue; 268 continue;
268 catPassed = true; 269 catPassed = true;
269 break; 270 break;
270 } 271 }
271 272
272 /* 273 /*
273 * If none of the Categories matched 274 * If none of the Categories matched
274 * continue 275 * continue
275 */ 276 */
276 if ( !catPassed ) 277 if ( !catPassed )
277 continue; 278 continue;
278 279
279 vector.insert(item++, contact ); 280 vector.insert(item++, contact );
280 } 281 }
281 282
282 vector.resize( item ); 283 vector.resize( item );
283 /* sort it now */ 284 /* sort it now */
284 vector.sort(); 285 vector.sort();
285 /* now get the uids */ 286 /* now get the uids */
286 UIDArray array( vector.count() ); 287 UIDArray array( vector.count() );
287 for (uint i= 0; i < vector.count(); i++ ) 288 for (uint i= 0; i < vector.count(); i++ )
288 array[i] = vector.uidAt( i ); 289 array[i] = vector.uidAt( i );
289 290
290 return array; 291 return array;
291} 292}
292 293
293OPimBackendOccurrence::List OPimContactAccessBackend::occurrences( const QDate& start, 294OPimBackendOccurrence::List OPimContactAccessBackend::occurrences( const QDate& start,
294 const QDate& end)const { 295 const QDate& end)const {
295 OPimBackendOccurrence::List lst; 296 OPimBackendOccurrence::List lst;
296 297
297 UIDArray records = allRecords(); 298 UIDArray records = allRecords();
298 const uint count = records.count(); 299 const uint count = records.count();
299 int uid; 300 int uid;
300 301
301 for ( uint i = 0; i < count; ++i ) { 302 for ( uint i = 0; i < count; ++i ) {
302 uid = records[i]; 303 uid = records[i];
303 OPimContact contact = find(uid, records, i, Frontend::Forward ); 304 OPimContact contact = find(uid, records, i, Frontend::Forward );
304 305
305 QDate date = contact.anniversary(); 306 QDate date = contact.anniversary();
306 date = QDate( start.year(), date.month(),date.day() ); 307 date = QDate( start.year(), date.month(),date.day() );
307 308
308// if ( date.isValid() && date.) { 309// if ( date.isValid() && date.) {
309// } 310// }
310 } 311 }
311 312
312 return lst; 313 return lst;
313} 314}
314} 315}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index 27d70ab..d5c463b 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -1,111 +1,112 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) Holger Freyther <freyther@handhelds.org>
4 Copyright (C) Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 14 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 21++= -. .` .: details.
21 : = ...= . :.=- 22 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
28*/ 29*/
29/** 30/**
30 * The class responsible for managing a backend. 31 * The class responsible for managing a backend.
31 * The implementation of this abstract class contains 32 * The implementation of this abstract class contains
32 * the complete database handling. 33 * the complete database handling.
33 * 34 *
34 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 35 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
35 * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) 36 * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
36 * 37 *
37 */ 38 */
38 39
39#ifndef _OCONTACTACCESSBACKEND_H_ 40#ifndef _OCONTACTACCESSBACKEND_H_
40#define _OCONTACTACCESSBACKEND_H_ 41#define _OCONTACTACCESSBACKEND_H_
41 42
42#include <opie2/opimcontact.h> 43#include <opie2/opimcontact.h>
43#include <opie2/opimaccessbackend.h> 44#include <opie2/opimaccessbackend.h>
44 45
45#include <qregexp.h> 46#include <qregexp.h>
46 47
47namespace Opie { 48namespace Opie {
48/** 49/**
49 * This class represents the interface of all Contact Backends. 50 * This class represents the interface of all Contact Backends.
50 * Derivates of this class will be used to access the contacts. 51 * Derivates of this class will be used to access the contacts.
51 * As implementation currently XML and vCard exist. This class needs to be implemented 52 * As implementation currently XML and vCard exist. This class needs to be implemented
52 * if you want to provide your own storage. 53 * if you want to provide your own storage.
53 * In all queries a list of uids is passed on instead of loading the actual record! 54 * In all queries a list of uids is passed on instead of loading the actual record!
54 * 55 *
55 * @see OPimContactAccessBackend_VCard 56 * @see OPimContactAccessBackend_VCard
56 * @see OPimContactAccessBackend_XML 57 * @see OPimContactAccessBackend_XML
57 */ 58 */
58class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> { 59class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> {
59 public: 60 public:
60 OPimContactAccessBackend(); 61 OPimContactAccessBackend();
61 62
62 63
63 /** 64 /**
64 * Return if database was changed externally. 65 * Return if database was changed externally.
65 * This may just make sense on file based databases like a XML-File. 66 * This may just make sense on file based databases like a XML-File.
66 * It is used to prevent to overwrite the current database content 67 * It is used to prevent to overwrite the current database content
67 * if the file was already changed by something else ! 68 * if the file was already changed by something else !
68 * If this happens, we have to reload before save our data. 69 * If this happens, we have to reload before save our data.
69 * If we use real databases, this should be handled by the database 70 * If we use real databases, this should be handled by the database
70 * management system themselve, therefore this function should always return false in 71 * management system themselve, therefore this function should always return false in
71 * this case. It is not our problem to handle this conflict ... 72 * this case. It is not our problem to handle this conflict ...
72 * @return <i>true</i> if the database was changed and if save without reload will 73 * @return <i>true</i> if the database was changed and if save without reload will
73 * be dangerous. <i>false</i> if the database was not changed or it is save to write 74 * be dangerous. <i>false</i> if the database was not changed or it is save to write
74 * in this situation. 75 * in this situation.
75 */ 76 */
76 virtual bool wasChangedExternally() = 0; 77 virtual bool wasChangedExternally() = 0;
77 78
78 /** 79 /**
79 * Return all possible settings. 80 * Return all possible settings.
80 * @return All settings provided by the current backend 81 * @return All settings provided by the current backend
81 * (i.e.: query_WildCards & query_IgnoreCase) 82 * (i.e.: query_WildCards & query_IgnoreCase)
82 */ 83 */
83 const uint querySettings() const; 84 const uint querySettings() const;
84 85
85 /** 86 /**
86 * Check whether settings are correct. 87 * Check whether settings are correct.
87 * @return <i>true</i> if the given settings are correct and possible. 88 * @return <i>true</i> if the given settings are correct and possible.
88 */ 89 */
89 bool hasQuerySettings (uint querySettings) const; 90 bool hasQuerySettings (uint querySettings) const;
90 91
91 /** 92 /**
92 * Advanced search mechanism. 93 * Advanced search mechanism.
93 */ 94 */
94 UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const; 95 UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const;
95 /** 96 /**
96 * Slow and inefficent default implementation 97 * Slow and inefficent default implementation
97 */ 98 */
98//@{ 99//@{
99 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; 100 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
100 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; 101 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
101//@} 102//@}
102 103
103 104
104private: 105private:
105 class Private; 106 class Private;
106 Private *d; 107 Private *d;
107}; 108};
108 109
109} 110}
110 111
111#endif 112#endif
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index e44912a..6da0170 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -1,181 +1,233 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#include <qtl.h> 29#include <qtl.h>
30 30
31#include <opie2/odebug.h>
31#include <opie2/opimrecurrence.h> 32#include <opie2/opimrecurrence.h>
32 33#include <opie2/odatebookaccess.h>
33#include <opie2/odatebookaccessbackend.h> 34#include <opie2/odatebookaccessbackend.h>
35#include <opie2/private/opimeventsortvector.h>
34 36
35using namespace Opie; 37using namespace Opie;
36 38
37namespace { 39namespace {
38/* a small helper to get all NonRepeating events for a range of time */ 40/* a small helper to get all NonRepeating events for a range of time */
39void events( OPimBackendOccurrence::List& tmpList, 41void events( OPimBackendOccurrence::List& tmpList,
40 const OPimEvent::ValueList& events, 42 const OPimEvent::ValueList& events,
41 const QDate& from, const QDate& to ) { 43 const QDate& from, const QDate& to ) {
42 QDateTime dtStart, dtEnd; 44 QDateTime dtStart, dtEnd;
43 45
44 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { 46 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
45 dtStart = (*it).startDateTime(); 47 dtStart = (*it).startDateTime();
46 dtEnd = (*it).endDateTime(); 48 dtEnd = (*it).endDateTime();
47 49
48 /* 50 /*
49 * If in range 51 * If in range
50 */ 52 */
51 if (dtStart.date() >= from && dtEnd.date() <= to ) { 53 if (dtStart.date() >= from && dtEnd.date() <= to ) {
52 OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );; 54 OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );;
53 tmpList.append( eff ); 55 tmpList.append( eff );
54 } 56 }
55 } 57 }
56} 58}
57 59
58void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list, 60void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list,
59 const QDate& from, const QDate& to ) { 61 const QDate& from, const QDate& to ) {
60 QDate repeat; 62 QDate repeat;
61 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { 63 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
62 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); 64 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
63 QDate itDate = from.addDays(-dur ); 65 QDate itDate = from.addDays(-dur );
64 OPimRecurrence rec = (*it).recurrence(); 66 OPimRecurrence rec = (*it).recurrence();
65 if ( !rec.hasEndDate() || rec.endDate() > to ) { 67 if ( !rec.hasEndDate() || rec.endDate() > to ) {
66 rec.setEndDate( to ); 68 rec.setEndDate( to );
67 rec.setHasEndDate( true ); 69 rec.setHasEndDate( true );
68 } 70 }
69 71
70 QDateTime start, end; 72 QDateTime start, end;
71 while (rec.nextOcurrence(itDate, repeat ) ) { 73 while (rec.nextOcurrence(itDate, repeat ) ) {
72 if (repeat > to ) break; 74 if (repeat > to ) break;
73 75
74 OPimEvent event = *it; 76 OPimEvent event = *it;
75 start = QDateTime( repeat, event.startDateTime().time() ); 77 start = QDateTime( repeat, event.startDateTime().time() );
76 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() ); 78 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() );
77 OPimBackendOccurrence eff(start, end, event.uid() ); 79 OPimBackendOccurrence eff(start, end, event.uid() );
78 tmpList.append( eff ); 80 tmpList.append( eff );
79 } 81 }
80 } 82 }
81} 83}
82} 84}
83 85
84namespace Opie { 86namespace Opie {
85 87
86ODateBookAccessBackend::ODateBookAccessBackend() 88ODateBookAccessBackend::ODateBookAccessBackend()
87 : OPimAccessBackend<OPimEvent>() 89 : OPimAccessBackend<OPimEvent>()
88{ 90{
89 91
90} 92}
91ODateBookAccessBackend::~ODateBookAccessBackend() { 93ODateBookAccessBackend::~ODateBookAccessBackend() {
92 94
93} 95}
94OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from, 96OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from,
95 const QDate& to )const { 97 const QDate& to )const {
96 OPimBackendOccurrence::List tmpList; 98 OPimBackendOccurrence::List tmpList;
97 99
98 events( tmpList, directNonRepeats(), from, to ); 100 events( tmpList, directNonRepeats(), from, to );
99 repeat( tmpList, directRawRepeats(),from,to ); 101 repeat( tmpList, directRawRepeats(),from,to );
100 102
101 return tmpList; 103 return tmpList;
102} 104}
103 105
104OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const 106OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const
105{ 107{
106 OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() ); 108 OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
107 109
108 return filterOccurrences( day, dt ); 110 return filterOccurrences( day, dt );
109} 111}
110 112
111OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, 113OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
112 const QDate& to )const 114 const QDate& to )const
113{ 115{
114 OPimBackendOccurrence::List tmpList; 116 OPimBackendOccurrence::List tmpList;
115 OPimEvent::ValueList list = directNonRepeats(); 117 OPimEvent::ValueList list = directNonRepeats();
116 118
117 events( tmpList, list, from, to ); 119 events( tmpList, list, from, to );
118 120
119 return tmpList; 121 return tmpList;
120} 122}
121 123
122OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const 124OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const
123{ 125{
124 OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); 126 OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
125 return filterOccurrences( day,dt ); 127 return filterOccurrences( day,dt );
126} 128}
127 129
128const uint ODateBookAccessBackend::querySettings() const 130const uint ODateBookAccessBackend::querySettings() const
129{ 131{
130 return 0; 132 return 0;
131} 133}
132 134
133bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const 135bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const
134{ 136{
135 return false; 137 return false;
136} 138}
137 139
138 140
139 141
140UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, 142UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings,
141 const QDateTime& d )const 143 const QDateTime& d )const
142{ 144{
143 qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" ); 145 qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" );
144 return UIDArray(); 146 return UIDArray();
145} 147}
146 148
147UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { 149UIDArray ODateBookAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, int filter, const QArray<int>& categories )const {
148 return UIDArray(); 150 odebug << "Using Unaccelerated ODateBookAccessBackend sorted Implementation" << oendl;
151
152 Internal::OPimEventSortVector vector( ar.count(), asc, sortOrder );
153 int item = 0;
154
155 for ( uint i = 0; i < ar.count(); ++i ){
156 OPimEvent event = find( ar[i], ar, i, Frontend::Forward );
157 if ( event.isEmpty() )
158 continue;
159
160 bool catPassed = true;
161 if ( filter & ODateBookAccess::FilterCategory ){
162 catPassed = false;
163 // Filter Categories
164 for ( uint cat_idx = 0; cat_idx < categories.count(); ++cat_idx ){
165 int cat = categories[cat_idx];
166 if ( cat == -1 || cat == 0 ){
167 // Unfiled. Check next category if list is not empty.
168 // Else: take it as we will not filter unfiled events..
169 if ( !event.categories().isEmpty() )
170 continue;
171 else
172 catPassed = true;
173 } else {
174 if ( !event.categories().contains( cat ) )
175 continue;
176 else{
177 catPassed = true;
178 break;
179 }
180 }
181 }
182 }
183
184 // Continue to next event if the category filter removed this item
185 if ( !catPassed )
186 continue;
187
188 vector.insert( item++, event );
189 }
190
191 // Now sort the vector and return the list of UID's
192 vector.resize( item );
193 vector.sort();
194
195 UIDArray array( vector.count() );
196 for ( uint i= 0; i < vector.count(); i++ )
197 array[i] = vector.uidAt( i );
198
199 return array;
200
149} 201}
150 202
151OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, 203OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
152 const QDateTime& dt ) { 204 const QDateTime& dt ) {
153 OPimBackendOccurrence::List tmpList; 205 OPimBackendOccurrence::List tmpList;
154 OPimBackendOccurrence::List::ConstIterator it; 206 OPimBackendOccurrence::List::ConstIterator it;
155 207
156 for ( it = dayList.begin(); it != dayList.end(); ++it ) { 208 for ( it = dayList.begin(); it != dayList.end(); ++it ) {
157 OPimBackendOccurrence occ = *it; 209 OPimBackendOccurrence occ = *it;
158 210
159 /* 211 /*
160 * Let us find occurrences that are 'now'! 212 * Let us find occurrences that are 'now'!
161 * If the dt.date() is on the same day as start or end of the Occurrence 213 * If the dt.date() is on the same day as start or end of the Occurrence
162 * check how near start/end are. 214 * check how near start/end are.
163 * If it is in the middle of a multiday occurrence list it. 215 * If it is in the middle of a multiday occurrence list it.
164 * 216 *
165 * We might want to 'lose' the sixty second offset and list 217 * We might want to 'lose' the sixty second offset and list
166 * all Events which are active at that time. 218 * all Events which are active at that time.
167 */ 219 */
168 if ( dt.date() == occ.startDateTime().date() ) { 220 if ( dt.date() == occ.startDateTime().date() ) {
169 if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 ) 221 if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 )
170 tmpList.append( occ ); 222 tmpList.append( occ );
171 }else if ( dt.date() == occ.endDateTime().date() ) { 223 }else if ( dt.date() == occ.endDateTime().date() ) {
172 if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 ) 224 if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 )
173 tmpList.append( occ ); 225 tmpList.append( occ );
174 }else if ( dt.date() >= occ.startDateTime().date() && 226 }else if ( dt.date() >= occ.startDateTime().date() &&
175 dt.date() >= occ.endDateTime().date() ) 227 dt.date() >= occ.endDateTime().date() )
176 tmpList.append( occ ); 228 tmpList.append( occ );
177 } 229 }
178 230
179 return tmpList; 231 return tmpList;
180} 232}
181} 233}
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index 0be8606..d2e3925 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -1,76 +1,101 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_DATE_BOOK_ACCESS_H 29#ifndef OPIE_DATE_BOOK_ACCESS_H
30#define OPIE_DATE_BOOK_ACCESS_H 30#define OPIE_DATE_BOOK_ACCESS_H
31 31
32#include "odatebookaccessbackend.h" 32#include "odatebookaccessbackend.h"
33#include "opimaccesstemplate.h" 33#include "opimaccesstemplate.h"
34 34
35#include <opie2/opimevent.h> 35#include <opie2/opimevent.h>
36 36
37namespace Opie { 37namespace Opie {
38/** 38/**
39 * This is the object orientated datebook database. It'll use OBackendFactory 39 * This is the object orientated datebook database. It'll use OBackendFactory
40 * to query for a backend. 40 * to query for a backend.
41 * All access to the datebook should be done via this class. 41 * All access to the datebook should be done via this class.
42 * Make sure to load and save the datebook this is not part of 42 * Make sure to load and save the datebook this is not part of
43 * destructing and creating the object 43 * destructing and creating the object
44 * 44 *
45 * @author Holger Freyther, Stefan Eilers 45 * @author Holger Freyther, Stefan Eilers
46 */ 46 */
47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { 47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> {
48public: 48public:
49 /**
50 * Filter for sorted()
51 * @see SortFilterBase in OPimBase
52 */
53 enum SortFilter {
54
55 };
56
57 /**
58 * Sort order for sorted()
59 * @see SortOrderBase in OPimBase
60 */
61 enum SortOrder {
62 SortDescription = SortCustom,
63 SortLocation,
64 SortNote,
65 SortStartTime,
66 SortEndTime,
67 SortStartDate,
68 SortEndDate,
69 SortStartDateTime,
70 SortEndDateTime,
71 SortAlarmDateTime,
72 };
73
49 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); 74 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
50 ~ODateBookAccess(); 75 ~ODateBookAccess();
51 76
52 /* return repeating events */ 77 /* return repeating events */
53 List rawRepeats()const; 78 List rawRepeats()const;
54 79
55 /* return non repeating events */ 80 /* return non repeating events */
56 List nonRepeats()const; 81 List nonRepeats()const;
57 82
58 /* return non repeating events (from,to) */ 83 /* return non repeating events (from,to) */
59 OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; 84 OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
60 OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const; 85 OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const;
61 86
62 /** 87 /**
63 * Return identification of used records 88 * Return identification of used records
64 */ 89 */
65 int rtti() const; 90 int rtti() const;
66 91
67 92
68private: 93private:
69 ODateBookAccessBackend* m_backEnd; 94 ODateBookAccessBackend* m_backEnd;
70 class Private; 95 class Private;
71 Private* d; 96 Private* d;
72}; 97};
73 98
74} 99}
75 100
76#endif 101#endif
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
37namespace Opie {
38namespace Internal {
39
40namespace{
41
42inline 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
78OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort )
79 : OPimSortVector<OPimEvent>( size, asc, sort ) {}
80
81int 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}
diff --git a/libopie2/opiepim/private/opimeventsortvector.h b/libopie2/opiepim/private/opimeventsortvector.h
new file mode 100644
index 0000000..dde26df
--- a/dev/null
+++ b/libopie2/opiepim/private/opimeventsortvector.h
@@ -0,0 +1,48 @@
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#ifndef OPIM_CONTACT_SORT_VECTOR_H
31#define OPIM_CONTACT_SORT_VECTOR_H
32
33#include <opie2/opimevent.h>
34#include <opie2/private/opimsortvector.h>
35
36namespace Opie {
37namespace Internal {
38class OPimEventSortVector : public OPimSortVector<OPimEvent> {
39public:
40 OPimEventSortVector( uint size, bool asc, int sort );
41private:
42 int compareItems( const OPimEvent&, const OPimEvent& );
43};
44}
45}
46
47
48#endif
diff --git a/libopie2/opiepim/private/opimsortvector.h b/libopie2/opiepim/private/opimsortvector.h
index 6c21339..11a40ac 100644
--- a/libopie2/opiepim/private/opimsortvector.h
+++ b/libopie2/opiepim/private/opimsortvector.h
@@ -1,138 +1,172 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org> 3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OPIE_PIM_SORT_VECTOR_H 30#ifndef OPIE_PIM_SORT_VECTOR_H
31#define OPIE_PIM_SORT_VECTOR_H 31#define OPIE_PIM_SORT_VECTOR_H
32 32
33#include <opie2/opimglobal.h> 33#include <opie2/opimglobal.h>
34 34
35#include <qvector.h> 35#include <qvector.h>
36 36
37namespace Opie { 37namespace Opie {
38namespace Internal { 38namespace Internal {
39template<class T> 39template<class T>
40struct OPimSortVectorContainer { 40struct OPimSortVectorContainer {
41 T item; 41 T item;
42}; 42};
43 43
44template<class T> 44template<class T>
45class OPimSortVector : public QVector<OPimSortVectorContainer<T> > { 45class OPimSortVector : public QVector<OPimSortVectorContainer<T> > {
46 typedef OPimSortVectorContainer<T> VectorItem; 46 typedef OPimSortVectorContainer<T> VectorItem;
47public: 47public:
48 OPimSortVector( uint size, bool asc, int sort ); 48 OPimSortVector( uint size, bool asc, int sort );
49 int compareItems( QCollection::Item d1, QCollection::Item d2 ); 49 int compareItems( QCollection::Item d1, QCollection::Item d2 );
50 bool insert( uint, const T& t ); 50 bool insert( uint, const T& t );
51 UID uidAt( uint i )const; 51 UID uidAt( uint i )const;
52 52
53protected: 53protected:
54 int testString( const QString&, const QString& )const; 54 int testString( const QString&, const QString& )const;
55 int testDate( const QDate&, const QDate& )const; 55 int testDate( const QDate&, const QDate& )const;
56 int testTime( const QTime&, const QTime& )const;
57 int testDateTime( const QDateTime& left,
58 const QDateTime& right )const;
56protected: 59protected:
57 bool sortAscending()const; 60 bool sortAscending()const;
58 int sortOrder()const; 61 int sortOrder()const;
59 62
60private: 63private:
61 bool m_ascending : 1; 64 bool m_ascending : 1;
62 int m_sort; 65 int m_sort;
63 virtual int compareItems( const T& item1, const T& item2 ) = 0; 66 virtual int compareItems( const T& item1, const T& item2 ) = 0;
64}; 67};
65 68
66template<class T> 69template<class T>
67OPimSortVector<T>::OPimSortVector( uint size, bool asc, int sort ) 70OPimSortVector<T>::OPimSortVector( uint size, bool asc, int sort )
68 : QVector<VectorItem>( size ), m_ascending( asc ), 71 : QVector<VectorItem>( size ), m_ascending( asc ),
69 m_sort( sort ) { 72 m_sort( sort ) {
70 this->setAutoDelete( true ); 73 this->setAutoDelete( true );
71} 74}
72 75
73/** 76/**
74 * Returns: 77 * Returns:
75 * 0 if item1 == item2 78 * 0 if item1 == item2
76 * 79 *
77 * non-zero if item1 != item2 80 * non-zero if item1 != item2
78 * 81 *
79 * This function returns int rather than bool so that reimplementations 82 * This function returns int rather than bool so that reimplementations
80 * can return one of three values and use it to sort by: 83 * can return one of three values and use it to sort by:
81 * 84 *
82 * 0 if item1 == item2 85 * 0 if item1 == item2
83 * 86 *
84 * > 0 (positive integer) if item1 > item2 87 * > 0 (positive integer) if item1 > item2
85 * 88 *
86 * < 0 (negative integer) if item1 < item2 89 * < 0 (negative integer) if item1 < item2
87 * 90 *
88 */ 91 */
89template<class T> 92template<class T>
90int OPimSortVector<T>::compareItems( QCollection::Item d1, QCollection::Item d2 ) { 93int OPimSortVector<T>::compareItems( QCollection::Item d1, QCollection::Item d2 ) {
91 return compareItems( ((VectorItem*)d1)->item, 94 return compareItems( ((VectorItem*)d1)->item,
92 ((VectorItem*)d2)->item ); 95 ((VectorItem*)d2)->item );
93} 96}
94 97
95template<class T> 98template<class T>
96bool OPimSortVector<T>::sortAscending()const { 99bool OPimSortVector<T>::sortAscending()const {
97 return m_ascending; 100 return m_ascending;
98} 101}
99 102
100template<class T> 103template<class T>
101int OPimSortVector<T>::sortOrder()const { 104int OPimSortVector<T>::sortOrder()const {
102 return m_sort; 105 return m_sort;
103} 106}
104 107
105template<class T> 108template<class T>
106bool OPimSortVector<T>::insert( uint i, const T& record ) { 109bool OPimSortVector<T>::insert( uint i, const T& record ) {
107 VectorItem *item = new VectorItem; 110 VectorItem *item = new VectorItem;
108 item->item = record; 111 item->item = record;
109 return QVector<VectorItem>::insert( i, item ); 112 return QVector<VectorItem>::insert( i, item );
110} 113}
111 114
112template<class T> 115template<class T>
113UID OPimSortVector<T>::uidAt( uint index )const { 116UID OPimSortVector<T>::uidAt( uint index )const {
114 return this->at( index )->item.uid(); 117 return this->at( index )->item.uid();
115} 118}
116 119
117template<class T> 120template<class T>
118inline int OPimSortVector<T>::testString( const QString& left, 121inline int OPimSortVector<T>::testString( const QString& left,
119 const QString& right )const { 122 const QString& right )const {
120 return QString::compare( left, right ); 123 return QString::compare( left, right );
121} 124}
122 125
126
123template<class T> 127template<class T>
124inline int OPimSortVector<T>::testDate( const QDate& left, 128inline int OPimSortVector<T>::testDate( const QDate& left,
125 const QDate& right )const { 129 const QDate& right )const {
126 int ret = 0; 130 int ret = 0;
127 if ( !left .isValid() ) ret++; 131 if ( !left .isValid() ) ret++;
128 if ( !right.isValid() ) ret--; 132 if ( !right.isValid() ) ret--;
129 133
130 if ( left.isValid() && right.isValid() ) 134 if ( left.isValid() && right.isValid() )
131 ret += left < right ? -1 : 1; 135 ret += left < right ? -1 : 1;
132 136
133 return ret; 137 return ret;
134} 138}
139
140template<class T>
141inline int OPimSortVector<T>::testTime( const QTime& left,
142 const QTime& right )const {
143 int ret = 0;
144 if ( !left .isValid() ) ret++;
145 if ( !right.isValid() ) ret--;
146
147 if ( left.isValid() && right.isValid() ){
148 ret += left < right ? -1 : 1;
149 }
150
151 return ret;
152}
153
154template<class T>
155inline int OPimSortVector<T>::testDateTime( const QDateTime& left,
156 const QDateTime& right )const {
157 int ret = 0;
158 if ( !left .isValid() ) ret++;
159 if ( !right.isValid() ) ret--;
160
161 if ( left.isValid() && right.isValid() ){
162 ret += left < right ? -1 : 1;
163 }
164
165 return ret;
166
167}
168
135} 169}
136} 170}
137 171
138#endif 172#endif
diff --git a/libopie2/opiepim/private/opimtodosortvector.cpp b/libopie2/opiepim/private/opimtodosortvector.cpp
index 8d15710..1db20df 100644
--- a/libopie2/opiepim/private/opimtodosortvector.cpp
+++ b/libopie2/opiepim/private/opimtodosortvector.cpp
@@ -1,163 +1,165 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org> 3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimtodosortvector.h" 30#include "opimtodosortvector.h"
31#include <opie2/otodoaccess.h> 31#include <opie2/otodoaccess.h>
32 32
33namespace Opie { 33namespace Opie {
34namespace Internal { 34namespace Internal {
35 35
36namespace{
36inline QString string( const OPimTodo& todo) { 37inline QString string( const OPimTodo& todo) {
37 return todo.summary().isEmpty() ? 38 return todo.summary().isEmpty() ?
38 todo.description().left(20 ) : 39 todo.description().left(20 ) :
39 todo.summary(); 40 todo.summary();
40} 41}
41 42
42inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) { 43inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) {
43 int ret = 0; 44 int ret = 0;
44 if ( todo1.isCompleted() ) ret++; 45 if ( todo1.isCompleted() ) ret++;
45 if ( todo2.isCompleted() ) ret--; 46 if ( todo2.isCompleted() ) ret--;
46 return ret; 47 return ret;
47} 48}
48 49
49inline int priority( const OPimTodo& t1, const OPimTodo& t2) { 50inline int priority( const OPimTodo& t1, const OPimTodo& t2) {
50 return ( t1.priority() - t2.priority() ); 51 return ( t1.priority() - t2.priority() );
51} 52}
52 53
53inline int summary( const OPimTodo& t1, const OPimTodo& t2) { 54inline int summary( const OPimTodo& t1, const OPimTodo& t2) {
54 return QString::compare( string(t1), string(t2) ); 55 return QString::compare( string(t1), string(t2) );
55} 56}
56 57
57inline int deadline( const OPimTodo& t1, const OPimTodo& t2) { 58inline int deadline( const OPimTodo& t1, const OPimTodo& t2) {
58 int ret = 0; 59 int ret = 0;
59 if ( t1.hasDueDate() && 60 if ( t1.hasDueDate() &&
60 t2.hasDueDate() ) 61 t2.hasDueDate() )
61 ret = t2.dueDate().daysTo( t1.dueDate() ); 62 ret = t2.dueDate().daysTo( t1.dueDate() );
62 else if ( t1.hasDueDate() ) 63 else if ( t1.hasDueDate() )
63 ret = -1; 64 ret = -1;
64 else if ( t2.hasDueDate() ) 65 else if ( t2.hasDueDate() )
65 ret = 1; 66 ret = 1;
66 else 67 else
67 ret = 0; 68 ret = 0;
68 69
69 return ret; 70 return ret;
70} 71}
71 72
73}
72 74
73OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort ) 75OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort )
74 : OPimSortVector<OPimTodo>( size, asc, sort ) 76 : OPimSortVector<OPimTodo>( size, asc, sort )
75{} 77{}
76 78
77int OPimTodoSortVector::compareItems( const OPimTodo& con1, const OPimTodo& con2 ) { 79int OPimTodoSortVector::compareItems( const OPimTodo& con1, const OPimTodo& con2 ) {
78 bool seComp, sePrio, seSum, seDeadline; 80 bool seComp, sePrio, seSum, seDeadline;
79 seComp = sePrio = seDeadline = seSum = false; 81 seComp = sePrio = seDeadline = seSum = false;
80 int ret =0; 82 int ret =0;
81 bool asc = sortAscending(); 83 bool asc = sortAscending();
82 84
83 /* same item */ 85 /* same item */
84 if ( con1.uid() == con2.uid() ) 86 if ( con1.uid() == con2.uid() )
85 return 0; 87 return 0;
86 88
87 switch ( sortOrder() ) { 89 switch ( sortOrder() ) {
88 case OPimTodoAccess::Completed: { 90 case OPimTodoAccess::Completed: {
89 ret = completed( con1, con2 ); 91 ret = completed( con1, con2 );
90 seComp = TRUE; 92 seComp = TRUE;
91 break; 93 break;
92 } 94 }
93 case OPimTodoAccess::Priority: { 95 case OPimTodoAccess::Priority: {
94 ret = priority( con1, con2 ); 96 ret = priority( con1, con2 );
95 sePrio = TRUE; 97 sePrio = TRUE;
96 break; 98 break;
97 } 99 }
98 case OPimTodoAccess::SortSummary: { 100 case OPimTodoAccess::SortSummary: {
99 ret = summary( con1, con2 ); 101 ret = summary( con1, con2 );
100 seSum = TRUE; 102 seSum = TRUE;
101 break; 103 break;
102 } 104 }
103 case OPimTodoAccess::SortByDate: 105 case OPimTodoAccess::SortByDate:
104 case OPimTodoAccess::Deadline: { 106 case OPimTodoAccess::Deadline: {
105 ret = deadline( con1, con2 ); 107 ret = deadline( con1, con2 );
106 seDeadline = TRUE; 108 seDeadline = TRUE;
107 break; 109 break;
108 } 110 }
109 default: 111 default:
110 ret = 0; 112 ret = 0;
111 break; 113 break;
112 }; 114 };
113 /* 115 /*
114 * FIXME do better sorting if the first sort criteria 116 * FIXME do better sorting if the first sort criteria
115 * ret equals 0 start with complete and so on... 117 * ret equals 0 start with complete and so on...
116 */ 118 */
117 119
118 /* twist it we're not ascending*/ 120 /* twist it we're not ascending*/
119 if (!asc) 121 if (!asc)
120 ret = ret * -1; 122 ret = ret * -1;
121 123
122 if ( ret ) 124 if ( ret )
123 return ret; 125 return ret;
124 126
125 // default did not gave difference let's try it other way around 127 // default did not gave difference let's try it other way around
126 /* 128 /*
127 * General try if already checked if not test 129 * General try if already checked if not test
128 * and return 130 * and return
129 * 1.Completed 131 * 1.Completed
130 * 2.Priority 132 * 2.Priority
131 * 3.Description 133 * 3.Description
132 * 4.DueDate 134 * 4.DueDate
133 */ 135 */
134 if (!seComp ) { 136 if (!seComp ) {
135 if ( (ret = completed( con1, con2 ) ) ) { 137 if ( (ret = completed( con1, con2 ) ) ) {
136 if (!asc ) ret *= -1; 138 if (!asc ) ret *= -1;
137 return ret; 139 return ret;
138 } 140 }
139 } 141 }
140 if (!sePrio ) { 142 if (!sePrio ) {
141 if ( (ret = priority( con1, con2 ) ) ) { 143 if ( (ret = priority( con1, con2 ) ) ) {
142 if (!asc ) ret *= -1; 144 if (!asc ) ret *= -1;
143 return ret; 145 return ret;
144 } 146 }
145 } 147 }
146 if (!seSum ) { 148 if (!seSum ) {
147 if ( (ret = summary(con1, con2 ) ) ) { 149 if ( (ret = summary(con1, con2 ) ) ) {
148 if (!asc) ret *= -1; 150 if (!asc) ret *= -1;
149 return ret; 151 return ret;
150 } 152 }
151 } 153 }
152 if (!seDeadline) { 154 if (!seDeadline) {
153 if ( (ret = deadline( con1, con2 ) ) ) { 155 if ( (ret = deadline( con1, con2 ) ) ) {
154 if (!asc) ret *= -1; 156 if (!asc) ret *= -1;
155 return ret; 157 return ret;
156 } 158 }
157 } 159 }
158 160
159 return 0; 161 return 0;
160} 162}
161 163
162} 164}
163} 165}
diff --git a/libopie2/opiepim/private/private.pro b/libopie2/opiepim/private/private.pro
index 618c2d6..92c24cb 100644
--- a/libopie2/opiepim/private/private.pro
+++ b/libopie2/opiepim/private/private.pro
@@ -1,9 +1,11 @@
1HEADERS += private/vobject_p.h \ 1HEADERS += private/vobject_p.h \
2 private/opimcontactsortvector.h \ 2 private/opimcontactsortvector.h \
3 private/opimeventsortvector.h \
3 private/opimoccurrence_p.h \ 4 private/opimoccurrence_p.h \
4 private/opimsortvector.h \ 5 private/opimsortvector.h \
5 private/opimtodosortvector.h 6 private/opimtodosortvector.h
6 7
7SOURCES += private/opimcontactsortvector.cpp \ 8SOURCES += private/opimcontactsortvector.cpp \
9 private/opimeventsortvector.cpp \
8 private/opimtodosortvector.cpp 10 private/opimtodosortvector.cpp
9 11