Diffstat (limited to 'libopie/pim/ocontactaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.cpp | 171 |
1 files changed, 88 insertions, 83 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp index c5a7820..661cd51 100644 --- a/libopie/pim/ocontactaccessbackend_xml.cpp +++ b/libopie/pim/ocontactaccessbackend_xml.cpp | |||
@@ -19,2 +19,7 @@ | |||
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 25 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
@@ -95,3 +100,3 @@ | |||
95 | #include <qmap.h> | 100 | #include <qmap.h> |
96 | #include <qdatetime.h> | 101 | #include <qdatetime.h> |
97 | 102 | ||
@@ -109,3 +114,3 @@ using namespace Opie; | |||
109 | 114 | ||
110 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ): | 115 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
111 | m_changed( false ) | 116 | m_changed( false ) |
@@ -118,3 +123,3 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString | |||
118 | m_appName = appname; | 123 | m_appName = appname; |
119 | 124 | ||
120 | /* Set journalfile name ... */ | 125 | /* Set journalfile name ... */ |
@@ -122,3 +127,3 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString | |||
122 | m_journalName +="/.abjournal" + appname; | 127 | m_journalName +="/.abjournal" + appname; |
123 | 128 | ||
124 | /* Expecting to access the default filename if nothing else is set */ | 129 | /* Expecting to access the default filename if nothing else is set */ |
@@ -128,3 +133,3 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString | |||
128 | m_fileName = filename; | 133 | m_fileName = filename; |
129 | 134 | ||
130 | /* Load Database now */ | 135 | /* Load Database now */ |
@@ -133,8 +138,8 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString | |||
133 | 138 | ||
134 | bool OContactAccessBackend_XML::save() | 139 | bool OContactAccessBackend_XML::save() |
135 | { | 140 | { |
136 | 141 | ||
137 | if ( !m_changed ) | 142 | if ( !m_changed ) |
138 | return true; | 143 | return true; |
139 | 144 | ||
140 | QString strNewFile = m_fileName + ".new"; | 145 | QString strNewFile = m_fileName + ".new"; |
@@ -143,3 +148,3 @@ bool OContactAccessBackend_XML::save() | |||
143 | return false; | 148 | return false; |
144 | 149 | ||
145 | int total_written; | 150 | int total_written; |
@@ -176,3 +181,3 @@ bool OContactAccessBackend_XML::save() | |||
176 | out += " </Contacts>\n</AddressBook>\n"; | 181 | out += " </Contacts>\n</AddressBook>\n"; |
177 | 182 | ||
178 | // Write Footer | 183 | // Write Footer |
@@ -186,3 +191,3 @@ bool OContactAccessBackend_XML::save() | |||
186 | f.close(); | 191 | f.close(); |
187 | 192 | ||
188 | // move the file over, I'm just going to use the system call | 193 | // move the file over, I'm just going to use the system call |
@@ -195,6 +200,6 @@ bool OContactAccessBackend_XML::save() | |||
195 | } | 200 | } |
196 | 201 | ||
197 | /* The journalfile should be removed now... */ | 202 | /* The journalfile should be removed now... */ |
198 | removeJournal(); | 203 | removeJournal(); |
199 | 204 | ||
200 | m_changed = false; | 205 | m_changed = false; |
@@ -203,3 +208,3 @@ bool OContactAccessBackend_XML::save() | |||
203 | 208 | ||
204 | bool OContactAccessBackend_XML::load () | 209 | bool OContactAccessBackend_XML::load () |
205 | { | 210 | { |
@@ -207,3 +212,3 @@ bool OContactAccessBackend_XML::load () | |||
207 | m_uidToContact.clear(); | 212 | m_uidToContact.clear(); |
208 | 213 | ||
209 | /* Load XML-File and journal if it exists */ | 214 | /* Load XML-File and journal if it exists */ |
@@ -218,3 +223,3 @@ bool OContactAccessBackend_XML::load () | |||
218 | load (m_journalName, true); | 223 | load (m_journalName, true); |
219 | 224 | ||
220 | return true; | 225 | return true; |
@@ -222,3 +227,3 @@ bool OContactAccessBackend_XML::load () | |||
222 | 227 | ||
223 | void OContactAccessBackend_XML::clear () | 228 | void OContactAccessBackend_XML::clear () |
224 | { | 229 | { |
@@ -233,5 +238,5 @@ bool OContactAccessBackend_XML::wasChangedExternally() | |||
233 | QFileInfo fi( m_fileName ); | 238 | QFileInfo fi( m_fileName ); |
234 | 239 | ||
235 | QDateTime lastmod = fi.lastModified (); | 240 | QDateTime lastmod = fi.lastModified (); |
236 | 241 | ||
237 | return (lastmod != m_readtime); | 242 | return (lastmod != m_readtime); |
@@ -239,7 +244,7 @@ bool OContactAccessBackend_XML::wasChangedExternally() | |||
239 | 244 | ||
240 | QArray<int> OContactAccessBackend_XML::allRecords() const | 245 | QArray<int> OContactAccessBackend_XML::allRecords() const |
241 | { | 246 | { |
242 | QArray<int> uid_list( m_contactList.count() ); | 247 | QArray<int> uid_list( m_contactList.count() ); |
243 | 248 | ||
244 | uint counter = 0; | 249 | uint counter = 0; |
245 | QListIterator<OContact> it( m_contactList ); | 250 | QListIterator<OContact> it( m_contactList ); |
@@ -248,3 +253,3 @@ QArray<int> OContactAccessBackend_XML::allRecords() const | |||
248 | } | 253 | } |
249 | 254 | ||
250 | return ( uid_list ); | 255 | return ( uid_list ); |
@@ -255,3 +260,3 @@ OContact OContactAccessBackend_XML::find ( int uid ) const | |||
255 | OContact foundContact; //Create empty contact | 260 | OContact foundContact; //Create empty contact |
256 | 261 | ||
257 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 262 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
@@ -261,3 +266,3 @@ OContact OContactAccessBackend_XML::find ( int uid ) const | |||
261 | } | 266 | } |
262 | 267 | ||
263 | return ( foundContact ); | 268 | return ( foundContact ); |
@@ -265,6 +270,6 @@ OContact OContactAccessBackend_XML::find ( int uid ) const | |||
265 | 270 | ||
266 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 271 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
267 | const QDateTime& d ) | 272 | const QDateTime& d ) |
268 | { | 273 | { |
269 | 274 | ||
270 | QArray<int> m_currentQuery( m_contactList.count() ); | 275 | QArray<int> m_currentQuery( m_contactList.count() ); |
@@ -272,3 +277,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
272 | uint arraycounter = 0; | 277 | uint arraycounter = 0; |
273 | 278 | ||
274 | for( ; it.current(); ++it ){ | 279 | for( ; it.current(); ++it ){ |
@@ -292,3 +297,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
292 | } | 297 | } |
293 | 298 | ||
294 | if ( queryDate->isValid() ){ | 299 | if ( queryDate->isValid() ){ |
@@ -298,3 +303,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
298 | allcorrect = false; | 303 | allcorrect = false; |
299 | } | 304 | } |
300 | if ( settings & OContactAccess::DateMonth ){ | 305 | if ( settings & OContactAccess::DateMonth ){ |
@@ -302,3 +307,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
302 | allcorrect = false; | 307 | allcorrect = false; |
303 | } | 308 | } |
304 | if ( settings & OContactAccess::DateDay ){ | 309 | if ( settings & OContactAccess::DateDay ){ |
@@ -306,3 +311,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
306 | allcorrect = false; | 311 | allcorrect = false; |
307 | } | 312 | } |
308 | if ( settings & OContactAccess::DateDiff ) { | 313 | if ( settings & OContactAccess::DateDiff ) { |
@@ -311,3 +316,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
311 | // will take this date instead of | 316 | // will take this date instead of |
312 | // the current one.. | 317 | // the current one.. |
313 | if ( !d.date().isValid() ) | 318 | if ( !d.date().isValid() ) |
@@ -319,8 +324,8 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
319 | // the search will fail.. | 324 | // the search will fail.. |
320 | checkDate->setYMD( current.year(), | 325 | checkDate->setYMD( current.year(), |
321 | checkDate->month(), | 326 | checkDate->month(), |
322 | checkDate->day() ); | 327 | checkDate->day() ); |
323 | if ( *checkDate < current ) | 328 | if ( *checkDate < current ) |
324 | checkDate->setYMD( current.year()+1, | 329 | checkDate->setYMD( current.year()+1, |
325 | checkDate->month(), | 330 | checkDate->month(), |
326 | checkDate->day() ); | 331 | checkDate->day() ); |
@@ -330,8 +335,8 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
330 | // ( maximum time range ) ! | 335 | // ( maximum time range ) ! |
331 | qWarning("Checking if %s is between %s and %s ! ", | 336 | qWarning("Checking if %s is between %s and %s ! ", |
332 | checkDate->toString().latin1(), | 337 | checkDate->toString().latin1(), |
333 | current.toString().latin1(), | 338 | current.toString().latin1(), |
334 | queryDate->toString().latin1() ); | 339 | queryDate->toString().latin1() ); |
335 | if ( current.daysTo( *queryDate ) >= 0 ){ | 340 | if ( current.daysTo( *queryDate ) >= 0 ){ |
336 | if ( !( ( *checkDate >= current ) && | 341 | if ( !( ( *checkDate >= current ) && |
337 | ( *checkDate <= *queryDate ) ) ){ | 342 | ( *checkDate <= *queryDate ) ) ){ |
@@ -347,3 +352,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
347 | } | 352 | } |
348 | 353 | ||
349 | delete queryDate; | 354 | delete queryDate; |
@@ -361,5 +366,5 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
361 | | OContactAccess::DateDay | 366 | | OContactAccess::DateDay |
362 | | OContactAccess::MatchOne | 367 | | OContactAccess::MatchOne |
363 | ) ){ | 368 | ) ){ |
364 | 369 | ||
365 | case OContactAccess::RegExp:{ | 370 | case OContactAccess::RegExp:{ |
@@ -399,6 +404,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
399 | } | 404 | } |
400 | 405 | ||
401 | // Shrink to fit.. | 406 | // Shrink to fit.. |
402 | m_currentQuery.resize(arraycounter); | 407 | m_currentQuery.resize(arraycounter); |
403 | 408 | ||
404 | return m_currentQuery; | 409 | return m_currentQuery; |
@@ -411,3 +416,3 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | |||
411 | uint arraycounter = 0; | 416 | uint arraycounter = 0; |
412 | 417 | ||
413 | for( ; it.current(); ++it ){ | 418 | for( ; it.current(); ++it ){ |
@@ -416,3 +421,3 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | |||
416 | } | 421 | } |
417 | 422 | ||
418 | } | 423 | } |
@@ -420,3 +425,3 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | |||
420 | m_currentQuery.resize(arraycounter); | 425 | m_currentQuery.resize(arraycounter); |
421 | 426 | ||
422 | return m_currentQuery; | 427 | return m_currentQuery; |
@@ -429,3 +434,3 @@ const uint OContactAccessBackend_XML::querySettings() | |||
429 | | OContactAccess::RegExp | 434 | | OContactAccess::RegExp |
430 | | OContactAccess::ExactMatch | 435 | | OContactAccess::ExactMatch |
431 | | OContactAccess::DateDiff | 436 | | OContactAccess::DateDiff |
@@ -439,3 +444,3 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | |||
439 | { | 444 | { |
440 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 445 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
441 | * may be added with any of the other settings. IgnoreCase should never used alone. | 446 | * may be added with any of the other settings. IgnoreCase should never used alone. |
@@ -443,6 +448,6 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | |||
443 | */ | 448 | */ |
444 | 449 | ||
445 | if ( querySettings == OContactAccess::IgnoreCase ) | 450 | if ( querySettings == OContactAccess::IgnoreCase ) |
446 | return false; | 451 | return false; |
447 | 452 | ||
448 | switch ( querySettings & ~( OContactAccess::IgnoreCase | 453 | switch ( querySettings & ~( OContactAccess::IgnoreCase |
@@ -452,3 +457,3 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | |||
452 | | OContactAccess::DateDay | 457 | | OContactAccess::DateDay |
453 | ) | 458 | ) |
454 | ){ | 459 | ){ |
@@ -465,4 +470,4 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | |||
465 | 470 | ||
466 | // Currently only asc implemented.. | 471 | // Currently only asc implemented.. |
467 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 472 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
468 | { | 473 | { |
@@ -471,4 +476,4 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
471 | QArray<int> m_currentQuery( m_contactList.count() ); | 476 | QArray<int> m_currentQuery( m_contactList.count() ); |
472 | 477 | ||
473 | // First fill map and StringList with all Names | 478 | // First fill map and StringList with all Names |
474 | // Afterwards sort namelist and use map to fill array to return.. | 479 | // Afterwards sort namelist and use map to fill array to return.. |
@@ -480,3 +485,3 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
480 | names.sort(); | 485 | names.sort(); |
481 | 486 | ||
482 | int i = 0; | 487 | int i = 0; |
@@ -489,5 +494,5 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
489 | } | 494 | } |
490 | 495 | ||
491 | return m_currentQuery; | 496 | return m_currentQuery; |
492 | 497 | ||
493 | } | 498 | } |
@@ -499,5 +504,5 @@ bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | |||
499 | addContact_p( newcontact ); | 504 | addContact_p( newcontact ); |
500 | 505 | ||
501 | m_changed = true; | 506 | m_changed = true; |
502 | 507 | ||
503 | return true; | 508 | return true; |
@@ -508,3 +513,3 @@ bool OContactAccessBackend_XML::replace ( const OContact &contact ) | |||
508 | m_changed = true; | 513 | m_changed = true; |
509 | 514 | ||
510 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); | 515 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
@@ -530,3 +535,3 @@ bool OContactAccessBackend_XML::remove ( int uid ) | |||
530 | m_changed = true; | 535 | m_changed = true; |
531 | 536 | ||
532 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 537 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
@@ -557,5 +562,5 @@ void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | |||
557 | /* This function loads the xml-database and the journalfile */ | 562 | /* This function loads the xml-database and the journalfile */ |
558 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 563 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
559 | { | 564 | { |
560 | 565 | ||
561 | /* We use the time of the last read to check if the file was | 566 | /* We use the time of the last read to check if the file was |
@@ -567,6 +572,6 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
567 | } | 572 | } |
568 | 573 | ||
569 | const int JOURNALACTION = Qtopia::Notes + 1; | 574 | const int JOURNALACTION = Qtopia::Notes + 1; |
570 | const int JOURNALROW = JOURNALACTION + 1; | 575 | const int JOURNALROW = JOURNALACTION + 1; |
571 | 576 | ||
572 | bool foundAction = false; | 577 | bool foundAction = false; |
@@ -578,3 +583,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
578 | QAsciiDict<int> dict( 47 ); | 583 | QAsciiDict<int> dict( 47 ); |
579 | 584 | ||
580 | dict.setAutoDelete( TRUE ); | 585 | dict.setAutoDelete( TRUE ); |
@@ -625,5 +630,5 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
625 | dict.insert( "actionrow", new int(JOURNALROW) ); | 630 | dict.insert( "actionrow", new int(JOURNALROW) ); |
626 | 631 | ||
627 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 632 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
628 | 633 | ||
629 | XMLElement *root = XMLElement::load( filename ); | 634 | XMLElement *root = XMLElement::load( filename ); |
@@ -636,3 +641,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
636 | element = element->firstChild(); | 641 | element = element->firstChild(); |
637 | 642 | ||
638 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 643 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
@@ -663,3 +668,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
663 | foundAction = false; | 668 | foundAction = false; |
664 | 669 | ||
665 | XMLElement::AttributeMap aMap = element->attributes(); | 670 | XMLElement::AttributeMap aMap = element->attributes(); |
@@ -670,3 +675,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
670 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 675 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
671 | 676 | ||
672 | int *find = dict[ it.key() ]; | 677 | int *find = dict[ it.key() ]; |
@@ -679,3 +684,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
679 | } | 684 | } |
680 | 685 | ||
681 | /* Check if special conversion is needed and add attribute | 686 | /* Check if special conversion is needed and add attribute |
@@ -707,3 +712,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
707 | OContact contact( contactMap ); | 712 | OContact contact( contactMap ); |
708 | 713 | ||
709 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 714 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
@@ -711,3 +716,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
711 | } | 716 | } |
712 | 717 | ||
713 | if (foundAction){ | 718 | if (foundAction){ |
@@ -736,3 +741,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
736 | } | 741 | } |
737 | 742 | ||
738 | /* Move to next element */ | 743 | /* Move to next element */ |
@@ -750,3 +755,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
750 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 755 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
751 | journal_action action ) | 756 | journal_action action ) |
752 | { | 757 | { |
@@ -756,6 +761,6 @@ void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | |||
756 | return; | 761 | return; |
757 | 762 | ||
758 | QString buf; | 763 | QString buf; |
759 | QCString str; | 764 | QCString str; |
760 | 765 | ||
761 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 766 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
@@ -768,3 +773,3 @@ void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | |||
768 | } | 773 | } |
769 | 774 | ||
770 | buf = "<Contact "; | 775 | buf = "<Contact "; |