-rw-r--r-- | kabc/addressbook.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 3641c0c..2785131 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -460,192 +460,200 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | |||
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 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int 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 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | ||
557 | { | ||
558 | Iterator ait; | ||
559 | for ( ait = begin(); ait != end(); ++ait ) { | ||
560 | (*ait).removeID( syncProfile ); | ||
561 | } | ||
562 | |||
563 | } | ||
556 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 564 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
557 | { | 565 | { |
558 | Iterator ait; | 566 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 567 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | QString id = (*ait).IDStr(); | 568 | QString id = (*ait).IDStr(); |
561 | (*ait).setIDStr( ":"); | 569 | (*ait).setIDStr( ":"); |
562 | (*ait).setExternalUID( id ); | 570 | (*ait).setExternalUID( id ); |
563 | (*ait).setOriginalExternalUID( id ); | 571 | (*ait).setOriginalExternalUID( id ); |
564 | if ( isPreSync ) | 572 | if ( isPreSync ) |
565 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 573 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
566 | else { | 574 | else { |
567 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 575 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
568 | (*ait).setID( currentSyncDevice,id ); | 576 | (*ait).setID( currentSyncDevice,id ); |
569 | 577 | ||
570 | } | 578 | } |
571 | } | 579 | } |
572 | } | 580 | } |
573 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 581 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
574 | { | 582 | { |
575 | 583 | ||
576 | setUntagged(); | 584 | setUntagged(); |
577 | KABC::Addressee::List list; | 585 | KABC::Addressee::List list; |
578 | QFile file( fileName ); | 586 | QFile file( fileName ); |
579 | file.open( IO_ReadOnly ); | 587 | file.open( IO_ReadOnly ); |
580 | QByteArray rawData = file.readAll(); | 588 | QByteArray rawData = file.readAll(); |
581 | file.close(); | 589 | file.close(); |
582 | QString data; | 590 | QString data; |
583 | 591 | ||
584 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 592 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
585 | KABC::VCardTool tool; | 593 | KABC::VCardTool tool; |
586 | list = tool.parseVCards( data ); | 594 | list = tool.parseVCards( data ); |
587 | KABC::Addressee::List::Iterator it; | 595 | KABC::Addressee::List::Iterator it; |
588 | for ( it = list.begin(); it != list.end(); ++it ) { | 596 | for ( it = list.begin(); it != list.end(); ++it ) { |
589 | Iterator ait; | 597 | Iterator ait; |
590 | for ( ait = begin(); ait != end(); ++ait ) { | 598 | for ( ait = begin(); ait != end(); ++ait ) { |
591 | if ( !(*ait).tagged() ) { | 599 | if ( !(*ait).tagged() ) { |
592 | if ( (*ait).containsAdr(*it)) { | 600 | if ( (*ait).containsAdr(*it)) { |
593 | (*ait).setTagged(true); | 601 | (*ait).setTagged(true); |
594 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 602 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
595 | (*it).setIDStr( ":"); | 603 | (*it).setIDStr( ":"); |
596 | (*it).setID( currentSyncDevice,id ); | 604 | (*it).setID( currentSyncDevice,id ); |
597 | (*it).setExternalUID( id ); | 605 | (*it).setExternalUID( id ); |
598 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 606 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
599 | (*it).setUid( ( (*ait).uid() )); | 607 | (*it).setUid( ( (*ait).uid() )); |
600 | break; | 608 | break; |
601 | } | 609 | } |
602 | } | 610 | } |
603 | 611 | ||
604 | } | 612 | } |
605 | if ( ait == end() ) | 613 | if ( ait == end() ) |
606 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 614 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
607 | } | 615 | } |
608 | clear(); | 616 | clear(); |
609 | for ( it = list.begin(); it != list.end(); ++it ) { | 617 | for ( it = list.begin(); it != list.end(); ++it ) { |
610 | insertAddressee( (*it) ); | 618 | insertAddressee( (*it) ); |
611 | } | 619 | } |
612 | } | 620 | } |
613 | 621 | ||
614 | bool AddressBook::saveABphone( QString fileName ) | 622 | bool AddressBook::saveABphone( QString fileName ) |
615 | { | 623 | { |
616 | //smplifyAddressees(); | 624 | //smplifyAddressees(); |
617 | qDebug("saveABphone:: saving AB... "); | 625 | qDebug("saveABphone:: saving AB... "); |
618 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 626 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
619 | return false; | 627 | return false; |
620 | qDebug("saveABphone:: writing to phone... "); | 628 | qDebug("saveABphone:: writing to phone... "); |
621 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 629 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
622 | return false; | 630 | return false; |
623 | } | 631 | } |
624 | qDebug("saveABphone:: re-reading from phone... "); | 632 | qDebug("saveABphone:: re-reading from phone... "); |
625 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 633 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
626 | return false; | 634 | return false; |
627 | } | 635 | } |
628 | return true; | 636 | return true; |
629 | } | 637 | } |
630 | bool AddressBook::saveAB() | 638 | bool AddressBook::saveAB() |
631 | { | 639 | { |
632 | bool ok = true; | 640 | bool ok = true; |
633 | 641 | ||
634 | deleteRemovedAddressees(); | 642 | deleteRemovedAddressees(); |
635 | Iterator ait; | 643 | Iterator ait; |
636 | for ( ait = begin(); ait != end(); ++ait ) { | 644 | for ( ait = begin(); ait != end(); ++ait ) { |
637 | if ( !(*ait).IDStr().isEmpty() ) { | 645 | if ( !(*ait).IDStr().isEmpty() ) { |
638 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 646 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
639 | } | 647 | } |
640 | } | 648 | } |
641 | KRES::Manager<Resource>::ActiveIterator it; | 649 | KRES::Manager<Resource>::ActiveIterator it; |
642 | KRES::Manager<Resource> *manager = d->mManager; | 650 | KRES::Manager<Resource> *manager = d->mManager; |
643 | qDebug("SaveAB::saving..." ); | 651 | qDebug("SaveAB::saving..." ); |
644 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 652 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
645 | qDebug("SaveAB::checking resource..." ); | 653 | qDebug("SaveAB::checking resource..." ); |
646 | if ( (*it)->readOnly() ) | 654 | if ( (*it)->readOnly() ) |
647 | qDebug("resource is readonly." ); | 655 | qDebug("resource is readonly." ); |
648 | if ( (*it)->isOpen() ) | 656 | if ( (*it)->isOpen() ) |
649 | qDebug("resource is open" ); | 657 | qDebug("resource is open" ); |
650 | 658 | ||
651 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 659 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |