author | eilers <eilers> | 2003-03-21 12:26:28 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-03-21 12:26:28 (UTC) |
commit | 6d066b0ed3fd7fbedce84616a8fa279eec480f13 (patch) (unidiff) | |
tree | e4da9ca6c25236a72bd88f58876c1814bfbd174d | |
parent | 8136284c38384b169cd2843ee61480d45b6c1cba (diff) | |
download | opie-6d066b0ed3fd7fbedce84616a8fa279eec480f13.zip opie-6d066b0ed3fd7fbedce84616a8fa279eec480f13.tar.gz opie-6d066b0ed3fd7fbedce84616a8fa279eec480f13.tar.bz2 |
Fixing small bug: If we search a birthday from today to today, it returned
every contact ..
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.cpp | 6 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp index 4abf4d9..9fe3d1e 100644 --- a/libopie/pim/ocontactaccessbackend_xml.cpp +++ b/libopie/pim/ocontactaccessbackend_xml.cpp | |||
@@ -1,83 +1,87 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.3 2003/03/21 12:26:28 eilers | ||
21 | * Fixing small bug: If we search a birthday from today to today, it returned | ||
22 | * every contact .. | ||
23 | * | ||
20 | * Revision 1.2 2003/03/21 10:33:09 eilers | 24 | * Revision 1.2 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 25 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 26 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 27 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 28 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 29 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 30 | * the binaries for today-addressbook. |
27 | * | 31 | * |
28 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 32 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
29 | * Speed optimization. Removed the sequential search loops. | 33 | * Speed optimization. Removed the sequential search loops. |
30 | * | 34 | * |
31 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 35 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
32 | * Writing offsets to debug output.. | 36 | * Writing offsets to debug output.. |
33 | * | 37 | * |
34 | * Revision 1.1 2003/02/09 15:05:01 eilers | 38 | * Revision 1.1 2003/02/09 15:05:01 eilers |
35 | * Nothing happened.. Just some cleanup before I will start.. | 39 | * Nothing happened.. Just some cleanup before I will start.. |
36 | * | 40 | * |
37 | * Revision 1.12 2003/01/03 16:58:03 eilers | 41 | * Revision 1.12 2003/01/03 16:58:03 eilers |
38 | * Reenable debug output | 42 | * Reenable debug output |
39 | * | 43 | * |
40 | * Revision 1.11 2003/01/03 12:31:28 eilers | 44 | * Revision 1.11 2003/01/03 12:31:28 eilers |
41 | * Bugfix for calculating data diffs.. | 45 | * Bugfix for calculating data diffs.. |
42 | * | 46 | * |
43 | * Revision 1.10 2003/01/02 14:27:12 eilers | 47 | * Revision 1.10 2003/01/02 14:27:12 eilers |
44 | * Improved query by example: Search by date is possible.. First step | 48 | * Improved query by example: Search by date is possible.. First step |
45 | * for a today plugin for birthdays.. | 49 | * for a today plugin for birthdays.. |
46 | * | 50 | * |
47 | * Revision 1.9 2002/12/08 12:48:57 eilers | 51 | * Revision 1.9 2002/12/08 12:48:57 eilers |
48 | * Moved journal-enum from ocontact into i the xml-backend.. | 52 | * Moved journal-enum from ocontact into i the xml-backend.. |
49 | * | 53 | * |
50 | * Revision 1.8 2002/11/14 17:04:24 eilers | 54 | * Revision 1.8 2002/11/14 17:04:24 eilers |
51 | * Sorting will now work if fullname is identical on some entries | 55 | * Sorting will now work if fullname is identical on some entries |
52 | * | 56 | * |
53 | * Revision 1.7 2002/11/13 15:02:46 eilers | 57 | * Revision 1.7 2002/11/13 15:02:46 eilers |
54 | * Small Bug in sorted fixed | 58 | * Small Bug in sorted fixed |
55 | * | 59 | * |
56 | * Revision 1.6 2002/11/13 14:14:51 eilers | 60 | * Revision 1.6 2002/11/13 14:14:51 eilers |
57 | * Added sorted for Contacts.. | 61 | * Added sorted for Contacts.. |
58 | * | 62 | * |
59 | * Revision 1.5 2002/11/01 15:10:42 eilers | 63 | * Revision 1.5 2002/11/01 15:10:42 eilers |
60 | * Added regExp-search in database for all fields in a contact. | 64 | * Added regExp-search in database for all fields in a contact. |
61 | * | 65 | * |
62 | * Revision 1.4 2002/10/16 10:52:40 eilers | 66 | * Revision 1.4 2002/10/16 10:52:40 eilers |
63 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 67 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
64 | * | 68 | * |
65 | * Revision 1.3 2002/10/14 16:21:54 eilers | 69 | * Revision 1.3 2002/10/14 16:21:54 eilers |
66 | * Some minor interface updates | 70 | * Some minor interface updates |
67 | * | 71 | * |
68 | * Revision 1.2 2002/10/07 17:34:24 eilers | 72 | * Revision 1.2 2002/10/07 17:34:24 eilers |
69 | * added OBackendFactory for advanced backend access | 73 | * added OBackendFactory for advanced backend access |
70 | * | 74 | * |
71 | * Revision 1.1 2002/09/27 17:11:44 eilers | 75 | * Revision 1.1 2002/09/27 17:11:44 eilers |
72 | * Added API for accessing the Contact-Database ! It is compiling, but | 76 | * Added API for accessing the Contact-Database ! It is compiling, but |
73 | * please do not expect that anything is working ! | 77 | * please do not expect that anything is working ! |
74 | * I will debug that stuff in the next time .. | 78 | * I will debug that stuff in the next time .. |
75 | * Please read README_COMPILE for compiling ! | 79 | * Please read README_COMPILE for compiling ! |
76 | * | 80 | * |
77 | * | 81 | * |
78 | */ | 82 | */ |
79 | 83 | ||
80 | #include "ocontactaccessbackend_xml.h" | 84 | #include "ocontactaccessbackend_xml.h" |
81 | 85 | ||
82 | #include <qasciidict.h> | 86 | #include <qasciidict.h> |
83 | #include <qdatetime.h> | 87 | #include <qdatetime.h> |
@@ -264,129 +268,129 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
264 | QListIterator<OContact> it( m_contactList ); | 268 | QListIterator<OContact> it( m_contactList ); |
265 | uint arraycounter = 0; | 269 | uint arraycounter = 0; |
266 | 270 | ||
267 | for( ; it.current(); ++it ){ | 271 | for( ; it.current(); ++it ){ |
268 | /* Search all fields and compare them with query object. Store them into list | 272 | /* Search all fields and compare them with query object. Store them into list |
269 | * if all fields matches. | 273 | * if all fields matches. |
270 | */ | 274 | */ |
271 | QDate* queryDate = 0l; | 275 | QDate* queryDate = 0l; |
272 | QDate* checkDate = 0l; | 276 | QDate* checkDate = 0l; |
273 | bool allcorrect = true; | 277 | bool allcorrect = true; |
274 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 278 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
275 | // Birthday and anniversary are special nonstring fields and should | 279 | // Birthday and anniversary are special nonstring fields and should |
276 | // be handled specially | 280 | // be handled specially |
277 | switch ( i ){ | 281 | switch ( i ){ |
278 | case Qtopia::Birthday: | 282 | case Qtopia::Birthday: |
279 | queryDate = new QDate( query.birthday() ); | 283 | queryDate = new QDate( query.birthday() ); |
280 | checkDate = new QDate( (*it)->birthday() ); | 284 | checkDate = new QDate( (*it)->birthday() ); |
281 | case Qtopia::Anniversary: | 285 | case Qtopia::Anniversary: |
282 | if ( queryDate == 0l ){ | 286 | if ( queryDate == 0l ){ |
283 | queryDate = new QDate( query.anniversary() ); | 287 | queryDate = new QDate( query.anniversary() ); |
284 | checkDate = new QDate( (*it)->anniversary() ); | 288 | checkDate = new QDate( (*it)->anniversary() ); |
285 | } | 289 | } |
286 | 290 | ||
287 | if ( queryDate->isValid() ){ | 291 | if ( queryDate->isValid() ){ |
288 | if( checkDate->isValid() ){ | 292 | if( checkDate->isValid() ){ |
289 | if ( settings & OContactAccess::DateYear ){ | 293 | if ( settings & OContactAccess::DateYear ){ |
290 | if ( queryDate->year() != checkDate->year() ) | 294 | if ( queryDate->year() != checkDate->year() ) |
291 | allcorrect = false; | 295 | allcorrect = false; |
292 | } | 296 | } |
293 | if ( settings & OContactAccess::DateMonth ){ | 297 | if ( settings & OContactAccess::DateMonth ){ |
294 | if ( queryDate->month() != checkDate->month() ) | 298 | if ( queryDate->month() != checkDate->month() ) |
295 | allcorrect = false; | 299 | allcorrect = false; |
296 | } | 300 | } |
297 | if ( settings & OContactAccess::DateDay ){ | 301 | if ( settings & OContactAccess::DateDay ){ |
298 | if ( queryDate->day() != checkDate->day() ) | 302 | if ( queryDate->day() != checkDate->day() ) |
299 | allcorrect = false; | 303 | allcorrect = false; |
300 | } | 304 | } |
301 | if ( settings & OContactAccess::DateDiff ) { | 305 | if ( settings & OContactAccess::DateDiff ) { |
302 | QDate current; | 306 | QDate current; |
303 | // If we get an additional date, we | 307 | // If we get an additional date, we |
304 | // will take this date instead of | 308 | // will take this date instead of |
305 | // the current one.. | 309 | // the current one.. |
306 | if ( !d.date().isValid() ) | 310 | if ( !d.date().isValid() ) |
307 | current = QDate::currentDate(); | 311 | current = QDate::currentDate(); |
308 | else | 312 | else |
309 | current = d.date(); | 313 | current = d.date(); |
310 | 314 | ||
311 | // We have to equalize the year, otherwise | 315 | // We have to equalize the year, otherwise |
312 | // the search will fail.. | 316 | // the search will fail.. |
313 | checkDate->setYMD( current.year(), | 317 | checkDate->setYMD( current.year(), |
314 | checkDate->month(), | 318 | checkDate->month(), |
315 | checkDate->day() ); | 319 | checkDate->day() ); |
316 | if ( *checkDate < current ) | 320 | if ( *checkDate < current ) |
317 | checkDate->setYMD( current.year()+1, | 321 | checkDate->setYMD( current.year()+1, |
318 | checkDate->month(), | 322 | checkDate->month(), |
319 | checkDate->day() ); | 323 | checkDate->day() ); |
320 | 324 | ||
321 | // Check whether the birthday/anniversary date is between | 325 | // Check whether the birthday/anniversary date is between |
322 | // the current/given date and the maximum date | 326 | // the current/given date and the maximum date |
323 | // ( maximum time range ) ! | 327 | // ( maximum time range ) ! |
324 | qWarning("Checking if %s is between %s and %s ! ", | 328 | qWarning("Checking if %s is between %s and %s ! ", |
325 | checkDate->toString().latin1(), | 329 | checkDate->toString().latin1(), |
326 | current.toString().latin1(), | 330 | current.toString().latin1(), |
327 | queryDate->toString().latin1() ); | 331 | queryDate->toString().latin1() ); |
328 | if ( current.daysTo( *queryDate ) > 0 ){ | 332 | if ( current.daysTo( *queryDate ) >= 0 ){ |
329 | if ( !( ( *checkDate >= current ) && | 333 | if ( !( ( *checkDate >= current ) && |
330 | ( *checkDate <= *queryDate ) ) ){ | 334 | ( *checkDate <= *queryDate ) ) ){ |
331 | allcorrect = false; | 335 | allcorrect = false; |
332 | qWarning (" Nope!.."); | 336 | qWarning (" Nope!.."); |
333 | } | 337 | } |
334 | } | 338 | } |
335 | } | 339 | } |
336 | } else{ | 340 | } else{ |
337 | // checkDate is invalid. Therefore this entry is always rejected | 341 | // checkDate is invalid. Therefore this entry is always rejected |
338 | allcorrect = false; | 342 | allcorrect = false; |
339 | } | 343 | } |
340 | } | 344 | } |
341 | 345 | ||
342 | delete queryDate; | 346 | delete queryDate; |
343 | queryDate = 0l; | 347 | queryDate = 0l; |
344 | delete checkDate; | 348 | delete checkDate; |
345 | checkDate = 0l; | 349 | checkDate = 0l; |
346 | break; | 350 | break; |
347 | default: | 351 | default: |
348 | /* Just compare fields which are not empty in the query object */ | 352 | /* Just compare fields which are not empty in the query object */ |
349 | if ( !query.field(i).isEmpty() ){ | 353 | if ( !query.field(i).isEmpty() ){ |
350 | switch ( settings & ~( OContactAccess::IgnoreCase | 354 | switch ( settings & ~( OContactAccess::IgnoreCase |
351 | | OContactAccess::DateDiff | 355 | | OContactAccess::DateDiff |
352 | | OContactAccess::DateYear | 356 | | OContactAccess::DateYear |
353 | | OContactAccess::DateMonth | 357 | | OContactAccess::DateMonth |
354 | | OContactAccess::DateDay | 358 | | OContactAccess::DateDay |
355 | | OContactAccess::MatchOne | 359 | | OContactAccess::MatchOne |
356 | ) ){ | 360 | ) ){ |
357 | 361 | ||
358 | case OContactAccess::RegExp:{ | 362 | case OContactAccess::RegExp:{ |
359 | QRegExp expr ( query.field(i), | 363 | QRegExp expr ( query.field(i), |
360 | !(settings & OContactAccess::IgnoreCase), | 364 | !(settings & OContactAccess::IgnoreCase), |
361 | false ); | 365 | false ); |
362 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 366 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
363 | allcorrect = false; | 367 | allcorrect = false; |
364 | } | 368 | } |
365 | break; | 369 | break; |
366 | case OContactAccess::WildCards:{ | 370 | case OContactAccess::WildCards:{ |
367 | QRegExp expr ( query.field(i), | 371 | QRegExp expr ( query.field(i), |
368 | !(settings & OContactAccess::IgnoreCase), | 372 | !(settings & OContactAccess::IgnoreCase), |
369 | true ); | 373 | true ); |
370 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 374 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
371 | allcorrect = false; | 375 | allcorrect = false; |
372 | } | 376 | } |
373 | break; | 377 | break; |
374 | case OContactAccess::ExactMatch:{ | 378 | case OContactAccess::ExactMatch:{ |
375 | if (settings & OContactAccess::IgnoreCase){ | 379 | if (settings & OContactAccess::IgnoreCase){ |
376 | if ( query.field(i).upper() != | 380 | if ( query.field(i).upper() != |
377 | (*it)->field(i).upper() ) | 381 | (*it)->field(i).upper() ) |
378 | allcorrect = false; | 382 | allcorrect = false; |
379 | }else{ | 383 | }else{ |
380 | if ( query.field(i) != (*it)->field(i) ) | 384 | if ( query.field(i) != (*it)->field(i) ) |
381 | allcorrect = false; | 385 | allcorrect = false; |
382 | } | 386 | } |
383 | } | 387 | } |
384 | break; | 388 | break; |
385 | } | 389 | } |
386 | } | 390 | } |
387 | } | 391 | } |
388 | } | 392 | } |
389 | if ( allcorrect ){ | 393 | if ( allcorrect ){ |
390 | m_currentQuery[arraycounter++] = (*it)->uid(); | 394 | m_currentQuery[arraycounter++] = (*it)->uid(); |
391 | } | 395 | } |
392 | } | 396 | } |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 4abf4d9..9fe3d1e 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -1,83 +1,87 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.3 2003/03/21 12:26:28 eilers | ||
21 | * Fixing small bug: If we search a birthday from today to today, it returned | ||
22 | * every contact .. | ||
23 | * | ||
20 | * Revision 1.2 2003/03/21 10:33:09 eilers | 24 | * Revision 1.2 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 25 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 26 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 27 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 28 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 29 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 30 | * the binaries for today-addressbook. |
27 | * | 31 | * |
28 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 32 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
29 | * Speed optimization. Removed the sequential search loops. | 33 | * Speed optimization. Removed the sequential search loops. |
30 | * | 34 | * |
31 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 35 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
32 | * Writing offsets to debug output.. | 36 | * Writing offsets to debug output.. |
33 | * | 37 | * |
34 | * Revision 1.1 2003/02/09 15:05:01 eilers | 38 | * Revision 1.1 2003/02/09 15:05:01 eilers |
35 | * Nothing happened.. Just some cleanup before I will start.. | 39 | * Nothing happened.. Just some cleanup before I will start.. |
36 | * | 40 | * |
37 | * Revision 1.12 2003/01/03 16:58:03 eilers | 41 | * Revision 1.12 2003/01/03 16:58:03 eilers |
38 | * Reenable debug output | 42 | * Reenable debug output |
39 | * | 43 | * |
40 | * Revision 1.11 2003/01/03 12:31:28 eilers | 44 | * Revision 1.11 2003/01/03 12:31:28 eilers |
41 | * Bugfix for calculating data diffs.. | 45 | * Bugfix for calculating data diffs.. |
42 | * | 46 | * |
43 | * Revision 1.10 2003/01/02 14:27:12 eilers | 47 | * Revision 1.10 2003/01/02 14:27:12 eilers |
44 | * Improved query by example: Search by date is possible.. First step | 48 | * Improved query by example: Search by date is possible.. First step |
45 | * for a today plugin for birthdays.. | 49 | * for a today plugin for birthdays.. |
46 | * | 50 | * |
47 | * Revision 1.9 2002/12/08 12:48:57 eilers | 51 | * Revision 1.9 2002/12/08 12:48:57 eilers |
48 | * Moved journal-enum from ocontact into i the xml-backend.. | 52 | * Moved journal-enum from ocontact into i the xml-backend.. |
49 | * | 53 | * |
50 | * Revision 1.8 2002/11/14 17:04:24 eilers | 54 | * Revision 1.8 2002/11/14 17:04:24 eilers |
51 | * Sorting will now work if fullname is identical on some entries | 55 | * Sorting will now work if fullname is identical on some entries |
52 | * | 56 | * |
53 | * Revision 1.7 2002/11/13 15:02:46 eilers | 57 | * Revision 1.7 2002/11/13 15:02:46 eilers |
54 | * Small Bug in sorted fixed | 58 | * Small Bug in sorted fixed |
55 | * | 59 | * |
56 | * Revision 1.6 2002/11/13 14:14:51 eilers | 60 | * Revision 1.6 2002/11/13 14:14:51 eilers |
57 | * Added sorted for Contacts.. | 61 | * Added sorted for Contacts.. |
58 | * | 62 | * |
59 | * Revision 1.5 2002/11/01 15:10:42 eilers | 63 | * Revision 1.5 2002/11/01 15:10:42 eilers |
60 | * Added regExp-search in database for all fields in a contact. | 64 | * Added regExp-search in database for all fields in a contact. |
61 | * | 65 | * |
62 | * Revision 1.4 2002/10/16 10:52:40 eilers | 66 | * Revision 1.4 2002/10/16 10:52:40 eilers |
63 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 67 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
64 | * | 68 | * |
65 | * Revision 1.3 2002/10/14 16:21:54 eilers | 69 | * Revision 1.3 2002/10/14 16:21:54 eilers |
66 | * Some minor interface updates | 70 | * Some minor interface updates |
67 | * | 71 | * |
68 | * Revision 1.2 2002/10/07 17:34:24 eilers | 72 | * Revision 1.2 2002/10/07 17:34:24 eilers |
69 | * added OBackendFactory for advanced backend access | 73 | * added OBackendFactory for advanced backend access |
70 | * | 74 | * |
71 | * Revision 1.1 2002/09/27 17:11:44 eilers | 75 | * Revision 1.1 2002/09/27 17:11:44 eilers |
72 | * Added API for accessing the Contact-Database ! It is compiling, but | 76 | * Added API for accessing the Contact-Database ! It is compiling, but |
73 | * please do not expect that anything is working ! | 77 | * please do not expect that anything is working ! |
74 | * I will debug that stuff in the next time .. | 78 | * I will debug that stuff in the next time .. |
75 | * Please read README_COMPILE for compiling ! | 79 | * Please read README_COMPILE for compiling ! |
76 | * | 80 | * |
77 | * | 81 | * |
78 | */ | 82 | */ |
79 | 83 | ||
80 | #include "ocontactaccessbackend_xml.h" | 84 | #include "ocontactaccessbackend_xml.h" |
81 | 85 | ||
82 | #include <qasciidict.h> | 86 | #include <qasciidict.h> |
83 | #include <qdatetime.h> | 87 | #include <qdatetime.h> |
@@ -264,129 +268,129 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
264 | QListIterator<OContact> it( m_contactList ); | 268 | QListIterator<OContact> it( m_contactList ); |
265 | uint arraycounter = 0; | 269 | uint arraycounter = 0; |
266 | 270 | ||
267 | for( ; it.current(); ++it ){ | 271 | for( ; it.current(); ++it ){ |
268 | /* Search all fields and compare them with query object. Store them into list | 272 | /* Search all fields and compare them with query object. Store them into list |
269 | * if all fields matches. | 273 | * if all fields matches. |
270 | */ | 274 | */ |
271 | QDate* queryDate = 0l; | 275 | QDate* queryDate = 0l; |
272 | QDate* checkDate = 0l; | 276 | QDate* checkDate = 0l; |
273 | bool allcorrect = true; | 277 | bool allcorrect = true; |
274 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 278 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
275 | // Birthday and anniversary are special nonstring fields and should | 279 | // Birthday and anniversary are special nonstring fields and should |
276 | // be handled specially | 280 | // be handled specially |
277 | switch ( i ){ | 281 | switch ( i ){ |
278 | case Qtopia::Birthday: | 282 | case Qtopia::Birthday: |
279 | queryDate = new QDate( query.birthday() ); | 283 | queryDate = new QDate( query.birthday() ); |
280 | checkDate = new QDate( (*it)->birthday() ); | 284 | checkDate = new QDate( (*it)->birthday() ); |
281 | case Qtopia::Anniversary: | 285 | case Qtopia::Anniversary: |
282 | if ( queryDate == 0l ){ | 286 | if ( queryDate == 0l ){ |
283 | queryDate = new QDate( query.anniversary() ); | 287 | queryDate = new QDate( query.anniversary() ); |
284 | checkDate = new QDate( (*it)->anniversary() ); | 288 | checkDate = new QDate( (*it)->anniversary() ); |
285 | } | 289 | } |
286 | 290 | ||
287 | if ( queryDate->isValid() ){ | 291 | if ( queryDate->isValid() ){ |
288 | if( checkDate->isValid() ){ | 292 | if( checkDate->isValid() ){ |
289 | if ( settings & OContactAccess::DateYear ){ | 293 | if ( settings & OContactAccess::DateYear ){ |
290 | if ( queryDate->year() != checkDate->year() ) | 294 | if ( queryDate->year() != checkDate->year() ) |
291 | allcorrect = false; | 295 | allcorrect = false; |
292 | } | 296 | } |
293 | if ( settings & OContactAccess::DateMonth ){ | 297 | if ( settings & OContactAccess::DateMonth ){ |
294 | if ( queryDate->month() != checkDate->month() ) | 298 | if ( queryDate->month() != checkDate->month() ) |
295 | allcorrect = false; | 299 | allcorrect = false; |
296 | } | 300 | } |
297 | if ( settings & OContactAccess::DateDay ){ | 301 | if ( settings & OContactAccess::DateDay ){ |
298 | if ( queryDate->day() != checkDate->day() ) | 302 | if ( queryDate->day() != checkDate->day() ) |
299 | allcorrect = false; | 303 | allcorrect = false; |
300 | } | 304 | } |
301 | if ( settings & OContactAccess::DateDiff ) { | 305 | if ( settings & OContactAccess::DateDiff ) { |
302 | QDate current; | 306 | QDate current; |
303 | // If we get an additional date, we | 307 | // If we get an additional date, we |
304 | // will take this date instead of | 308 | // will take this date instead of |
305 | // the current one.. | 309 | // the current one.. |
306 | if ( !d.date().isValid() ) | 310 | if ( !d.date().isValid() ) |
307 | current = QDate::currentDate(); | 311 | current = QDate::currentDate(); |
308 | else | 312 | else |
309 | current = d.date(); | 313 | current = d.date(); |
310 | 314 | ||
311 | // We have to equalize the year, otherwise | 315 | // We have to equalize the year, otherwise |
312 | // the search will fail.. | 316 | // the search will fail.. |
313 | checkDate->setYMD( current.year(), | 317 | checkDate->setYMD( current.year(), |
314 | checkDate->month(), | 318 | checkDate->month(), |
315 | checkDate->day() ); | 319 | checkDate->day() ); |
316 | if ( *checkDate < current ) | 320 | if ( *checkDate < current ) |
317 | checkDate->setYMD( current.year()+1, | 321 | checkDate->setYMD( current.year()+1, |
318 | checkDate->month(), | 322 | checkDate->month(), |
319 | checkDate->day() ); | 323 | checkDate->day() ); |
320 | 324 | ||
321 | // Check whether the birthday/anniversary date is between | 325 | // Check whether the birthday/anniversary date is between |
322 | // the current/given date and the maximum date | 326 | // the current/given date and the maximum date |
323 | // ( maximum time range ) ! | 327 | // ( maximum time range ) ! |
324 | qWarning("Checking if %s is between %s and %s ! ", | 328 | qWarning("Checking if %s is between %s and %s ! ", |
325 | checkDate->toString().latin1(), | 329 | checkDate->toString().latin1(), |
326 | current.toString().latin1(), | 330 | current.toString().latin1(), |
327 | queryDate->toString().latin1() ); | 331 | queryDate->toString().latin1() ); |
328 | if ( current.daysTo( *queryDate ) > 0 ){ | 332 | if ( current.daysTo( *queryDate ) >= 0 ){ |
329 | if ( !( ( *checkDate >= current ) && | 333 | if ( !( ( *checkDate >= current ) && |
330 | ( *checkDate <= *queryDate ) ) ){ | 334 | ( *checkDate <= *queryDate ) ) ){ |
331 | allcorrect = false; | 335 | allcorrect = false; |
332 | qWarning (" Nope!.."); | 336 | qWarning (" Nope!.."); |
333 | } | 337 | } |
334 | } | 338 | } |
335 | } | 339 | } |
336 | } else{ | 340 | } else{ |
337 | // checkDate is invalid. Therefore this entry is always rejected | 341 | // checkDate is invalid. Therefore this entry is always rejected |
338 | allcorrect = false; | 342 | allcorrect = false; |
339 | } | 343 | } |
340 | } | 344 | } |
341 | 345 | ||
342 | delete queryDate; | 346 | delete queryDate; |
343 | queryDate = 0l; | 347 | queryDate = 0l; |
344 | delete checkDate; | 348 | delete checkDate; |
345 | checkDate = 0l; | 349 | checkDate = 0l; |
346 | break; | 350 | break; |
347 | default: | 351 | default: |
348 | /* Just compare fields which are not empty in the query object */ | 352 | /* Just compare fields which are not empty in the query object */ |
349 | if ( !query.field(i).isEmpty() ){ | 353 | if ( !query.field(i).isEmpty() ){ |
350 | switch ( settings & ~( OContactAccess::IgnoreCase | 354 | switch ( settings & ~( OContactAccess::IgnoreCase |
351 | | OContactAccess::DateDiff | 355 | | OContactAccess::DateDiff |
352 | | OContactAccess::DateYear | 356 | | OContactAccess::DateYear |
353 | | OContactAccess::DateMonth | 357 | | OContactAccess::DateMonth |
354 | | OContactAccess::DateDay | 358 | | OContactAccess::DateDay |
355 | | OContactAccess::MatchOne | 359 | | OContactAccess::MatchOne |
356 | ) ){ | 360 | ) ){ |
357 | 361 | ||
358 | case OContactAccess::RegExp:{ | 362 | case OContactAccess::RegExp:{ |
359 | QRegExp expr ( query.field(i), | 363 | QRegExp expr ( query.field(i), |
360 | !(settings & OContactAccess::IgnoreCase), | 364 | !(settings & OContactAccess::IgnoreCase), |
361 | false ); | 365 | false ); |
362 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 366 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
363 | allcorrect = false; | 367 | allcorrect = false; |
364 | } | 368 | } |
365 | break; | 369 | break; |
366 | case OContactAccess::WildCards:{ | 370 | case OContactAccess::WildCards:{ |
367 | QRegExp expr ( query.field(i), | 371 | QRegExp expr ( query.field(i), |
368 | !(settings & OContactAccess::IgnoreCase), | 372 | !(settings & OContactAccess::IgnoreCase), |
369 | true ); | 373 | true ); |
370 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 374 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
371 | allcorrect = false; | 375 | allcorrect = false; |
372 | } | 376 | } |
373 | break; | 377 | break; |
374 | case OContactAccess::ExactMatch:{ | 378 | case OContactAccess::ExactMatch:{ |
375 | if (settings & OContactAccess::IgnoreCase){ | 379 | if (settings & OContactAccess::IgnoreCase){ |
376 | if ( query.field(i).upper() != | 380 | if ( query.field(i).upper() != |
377 | (*it)->field(i).upper() ) | 381 | (*it)->field(i).upper() ) |
378 | allcorrect = false; | 382 | allcorrect = false; |
379 | }else{ | 383 | }else{ |
380 | if ( query.field(i) != (*it)->field(i) ) | 384 | if ( query.field(i) != (*it)->field(i) ) |
381 | allcorrect = false; | 385 | allcorrect = false; |
382 | } | 386 | } |
383 | } | 387 | } |
384 | break; | 388 | break; |
385 | } | 389 | } |
386 | } | 390 | } |
387 | } | 391 | } |
388 | } | 392 | } |
389 | if ( allcorrect ){ | 393 | if ( allcorrect ){ |
390 | m_currentQuery[arraycounter++] = (*it)->uid(); | 394 | m_currentQuery[arraycounter++] = (*it)->uid(); |
391 | } | 395 | } |
392 | } | 396 | } |