summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-13 13:18:51 (UTC)
committer zautrix <zautrix>2004-10-13 13:18:51 (UTC)
commitd41893fb0a49fbb080326a4c1fd98e1a032a182a (patch) (side-by-side diff)
tree9b95603ff93801accaa94de4b73d88ea9c5c9386
parentefdd0735bda81dcd82dfb6d6dc0d0c143f249336 (diff)
downloadkdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.zip
kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.tar.gz
kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.tar.bz2
merge contact fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp8
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp82
-rw-r--r--kabc/addressee.h2
-rw-r--r--kaddressbook/kabcore.cpp6
5 files changed, 68 insertions, 34 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 19c26eb..8882259 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -863,7 +863,7 @@ Addressee AddressBook::findByUid( const QString &uid )
}
return Addressee();
}
-void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
+void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
{
//qDebug("AddressBook::preExternSync ");
AddressBook::Iterator it;
@@ -871,7 +871,7 @@ void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
(*it).setID( csd, (*it).externalUID() );
(*it).computeCsum( csd );
}
- mergeAB( aBook ,csd );
+ mergeAB( aBook ,csd, isSubset );
}
void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
{
@@ -913,14 +913,14 @@ Addressee AddressBook::findByExternUid( const QString& uid , const QString& pr
}
return Addressee();
}
-void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
+void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
{
Iterator it;
Addressee ad;
for ( it = begin(); it != end(); ++it ) {
ad = aBook->findByExternUid( (*it).externalUID(), profile );
if ( !ad.isEmpty() ) {
- (*it).mergeContact( ad );
+ (*it).mergeContact( ad ,isSubset);
}
}
#if 0
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index df9048b..a6bf451 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -301,11 +301,11 @@ class AddressBook : public QObject
void resetTempSyncStat();
QStringList uidList();
void removeSyncAddressees( bool removeDeleted = false );
- void mergeAB( AddressBook *aBook, const QString& profile );
+ void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
Addressee findByExternUid( const QString& uid , const QString& profile );
bool containsExternalUid( const QString& uid );
- void preExternSync( AddressBook* aBook, const QString& csd );
+ void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
void postExternSync( AddressBook* aBook, const QString& csd );
signals:
/**
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 2aca559..295ee4f 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -299,39 +299,38 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
QStringList t;
QStringList tAD;
uint iii;
- if ( isSubSet ) {
- // ********** phone numbers
- PhoneNumber::List phoneAD = ad.phoneNumbers();
- PhoneNumber::List::Iterator phoneItAD;
- for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
- bool found = false;
- PhoneNumber::List::Iterator it;
- for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
- if ( ( *phoneItAD ).contains( (*it) ) ) {
- found = true;
- (*it).setType( ( *phoneItAD ).type() );
- break;
- }
+
+ // ********** phone numbers
+ PhoneNumber::List phoneAD = ad.phoneNumbers();
+ PhoneNumber::List::Iterator phoneItAD;
+ for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
+ bool found = false;
+ PhoneNumber::List::Iterator it;
+ for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
+ if ( ( *phoneItAD ).contains( (*it) ) ) {
+ found = true;
+ (*it).setType( ( *phoneItAD ).type() );
+ break;
}
- if ( ! found )
- mData->phoneNumbers.append( *phoneItAD );
}
+ if ( isSubSet && ! found )
+ mData->phoneNumbers.append( *phoneItAD );
+ }
+ if ( isSubSet ) {
// ************* emails;
t = mData->emails;
tAD = ad.mData->emails;
for ( iii = 0; iii < tAD.count(); ++iii)
if ( !t.contains(tAD[iii] ) )
mData->emails.append( tAD[iii] );
- // ************* categories;
- t = mData->categories;
- tAD = ad.mData->categories;
- for ( iii = 0; iii < tAD.count(); ++iii)
- if ( !t.contains(tAD[iii] ) )
- mData->categories.append( tAD[iii] );
-
-
}
+ // ************* categories;
+ t = mData->categories;
+ tAD = ad.mData->categories;
+ for ( iii = 0; iii < tAD.count(); ++iii)
+ if ( !t.contains(tAD[iii] ) )
+ mData->categories.append( tAD[iii] );
QStringList::ConstIterator it;
for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
QString qualifiedName = (*it).left( (*it).find( ":" ));
@@ -389,7 +388,7 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
}
}
- if ( ! found ) {
+ if ( isSubSet && ! found ) {
mData->addresses.append( *addressIterA );
}
}
@@ -478,8 +477,43 @@ void Addressee::simplifyEmails()
void Addressee::simplifyPhoneNumbers()
{
+ int max = 4;
+ int inList = mData->phoneNumbers.count();
KABC::PhoneNumber::List removeNumbers;
KABC::PhoneNumber::List::Iterator phoneIter;
+ if ( inList > max ) {
+ // delete non-preferred numbers
+ for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
+ ++phoneIter ) {
+ if ( inList > max ) {
+ if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
+ removeNumbers.append( ( *phoneIter ) );
+ --inList;
+ }
+ } else
+ break;
+ }
+ for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
+ ++phoneIter ) {
+ removePhoneNumber(( *phoneIter ));
+ }
+ // delete preferred numbers
+ if ( inList > max ) {
+ for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
+ ++phoneIter ) {
+ if ( inList > max ) {
+ removeNumbers.append( ( *phoneIter ) );
+ --inList;
+ } else
+ break;
+ }
+ for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
+ ++phoneIter ) {
+ removePhoneNumber(( *phoneIter ));
+ }
+ }
+ }
+ // remove non-numeric characters
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter ) {
if ( ! ( *phoneIter ).simplifyNumber() )
diff --git a/kabc/addressee.h b/kabc/addressee.h
index e7900c6..2c81c1a 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -116,7 +116,7 @@ class Addressee
QString externalUID() const;
void setOriginalExternalUID( const QString &id );
QString originalExternalUID() const;
- void mergeContact( const Addressee& ad, bool isSubSet = false );
+ void mergeContact( const Addressee& ad, bool isSubSet );
void simplifyEmails();
void simplifyAddresses();
void simplifyPhoneNumbers();
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 205dbc8..ea34be2 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2732,7 +2732,7 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
if ( filename.right(4) == ".xml") {
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
isXML = true;
- abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
+ abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
} else {
external = !manager->mIsKapiFile;
if ( external ) {
@@ -2787,7 +2787,7 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
if ( abLocal.load() ) {
qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
- abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
+ abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {
@@ -2829,7 +2829,7 @@ bool KABCore::syncPhone()
qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
abLocal.preparePhoneSync( mCurrentSyncDevice, true );
- abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
+ abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {