-rw-r--r-- | kabc/addressbook.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index dc3cda1..bf6d053 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -389,48 +389,56 @@ void AddressBook::export2File( QString fileName ) | |||
389 | Iterator it; | 389 | Iterator it; |
390 | KABC::VCardConverter::Version version; | 390 | KABC::VCardConverter::Version version; |
391 | version = KABC::VCardConverter::v3_0; | 391 | version = KABC::VCardConverter::v3_0; |
392 | for ( it = begin(); it != end(); ++it ) { | 392 | for ( it = begin(); it != end(); ++it ) { |
393 | if ( !(*it).IDStr().isEmpty() ) { | 393 | if ( !(*it).IDStr().isEmpty() ) { |
394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
395 | } | 395 | } |
396 | KABC::VCardConverter converter; | 396 | KABC::VCardConverter converter; |
397 | QString vcard; | 397 | QString vcard; |
398 | //Resource *resource() const; | 398 | //Resource *resource() const; |
399 | converter.addresseeToVCard( *it, vcard, version ); | 399 | converter.addresseeToVCard( *it, vcard, version ); |
400 | t << vcard << "\r\n"; | 400 | t << vcard << "\r\n"; |
401 | } | 401 | } |
402 | t << "\r\n\r\n"; | 402 | t << "\r\n\r\n"; |
403 | outFile.close(); | 403 | outFile.close(); |
404 | } | 404 | } |
405 | void AddressBook::importFromFile( QString fileName ) | 405 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) |
406 | { | 406 | { |
407 | 407 | ||
408 | KABC::Addressee::List list; | 408 | KABC::Addressee::List list; |
409 | QFile file( fileName ); | 409 | QFile file( fileName ); |
410 | 410 | ||
411 | file.open( IO_ReadOnly ); | 411 | file.open( IO_ReadOnly ); |
412 | QByteArray rawData = file.readAll(); | 412 | QByteArray rawData = file.readAll(); |
413 | file.close(); | 413 | file.close(); |
414 | 414 | qDebug("AddressBook::importFromFile "); | |
415 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 415 | QString data; |
416 | if ( replaceLabel ) { | ||
417 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | ||
418 | data.replace ( QRegExp("LABEL") , "ADR" ); | ||
419 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | ||
420 | } else | ||
421 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | ||
416 | KABC::VCardTool tool; | 422 | KABC::VCardTool tool; |
417 | list = tool.parseVCards( data ); | 423 | list = tool.parseVCards( data ); |
418 | KABC::Addressee::List::Iterator it; | 424 | KABC::Addressee::List::Iterator it; |
419 | for ( it = list.begin(); it != list.end(); ++it ) { | 425 | for ( it = list.begin(); it != list.end(); ++it ) { |
420 | (*it).setResource( 0 ); | 426 | (*it).setResource( 0 ); |
427 | if ( replaceLabel ) | ||
428 | (*it).removeVoice(); | ||
421 | insertAddressee( (*it), false, true ); | 429 | insertAddressee( (*it), false, true ); |
422 | } | 430 | } |
423 | 431 | ||
424 | } | 432 | } |
425 | 433 | ||
426 | bool AddressBook::saveAB() | 434 | bool AddressBook::saveAB() |
427 | { | 435 | { |
428 | bool ok = true; | 436 | bool ok = true; |
429 | 437 | ||
430 | deleteRemovedAddressees(); | 438 | deleteRemovedAddressees(); |
431 | Iterator ait; | 439 | Iterator ait; |
432 | for ( ait = begin(); ait != end(); ++ait ) { | 440 | for ( ait = begin(); ait != end(); ++ait ) { |
433 | if ( !(*ait).IDStr().isEmpty() ) { | 441 | if ( !(*ait).IDStr().isEmpty() ) { |
434 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 442 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
435 | } | 443 | } |
436 | } | 444 | } |