Diffstat (limited to 'libopie/pim/ocontactaccessbackend_xml.h') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.h | 89 |
1 files changed, 80 insertions, 9 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h index c765ff5..c6e6cbc 100644 --- a/libopie/pim/ocontactaccessbackend_xml.h +++ b/libopie/pim/ocontactaccessbackend_xml.h | |||
@@ -14,12 +14,16 @@ | |||
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.10 2003/01/02 14:27:12 eilers | ||
21 | * Improved query by example: Search by date is possible.. First step | ||
22 | * for a today plugin for birthdays.. | ||
23 | * | ||
20 | * Revision 1.9 2002/12/08 12:48:57 eilers | 24 | * Revision 1.9 2002/12/08 12:48:57 eilers |
21 | * Moved journal-enum from ocontact into i the xml-backend.. | 25 | * Moved journal-enum from ocontact into i the xml-backend.. |
22 | * | 26 | * |
23 | * Revision 1.8 2002/11/14 17:04:24 eilers | 27 | * Revision 1.8 2002/11/14 17:04:24 eilers |
24 | * Sorting will now work if fullname is identical on some entries | 28 | * Sorting will now work if fullname is identical on some entries |
25 | * | 29 | * |
@@ -57,12 +61,13 @@ | |||
57 | #include <qdatetime.h> | 61 | #include <qdatetime.h> |
58 | #include <qfile.h> | 62 | #include <qfile.h> |
59 | #include <qfileinfo.h> | 63 | #include <qfileinfo.h> |
60 | #include <qregexp.h> | 64 | #include <qregexp.h> |
61 | #include <qarray.h> | 65 | #include <qarray.h> |
62 | #include <qmap.h> | 66 | #include <qmap.h> |
67 | #include <qdatetime.h> | ||
63 | 68 | ||
64 | #include <qpe/global.h> | 69 | #include <qpe/global.h> |
65 | 70 | ||
66 | #include <opie/xmltree.h> | 71 | #include <opie/xmltree.h> |
67 | #include "ocontactaccessbackend.h" | 72 | #include "ocontactaccessbackend.h" |
68 | #include "ocontactaccess.h" | 73 | #include "ocontactaccess.h" |
@@ -222,17 +227,67 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
222 | uint arraycounter = 0; | 227 | uint arraycounter = 0; |
223 | 228 | ||
224 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 229 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
225 | /* Search all fields and compare them with query object. Store them into list | 230 | /* Search all fields and compare them with query object. Store them into list |
226 | * if all fields matches. | 231 | * if all fields matches. |
227 | */ | 232 | */ |
233 | QDate* queryDate = 0l; | ||
234 | QDate* checkDate = 0l; | ||
228 | bool allcorrect = true; | 235 | bool allcorrect = true; |
229 | for ( int i = 0; i < Qtopia::rid; i++ ) { | 236 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
237 | // Birthday and anniversary are special nonstring fields and should | ||
238 | // be handled especially | ||
239 | switch ( i ){ | ||
240 | case Qtopia::Birthday: | ||
241 | queryDate = new QDate( query.birthday() ); | ||
242 | checkDate = new QDate( (*it).birthday() ); | ||
243 | case Qtopia::Anniversary: | ||
244 | if ( queryDate == 0l ){ | ||
245 | queryDate = new QDate( query.anniversary() ); | ||
246 | checkDate = new QDate( (*it).anniversary() ); | ||
247 | } | ||
248 | |||
249 | if ( queryDate->isValid() ){ | ||
250 | if ( settings & OContactAccess::DateYear ){ | ||
251 | if ( queryDate->year() != checkDate->year() ) | ||
252 | allcorrect = false; | ||
253 | } | ||
254 | if ( settings & OContactAccess::DateMonth ){ | ||
255 | if ( queryDate->month() != checkDate->month() ) | ||
256 | allcorrect = false; | ||
257 | } | ||
258 | if ( settings & OContactAccess::DateDay ){ | ||
259 | if ( queryDate->day() != checkDate->day() ) | ||
260 | allcorrect = false; | ||
261 | } | ||
262 | if ( settings & OContactAccess::DateDiff ) { | ||
263 | QDate current = QDate::currentDate(); | ||
264 | if ( current.daysTo( *queryDate ) > 0 ){ | ||
265 | if ( !( ( *checkDate >= current ) && | ||
266 | ( *checkDate <= *queryDate ) ) ) | ||
267 | allcorrect = false; | ||
268 | } | ||
269 | } | ||
270 | } | ||
271 | |||
272 | delete queryDate; | ||
273 | queryDate = 0l; | ||
274 | delete checkDate; | ||
275 | checkDate = 0l; | ||
276 | break; | ||
277 | default: | ||
230 | /* Just compare fields which are not empty in the query object */ | 278 | /* Just compare fields which are not empty in the query object */ |
231 | if ( !query.field(i).isEmpty() ){ | 279 | if ( !query.field(i).isEmpty() ){ |
232 | switch ( settings & ~OContactAccess::IgnoreCase ){ | 280 | switch ( settings & ~( OContactAccess::IgnoreCase |
281 | | OContactAccess::DateDiff | ||
282 | | OContactAccess::DateYear | ||
283 | | OContactAccess::DateMonth | ||
284 | | OContactAccess::DateDay | ||
285 | | OContactAccess::MatchOne | ||
286 | ) ){ | ||
287 | |||
233 | case OContactAccess::RegExp:{ | 288 | case OContactAccess::RegExp:{ |
234 | QRegExp expr ( query.field(i), | 289 | QRegExp expr ( query.field(i), |
235 | !(settings & OContactAccess::IgnoreCase), | 290 | !(settings & OContactAccess::IgnoreCase), |
236 | false ); | 291 | false ); |
237 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 292 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) |
238 | allcorrect = false; | 293 | allcorrect = false; |
@@ -257,12 +312,13 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
257 | } | 312 | } |
258 | } | 313 | } |
259 | break; | 314 | break; |
260 | } | 315 | } |
261 | } | 316 | } |
262 | } | 317 | } |
318 | } | ||
263 | if ( allcorrect ){ | 319 | if ( allcorrect ){ |
264 | m_currentQuery[arraycounter++] = (*it).uid(); | 320 | m_currentQuery[arraycounter++] = (*it).uid(); |
265 | } | 321 | } |
266 | } | 322 | } |
267 | 323 | ||
268 | // Shrink to fit.. | 324 | // Shrink to fit.. |
@@ -288,24 +344,39 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
288 | return m_currentQuery; | 344 | return m_currentQuery; |
289 | } | 345 | } |
290 | 346 | ||
291 | const uint querySettings() | 347 | const uint querySettings() |
292 | { | 348 | { |
293 | return ( OContactAccess::WildCards | 349 | return ( OContactAccess::WildCards |
294 | & OContactAccess::IgnoreCase | 350 | | OContactAccess::IgnoreCase |
295 | & OContactAccess::RegExp | 351 | | OContactAccess::RegExp |
296 | & OContactAccess::ExactMatch ); | 352 | | OContactAccess::ExactMatch |
353 | | OContactAccess::DateDiff | ||
354 | | OContactAccess::DateYear | ||
355 | | OContactAccess::DateMonth | ||
356 | | OContactAccess::DateDay | ||
357 | ); | ||
297 | } | 358 | } |
298 | 359 | ||
299 | bool hasQuerySettings (uint querySettings) const | 360 | bool hasQuerySettings (uint querySettings) const |
300 | { | 361 | { |
301 | /* OContactAccess::IgnoreCase may be added with one | 362 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
302 | * of the other settings, but never used alone. | 363 | * may be added with any of the other settings. IgnoreCase should never used alone. |
303 | * The other settings are just valid alone... | 364 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
304 | */ | 365 | */ |
305 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ | 366 | |
367 | if ( querySettings == OContactAccess::IgnoreCase ) | ||
368 | return false; | ||
369 | |||
370 | switch ( querySettings & ~( OContactAccess::IgnoreCase | ||
371 | | OContactAccess::DateDiff | ||
372 | | OContactAccess::DateYear | ||
373 | | OContactAccess::DateMonth | ||
374 | | OContactAccess::DateDay | ||
375 | ) | ||
376 | ){ | ||
306 | case OContactAccess::RegExp: | 377 | case OContactAccess::RegExp: |
307 | return ( true ); | 378 | return ( true ); |
308 | case OContactAccess::WildCards: | 379 | case OContactAccess::WildCards: |
309 | return ( true ); | 380 | return ( true ); |
310 | case OContactAccess::ExactMatch: | 381 | case OContactAccess::ExactMatch: |
311 | return ( true ); | 382 | return ( true ); |