summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccess.h10
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h137
2 files changed, 113 insertions, 34 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
@@ -8,24 +8,28 @@
8 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
9 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; 10 * License as published by the Free Software Foundation;
11 * either version 2 of the License, or (at your option) any later 11 * either version 2 of the License, or (at your option) any later
12 * version. 12 * version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: Define enum for query settings 14 * ToDo: Define enum for query settings
15 * ===================================================================== 15 * =====================================================================
16 * Version: $Id$ 16 * Version: $Id$
17 * ===================================================================== 17 * =====================================================================
18 * History: 18 * History:
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
21 * Added sorted for Contacts.. 25 * Added sorted for Contacts..
22 * 26 *
23 * Revision 1.4 2002/11/01 15:10:42 eilers 27 * Revision 1.4 2002/11/01 15:10:42 eilers
24 * Added regExp-search in database for all fields in a contact. 28 * Added regExp-search in database for all fields in a contact.
25 * 29 *
26 * Revision 1.3 2002/10/16 10:52:40 eilers 30 * Revision 1.3 2002/10/16 10:52:40 eilers
27 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 31 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
28 * 32 *
29 * Revision 1.2 2002/10/14 16:21:54 eilers 33 * Revision 1.2 2002/10/14 16:21:54 eilers
30 * Some minor interface updates 34 * Some minor interface updates
31 * 35 *
@@ -79,25 +83,29 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
79 ~OContactAccess (); 83 ~OContactAccess ();
80 84
81 /** Constants for query. 85 /** Constants for query.
82 * Use this constants to set the query parameters. 86 * Use this constants to set the query parameters.
83 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! 87 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
84 * @see queryByExample() 88 * @see queryByExample()
85 */ 89 */
86 enum QuerySettings { 90 enum QuerySettings {
87 WildCards = 0x0001, 91 WildCards = 0x0001,
88 IgnoreCase = 0x0002, 92 IgnoreCase = 0x0002,
89 RegExp = 0x0004, 93 RegExp = 0x0004,
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 };
93 101
94 102
95 ORecordList<OContact> matchRegexp( const QRegExp &r )const; 103 ORecordList<OContact> matchRegexp( const QRegExp &r )const;
96 104
97 /** Return all Contacts in a sorted manner. 105 /** Return all Contacts in a sorted manner.
98 * @param ascending true: Sorted in acending order. 106 * @param ascending true: Sorted in acending order.
99 * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess 107 * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess
100 * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess 108 * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess
101 * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess 109 * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess
102 */ 110 */
103 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; 111 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const;
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
@@ -8,24 +8,28 @@
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.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 *
26 * Revision 1.7 2002/11/13 15:02:46 eilers 30 * Revision 1.7 2002/11/13 15:02:46 eilers
27 * Small Bug in sorted fixed 31 * Small Bug in sorted fixed
28 * 32 *
29 * Revision 1.6 2002/11/13 14:14:51 eilers 33 * Revision 1.6 2002/11/13 14:14:51 eilers
30 * Added sorted for Contacts.. 34 * Added sorted for Contacts..
31 * 35 *
@@ -51,24 +55,25 @@
51 */ 55 */
52 56
53#ifndef _OContactAccessBackend_XML_ 57#ifndef _OContactAccessBackend_XML_
54#define _OContactAccessBackend_XML_ 58#define _OContactAccessBackend_XML_
55 59
56#include <qasciidict.h> 60#include <qasciidict.h>
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"
69 74
70#include <stdlib.h> 75#include <stdlib.h>
71#include <errno.h> 76#include <errno.h>
72 77
73using namespace Opie; 78using namespace Opie;
74 79
@@ -216,56 +221,107 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
216 } 221 }
217 222
218 QArray<int> queryByExample ( const OContact &query, int settings ){ 223 QArray<int> queryByExample ( const OContact &query, int settings ){
219 224
220 QArray<int> m_currentQuery( m_contactList.count() ); 225 QArray<int> m_currentQuery( m_contactList.count() );
221 QValueListConstIterator<OContact> it; 226 QValueListConstIterator<OContact> it;
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++ ) {
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 }
261 } 317 }
262 } 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..
269 m_currentQuery.resize(arraycounter); 325 m_currentQuery.resize(arraycounter);
270 326
271 return m_currentQuery; 327 return m_currentQuery;
@@ -282,36 +338,51 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
282 } 338 }
283 339
284 } 340 }
285 // Shrink to fit.. 341 // Shrink to fit..
286 m_currentQuery.resize(arraycounter); 342 m_currentQuery.resize(arraycounter);
287 343
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 );
312 default: 383 default:
313 return ( false ); 384 return ( false );
314 } 385 }
315 } 386 }
316 387
317 // Currently only asc implemented.. 388 // Currently only asc implemented..