summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-10-29 09:03:54 (UTC)
committer zautrix <zautrix>2004-10-29 09:03:54 (UTC)
commit6500d6ebb080f1de58fe676aa0a730d47fcf64f5 (patch) (side-by-side diff)
tree41841e05bf1e6b88e6e55f42011dce5f6bed85b4 /kabc
parent41e3625b8c38ff45e70b59416a519d59a5f4d937 (diff)
downloadkdepimpi-6500d6ebb080f1de58fe676aa0a730d47fcf64f5.zip
kdepimpi-6500d6ebb080f1de58fe676aa0a730d47fcf64f5.tar.gz
kdepimpi-6500d6ebb080f1de58fe676aa0a730d47fcf64f5.tar.bz2
sync fixes
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp26
-rw-r--r--kabc/addressee.cpp25
2 files changed, 29 insertions, 22 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 6194d6d..4c4ae09 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -541,49 +541,48 @@ void AddressBook::removeUntagged()
}
if ( todelete )
removeAddressee( todel );
deleteRemovedAddressees();
}
void AddressBook::smplifyAddressees()
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
(*ait).simplifyEmails();
(*ait).simplifyPhoneNumbers();
(*ait).simplifyPhoneNumberTypes();
(*ait).simplifyAddresses();
}
}
void AddressBook::removeSyncInfo( QString syncProfile)
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
(*ait).removeID( syncProfile );
}
if ( syncProfile.isEmpty() ) {
Iterator it = begin();
Iterator it2 ;
- QDateTime dt ( QDate( 2004,1,1) );
while ( it != end() ) {
if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
it2 = it;
//qDebug("removing %s ",(*it).uid().latin1() );
++it;
removeAddressee( it2 );
} else {
//qDebug("skipping %s ",(*it).uid().latin1() );
++it;
}
}
} else {
Addressee lse;
lse = findByUid( "last-syncAddressee-"+ syncProfile );
if ( ! lse.isEmpty() )
removeAddressee( lse );
}
}
void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
QString id = (*ait).IDStr();
@@ -765,142 +764,135 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeRes
return;
}
//qDebug("inserting.... %s ",a.uid().latin1() );
bool found = false;
Addressee::List::Iterator it;
for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
bool changed = false;
Addressee addr = a;
if ( addr != (*it) )
changed = true;
if ( takeResource ) {
Resource * res = (*it).resource();
(*it) = a;
(*it).setResource( res );
} else {
(*it) = a;
if ( (*it).resource() == 0 )
(*it).setResource( standardResource() );
}
if ( changed ) {
if ( setRev ) {
-
- // get rid of micro seconds
- QDateTime dt = QDateTime::currentDateTime();
- QTime t = dt.time();
- dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
- (*it).setRevision( dt );
+ (*it).setRevision( QDateTime::currentDateTime() );
}
(*it).setChanged( true );
}
found = true;
} else {
if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
QString name = (*it).uid().mid( 19 );
Addressee b = a;
QString id = b.getID( name );
if ( ! id.isEmpty() ) {
QString des = (*it).note();
int startN;
if( (startN = des.find( id ) ) >= 0 ) {
int endN = des.find( ",", startN+1 );
des = des.left( startN ) + des.mid( endN+1 );
(*it).setNote( des );
}
}
}
}
}
if ( found )
- return;
+ return;
+
d->mAddressees.append( a );
Addressee& addr = d->mAddressees.last();
if ( addr.resource() == 0 )
addr.setResource( standardResource() );
-
addr.setChanged( true );
}
void AddressBook::removeAddressee( const Addressee &a )
{
Iterator it;
Iterator it2;
bool found = false;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
found = true;
it2 = it;
} else {
if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
QString name = (*it).uid().mid( 19 );
Addressee b = a;
QString id = b.getID( name );
if ( ! id.isEmpty() ) {
QString des = (*it).note();
if( des.find( id ) < 0 ) {
des += id + ",";
(*it).setNote( des );
}
}
}
}
}
if ( found )
removeAddressee( it2 );
}
void AddressBook::removeSyncAddressees( bool removeDeleted )
{
Iterator it = begin();
Iterator it2 ;
- QDateTime dt ( QDate( 2004,1,1) );
+ QDateTime dt ( QDate( 2003,1,1) );
while ( it != end() ) {
(*it).setRevision( dt );
if (( *it).IDStr() != "changed" ) {
// "changed" is used for tagging changed addressees when syncing with KDE or OL
(*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
- (*it).setIDStr("");
+ (*it).setIDStr(":");
}
if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
it2 = it;
//qDebug("removing %s ",(*it).uid().latin1() );
++it;
removeAddressee( it2 );
} else {
//qDebug("skipping %s ",(*it).uid().latin1() );
if ( removeDeleted ) {
// we have no postprocessing in the resource, we have to do it here
// we have to compute csum for all, because it could be the first sync
(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
-
-
}
++it;
}
}
deleteRemovedAddressees();
}
void AddressBook::removeAddressee( const Iterator &it )
{
d->mRemovedAddressees.append( (*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();
}
@@ -910,62 +902,64 @@ Addressee AddressBook::findByUid( const QString &uid )
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).uid() ) {
return *it;
}
}
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::postExternSync( AddressBook* aBook , const QString& csd, bool setID)
{
//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 ) {
+ (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ||
+ (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) {
Addressee ad = aBook->findByUid( ( (*it).uid() ));
if ( ad.isEmpty() ) {
qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
} else {
(*it).setIDStr(":");
- (*it).computeCsum( csd );
if ( setID ) {
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 ) );
- aBook->insertAddressee( ad );
+ //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() );
+ aBook->insertAddressee( ad , false);
}
}
}
}
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 , bool isSubset )
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index d5a110a..3d4992c 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -188,106 +188,116 @@ ulong Addressee::getCsum4List( const QStringList & attList)
QString s = attList[i];
if ( ! s.isEmpty() ){
j = s.length();
for ( k = 0; k < j; ++k ) {
int mul = k +1;
add = s[k].unicode ();
if ( k < 16 )
mul = mul * mul;
int ii = i+1;
add = add * mul *ii*ii*ii;
cSum += add;
}
}
}
//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->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->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 );
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());
// if ( !mData->logo.isEmpty() ) l.append( );
//if ( !mData->photo.isEmpty() ) l.append( );
//if ( !mData->sound.isEmpty() ) l.append( );
//if ( !mData->agent.isEmpty() ) l.append( );
if ( mData->url.isValid() )
if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
KABC::PhoneNumber::List phoneNumbers;
KABC::PhoneNumber::List::Iterator phoneIter;
QStringList t;
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter )
t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
t.sort();
uint iii;
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->emails;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->categories;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->custom;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
- l.append( t[iii] );
+ if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
+ int find = t[iii].find (':')+1;
+ //qDebug("lennnn %d %d ", find, t[iii].length());
+ if ( find < t[iii].length())
+ l.append( t[iii] );
+
+ }
KABC::Address::List::Iterator addressIter;
for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
++addressIter ) {
t = (*addressIter).asList();
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
}
uint cs = getCsum4List(l);
- //qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
+#if 1
+ for ( iii = 0; iii < l.count(); ++iii)
+ qDebug("%d***%s***",iii,l[iii].latin1());
+ qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
+#endif
setCsum( dev, QString::number (cs ));
}
void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
{
detach();
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;
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 ;
@@ -1090,49 +1100,52 @@ QString Addressee::noteLabel()
void Addressee::setProductId( const QString &productId )
{
if ( productId == mData->productId ) return;
detach();
mData->empty = false;
mData->productId = productId;
}
QString Addressee::productId() const
{
return mData->productId;
}
QString Addressee::productIdLabel()
{
return i18n("Product Identifier");
}
void Addressee::setRevision( const QDateTime &revision )
{
if ( revision == mData->revision ) return;
detach();
mData->empty = false;
- mData->revision = revision;
+ mData->revision = QDateTime( revision.date(),
+ QTime (revision.time().hour(),
+ revision.time().minute(),
+ revision.time().second()));
}
QDateTime Addressee::revision() const
{
return mData->revision;
}
QString Addressee::revisionLabel()
{
return i18n("Revision Date");
}
void Addressee::setSortString( const QString &sortString )
{
if ( sortString == mData->sortString ) return;
detach();
mData->empty = false;
mData->sortString = sortString;
}
QString Addressee::sortString() const
{
return mData->sortString;