summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2006-02-24 18:49:56 (UTC)
committer zautrix <zautrix>2006-02-24 18:49:56 (UTC)
commitd7738fdfc685192eb2f8317db6ffad3c246001c8 (patch) (side-by-side diff)
treed9aae6ca97851fd1b53c4d9e74740a5ee2b69ea9 /kabc
parent987757f168bbae56100f2aff763b865e81ceec18 (diff)
downloadkdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.zip
kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.gz
kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.bz2
kapi sync
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp22
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp75
-rw-r--r--kabc/addressee.h4
-rw-r--r--kabc/phonenumber.cpp24
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
@@ -937,44 +937,62 @@ Addressee AddressBook::findByUid( const QString &uid )
return Addressee();
}
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, 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 ||
(*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ||
(*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) {
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);
}
}
}
if ( foundEmpty ) {
qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty );
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index e6daa5e..a8a9fc1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -299,24 +299,25 @@ class AddressBook : public QObject
void cleanUp();
// sync stuff
//Addressee::List getExternLastSyncAddressees();
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 * );
/**
Emitted, when the address book has been locked for writing.
*/
void addressBookLocked( AddressBook * );
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 6cfac80..e8e440c 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -23,24 +23,25 @@
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$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"
using namespace KABC;
static bool matchBinaryPattern( int value, int pattern );
static bool matchBinaryPatternA( int value, int pattern );
@@ -202,25 +203,25 @@ ulong Addressee::getCsum4List( const QStringList & attList)
}
//QString dump = attList.join(",");
//qDebug("csum: %d %s", cSum,dump.latin1());
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 );
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 );
@@ -323,24 +324,71 @@ bool Addressee::matchPhoneNumber( QRegExp* re ) const
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) {
#if QT_VERSION >= 0x030000
if (re->search( (*phoneIter).number() ) == 0)
#else
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;
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;
@@ -1644,25 +1692,24 @@ QString Addressee::preferredEmail() const
QStringList Addressee::emails() const
{
return mData->emails;
}
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 );
}
void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
{
@@ -1711,24 +1758,35 @@ int Addressee::hasPhoneNumberType( int type )
PhoneNumber::List Addressee::phoneNumbers( int type ) const
{
PhoneNumber::List list;
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;
}
}
return PhoneNumber();
}
@@ -1916,25 +1974,36 @@ void Addressee::insertAddress( const Address &address )
void Addressee::removeAddress( const Address &address )
{
detach();
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);
else if ( address.isEmpty() )
address = (*it);
}
}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index aac78dc..0ea1803 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -109,24 +109,25 @@ class Addressee
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 );
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 );
/**
Set unique identifier.
*/
@@ -638,24 +639,25 @@ class Addressee
void insertPhoneNumber( const PhoneNumber &phoneNumber );
/**
Remove phone number. If no phone number with the given id exists for this
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;
/**
Return list of phone numbers with a special type.
*/
@@ -722,25 +724,25 @@ class Addressee
*/
void removeAddress( const Address &address );
/**
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.
*/
Address findAddress( const QString &id ) const;
/**
Insert category. If the category already exists it is not duplicated.
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 12b9b09..1752745 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -223,24 +223,48 @@ PhoneNumber::TypeList PhoneNumber::typeList()
list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
<< Bbs << Modem << Car << Isdn << Pcs << Pager;
return list;
}
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;
}
int PhoneNumber::typeListIndex4Type(int type )
{
TypeList list = supportedTypeList();
int i = 0;