-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 @@ -943,12 +943,29 @@ void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool i 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 ) { @@ -961,14 +978,15 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool ++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 @@ -305,12 +305,13 @@ class AddressBook : public QObject 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 @@ -29,12 +29,13 @@ $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" @@ -208,13 +209,13 @@ ulong Addressee::getCsum4List( const QStringList & attList) } 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 ); @@ -329,12 +330,59 @@ bool Addressee::matchPhoneNumber( QRegExp* re ) const 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(); @@ -1650,13 +1698,12 @@ void Addressee::setEmails( const QStringList& emails ) { 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; } @@ -1717,12 +1764,23 @@ PhoneNumber::List Addressee::phoneNumbers( int type ) const 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 ) { @@ -1922,13 +1980,24 @@ void Addressee::removeAddress( const Address &address ) 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 ) ) { diff --git a/kabc/addressee.h b/kabc/addressee.h index aac78dc..0ea1803 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -115,12 +115,13 @@ class Addressee 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 ); @@ -644,12 +645,13 @@ class Addressee 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. @@ -728,13 +730,13 @@ class Addressee 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; /** diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 12b9b09..1752745 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp @@ -229,12 +229,36 @@ 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; |