-rw-r--r-- | kabc/addressbook.cpp | 42 |
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 @@ -483,11 +483,11 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) return true; } -int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) +int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource ) { if ( removeOld ) - setUntagged( true ); + setUntagged( true, resource ); KABC::Addressee::List list; QFile file( fileName ); file.open( IO_ReadOnly ); @@ -503,11 +503,25 @@ int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool remo KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; + + Resource * setRes = 0; + if ( !resource.isEmpty() ) { + KRES::Manager<Resource>::ActiveIterator it; + KRES::Manager<Resource> *manager = d->mManager; + for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { + qDebug("SaveAB::checking resource..." ); + if ( (*it)->name() == resource ) { + setRes = (*it); + qDebug("Inserting imported contacs to resource %s", resource.latin1()); + break; + } + } + } for ( it = list.begin(); it != list.end(); ++it ) { QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) (*it).setIDStr(id ); - (*it).setResource( 0 ); + (*it).setResource( setRes ); if ( replaceLabel ) (*it).removeVoice(); if ( removeOld ) @@ -518,17 +532,27 @@ int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool remo removeUntagged(); return list.count(); } -void AddressBook::setUntagged(bool setNonSyncTagged) // = false) +void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "") { Iterator ait; - for ( ait = begin(); ait != end(); ++ait ) { - if ( setNonSyncTagged ) { - if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { + if ( !resource.isEmpty() ) { + for ( ait = begin(); ait != end(); ++ait ) { + if ( (*ait).resource() && (*ait).resource()->name() == resource ) { + (*ait).setTagged( false ); + } + else (*ait).setTagged( true ); + } + } else { + for ( ait = begin(); ait != end(); ++ait ) { + if ( setNonSyncTagged ) { + if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { + (*ait).setTagged( true ); + } else + (*ait).setTagged( false ); } else (*ait).setTagged( false ); - } else - (*ait).setTagged( false ); + } } } void AddressBook::removeUntagged() |