summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h57
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h57
2 files changed, 78 insertions, 36 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index c6e6cbc..6a1c91d 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,43 +1,46 @@
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.11 2003/01/03 12:31:28 eilers
21 * Bugfix for calculating data diffs..
22 *
20 * Revision 1.10 2003/01/02 14:27:12 eilers 23 * Revision 1.10 2003/01/02 14:27:12 eilers
21 * Improved query by example: Search by date is possible.. First step 24 * Improved query by example: Search by date is possible.. First step
22 * for a today plugin for birthdays.. 25 * for a today plugin for birthdays..
23 * 26 *
24 * Revision 1.9 2002/12/08 12:48:57 eilers 27 * Revision 1.9 2002/12/08 12:48:57 eilers
25 * Moved journal-enum from ocontact into i the xml-backend.. 28 * Moved journal-enum from ocontact into i the xml-backend..
26 * 29 *
27 * Revision 1.8 2002/11/14 17:04:24 eilers 30 * Revision 1.8 2002/11/14 17:04:24 eilers
28 * Sorting will now work if fullname is identical on some entries 31 * Sorting will now work if fullname is identical on some entries
29 * 32 *
30 * Revision 1.7 2002/11/13 15:02:46 eilers 33 * Revision 1.7 2002/11/13 15:02:46 eilers
31 * Small Bug in sorted fixed 34 * Small Bug in sorted fixed
32 * 35 *
33 * Revision 1.6 2002/11/13 14:14:51 eilers 36 * Revision 1.6 2002/11/13 14:14:51 eilers
34 * Added sorted for Contacts.. 37 * Added sorted for Contacts..
35 * 38 *
36 * Revision 1.5 2002/11/01 15:10:42 eilers 39 * Revision 1.5 2002/11/01 15:10:42 eilers
37 * Added regExp-search in database for all fields in a contact. 40 * Added regExp-search in database for all fields in a contact.
38 * 41 *
39 * Revision 1.4 2002/10/16 10:52:40 eilers 42 * Revision 1.4 2002/10/16 10:52:40 eilers
40 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 43 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
41 * 44 *
42 * Revision 1.3 2002/10/14 16:21:54 eilers 45 * Revision 1.3 2002/10/14 16:21:54 eilers
43 * Some minor interface updates 46 * Some minor interface updates
@@ -214,79 +217,97 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
214 } 217 }
215 } 218 }
216 if ( found ){ 219 if ( found ){
217 foundContact = *it; 220 foundContact = *it;
218 } 221 }
219 222
220 return ( foundContact ); 223 return ( foundContact );
221 } 224 }
222 225
223 QArray<int> queryByExample ( const OContact &query, int settings ){ 226 QArray<int> queryByExample ( const OContact &query, int settings ){
224 227
225 QArray<int> m_currentQuery( m_contactList.count() ); 228 QArray<int> m_currentQuery( m_contactList.count() );
226 QValueListConstIterator<OContact> it; 229 QValueListConstIterator<OContact> it;
227 uint arraycounter = 0; 230 uint arraycounter = 0;
228 231
229 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 232 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
230 /* Search all fields and compare them with query object. Store them into list 233 /* Search all fields and compare them with query object. Store them into list
231 * if all fields matches. 234 * if all fields matches.
232 */ 235 */
233 QDate* queryDate = 0l; 236 QDate* queryDate = 0l;
234 QDate* checkDate = 0l; 237 QDate* checkDate = 0l;
235 bool allcorrect = true; 238 bool allcorrect = true;
236 for ( int i = 0; i < Qtopia::Groups; i++ ) { 239 for ( int i = 0; i < Qtopia::Groups; i++ ) {
237 // Birthday and anniversary are special nonstring fields and should 240 // Birthday and anniversary are special nonstring fields and should
238 // be handled especially 241 // be handled specially
239 switch ( i ){ 242 switch ( i ){
240 case Qtopia::Birthday: 243 case Qtopia::Birthday:
241 queryDate = new QDate( query.birthday() ); 244 queryDate = new QDate( query.birthday() );
242 checkDate = new QDate( (*it).birthday() ); 245 checkDate = new QDate( (*it).birthday() );
243 case Qtopia::Anniversary: 246 case Qtopia::Anniversary:
244 if ( queryDate == 0l ){ 247 if ( queryDate == 0l ){
245 queryDate = new QDate( query.anniversary() ); 248 queryDate = new QDate( query.anniversary() );
246 checkDate = new QDate( (*it).anniversary() ); 249 checkDate = new QDate( (*it).anniversary() );
247 } 250 }
248 251
249 if ( queryDate->isValid() ){ 252 if ( queryDate->isValid() ){
250 if ( settings & OContactAccess::DateYear ){ 253 if( checkDate->isValid() ){
251 if ( queryDate->year() != checkDate->year() ) 254 if ( settings & OContactAccess::DateYear ){
252 allcorrect = false; 255 if ( queryDate->year() != checkDate->year() )
253 } 256 allcorrect = false;
254 if ( settings & OContactAccess::DateMonth ){ 257 }
255 if ( queryDate->month() != checkDate->month() ) 258 if ( settings & OContactAccess::DateMonth ){
256 allcorrect = false; 259 if ( queryDate->month() != checkDate->month() )
257 } 260 allcorrect = false;
258 if ( settings & OContactAccess::DateDay ){ 261 }
259 if ( queryDate->day() != checkDate->day() ) 262 if ( settings & OContactAccess::DateDay ){
260 allcorrect = false; 263 if ( queryDate->day() != checkDate->day() )
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; 264 allcorrect = false;
265 }
266 if ( settings & OContactAccess::DateDiff ) {
267 QDate current = QDate::currentDate();
268 // We have to equalize the year, otherwise
269 // the search will fail..
270 checkDate->setYMD( current.year(), checkDate->month(), checkDate->day() );
271 if ( *checkDate < current )
272 checkDate->setYMD( current.year()+1,
273 checkDate->month(),
274 checkDate->day() );
275 // qWarning("Checking if %s is between %s and %s ! ",
276 // checkDate->toString().latin1(),
277 // current.toString().latin1(),
278 // queryDate->toString().latin1() );
279 if ( current.daysTo( *queryDate ) > 0 ){
280 if ( !( ( *checkDate >= current ) &&
281 ( *checkDate <= *queryDate ) ) ){
282 allcorrect = false;
283 //qWarning (" Nope!..");
284 }
285 }
268 } 286 }
287 } else{
288 // checkDate is invalid. Therfore this entry is always rejected
289 allcorrect = false;
269 } 290 }
270 } 291 }
271 292
272 delete queryDate; 293 delete queryDate;
273 queryDate = 0l; 294 queryDate = 0l;
274 delete checkDate; 295 delete checkDate;
275 checkDate = 0l; 296 checkDate = 0l;
276 break; 297 break;
277 default: 298 default:
278 /* Just compare fields which are not empty in the query object */ 299 /* Just compare fields which are not empty in the query object */
279 if ( !query.field(i).isEmpty() ){ 300 if ( !query.field(i).isEmpty() ){
280 switch ( settings & ~( OContactAccess::IgnoreCase 301 switch ( settings & ~( OContactAccess::IgnoreCase
281 | OContactAccess::DateDiff 302 | OContactAccess::DateDiff
282 | OContactAccess::DateYear 303 | OContactAccess::DateYear
283 | OContactAccess::DateMonth 304 | OContactAccess::DateMonth
284 | OContactAccess::DateDay 305 | OContactAccess::DateDay
285 | OContactAccess::MatchOne 306 | OContactAccess::MatchOne
286 ) ){ 307 ) ){
287 308
288 case OContactAccess::RegExp:{ 309 case OContactAccess::RegExp:{
289 QRegExp expr ( query.field(i), 310 QRegExp expr ( query.field(i),
290 !(settings & OContactAccess::IgnoreCase), 311 !(settings & OContactAccess::IgnoreCase),
291 false ); 312 false );
292 if ( expr.find ( (*it).field(i), 0 ) == -1 ) 313 if ( expr.find ( (*it).field(i), 0 ) == -1 )
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index c6e6cbc..6a1c91d 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -1,43 +1,46 @@
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.11 2003/01/03 12:31:28 eilers
21 * Bugfix for calculating data diffs..
22 *
20 * Revision 1.10 2003/01/02 14:27:12 eilers 23 * Revision 1.10 2003/01/02 14:27:12 eilers
21 * Improved query by example: Search by date is possible.. First step 24 * Improved query by example: Search by date is possible.. First step
22 * for a today plugin for birthdays.. 25 * for a today plugin for birthdays..
23 * 26 *
24 * Revision 1.9 2002/12/08 12:48:57 eilers 27 * Revision 1.9 2002/12/08 12:48:57 eilers
25 * Moved journal-enum from ocontact into i the xml-backend.. 28 * Moved journal-enum from ocontact into i the xml-backend..
26 * 29 *
27 * Revision 1.8 2002/11/14 17:04:24 eilers 30 * Revision 1.8 2002/11/14 17:04:24 eilers
28 * Sorting will now work if fullname is identical on some entries 31 * Sorting will now work if fullname is identical on some entries
29 * 32 *
30 * Revision 1.7 2002/11/13 15:02:46 eilers 33 * Revision 1.7 2002/11/13 15:02:46 eilers
31 * Small Bug in sorted fixed 34 * Small Bug in sorted fixed
32 * 35 *
33 * Revision 1.6 2002/11/13 14:14:51 eilers 36 * Revision 1.6 2002/11/13 14:14:51 eilers
34 * Added sorted for Contacts.. 37 * Added sorted for Contacts..
35 * 38 *
36 * Revision 1.5 2002/11/01 15:10:42 eilers 39 * Revision 1.5 2002/11/01 15:10:42 eilers
37 * Added regExp-search in database for all fields in a contact. 40 * Added regExp-search in database for all fields in a contact.
38 * 41 *
39 * Revision 1.4 2002/10/16 10:52:40 eilers 42 * Revision 1.4 2002/10/16 10:52:40 eilers
40 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 43 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
41 * 44 *
42 * Revision 1.3 2002/10/14 16:21:54 eilers 45 * Revision 1.3 2002/10/14 16:21:54 eilers
43 * Some minor interface updates 46 * Some minor interface updates
@@ -214,79 +217,97 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
214 } 217 }
215 } 218 }
216 if ( found ){ 219 if ( found ){
217 foundContact = *it; 220 foundContact = *it;
218 } 221 }
219 222
220 return ( foundContact ); 223 return ( foundContact );
221 } 224 }
222 225
223 QArray<int> queryByExample ( const OContact &query, int settings ){ 226 QArray<int> queryByExample ( const OContact &query, int settings ){
224 227
225 QArray<int> m_currentQuery( m_contactList.count() ); 228 QArray<int> m_currentQuery( m_contactList.count() );
226 QValueListConstIterator<OContact> it; 229 QValueListConstIterator<OContact> it;
227 uint arraycounter = 0; 230 uint arraycounter = 0;
228 231
229 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 232 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
230 /* Search all fields and compare them with query object. Store them into list 233 /* Search all fields and compare them with query object. Store them into list
231 * if all fields matches. 234 * if all fields matches.
232 */ 235 */
233 QDate* queryDate = 0l; 236 QDate* queryDate = 0l;
234 QDate* checkDate = 0l; 237 QDate* checkDate = 0l;
235 bool allcorrect = true; 238 bool allcorrect = true;
236 for ( int i = 0; i < Qtopia::Groups; i++ ) { 239 for ( int i = 0; i < Qtopia::Groups; i++ ) {
237 // Birthday and anniversary are special nonstring fields and should 240 // Birthday and anniversary are special nonstring fields and should
238 // be handled especially 241 // be handled specially
239 switch ( i ){ 242 switch ( i ){
240 case Qtopia::Birthday: 243 case Qtopia::Birthday:
241 queryDate = new QDate( query.birthday() ); 244 queryDate = new QDate( query.birthday() );
242 checkDate = new QDate( (*it).birthday() ); 245 checkDate = new QDate( (*it).birthday() );
243 case Qtopia::Anniversary: 246 case Qtopia::Anniversary:
244 if ( queryDate == 0l ){ 247 if ( queryDate == 0l ){
245 queryDate = new QDate( query.anniversary() ); 248 queryDate = new QDate( query.anniversary() );
246 checkDate = new QDate( (*it).anniversary() ); 249 checkDate = new QDate( (*it).anniversary() );
247 } 250 }
248 251
249 if ( queryDate->isValid() ){ 252 if ( queryDate->isValid() ){
250 if ( settings & OContactAccess::DateYear ){ 253 if( checkDate->isValid() ){
251 if ( queryDate->year() != checkDate->year() ) 254 if ( settings & OContactAccess::DateYear ){
252 allcorrect = false; 255 if ( queryDate->year() != checkDate->year() )
253 } 256 allcorrect = false;
254 if ( settings & OContactAccess::DateMonth ){ 257 }
255 if ( queryDate->month() != checkDate->month() ) 258 if ( settings & OContactAccess::DateMonth ){
256 allcorrect = false; 259 if ( queryDate->month() != checkDate->month() )
257 } 260 allcorrect = false;
258 if ( settings & OContactAccess::DateDay ){ 261 }
259 if ( queryDate->day() != checkDate->day() ) 262 if ( settings & OContactAccess::DateDay ){
260 allcorrect = false; 263 if ( queryDate->day() != checkDate->day() )
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; 264 allcorrect = false;
265 }
266 if ( settings & OContactAccess::DateDiff ) {
267 QDate current = QDate::currentDate();
268 // We have to equalize the year, otherwise
269 // the search will fail..
270 checkDate->setYMD( current.year(), checkDate->month(), checkDate->day() );
271 if ( *checkDate < current )
272 checkDate->setYMD( current.year()+1,
273 checkDate->month(),
274 checkDate->day() );
275 // qWarning("Checking if %s is between %s and %s ! ",
276 // checkDate->toString().latin1(),
277 // current.toString().latin1(),
278 // queryDate->toString().latin1() );
279 if ( current.daysTo( *queryDate ) > 0 ){
280 if ( !( ( *checkDate >= current ) &&
281 ( *checkDate <= *queryDate ) ) ){
282 allcorrect = false;
283 //qWarning (" Nope!..");
284 }
285 }
268 } 286 }
287 } else{
288 // checkDate is invalid. Therfore this entry is always rejected
289 allcorrect = false;
269 } 290 }
270 } 291 }
271 292
272 delete queryDate; 293 delete queryDate;
273 queryDate = 0l; 294 queryDate = 0l;
274 delete checkDate; 295 delete checkDate;
275 checkDate = 0l; 296 checkDate = 0l;
276 break; 297 break;
277 default: 298 default:
278 /* Just compare fields which are not empty in the query object */ 299 /* Just compare fields which are not empty in the query object */
279 if ( !query.field(i).isEmpty() ){ 300 if ( !query.field(i).isEmpty() ){
280 switch ( settings & ~( OContactAccess::IgnoreCase 301 switch ( settings & ~( OContactAccess::IgnoreCase
281 | OContactAccess::DateDiff 302 | OContactAccess::DateDiff
282 | OContactAccess::DateYear 303 | OContactAccess::DateYear
283 | OContactAccess::DateMonth 304 | OContactAccess::DateMonth
284 | OContactAccess::DateDay 305 | OContactAccess::DateDay
285 | OContactAccess::MatchOne 306 | OContactAccess::MatchOne
286 ) ){ 307 ) ){
287 308
288 case OContactAccess::RegExp:{ 309 case OContactAccess::RegExp:{
289 QRegExp expr ( query.field(i), 310 QRegExp expr ( query.field(i),
290 !(settings & OContactAccess::IgnoreCase), 311 !(settings & OContactAccess::IgnoreCase),
291 false ); 312 false );
292 if ( expr.find ( (*it).field(i), 0 ) == -1 ) 313 if ( expr.find ( (*it).field(i), 0 ) == -1 )