-rw-r--r-- | kabc/address.h | 1 | ||||
-rw-r--r-- | kabc/addressbook.cpp | 28 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 39 | ||||
-rw-r--r-- | kabc/addressee.h | 4 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 9 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 2 |
7 files changed, 81 insertions, 6 deletions
diff --git a/kabc/address.h b/kabc/address.h index 6b53c7e..37dd851 100644 --- a/kabc/address.h +++ b/kabc/address.h @@ -29,8 +29,9 @@ $Id$ #define KABC_ADDRESS_H #include <qmap.h> #include <qstring.h> +#include <qstringlist.h> #include <qvaluelist.h> // template tags for address formatting localization #define KABC_FMTTAG_realname QString("%n") diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 46a9cf4..64832f1 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -247,13 +247,16 @@ void AddressBook::init(const QString &config, const QString &family ) con->setGroup( "General" ); con->writeEntry( "ResourceKeys", QString("sync") ); con->writeEntry( "Standard", QString("sync") ); con->setGroup( "Resource_sync" ); - con->writeEntry( "FileFormat", QString("vcard") ); con->writeEntry( "FileName", config ); + con->writeEntry( "FileFormat", QString("vcard") ); con->writeEntry( "ResourceIdentifier", QString("sync") ); con->writeEntry( "ResourceName", QString("sync_res") ); - con->writeEntry( "ResourceType", QString("file") ); + if ( config.right(4) == ".xml" ) + con->writeEntry( "ResourceType", QString("qtopia") ); + else + con->writeEntry( "ResourceType", QString("file") ); //con->sync(); d->mConfig = con; } else @@ -598,8 +601,29 @@ Addressee AddressBook::findByUid( const QString &uid ) } } return Addressee(); } +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 ) +{ + Iterator it; + Addressee ad; + for ( it = begin(); it != end(); ++it ) { + ad = aBook->findByExternUid( (*it).externalUID(), profile ); + if ( !ad.isEmpty() ) { + (*it).mergeContact( ad ); + } + } +} + #if 0 Addressee::List AddressBook::getExternLastSyncAddressees() { Addressee::List results; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 2f2678b..f40e015 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -292,10 +292,10 @@ class AddressBook : public QObject //Addressee::List getExternLastSyncAddressees(); void resetTempSyncStat(); QStringList uidList(); void removeDeletedAddressees(); - - + void mergeAB( AddressBook *aBook, const QString& profile ); + Addressee findByExternUid( const QString& uid , const QString& profile ); signals: /** Emitted, when the address book has changed on disk. */ diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index c34f671..711c261 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -65,8 +65,9 @@ struct Addressee::AddresseeData : public KShared QString note; QString productId; QDateTime revision; QString sortString; + QString externalUID; KURL url; Secrecy secrecy; Picture logo; Picture photo; @@ -270,8 +271,34 @@ void Addressee::computeCsum(const QString &dev) uint cs = getCsum4List(l); // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); setCsum( dev, QString::number (cs )); } + +void Addressee::mergeContact( Addressee ad ) +{ +#if 0 + if ( !mData->name.isEmpty() ) l.append(mData->name); + if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); + if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); + if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); + if ( !mData->additionalName ) l.append( mData->additionalName ); + if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); + if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); + if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); + if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); + if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); + if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); + if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); + if ( !mData->title .isEmpty() ) l.append( mData->title ); + if ( !mData->role.isEmpty() ) l.append( mData->role ); + if ( !mData->organization.isEmpty() ) l.append( mData->organization ); + if ( !mData->note.isEmpty() ) l.append( mData->note ); + if ( !mData->productId.isEmpty() ) l.append(mData->productId ); + if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); + if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); +#endif +} + void Addressee::removeID(const QString &prof) { detach(); mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); @@ -322,8 +349,20 @@ QString Addressee::IDStr() const { return mData->mExternalId; } +void Addressee::setExternalUID( const QString &id ) +{ + if ( id == mData->externalUID ) return; + detach(); + mData->empty = false; + mData->externalUID = id; +} + +QString Addressee::externalUID() const +{ + return mData->externalUID; +} void Addressee::setUid( const QString &id ) { if ( id == mData->uid ) return; diff --git a/kabc/addressee.h b/kabc/addressee.h index bfb0840..59fcbd8 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -111,9 +111,11 @@ class Addressee /** Return, if the address book entry is empty. */ bool isEmpty() const; - + void setExternalUID( const QString &id ); + QString externalUID() const; + void mergeContact( Addressee ad ); /** Set unique identifier. */ void setUid( const QString &uid ); diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index ac513b6..7d00a3f 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -74,9 +74,16 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a addr.setGivenName( contact.firstName() ); addr.setAdditionalName( contact.middleName() ); addr.setPrefix( contact.nameTitle() ); addr.setSuffix( contact.suffix() ); - + QString exuid = contact.uid().toString(); + int ente = exuid.find( "-0000"); + if ( exuid.left(1) == "{" ) + exuid = exuid.mid(1); + if ( ente > -1 ) + exuid = exuid.left( ente-1 ); + addr.setExternalUID( exuid ); + //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); // email QStringList emails = contact.emailList(); for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index fa0c51f..d6482fb 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2949,8 +2949,10 @@ bool KABCore::syncAB(QString filename, int mode) //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} + if ( filename.right(4) == ".xml") + abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) { |