-rw-r--r-- | kabc/addressbook.cpp | 72 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 12 | ||||
-rw-r--r-- | kabc/addressee.h | 5 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 2 |
5 files changed, 66 insertions, 29 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 1050f55..ff05f7e 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -405,30 +405,50 @@ void AddressBook::export2File( QString fileName ) | |||
405 | } | 405 | } |
406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) | 406 | void 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 | } | ||
437 | void AddressBook::setUntagged() | ||
438 | { | ||
439 | Iterator ait; | ||
440 | for ( ait = begin(); ait != end(); ++ait ) { | ||
441 | (*ait).setTagged( false ); | ||
442 | } | ||
443 | } | ||
444 | void 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 | |||
434 | bool AddressBook::saveAB() | 454 | bool AddressBook::saveAB() |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index cea1b03..532e05d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -145,3 +145,5 @@ class AddressBook : public QObject | |||
145 | void export2File( QString fileName ); | 145 | void export2File( QString fileName ); |
146 | void importFromFile( QString fileName, bool replaceLabel = false ); | 146 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
147 | void setUntagged(); | ||
148 | void removeUntagged(); | ||
147 | /** | 149 | /** |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 3f3d5c0..607ae26 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -90,2 +90,3 @@ struct Addressee::AddresseeData : public KShared | |||
90 | bool changed :1; | 90 | bool changed :1; |
91 | bool tagged :1; | ||
91 | }; | 92 | }; |
@@ -1823,2 +1824,13 @@ bool Addressee::changed() const | |||
1823 | 1824 | ||
1825 | void Addressee::setTagged( bool value ) | ||
1826 | { | ||
1827 | detach(); | ||
1828 | mData->tagged = value; | ||
1829 | } | ||
1830 | |||
1831 | bool Addressee::tagged() const | ||
1832 | { | ||
1833 | return mData->tagged; | ||
1834 | } | ||
1835 | |||
1824 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 1836 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
diff --git a/kabc/addressee.h b/kabc/addressee.h index 9336edc..0aa2c51 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -833,3 +833,6 @@ class Addressee | |||
833 | */ | 833 | */ |
834 | bool changed() const; | 834 | bool changed() const; |
835 | |||
836 | void setTagged( bool value ); | ||
837 | bool tagged() const; | ||
835 | 838 | ||
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 7ec3fca..452f1bc 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2878,3 +2878,3 @@ void KABCore::getFile( bool success ) | |||
2878 | } | 2878 | } |
2879 | mAddressBook->importFromFile( sentSyncFile() ); | 2879 | mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2880 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 2880 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |