author | zautrix <zautrix> | 2006-02-24 18:49:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2006-02-24 18:49:56 (UTC) |
commit | d7738fdfc685192eb2f8317db6ffad3c246001c8 (patch) (side-by-side diff) | |
tree | d9aae6ca97851fd1b53c4d9e74740a5ee2b69ea9 /kabc | |
parent | 987757f168bbae56100f2aff763b865e81ceec18 (diff) | |
download | kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.zip kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.gz kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.bz2 |
kapi sync
-rw-r--r-- | kabc/addressbook.cpp | 22 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kabc/addressee.cpp | 75 | ||||
-rw-r--r-- | kabc/addressee.h | 4 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 24 |
5 files changed, 120 insertions, 6 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index f9e4387..fe59fcb 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -941,16 +941,33 @@ void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool i //qDebug("AddressBook::preExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { (*it).setID( csd, (*it).externalUID() ); (*it).computeCsum( csd ); } mergeAB( aBook ,csd, isSubset ); } +void AddressBook::preOLSync( AddressBook* aBook, const QString& csd ) +{ + //qDebug("AddressBook::preExternSync "); + AddressBook::Iterator it; + for ( it = begin(); it != end(); ++it ) { + (*it).setID( csd, (*it).externalUID() ); + (*it).computeCsum( csd ); + } + + Addressee ad; + for ( it = begin(); it != end(); ++it ) { + ad = aBook->findByExternUid( (*it).externalUID(), csd ); + if ( !ad.isEmpty() ) { + (*it).mergeOLContact( ad ); + } + } +} void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) { //qDebug("AddressBook::postExternSync "); AddressBook::Iterator it; int foundEmpty = 0; for ( it = begin(); it != end(); ++it ) { //qDebug("check uid %s ", (*it).uid().latin1() ); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || @@ -959,18 +976,19 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool Addressee ad = aBook->findByUid( ( (*it).uid() )); if ( ad.isEmpty() ) { ++foundEmpty; //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); } else { (*it).setIDStr(":"); if ( setID ) { - if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) - ad.setID( csd, (*it).externalUID() ); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) + ad.setID( csd, (*it).externalUID() );{ + } } else ad.setID( csd, (*it).uid() ); (*it).computeCsum( csd ); ad.setCsum( csd, (*it).getCsum( csd ) ); //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); aBook->insertAddressee( ad , false); } } diff --git a/kabc/addressbook.h b/kabc/addressbook.h index e6daa5e..a8a9fc1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -303,16 +303,17 @@ class AddressBook : public QObject void resetTempSyncStat(); QStringList uidList(); void removeSyncAddressees( bool removeDeleted = false ); void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); const Addressee findByExternUid( const QString& uid , const QString& profile ) const; bool containsExternalUid( const QString& uid ); void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); + void preOLSync( AddressBook* aBook, const QString& csd); void postExternSync( AddressBook* aBook, const QString& csd , bool setID ); signals: /** Emitted, when the address book has changed on disk. */ void addressBookChanged( AddressBook * ); /** diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 6cfac80..e8e440c 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -27,16 +27,17 @@ $Id$ */ #include <kconfig.h> #include <ksharedptr.h> #include <kdebug.h> #include <kapplication.h> #include <klocale.h> +#include <kmessagebox.h> #include <kidmanager.h> //US #include <kstandarddirs.h> #include <libkcal/syncdefines.h> //US #include "resource.h" #include "addressee.h" @@ -206,17 +207,17 @@ ulong Addressee::getCsum4List( const QStringList & attList) return cSum; } void Addressee::computeCsum(const QString &dev) { QStringList l; //if ( !mData->name.isEmpty() ) l.append(mData->name); - //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); + 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.isEmpty() ) 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 ); @@ -327,16 +328,63 @@ bool Addressee::matchPhoneNumber( QRegExp* re ) const if (re->match( (*phoneIter).number() ) == 0) #endif return true; } return false; } +void Addressee::mergeOLContact( const Addressee& ad ) +{ + if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; + 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->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() ) { + mData->agent = ad.mData->agent; + } + } + { + Key::List::Iterator itA; + for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { + bool found = false; + Key::List::Iterator it; + for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { + if ( (*it) == (*itA)) { + found = true; + break; + + } + } + if ( ! found ) { + mData->keys.append( *itA ); + } + } + } + + KABC::Address addthis = otherAddress(); + KABC::Address addother = ad.otherAddress(); + if ( !addthis.isEmpty() && !addother.isEmpty() ) + addthis.setType( addother.type() ); + //qDebug("merge contact %s ", ad.uid().latin1()); + setUid( ad.uid() ); + setRevision( ad.revision() ); + + +} + void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) { // merge all standard non-outlook fields. //if isSubSet (e.g. mobile phone sync) merge all fields detach(); if ( isSubSet ) { if ( mData->name.isEmpty() ) mData->name = ad.mData->name; @@ -1648,17 +1696,16 @@ QStringList Addressee::emails() const void Addressee::setEmails( const QStringList& emails ) { detach(); mData->emails = emails; } void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) { detach(); mData->empty = false; - PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { *it = phoneNumber; return; } } mData->phoneNumbers.append( phoneNumber ); @@ -1715,16 +1762,27 @@ PhoneNumber::List Addressee::phoneNumbers( int type ) const PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } +QString Addressee::phoneNumberString( int type ) const +{ + + PhoneNumber::List::ConstIterator it; + for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { + if ((*it).type() == type ) { + return ( *it ).number(); + } + } + return ""; +} PhoneNumber Addressee::findPhoneNumber( const QString &id ) const { PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == id ) { return *it; } @@ -1920,17 +1978,28 @@ void Addressee::removeAddress( const Address &address ) Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).id() == address.id() ) { mData->addresses.remove( it ); return; } } } - +Address Addressee::otherAddress() const +{ + Address::List::ConstIterator it; + for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { + if ( matchBinaryPatternA( (*it).type(), KABC::Address::Work ) ) + continue; + if ( matchBinaryPatternA( (*it).type(), KABC::Address::Home ) ) + continue; + return (*it); + } + return Address(); +} Address Addressee::address( int type ) const { Address address( type ); Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( matchBinaryPatternA( (*it).type(), type ) ) { if ( (*it).type() & Address::Pref ) return (*it); diff --git a/kabc/addressee.h b/kabc/addressee.h index aac78dc..0ea1803 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -113,16 +113,17 @@ class Addressee Return, if the address book entry is empty. */ bool isEmpty() const; void setExternalUID( const QString &id ); const QString externalUID() const; void setOriginalExternalUID( const QString &id ); QString originalExternalUID() const; void mergeContact( const Addressee& ad, bool isSubSet ); + void mergeOLContact( const Addressee& ad ); void simplifyEmails(); void simplifyAddresses(); void simplifyPhoneNumbers(); void simplifyPhoneNumberTypes(); void makePhoneNumbersOLcompatible(); int hasPhoneNumberType( int type ); bool removeVoice(); bool containsAdr(const Addressee& addr ); @@ -642,16 +643,17 @@ class Addressee addresse nothing happens. */ void removePhoneNumber( const PhoneNumber &phoneNumber ); /** Return phone number, which matches the given type. */ PhoneNumber phoneNumber( int type ) const; + QString phoneNumberString( int type ) const; bool matchPhoneNumber( QRegExp* searchExp ) const; bool matchAddress( QRegExp* searchExp ) const; /** Return list of all phone numbers. */ PhoneNumber::List phoneNumbers() const; @@ -726,17 +728,17 @@ class Addressee Return address, which matches the given type. */ Address address( int type ) const; /** Return list of all addresses. */ Address::List addresses() const; - + Address otherAddress() const; /** Return list of addresses with a special type. */ Address::List addresses( int type ) const; /** Return address with the given id. */ diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 12b9b09..1752745 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp @@ -227,16 +227,40 @@ PhoneNumber::TypeList PhoneNumber::typeList() } PhoneNumber::TypeList PhoneNumber::supportedTypeList() { static TypeList list; if ( list.count() == 0 ) list << (Home| Pref) << (Work| Pref) << Cell <<(Pcs|Pref)<< (Pcs|Voice)<< Home << Work << Car << Pcs <<(Work| Msg | Voice) << (Work| Msg) << (Home | Fax) << (Work| Fax) << Fax<< Pager << Isdn << Msg << Pref << Voice; return list; } + +#if 0 +Home| Pref i18n("Home") Home +Work| Pref i18n("Work") Business +Cell i18n("Mobile") Mobile +Pcs|Pref i18n("SiP") Radio +Pcs|Voice i18n("VoIP") TTY/TTD +Home i18n("Home2") Home 2 +Work i18n("Work2") Business 2 +Car i18n("Mobile2") Car +Pcs i18n("SiP2") Telex +Work| Msg | Voice i18n("Assistent") Assistent +Work| Msg i18n("Company") Company +Home | Fax i18n("Fax (Home)") Home Fax +Work| Fax i18n("Fax (Work)") Business Fax +Fax i18n("Fax (Other)") Other Fax +Pager i18n("Pager") Pager +Isdn i18n("ISDN") Isdn +Msg i18n("Callback") Callback +Pref i18n("Primary") Primary +Voice; i18n("Other") Other + +#endif + QStringList PhoneNumber::supportedTypeListNames() { static QStringList list; if ( list.count() == 0 ) list << i18n("Home") << i18n("Work") << i18n("Mobile") << i18n("SiP") << i18n("VoIP") <<i18n("Home2")<< i18n("Work2") << i18n("Mobile2") << i18n("SiP2") << i18n("Assistent") << i18n("Company") << i18n("Fax (Home)") << i18n("Fax (Work)") << i18n("Fax (Other)") << i18n("Pager") << i18n("ISDN") << i18n("Callback") << i18n("Primary")<< i18n("Other"); return list; } |