summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index e04f4b1..bdc2762 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -474,70 +474,94 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
474 t.setEncoding( QTextStream::UnicodeUTF8 ); 474 t.setEncoding( QTextStream::UnicodeUTF8 );
475 t <<datastream; 475 t <<datastream;
476 t << "\r\n\r\n"; 476 t << "\r\n\r\n";
477 outFile.close(); 477 outFile.close();
478 478
479 } else { 479 } else {
480 qDebug("Error open temp file "); 480 qDebug("Error open temp file ");
481 return false; 481 return false;
482 } 482 }
483 return true; 483 return true;
484 484
485} 485}
486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource )
487{ 487{
488 488
489 if ( removeOld ) 489 if ( removeOld )
490 setUntagged( true ); 490 setUntagged( true, resource );
491 KABC::Addressee::List list; 491 KABC::Addressee::List list;
492 QFile file( fileName ); 492 QFile file( fileName );
493 file.open( IO_ReadOnly ); 493 file.open( IO_ReadOnly );
494 QByteArray rawData = file.readAll(); 494 QByteArray rawData = file.readAll();
495 file.close(); 495 file.close();
496 QString data; 496 QString data;
497 if ( replaceLabel ) { 497 if ( replaceLabel ) {
498 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 498 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
499 data.replace ( QRegExp("LABEL") , "ADR" ); 499 data.replace ( QRegExp("LABEL") , "ADR" );
500 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 500 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
501 } else 501 } else
502 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 502 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
503 KABC::VCardTool tool; 503 KABC::VCardTool tool;
504 list = tool.parseVCards( data ); 504 list = tool.parseVCards( data );
505 KABC::Addressee::List::Iterator it; 505 KABC::Addressee::List::Iterator it;
506
507 Resource * setRes = 0;
508 if ( !resource.isEmpty() ) {
509 KRES::Manager<Resource>::ActiveIterator it;
510 KRES::Manager<Resource> *manager = d->mManager;
511 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
512 qDebug("SaveAB::checking resource..." );
513 if ( (*it)->name() == resource ) {
514 setRes = (*it);
515 qDebug("Inserting imported contacs to resource %s", resource.latin1());
516 break;
517 }
518 }
519 }
506 for ( it = list.begin(); it != list.end(); ++it ) { 520 for ( it = list.begin(); it != list.end(); ++it ) {
507 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 521 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
508 if ( !id.isEmpty() ) 522 if ( !id.isEmpty() )
509 (*it).setIDStr(id ); 523 (*it).setIDStr(id );
510 (*it).setResource( 0 ); 524 (*it).setResource( setRes );
511 if ( replaceLabel ) 525 if ( replaceLabel )
512 (*it).removeVoice(); 526 (*it).removeVoice();
513 if ( removeOld ) 527 if ( removeOld )
514 (*it).setTagged( true ); 528 (*it).setTagged( true );
515 insertAddressee( (*it), false, true ); 529 insertAddressee( (*it), false, true );
516 } 530 }
517 if ( removeOld ) 531 if ( removeOld )
518 removeUntagged(); 532 removeUntagged();
519 return list.count(); 533 return list.count();
520} 534}
521void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 535void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "")
522{ 536{
523 Iterator ait; 537 Iterator ait;
524 for ( ait = begin(); ait != end(); ++ait ) { 538 if ( !resource.isEmpty() ) {
525 if ( setNonSyncTagged ) { 539 for ( ait = begin(); ait != end(); ++ait ) {
526 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 540 if ( (*ait).resource() && (*ait).resource()->name() == resource ) {
541 (*ait).setTagged( false );
542 }
543 else
527 (*ait).setTagged( true ); 544 (*ait).setTagged( true );
545 }
546 } else {
547 for ( ait = begin(); ait != end(); ++ait ) {
548 if ( setNonSyncTagged ) {
549 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
550 (*ait).setTagged( true );
551 } else
552 (*ait).setTagged( false );
528 } else 553 } else
529 (*ait).setTagged( false ); 554 (*ait).setTagged( false );
530 } else 555 }
531 (*ait).setTagged( false );
532 } 556 }
533} 557}
534void AddressBook::removeUntagged() 558void AddressBook::removeUntagged()
535{ 559{
536 Iterator ait; 560 Iterator ait;
537 bool todelete = false; 561 bool todelete = false;
538 Iterator todel; 562 Iterator todel;
539 for ( ait = begin(); ait != end(); ++ait ) { 563 for ( ait = begin(); ait != end(); ++ait ) {
540 if ( todelete ) 564 if ( todelete )
541 removeAddressee( todel ); 565 removeAddressee( todel );
542 if (!(*ait).tagged()) { 566 if (!(*ait).tagged()) {
543 todelete = true; 567 todelete = true;