summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index c584c35..3641c0c 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -416,161 +416,162 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count();
513} 514}
514void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
515{ 516{
516 Iterator ait; 517 Iterator ait;
517 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
518 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
519 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
520 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
521 } else 522 } else
522 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
523 } else 524 } else
524 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
525 } 526 }
526} 527}
527void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
528{ 529{
529 Iterator ait; 530 Iterator ait;
530 bool todelete = false; 531 bool todelete = false;
531 Iterator todel; 532 Iterator todel;
532 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
533 if ( todelete ) 534 if ( todelete )
534 removeAddressee( todel ); 535 removeAddressee( todel );
535 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
536 todelete = true; 537 todelete = true;
537 todel = ait; 538 todel = ait;
538 } else 539 } else
539 todelete = false; 540 todelete = false;
540 } 541 }
541 if ( todelete ) 542 if ( todelete )
542 removeAddressee( todel ); 543 removeAddressee( todel );
543 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
544} 545}
545void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
546{ 547{
547 Iterator ait; 548 Iterator ait;
548 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
549 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
550 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
551 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
552 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
553 } 554 }
554} 555}
555void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 556void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
556{ 557{
557 Iterator ait; 558 Iterator ait;
558 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
559 QString id = (*ait).IDStr(); 560 QString id = (*ait).IDStr();
560 (*ait).setIDStr( ":"); 561 (*ait).setIDStr( ":");
561 (*ait).setExternalUID( id ); 562 (*ait).setExternalUID( id );
562 (*ait).setOriginalExternalUID( id ); 563 (*ait).setOriginalExternalUID( id );
563 if ( isPreSync ) 564 if ( isPreSync )
564 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 565 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
565 else { 566 else {
566 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 567 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
567 (*ait).setID( currentSyncDevice,id ); 568 (*ait).setID( currentSyncDevice,id );
568 569
569 } 570 }
570 } 571 }
571} 572}
572void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 573void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
573{ 574{
574 575
575 setUntagged(); 576 setUntagged();
576 KABC::Addressee::List list; 577 KABC::Addressee::List list;