author | eilers <eilers> | 2003-01-02 14:27:12 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-01-02 14:27:12 (UTC) |
commit | 8a9fc13259d7c2797068752687a011f57f613251 (patch) (unidiff) | |
tree | 26019057f2974c71881d9d7759732326cd0ede25 | |
parent | 12e9ed4ac80ac7fa042059b48d7447db0e59a86c (diff) | |
download | opie-8a9fc13259d7c2797068752687a011f57f613251.zip opie-8a9fc13259d7c2797068752687a011f57f613251.tar.gz opie-8a9fc13259d7c2797068752687a011f57f613251.tar.bz2 |
Improved query by example: Search by date is possible.. First step
for a today plugin for birthdays..
-rw-r--r-- | libopie/pim/ocontactaccess.h | 10 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.h | 137 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.h | 137 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 10 |
4 files changed, 226 insertions, 68 deletions
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index 961968f..32b2dcb 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -19,2 +19,6 @@ | |||
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.6 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.5 2002/11/13 14:14:51 eilers | 24 | * Revision 1.5 2002/11/13 14:14:51 eilers |
@@ -90,3 +94,7 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | |||
90 | ExactMatch = 0x0008, | 94 | ExactMatch = 0x0008, |
91 | MatchOne = 0x0010 // Only one Entry must match | 95 | MatchOne = 0x0010, // Only one Entry must match |
96 | DateDiff = 0x0020, // Find all entries from today until given date | ||
97 | DateYear = 0x0040, // The year matches | ||
98 | DateMonth = 0x0080, // The month matches | ||
99 | DateDay = 0x0100, // The day matches | ||
92 | }; | 100 | }; |
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 | |||
@@ -19,2 +19,6 @@ | |||
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 |
@@ -62,2 +66,3 @@ | |||
62 | #include <qmap.h> | 66 | #include <qmap.h> |
67 | #include <qdatetime.h> | ||
63 | 68 | ||
@@ -227,34 +232,85 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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++ ) { |
230 | /* Just compare fields which are not empty in the query object */ | 237 | // Birthday and anniversary are special nonstring fields and should |
231 | if ( !query.field(i).isEmpty() ){ | 238 | // be handled especially |
232 | switch ( settings & ~OContactAccess::IgnoreCase ){ | 239 | switch ( i ){ |
233 | case OContactAccess::RegExp:{ | 240 | case Qtopia::Birthday: |
234 | QRegExp expr ( query.field(i), | 241 | queryDate = new QDate( query.birthday() ); |
235 | !(settings & OContactAccess::IgnoreCase), | 242 | checkDate = new QDate( (*it).birthday() ); |
236 | false ); | 243 | case Qtopia::Anniversary: |
237 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 244 | if ( queryDate == 0l ){ |
238 | allcorrect = false; | 245 | queryDate = new QDate( query.anniversary() ); |
239 | } | 246 | checkDate = new QDate( (*it).anniversary() ); |
240 | break; | ||
241 | case OContactAccess::WildCards:{ | ||
242 | QRegExp expr ( query.field(i), | ||
243 | !(settings & OContactAccess::IgnoreCase), | ||
244 | true ); | ||
245 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | ||
246 | allcorrect = false; | ||
247 | } | 247 | } |
248 | break; | 248 | |
249 | case OContactAccess::ExactMatch:{ | 249 | if ( queryDate->isValid() ){ |
250 | if (settings & OContactAccess::IgnoreCase){ | 250 | if ( settings & OContactAccess::DateYear ){ |
251 | if ( query.field(i).upper() != | 251 | if ( queryDate->year() != checkDate->year() ) |
252 | (*it).field(i).upper() ) | ||
253 | allcorrect = false; | 252 | allcorrect = false; |
254 | }else{ | 253 | } |
255 | if ( query.field(i) != (*it).field(i) ) | 254 | if ( settings & OContactAccess::DateMonth ){ |
255 | if ( queryDate->month() != checkDate->month() ) | ||
256 | allcorrect = false; | 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 | } | ||
257 | } | 269 | } |
258 | } | 270 | } |
259 | break; | 271 | |
272 | delete queryDate; | ||
273 | queryDate = 0l; | ||
274 | delete checkDate; | ||
275 | checkDate = 0l; | ||
276 | break; | ||
277 | default: | ||
278 | /* Just compare fields which are not empty in the query object */ | ||
279 | if ( !query.field(i).isEmpty() ){ | ||
280 | switch ( settings & ~( OContactAccess::IgnoreCase | ||
281 | | OContactAccess::DateDiff | ||
282 | | OContactAccess::DateYear | ||
283 | | OContactAccess::DateMonth | ||
284 | | OContactAccess::DateDay | ||
285 | | OContactAccess::MatchOne | ||
286 | ) ){ | ||
287 | |||
288 | case OContactAccess::RegExp:{ | ||
289 | QRegExp expr ( query.field(i), | ||
290 | !(settings & OContactAccess::IgnoreCase), | ||
291 | false ); | ||
292 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | ||
293 | allcorrect = false; | ||
294 | } | ||
295 | break; | ||
296 | case OContactAccess::WildCards:{ | ||
297 | QRegExp expr ( query.field(i), | ||
298 | !(settings & OContactAccess::IgnoreCase), | ||
299 | true ); | ||
300 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | ||
301 | allcorrect = false; | ||
302 | } | ||
303 | break; | ||
304 | case OContactAccess::ExactMatch:{ | ||
305 | if (settings & OContactAccess::IgnoreCase){ | ||
306 | if ( query.field(i).upper() != | ||
307 | (*it).field(i).upper() ) | ||
308 | allcorrect = false; | ||
309 | }else{ | ||
310 | if ( query.field(i) != (*it).field(i) ) | ||
311 | allcorrect = false; | ||
312 | } | ||
313 | } | ||
314 | break; | ||
315 | } | ||
260 | } | 316 | } |
@@ -293,5 +349,10 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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 | } |
@@ -300,7 +361,17 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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: |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index c765ff5..c6e6cbc 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -19,2 +19,6 @@ | |||
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 |
@@ -62,2 +66,3 @@ | |||
62 | #include <qmap.h> | 66 | #include <qmap.h> |
67 | #include <qdatetime.h> | ||
63 | 68 | ||
@@ -227,34 +232,85 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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++ ) { |
230 | /* Just compare fields which are not empty in the query object */ | 237 | // Birthday and anniversary are special nonstring fields and should |
231 | if ( !query.field(i).isEmpty() ){ | 238 | // be handled especially |
232 | switch ( settings & ~OContactAccess::IgnoreCase ){ | 239 | switch ( i ){ |
233 | case OContactAccess::RegExp:{ | 240 | case Qtopia::Birthday: |
234 | QRegExp expr ( query.field(i), | 241 | queryDate = new QDate( query.birthday() ); |
235 | !(settings & OContactAccess::IgnoreCase), | 242 | checkDate = new QDate( (*it).birthday() ); |
236 | false ); | 243 | case Qtopia::Anniversary: |
237 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 244 | if ( queryDate == 0l ){ |
238 | allcorrect = false; | 245 | queryDate = new QDate( query.anniversary() ); |
239 | } | 246 | checkDate = new QDate( (*it).anniversary() ); |
240 | break; | ||
241 | case OContactAccess::WildCards:{ | ||
242 | QRegExp expr ( query.field(i), | ||
243 | !(settings & OContactAccess::IgnoreCase), | ||
244 | true ); | ||
245 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | ||
246 | allcorrect = false; | ||
247 | } | 247 | } |
248 | break; | 248 | |
249 | case OContactAccess::ExactMatch:{ | 249 | if ( queryDate->isValid() ){ |
250 | if (settings & OContactAccess::IgnoreCase){ | 250 | if ( settings & OContactAccess::DateYear ){ |
251 | if ( query.field(i).upper() != | 251 | if ( queryDate->year() != checkDate->year() ) |
252 | (*it).field(i).upper() ) | ||
253 | allcorrect = false; | 252 | allcorrect = false; |
254 | }else{ | 253 | } |
255 | if ( query.field(i) != (*it).field(i) ) | 254 | if ( settings & OContactAccess::DateMonth ){ |
255 | if ( queryDate->month() != checkDate->month() ) | ||
256 | allcorrect = false; | 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 | } | ||
257 | } | 269 | } |
258 | } | 270 | } |
259 | break; | 271 | |
272 | delete queryDate; | ||
273 | queryDate = 0l; | ||
274 | delete checkDate; | ||
275 | checkDate = 0l; | ||
276 | break; | ||
277 | default: | ||
278 | /* Just compare fields which are not empty in the query object */ | ||
279 | if ( !query.field(i).isEmpty() ){ | ||
280 | switch ( settings & ~( OContactAccess::IgnoreCase | ||
281 | | OContactAccess::DateDiff | ||
282 | | OContactAccess::DateYear | ||
283 | | OContactAccess::DateMonth | ||
284 | | OContactAccess::DateDay | ||
285 | | OContactAccess::MatchOne | ||
286 | ) ){ | ||
287 | |||
288 | case OContactAccess::RegExp:{ | ||
289 | QRegExp expr ( query.field(i), | ||
290 | !(settings & OContactAccess::IgnoreCase), | ||
291 | false ); | ||
292 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | ||
293 | allcorrect = false; | ||
294 | } | ||
295 | break; | ||
296 | case OContactAccess::WildCards:{ | ||
297 | QRegExp expr ( query.field(i), | ||
298 | !(settings & OContactAccess::IgnoreCase), | ||
299 | true ); | ||
300 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | ||
301 | allcorrect = false; | ||
302 | } | ||
303 | break; | ||
304 | case OContactAccess::ExactMatch:{ | ||
305 | if (settings & OContactAccess::IgnoreCase){ | ||
306 | if ( query.field(i).upper() != | ||
307 | (*it).field(i).upper() ) | ||
308 | allcorrect = false; | ||
309 | }else{ | ||
310 | if ( query.field(i) != (*it).field(i) ) | ||
311 | allcorrect = false; | ||
312 | } | ||
313 | } | ||
314 | break; | ||
315 | } | ||
260 | } | 316 | } |
@@ -293,5 +349,10 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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 | } |
@@ -300,7 +361,17 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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: |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index 961968f..32b2dcb 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -19,2 +19,6 @@ | |||
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.6 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.5 2002/11/13 14:14:51 eilers | 24 | * Revision 1.5 2002/11/13 14:14:51 eilers |
@@ -90,3 +94,7 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | |||
90 | ExactMatch = 0x0008, | 94 | ExactMatch = 0x0008, |
91 | MatchOne = 0x0010 // Only one Entry must match | 95 | MatchOne = 0x0010, // Only one Entry must match |
96 | DateDiff = 0x0020, // Find all entries from today until given date | ||
97 | DateYear = 0x0040, // The year matches | ||
98 | DateMonth = 0x0080, // The month matches | ||
99 | DateDay = 0x0100, // The day matches | ||
92 | }; | 100 | }; |