From 59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 09 Oct 2004 16:58:08 +0000 Subject: fixed sync bug --- (limited to 'kabc') diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 1050f55..ff05f7e 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -403,34 +403,54 @@ void AddressBook::export2File( QString fileName ) t << "\r\n\r\n"; outFile.close(); } -void AddressBook::importFromFile( QString fileName, bool replaceLabel ) -{ - - KABC::Addressee::List list; - QFile file( fileName ); - - file.open( IO_ReadOnly ); - QByteArray rawData = file.readAll(); - file.close(); - QString data; - if ( replaceLabel ) { - data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); - data.replace ( QRegExp("LABEL") , "ADR" ); - data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); - } else - data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); - KABC::VCardTool tool; - list = tool.parseVCards( data ); - KABC::Addressee::List::Iterator it; - for ( it = list.begin(); it != list.end(); ++it ) { - (*it).setResource( 0 ); - if ( replaceLabel ) - (*it).removeVoice(); - insertAddressee( (*it), false, true ); +void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) +{ + + if ( removeOld ) + setUntagged(); + KABC::Addressee::List list; + QFile file( fileName ); + file.open( IO_ReadOnly ); + QByteArray rawData = file.readAll(); + file.close(); + QString data; + if ( replaceLabel ) { + data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); + data.replace ( QRegExp("LABEL") , "ADR" ); + data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); + } else + data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); + KABC::VCardTool tool; + list = tool.parseVCards( data ); + KABC::Addressee::List::Iterator it; + for ( it = list.begin(); it != list.end(); ++it ) { + (*it).setResource( 0 ); + if ( replaceLabel ) + (*it).removeVoice(); + if ( removeOld ) + (*it).setTagged( true ); + insertAddressee( (*it), false, true ); + } + if ( removeOld ) + removeUntagged(); +} +void AddressBook::setUntagged() +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + (*ait).setTagged( false ); + } +} +void AddressBook::removeUntagged() +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + if (!(*ait).tagged()) + removeAddressee( ait ); } - + + deleteRemovedAddressees(); } - bool AddressBook::saveAB() { bool ok = true; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index cea1b03..532e05d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -143,7 +143,9 @@ class AddressBook : public QObject bool save( Ticket *ticket ); bool saveAB( ); void export2File( QString fileName ); - void importFromFile( QString fileName, bool replaceLabel = false ); + void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); + void setUntagged(); + void removeUntagged(); /** Returns a iterator for first entry of address book. */ diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 3f3d5c0..607ae26 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -88,6 +88,7 @@ struct Addressee::AddresseeData : public KShared bool empty :1; bool changed :1; + bool tagged :1; }; Addressee::Addressee() @@ -1821,6 +1822,17 @@ bool Addressee::changed() const return mData->changed; } +void Addressee::setTagged( bool value ) +{ + detach(); + mData->tagged = value; +} + +bool Addressee::tagged() const +{ + return mData->tagged; +} + QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) { if (!a.mData) return s; diff --git a/kabc/addressee.h b/kabc/addressee.h index 9336edc..0aa2c51 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -831,7 +831,10 @@ class Addressee /** Return whether the addressee is changed. */ - bool changed() const; + bool changed() const; + + void setTagged( bool value ); + bool tagged() const; private: Addressee copy(); -- cgit v0.9.0.2