summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
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
@@ -394,52 +394,72 @@ void AddressBook::export2File( QString fileName )
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;