summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
authorzautrix <zautrix>2004-10-09 16:58:08 (UTC)
committer zautrix <zautrix>2004-10-09 16:58:08 (UTC)
commit59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 (patch) (unidiff)
tree8b1cbcf9c420e7dffd1e1293bcfa69e8e821f3fa /kabc/addressbook.cpp
parentb80a099d9432bdc3d4eea778b1813b82b2680ecf (diff)
downloadkdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.zip
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.gz
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.bz2
fixed sync bug
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp72
1 files changed, 46 insertions, 26 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 1050f55..ff05f7e 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -310,220 +310,240 @@ void AddressBook::init(const QString &config, const QString &family )
310 "X-ManagersName", "KADDRESSBOOK" ); 310 "X-ManagersName", "KADDRESSBOOK" );
311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
312 "X-SpousesName", "KADDRESSBOOK" ); 312 "X-SpousesName", "KADDRESSBOOK" );
313 addCustomField( i18n( "Office" ), KABC::Field::Personal, 313 addCustomField( i18n( "Office" ), KABC::Field::Personal,
314 "X-Office", "KADDRESSBOOK" ); 314 "X-Office", "KADDRESSBOOK" );
315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
316 "X-IMAddress", "KADDRESSBOOK" ); 316 "X-IMAddress", "KADDRESSBOOK" );
317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
318 "X-Anniversary", "KADDRESSBOOK" ); 318 "X-Anniversary", "KADDRESSBOOK" );
319 319
320 //US added this field to become compatible with Opie/qtopia addressbook 320 //US added this field to become compatible with Opie/qtopia addressbook
321 // values can be "female" or "male" or "". An empty field represents undefined. 321 // values can be "female" or "male" or "". An empty field represents undefined.
322 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 322 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
323 "X-Gender", "KADDRESSBOOK" ); 323 "X-Gender", "KADDRESSBOOK" );
324 addCustomField( i18n( "Children" ), KABC::Field::Personal, 324 addCustomField( i18n( "Children" ), KABC::Field::Personal,
325 "X-Children", "KADDRESSBOOK" ); 325 "X-Children", "KADDRESSBOOK" );
326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
327 "X-FreeBusyUrl", "KADDRESSBOOK" ); 327 "X-FreeBusyUrl", "KADDRESSBOOK" );
328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
329 "X-ExternalID", "KADDRESSBOOK" ); 329 "X-ExternalID", "KADDRESSBOOK" );
330} 330}
331 331
332AddressBook::~AddressBook() 332AddressBook::~AddressBook()
333{ 333{
334 delete d->mConfig; d->mConfig = 0; 334 delete d->mConfig; d->mConfig = 0;
335 delete d->mManager; d->mManager = 0; 335 delete d->mManager; d->mManager = 0;
336//US delete d->mErrorHandler; d->mErrorHandler = 0; 336//US delete d->mErrorHandler; d->mErrorHandler = 0;
337 delete d; d = 0; 337 delete d; d = 0;
338} 338}
339 339
340bool AddressBook::load() 340bool AddressBook::load()
341{ 341{
342 342
343 343
344 clear(); 344 clear();
345 345
346 KRES::Manager<Resource>::ActiveIterator it; 346 KRES::Manager<Resource>::ActiveIterator it;
347 bool ok = true; 347 bool ok = true;
348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
349 if ( !(*it)->load() ) { 349 if ( !(*it)->load() ) {
350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
351 ok = false; 351 ok = false;
352 } 352 }
353 353
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379void AddressBook::export2File( QString fileName ) 379void AddressBook::export2File( QString fileName )
380{ 380{
381 381
382 QFile outFile( fileName ); 382 QFile outFile( fileName );
383 if ( !outFile.open( IO_WriteOnly ) ) { 383 if ( !outFile.open( IO_WriteOnly ) ) {
384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
385 KMessageBox::error( 0, text.arg( fileName ) ); 385 KMessageBox::error( 0, text.arg( fileName ) );
386 return ; 386 return ;
387 } 387 }
388 QTextStream t( &outFile ); 388 QTextStream t( &outFile );
389 t.setEncoding( QTextStream::UnicodeUTF8 ); 389 t.setEncoding( QTextStream::UnicodeUTF8 );
390 Iterator it; 390 Iterator it;
391 KABC::VCardConverter::Version version; 391 KABC::VCardConverter::Version version;
392 version = KABC::VCardConverter::v3_0; 392 version = KABC::VCardConverter::v3_0;
393 for ( it = begin(); it != end(); ++it ) { 393 for ( it = begin(); it != end(); ++it ) {
394 if ( !(*it).IDStr().isEmpty() ) { 394 if ( !(*it).IDStr().isEmpty() ) {
395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
396 } 396 }
397 KABC::VCardConverter converter; 397 KABC::VCardConverter converter;
398 QString vcard; 398 QString vcard;
399 //Resource *resource() const; 399 //Resource *resource() const;
400 converter.addresseeToVCard( *it, vcard, version ); 400 converter.addresseeToVCard( *it, vcard, version );
401 t << vcard << "\r\n"; 401 t << vcard << "\r\n";
402 } 402 }
403 t << "\r\n\r\n"; 403 t << "\r\n\r\n";
404 outFile.close(); 404 outFile.close();
405} 405}
406void AddressBook::importFromFile( QString fileName, bool replaceLabel ) 406void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
407{ 407{
408 408
409 KABC::Addressee::List list; 409 if ( removeOld )
410 QFile file( fileName ); 410 setUntagged();
411 411 KABC::Addressee::List list;
412 file.open( IO_ReadOnly ); 412 QFile file( fileName );
413 QByteArray rawData = file.readAll(); 413 file.open( IO_ReadOnly );
414 file.close(); 414 QByteArray rawData = file.readAll();
415 QString data; 415 file.close();
416 if ( replaceLabel ) { 416 QString data;
417 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 417 if ( replaceLabel ) {
418 data.replace ( QRegExp("LABEL") , "ADR" ); 418 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
419 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 419 data.replace ( QRegExp("LABEL") , "ADR" );
420 } else 420 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
421 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 421 } else
422 KABC::VCardTool tool; 422 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
423 list = tool.parseVCards( data ); 423 KABC::VCardTool tool;
424 KABC::Addressee::List::Iterator it; 424 list = tool.parseVCards( data );
425 for ( it = list.begin(); it != list.end(); ++it ) { 425 KABC::Addressee::List::Iterator it;
426 (*it).setResource( 0 ); 426 for ( it = list.begin(); it != list.end(); ++it ) {
427 if ( replaceLabel ) 427 (*it).setResource( 0 );
428 (*it).removeVoice(); 428 if ( replaceLabel )
429 insertAddressee( (*it), false, true ); 429 (*it).removeVoice();
430 if ( removeOld )
431 (*it).setTagged( true );
432 insertAddressee( (*it), false, true );
433 }
434 if ( removeOld )
435 removeUntagged();
436}
437void AddressBook::setUntagged()
438{
439 Iterator ait;
440 for ( ait = begin(); ait != end(); ++ait ) {
441 (*ait).setTagged( false );
442 }
443}
444void AddressBook::removeUntagged()
445{
446 Iterator ait;
447 for ( ait = begin(); ait != end(); ++ait ) {
448 if (!(*ait).tagged())
449 removeAddressee( ait );
430 } 450 }
431 451
452 deleteRemovedAddressees();
432} 453}
433
434bool AddressBook::saveAB() 454bool AddressBook::saveAB()
435{ 455{
436 bool ok = true; 456 bool ok = true;
437 457
438 deleteRemovedAddressees(); 458 deleteRemovedAddressees();
439 Iterator ait; 459 Iterator ait;
440 for ( ait = begin(); ait != end(); ++ait ) { 460 for ( ait = begin(); ait != end(); ++ait ) {
441 if ( !(*ait).IDStr().isEmpty() ) { 461 if ( !(*ait).IDStr().isEmpty() ) {
442 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 462 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
443 } 463 }
444 } 464 }
445 KRES::Manager<Resource>::ActiveIterator it; 465 KRES::Manager<Resource>::ActiveIterator it;
446 KRES::Manager<Resource> *manager = d->mManager; 466 KRES::Manager<Resource> *manager = d->mManager;
447 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 467 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
448 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 468 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
449 Ticket *ticket = requestSaveTicket( *it ); 469 Ticket *ticket = requestSaveTicket( *it );
450// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 470// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
451 if ( !ticket ) { 471 if ( !ticket ) {
452 error( i18n( "Unable to save to resource '%1'. It is locked." ) 472 error( i18n( "Unable to save to resource '%1'. It is locked." )
453 .arg( (*it)->resourceName() ) ); 473 .arg( (*it)->resourceName() ) );
454 return false; 474 return false;
455 } 475 }
456 476
457 //if ( !save( ticket ) ) 477 //if ( !save( ticket ) )
458 if ( ticket->resource() ) { 478 if ( ticket->resource() ) {
459 if ( ! ticket->resource()->save( ticket ) ) 479 if ( ! ticket->resource()->save( ticket ) )
460 ok = false; 480 ok = false;
461 } else 481 } else
462 ok = false; 482 ok = false;
463 483
464 } 484 }
465 } 485 }
466 return ok; 486 return ok;
467} 487}
468 488
469AddressBook::Iterator AddressBook::begin() 489AddressBook::Iterator AddressBook::begin()
470{ 490{
471 Iterator it = Iterator(); 491 Iterator it = Iterator();
472 it.d->mIt = d->mAddressees.begin(); 492 it.d->mIt = d->mAddressees.begin();
473 return it; 493 return it;
474} 494}
475 495
476AddressBook::ConstIterator AddressBook::begin() const 496AddressBook::ConstIterator AddressBook::begin() const
477{ 497{
478 ConstIterator it = ConstIterator(); 498 ConstIterator it = ConstIterator();
479 it.d->mIt = d->mAddressees.begin(); 499 it.d->mIt = d->mAddressees.begin();
480 return it; 500 return it;
481} 501}
482 502
483AddressBook::Iterator AddressBook::end() 503AddressBook::Iterator AddressBook::end()
484{ 504{
485 Iterator it = Iterator(); 505 Iterator it = Iterator();
486 it.d->mIt = d->mAddressees.end(); 506 it.d->mIt = d->mAddressees.end();
487 return it; 507 return it;
488} 508}
489 509
490AddressBook::ConstIterator AddressBook::end() const 510AddressBook::ConstIterator AddressBook::end() const
491{ 511{
492 ConstIterator it = ConstIterator(); 512 ConstIterator it = ConstIterator();
493 it.d->mIt = d->mAddressees.end(); 513 it.d->mIt = d->mAddressees.end();
494 return it; 514 return it;
495} 515}
496 516
497void AddressBook::clear() 517void AddressBook::clear()
498{ 518{
499 d->mAddressees.clear(); 519 d->mAddressees.clear();
500} 520}
501 521
502Ticket *AddressBook::requestSaveTicket( Resource *resource ) 522Ticket *AddressBook::requestSaveTicket( Resource *resource )
503{ 523{
504 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 524 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
505 525
506 if ( !resource ) 526 if ( !resource )
507 { 527 {
508 qDebug("AddressBook::requestSaveTicket no resource" ); 528 qDebug("AddressBook::requestSaveTicket no resource" );
509 resource = standardResource(); 529 resource = standardResource();
510 } 530 }
511 531
512 KRES::Manager<Resource>::ActiveIterator it; 532 KRES::Manager<Resource>::ActiveIterator it;
513 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 533 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
514 if ( (*it) == resource ) { 534 if ( (*it) == resource ) {
515 if ( (*it)->readOnly() || !(*it)->isOpen() ) 535 if ( (*it)->readOnly() || !(*it)->isOpen() )
516 return 0; 536 return 0;
517 else 537 else
518 return (*it)->requestSaveTicket(); 538 return (*it)->requestSaveTicket();
519 } 539 }
520 } 540 }
521 541
522 return 0; 542 return 0;
523} 543}
524 544
525void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 545void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
526{ 546{
527 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 547 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
528 //qDebug("block insert "); 548 //qDebug("block insert ");
529 return; 549 return;