summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h7
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h7
2 files changed, 10 insertions, 4 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index adc8dc3..ae6ec9e 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,67 +1,70 @@
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.8 2002/11/14 17:04:24 eilers
21 * Sorting will now work if fullname is identical on some entries
22 *
20 * Revision 1.7 2002/11/13 15:02:46 eilers 23 * Revision 1.7 2002/11/13 15:02:46 eilers
21 * Small Bug in sorted fixed 24 * Small Bug in sorted fixed
22 * 25 *
23 * Revision 1.6 2002/11/13 14:14:51 eilers 26 * Revision 1.6 2002/11/13 14:14:51 eilers
24 * Added sorted for Contacts.. 27 * Added sorted for Contacts..
25 * 28 *
26 * Revision 1.5 2002/11/01 15:10:42 eilers 29 * Revision 1.5 2002/11/01 15:10:42 eilers
27 * Added regExp-search in database for all fields in a contact. 30 * Added regExp-search in database for all fields in a contact.
28 * 31 *
29 * Revision 1.4 2002/10/16 10:52:40 eilers 32 * Revision 1.4 2002/10/16 10:52:40 eilers
30 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 33 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
31 * 34 *
32 * Revision 1.3 2002/10/14 16:21:54 eilers 35 * Revision 1.3 2002/10/14 16:21:54 eilers
33 * Some minor interface updates 36 * Some minor interface updates
34 * 37 *
35 * Revision 1.2 2002/10/07 17:34:24 eilers 38 * Revision 1.2 2002/10/07 17:34:24 eilers
36 * added OBackendFactory for advanced backend access 39 * added OBackendFactory for advanced backend access
37 * 40 *
38 * Revision 1.1 2002/09/27 17:11:44 eilers 41 * Revision 1.1 2002/09/27 17:11:44 eilers
39 * Added API for accessing the Contact-Database ! It is compiling, but 42 * Added API for accessing the Contact-Database ! It is compiling, but
40 * please do not expect that anything is working ! 43 * please do not expect that anything is working !
41 * I will debug that stuff in the next time .. 44 * I will debug that stuff in the next time ..
42 * Please read README_COMPILE for compiling ! 45 * Please read README_COMPILE for compiling !
43 * 46 *
44 * 47 *
45 */ 48 */
46 49
47#ifndef _OContactAccessBackend_XML_ 50#ifndef _OContactAccessBackend_XML_
48#define _OContactAccessBackend_XML_ 51#define _OContactAccessBackend_XML_
49 52
50#include <qasciidict.h> 53#include <qasciidict.h>
51#include <qdatetime.h> 54#include <qdatetime.h>
52#include <qfile.h> 55#include <qfile.h>
53#include <qfileinfo.h> 56#include <qfileinfo.h>
54#include <qregexp.h> 57#include <qregexp.h>
55#include <qarray.h> 58#include <qarray.h>
56#include <qmap.h> 59#include <qmap.h>
57 60
58#include <qpe/global.h> 61#include <qpe/global.h>
59 62
60#include <opie/xmltree.h> 63#include <opie/xmltree.h>
61#include "ocontactaccessbackend.h" 64#include "ocontactaccessbackend.h"
62#include "ocontactaccess.h" 65#include "ocontactaccess.h"
63 66
64#include <stdlib.h> 67#include <stdlib.h>
65#include <errno.h> 68#include <errno.h>
66 69
67using namespace Opie; 70using namespace Opie;
@@ -274,98 +277,98 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
274 if ( (*it).match( r ) ){ 277 if ( (*it).match( r ) ){
275 m_currentQuery[arraycounter++] = (*it).uid(); 278 m_currentQuery[arraycounter++] = (*it).uid();
276 } 279 }
277 280
278 } 281 }
279 // Shrink to fit.. 282 // Shrink to fit..
280 m_currentQuery.resize(arraycounter); 283 m_currentQuery.resize(arraycounter);
281 284
282 return m_currentQuery; 285 return m_currentQuery;
283 } 286 }
284 287
285 const uint querySettings() 288 const uint querySettings()
286 { 289 {
287 return ( OContactAccess::WildCards 290 return ( OContactAccess::WildCards
288 & OContactAccess::IgnoreCase 291 & OContactAccess::IgnoreCase
289 & OContactAccess::RegExp 292 & OContactAccess::RegExp
290 & OContactAccess::ExactMatch ); 293 & OContactAccess::ExactMatch );
291 } 294 }
292 295
293 bool hasQuerySettings (uint querySettings) const 296 bool hasQuerySettings (uint querySettings) const
294 { 297 {
295 /* OContactAccess::IgnoreCase may be added with one 298 /* OContactAccess::IgnoreCase may be added with one
296 * of the other settings, but never used alone. 299 * of the other settings, but never used alone.
297 * The other settings are just valid alone... 300 * The other settings are just valid alone...
298 */ 301 */
299 switch ( querySettings & ~OContactAccess::IgnoreCase ){ 302 switch ( querySettings & ~OContactAccess::IgnoreCase ){
300 case OContactAccess::RegExp: 303 case OContactAccess::RegExp:
301 return ( true ); 304 return ( true );
302 case OContactAccess::WildCards: 305 case OContactAccess::WildCards:
303 return ( true ); 306 return ( true );
304 case OContactAccess::ExactMatch: 307 case OContactAccess::ExactMatch:
305 return ( true ); 308 return ( true );
306 default: 309 default:
307 return ( false ); 310 return ( false );
308 } 311 }
309 } 312 }
310 313
311 // Currently only asc implemented.. 314 // Currently only asc implemented..
312 QArray<int> sorted( bool asc, int , int , int ) 315 QArray<int> sorted( bool asc, int , int , int )
313 { 316 {
314 QMap<QString, int> nameToUid; 317 QMap<QString, int> nameToUid;
315 QStringList names; 318 QStringList names;
316 QArray<int> m_currentQuery( m_contactList.count() ); 319 QArray<int> m_currentQuery( m_contactList.count() );
317 320
318 // First fill map and StringList with all Names 321 // First fill map and StringList with all Names
319 // Afterwards sort namelist and use map to fill array to return.. 322 // Afterwards sort namelist and use map to fill array to return..
320 QValueListConstIterator<OContact> it; 323 QValueListConstIterator<OContact> it;
321 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 324 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
322 names.append( (*it).fileAs() ); 325 names.append( (*it).fileAs() + QString::number( (*it).uid() ) );
323 nameToUid.insert( (*it).fileAs(), (*it).uid() ); 326 nameToUid.insert( (*it).fileAs() + QString::number( (*it).uid() ), (*it).uid() );
324 } 327 }
325 names.sort(); 328 names.sort();
326 329
327 int i = 0; 330 int i = 0;
328 if ( asc ){ 331 if ( asc ){
329 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 332 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
330 m_currentQuery[i++] = nameToUid[ (*it) ]; 333 m_currentQuery[i++] = nameToUid[ (*it) ];
331 }else{ 334 }else{
332 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 335 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
333 m_currentQuery[i++] = nameToUid[ (*it) ]; 336 m_currentQuery[i++] = nameToUid[ (*it) ];
334 } 337 }
335 338
336 return m_currentQuery; 339 return m_currentQuery;
337 340
338 } 341 }
339 bool add ( const OContact &newcontact ) 342 bool add ( const OContact &newcontact )
340 { 343 {
341 //qWarning("odefaultbackend: ACTION::ADD"); 344 //qWarning("odefaultbackend: ACTION::ADD");
342 updateJournal (newcontact, OContact::ACTION_ADD); 345 updateJournal (newcontact, OContact::ACTION_ADD);
343 addContact_p( newcontact ); 346 addContact_p( newcontact );
344 347
345 m_changed = true; 348 m_changed = true;
346 349
347 return true; 350 return true;
348 } 351 }
349 352
350 bool replace ( const OContact &contact ) 353 bool replace ( const OContact &contact )
351 { 354 {
352 m_changed = true; 355 m_changed = true;
353 356
354 bool found = false; 357 bool found = false;
355 358
356 QValueListIterator<OContact> it; 359 QValueListIterator<OContact> it;
357 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 360 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
358 if ( (*it).uid() == contact.uid() ){ 361 if ( (*it).uid() == contact.uid() ){
359 found = true; 362 found = true;
360 break; 363 break;
361 } 364 }
362 } 365 }
363 if (found) { 366 if (found) {
364 updateJournal (contact, OContact::ACTION_REPLACE); 367 updateJournal (contact, OContact::ACTION_REPLACE);
365 m_contactList.remove (it); 368 m_contactList.remove (it);
366 m_contactList.append (contact); 369 m_contactList.append (contact);
367 return true; 370 return true;
368 } else 371 } else
369 return false; 372 return false;
370 } 373 }
371 374
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index adc8dc3..ae6ec9e 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -1,67 +1,70 @@
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.8 2002/11/14 17:04:24 eilers
21 * Sorting will now work if fullname is identical on some entries
22 *
20 * Revision 1.7 2002/11/13 15:02:46 eilers 23 * Revision 1.7 2002/11/13 15:02:46 eilers
21 * Small Bug in sorted fixed 24 * Small Bug in sorted fixed
22 * 25 *
23 * Revision 1.6 2002/11/13 14:14:51 eilers 26 * Revision 1.6 2002/11/13 14:14:51 eilers
24 * Added sorted for Contacts.. 27 * Added sorted for Contacts..
25 * 28 *
26 * Revision 1.5 2002/11/01 15:10:42 eilers 29 * Revision 1.5 2002/11/01 15:10:42 eilers
27 * Added regExp-search in database for all fields in a contact. 30 * Added regExp-search in database for all fields in a contact.
28 * 31 *
29 * Revision 1.4 2002/10/16 10:52:40 eilers 32 * Revision 1.4 2002/10/16 10:52:40 eilers
30 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 33 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
31 * 34 *
32 * Revision 1.3 2002/10/14 16:21:54 eilers 35 * Revision 1.3 2002/10/14 16:21:54 eilers
33 * Some minor interface updates 36 * Some minor interface updates
34 * 37 *
35 * Revision 1.2 2002/10/07 17:34:24 eilers 38 * Revision 1.2 2002/10/07 17:34:24 eilers
36 * added OBackendFactory for advanced backend access 39 * added OBackendFactory for advanced backend access
37 * 40 *
38 * Revision 1.1 2002/09/27 17:11:44 eilers 41 * Revision 1.1 2002/09/27 17:11:44 eilers
39 * Added API for accessing the Contact-Database ! It is compiling, but 42 * Added API for accessing the Contact-Database ! It is compiling, but
40 * please do not expect that anything is working ! 43 * please do not expect that anything is working !
41 * I will debug that stuff in the next time .. 44 * I will debug that stuff in the next time ..
42 * Please read README_COMPILE for compiling ! 45 * Please read README_COMPILE for compiling !
43 * 46 *
44 * 47 *
45 */ 48 */
46 49
47#ifndef _OContactAccessBackend_XML_ 50#ifndef _OContactAccessBackend_XML_
48#define _OContactAccessBackend_XML_ 51#define _OContactAccessBackend_XML_
49 52
50#include <qasciidict.h> 53#include <qasciidict.h>
51#include <qdatetime.h> 54#include <qdatetime.h>
52#include <qfile.h> 55#include <qfile.h>
53#include <qfileinfo.h> 56#include <qfileinfo.h>
54#include <qregexp.h> 57#include <qregexp.h>
55#include <qarray.h> 58#include <qarray.h>
56#include <qmap.h> 59#include <qmap.h>
57 60
58#include <qpe/global.h> 61#include <qpe/global.h>
59 62
60#include <opie/xmltree.h> 63#include <opie/xmltree.h>
61#include "ocontactaccessbackend.h" 64#include "ocontactaccessbackend.h"
62#include "ocontactaccess.h" 65#include "ocontactaccess.h"
63 66
64#include <stdlib.h> 67#include <stdlib.h>
65#include <errno.h> 68#include <errno.h>
66 69
67using namespace Opie; 70using namespace Opie;
@@ -274,98 +277,98 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
274 if ( (*it).match( r ) ){ 277 if ( (*it).match( r ) ){
275 m_currentQuery[arraycounter++] = (*it).uid(); 278 m_currentQuery[arraycounter++] = (*it).uid();
276 } 279 }
277 280
278 } 281 }
279 // Shrink to fit.. 282 // Shrink to fit..
280 m_currentQuery.resize(arraycounter); 283 m_currentQuery.resize(arraycounter);
281 284
282 return m_currentQuery; 285 return m_currentQuery;
283 } 286 }
284 287
285 const uint querySettings() 288 const uint querySettings()
286 { 289 {
287 return ( OContactAccess::WildCards 290 return ( OContactAccess::WildCards
288 & OContactAccess::IgnoreCase 291 & OContactAccess::IgnoreCase
289 & OContactAccess::RegExp 292 & OContactAccess::RegExp
290 & OContactAccess::ExactMatch ); 293 & OContactAccess::ExactMatch );
291 } 294 }
292 295
293 bool hasQuerySettings (uint querySettings) const 296 bool hasQuerySettings (uint querySettings) const
294 { 297 {
295 /* OContactAccess::IgnoreCase may be added with one 298 /* OContactAccess::IgnoreCase may be added with one
296 * of the other settings, but never used alone. 299 * of the other settings, but never used alone.
297 * The other settings are just valid alone... 300 * The other settings are just valid alone...
298 */ 301 */
299 switch ( querySettings & ~OContactAccess::IgnoreCase ){ 302 switch ( querySettings & ~OContactAccess::IgnoreCase ){
300 case OContactAccess::RegExp: 303 case OContactAccess::RegExp:
301 return ( true ); 304 return ( true );
302 case OContactAccess::WildCards: 305 case OContactAccess::WildCards:
303 return ( true ); 306 return ( true );
304 case OContactAccess::ExactMatch: 307 case OContactAccess::ExactMatch:
305 return ( true ); 308 return ( true );
306 default: 309 default:
307 return ( false ); 310 return ( false );
308 } 311 }
309 } 312 }
310 313
311 // Currently only asc implemented.. 314 // Currently only asc implemented..
312 QArray<int> sorted( bool asc, int , int , int ) 315 QArray<int> sorted( bool asc, int , int , int )
313 { 316 {
314 QMap<QString, int> nameToUid; 317 QMap<QString, int> nameToUid;
315 QStringList names; 318 QStringList names;
316 QArray<int> m_currentQuery( m_contactList.count() ); 319 QArray<int> m_currentQuery( m_contactList.count() );
317 320
318 // First fill map and StringList with all Names 321 // First fill map and StringList with all Names
319 // Afterwards sort namelist and use map to fill array to return.. 322 // Afterwards sort namelist and use map to fill array to return..
320 QValueListConstIterator<OContact> it; 323 QValueListConstIterator<OContact> it;
321 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 324 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
322 names.append( (*it).fileAs() ); 325 names.append( (*it).fileAs() + QString::number( (*it).uid() ) );
323 nameToUid.insert( (*it).fileAs(), (*it).uid() ); 326 nameToUid.insert( (*it).fileAs() + QString::number( (*it).uid() ), (*it).uid() );
324 } 327 }
325 names.sort(); 328 names.sort();
326 329
327 int i = 0; 330 int i = 0;
328 if ( asc ){ 331 if ( asc ){
329 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 332 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
330 m_currentQuery[i++] = nameToUid[ (*it) ]; 333 m_currentQuery[i++] = nameToUid[ (*it) ];
331 }else{ 334 }else{
332 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 335 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
333 m_currentQuery[i++] = nameToUid[ (*it) ]; 336 m_currentQuery[i++] = nameToUid[ (*it) ];
334 } 337 }
335 338
336 return m_currentQuery; 339 return m_currentQuery;
337 340
338 } 341 }
339 bool add ( const OContact &newcontact ) 342 bool add ( const OContact &newcontact )
340 { 343 {
341 //qWarning("odefaultbackend: ACTION::ADD"); 344 //qWarning("odefaultbackend: ACTION::ADD");
342 updateJournal (newcontact, OContact::ACTION_ADD); 345 updateJournal (newcontact, OContact::ACTION_ADD);
343 addContact_p( newcontact ); 346 addContact_p( newcontact );
344 347
345 m_changed = true; 348 m_changed = true;
346 349
347 return true; 350 return true;
348 } 351 }
349 352
350 bool replace ( const OContact &contact ) 353 bool replace ( const OContact &contact )
351 { 354 {
352 m_changed = true; 355 m_changed = true;
353 356
354 bool found = false; 357 bool found = false;
355 358
356 QValueListIterator<OContact> it; 359 QValueListIterator<OContact> it;
357 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 360 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
358 if ( (*it).uid() == contact.uid() ){ 361 if ( (*it).uid() == contact.uid() ){
359 found = true; 362 found = true;
360 break; 363 break;
361 } 364 }
362 } 365 }
363 if (found) { 366 if (found) {
364 updateJournal (contact, OContact::ACTION_REPLACE); 367 updateJournal (contact, OContact::ACTION_REPLACE);
365 m_contactList.remove (it); 368 m_contactList.remove (it);
366 m_contactList.append (contact); 369 m_contactList.append (contact);
367 return true; 370 return true;
368 } else 371 } else
369 return false; 372 return false;
370 } 373 }
371 374