summaryrefslogtreecommitdiffabout
Side-by-side diff
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
@@ -842,106 +842,106 @@ void AddressBook::removeAddressee( const Iterator &it )
d->mAddressees.remove( it.d->mIt );
}
AddressBook::Iterator AddressBook::find( const Addressee &a )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
return it;
}
}
return end();
}
Addressee AddressBook::findByUid( const QString &uid )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).uid() ) {
return *it;
}
}
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;
for ( it = begin(); it != end(); ++it ) {
(*it).setID( csd, (*it).externalUID() );
(*it).computeCsum( csd );
}
- mergeAB( aBook ,csd );
+ mergeAB( aBook ,csd, isSubset );
}
void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
{
//qDebug("AddressBook::postExternSync ");
AddressBook::Iterator it;
for ( it = begin(); it != end(); ++it ) {
// qDebug("check uid %s ", (*it).uid().latin1() );
if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
(*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
Addressee ad = aBook->findByUid( ( (*it).uid() ));
if ( ad.isEmpty() ) {
qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
} else {
(*it).computeCsum( csd );
if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
ad.setID( csd, (*it).externalUID() );
ad.setCsum( csd, (*it).getCsum( csd ) );
aBook->insertAddressee( ad );
}
}
}
}
bool AddressBook::containsExternalUid( const QString& uid )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).externalUID( ) )
return true;
}
return false;
}
Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).getID( profile ) )
return (*it);
}
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
// test only
for ( it = begin(); it != end(); ++it ) {
qDebug("uid %s ", (*it).uid().latin1());
}
#endif
}
#if 0
Addressee::List AddressBook::getExternLastSyncAddressees()
{
Addressee::List results;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
if ( (*it).familyName().left(4) == "!E: " )
results.append( *it );
}
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index df9048b..a6bf451 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -280,53 +280,53 @@ class AddressBook : public QObject
*/
QPtrList<Resource> resources();
/**
Set the @p ErrorHandler, that is used by @ref error() to
provide gui-independend error messages.
*/
void setErrorHandler( ErrorHandler * );
/**
Shows gui independend error messages.
*/
void error( const QString& );
/**
Query all resources to clean up their lock files
*/
void cleanUp();
// sync stuff
//Addressee::List getExternLastSyncAddressees();
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:
/**
Emitted, when the address book has changed on disk.
*/
void addressBookChanged( AddressBook * );
/**
Emitted, when the address book has been locked for writing.
*/
void addressBookLocked( AddressBook * );
/**
Emitted, when the address book has been unlocked.
*/
void addressBookUnlocked( AddressBook * );
protected:
void deleteRemovedAddressees();
void setStandardResource( Resource * );
Resource *standardResource();
KRES::Manager<Resource> *resourceManager();
void init(const QString &config, const QString &family);
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 2aca559..295ee4f 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -278,81 +278,80 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
if ( !mData->birthday.isValid() )
if ( ad.mData->birthday.isValid())
mData->birthday = ad.mData->birthday;
if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
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( ":" ));
bool found = false;
QStringList::ConstIterator itL;
for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
if ( (*itL).startsWith( qualifiedName ) ) {
found = true;
break;
}
}
if ( ! found ) {
mData->custom.append( *it );
}
}
if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
if ( !mData->sound.isIntern() ) {
if ( mData->sound.url().isEmpty() ) {
mData->sound = ad.mData->sound;
}
}
if ( !mData->agent.isIntern() ) {
if ( mData->agent.url().isEmpty() ) {
@@ -368,49 +367,49 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
if ( (*it) == (*itA)) {
found = true;
break;
}
}
if ( ! found ) {
mData->keys.append( *itA );
}
}
}
KABC::Address::List::Iterator addressIterA;
for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
bool found = false;
KABC::Address::List::Iterator addressIter;
for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
++addressIter ) {
if ( (*addressIter) == (*addressIterA)) {
found = true;
(*addressIter).setType( (*addressIterA).type() );
break;
}
}
- if ( ! found ) {
+ if ( isSubSet && ! found ) {
mData->addresses.append( *addressIterA );
}
}
//qDebug("merge contact %s ", ad.uid().latin1());
setUid( ad.uid() );
setRevision( ad.revision() );
}
bool Addressee::removeVoice()
{
PhoneNumber::List phoneN = phoneNumbers();
PhoneNumber::List::Iterator phoneIt;
bool found = false;
for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
if ((*phoneIt).type() - PhoneNumber::Voice ) {
(*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
insertPhoneNumber( (*phoneIt) );
found = true;
}
}
}
return found;
@@ -457,50 +456,85 @@ void Addressee::simplifyAddresses()
Address::List::Iterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( count >= max )
list.append( *it );
++count;
}
for( it = list.begin(); it != list.end(); ++it ) {
removeAddress( (*it) );
}
}
// removes all emails but the first
// needed by phone sync
void Addressee::simplifyEmails()
{
if ( mData->emails.count() == 0 ) return ;
QString email = mData->emails.first();
detach();
mData->emails.clear();
mData->emails.append( email );
}
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() )
removeNumbers.append( ( *phoneIter ) );
}
for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
++phoneIter ) {
removePhoneNumber(( *phoneIter ));
}
}
void Addressee::simplifyPhoneNumberTypes()
{
KABC::PhoneNumber::List::Iterator phoneIter;
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter )
( *phoneIter ).simplifyType();
}
void Addressee::removeID(const QString &prof)
{
detach();
mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
}
void Addressee::setID( const QString & prof , const QString & id )
diff --git a/kabc/addressee.h b/kabc/addressee.h
index e7900c6..2c81c1a 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -95,49 +95,49 @@ class Addressee
Addressee &operator=( const Addressee & );
bool operator==( const Addressee & ) const;
bool operator!=( const Addressee & ) const;
// sync stuff
void setTempSyncStat(int id);
int tempSyncStat() const;
void setIDStr( const QString & );
QString IDStr() const;
void setID( const QString &, const QString & );
QString getID( const QString & );
void setCsum( const QString &, const QString & );
QString getCsum( const QString & );
void removeID(const QString &);
void computeCsum(const QString &dev);
ulong getCsum4List( const QStringList & attList);
/**
Return, if the address book entry is empty.
*/
bool isEmpty() const;
void setExternalUID( const QString &id );
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();
void simplifyPhoneNumberTypes();
bool removeVoice();
bool containsAdr(const Addressee& addr );
/**
Set unique identifier.
*/
void setUid( const QString &uid );
/**
Return unique identifier.
*/
QString uid() const;
/**
Return translated label for uid field.
*/
static QString uidLabel();
/**
Set name.
*/
void setName( const QString &name );
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 205dbc8..ea34be2 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2711,49 +2711,49 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
}
qDebug( mes );
return syncOK;
}
//this is a overwritten callbackmethods from the syncinterface
bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
{
//pending prepare addresseeview for output
//pending detect, if remote file has REV field. if not switch to external sync
mGlobalSyncMode = SYNC_MODE_NORMAL;
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal(filename,"syncContact");
bool syncOK = false;
if ( abLocal.load() ) {
qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
bool external = false;
bool isXML = false;
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 ) {
qDebug("Setting vcf mode to external ");
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
AddressBook::Iterator it;
for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
(*it).setID( mCurrentSyncDevice, (*it).uid() );
(*it).computeCsum( mCurrentSyncDevice );
}
}
}
//AddressBook::Iterator it;
//QStringList vcards;
//for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
// qDebug("Name %s ", (*it).familyName().latin1());
//}
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
if ( syncOK ) {
if ( syncManager->mWriteBackFile )
{
if ( external )
abLocal.removeSyncAddressees( !isXML);
qDebug("Saving remote AB ");
@@ -2766,91 +2766,91 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
//this is a overwritten callbackmethods from the syncinterface
bool KABCore::syncExternal(KSyncManager* manager, QString resource)
{
if ( resource == "phone" )
return syncPhone();
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal( resource,"syncContact");
bool syncOK = false;
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 ) {
abLocal.removeSyncAddressees( false );
abLocal.saveAB();
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
void KABCore::message( QString m )
{
topLevelWidget()->setCaption( m );
QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
}
bool KABCore::syncPhone()
{
QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
QString fileName;
#ifdef _WIN32_
fileName = locateLocal("tmp", "phonefile.vcf");
#else
fileName = "/tmp/phonefile.vcf";
#endif
if ( !PhoneAccess::readFromPhone( fileName) ) {
message(i18n("Phone access failed!"));
return false;
}
AddressBook abLocal( fileName,"syncContact");
bool syncOK = false;
{
abLocal.importFromFile( fileName );
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 ) {
abLocal.removeSyncAddressees( true );
abLocal.saveABphone( fileName );
abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
//abLocal.preparePhoneSync( mCurrentSyncDevice, false );
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
void KABCore::getFile( bool success )
{
if ( ! success ) {
message( i18n("Error receiving file. Nothing changed!") );
return;
}
mAddressBook->importFromFile( sentSyncFile() , false, true );
message( i18n("Pi-Sync successful!") );