summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-09-18 22:33:39 (UTC)
committer zautrix <zautrix>2004-09-18 22:33:39 (UTC)
commitf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (patch) (unidiff)
treec1a9de8b305200a7cec885764a0afb4beb92dabb /kabc
parent28f894fd2a0dfbd5f09f9e530f359981efe0198c (diff)
downloadkdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.zip
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.gz
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.bz2
more AB sync
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp13
-rw-r--r--kabc/address.h1
-rw-r--r--kabc/addressbook.cpp133
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp99
-rw-r--r--kabc/addressee.h2
6 files changed, 213 insertions, 39 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index c820a6c..5ffe511 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -90,2 +90,15 @@ bool Address::isEmpty() const
90 90
91QStringList Address::asList()
92{
93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result;
103}
91void Address::clear() 104void Address::clear()
diff --git a/kabc/address.h b/kabc/address.h
index ad132a7..6b53c7e 100644
--- a/kabc/address.h
+++ b/kabc/address.h
@@ -109,2 +109,3 @@ class Address
109 void clear(); 109 void clear();
110 QStringList asList();
110 111
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16e1653..ec9f893 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -236,2 +236,3 @@ void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false;
237 d = new AddressBookData; 238 d = new AddressBookData;
@@ -347,2 +348,3 @@ bool AddressBook::load()
347 348
349 blockLSEchange = true;
348 return ok; 350 return ok;
@@ -449,38 +451,57 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
449{ 451{
450 Addressee::List::Iterator it; 452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 453 return;
452 if ( a.uid() == (*it).uid() ) { 454 }
453 if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 455 bool found = false;
454 return; 456 Addressee::List::Iterator it;
455 } 457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
456 bool changed = false; 458 if ( a.uid() == (*it).uid() ) {
457 Addressee addr = a; 459
458 if ( addr != (*it) ) 460 bool changed = false;
459 changed = true; 461 Addressee addr = a;
460 462 if ( addr != (*it) )
461 (*it) = a; 463 changed = true;
462 if ( (*it).resource() == 0 ) 464
463 (*it).setResource( standardResource() ); 465 (*it) = a;
464 466 if ( (*it).resource() == 0 )
465 if ( changed ) { 467 (*it).setResource( standardResource() );
466 if ( setRev ) { 468
469 if ( changed ) {
470 if ( setRev ) {
467 471
468 // get rid of micro seconds 472 // get rid of micro seconds
469 QDateTime dt = QDateTime::currentDateTime(); 473 QDateTime dt = QDateTime::currentDateTime();
470 QTime t = dt.time(); 474 QTime t = dt.time();
471 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
472 (*it).setRevision( dt ); 476 (*it).setRevision( dt );
473 } 477 }
474 (*it).setChanged( true ); 478 (*it).setChanged( true );
475 } 479 }
476 480
477 return; 481 found = true;
482 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 );
485 Addressee b = a;
486 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) {
488 QString des = (*it).note();
489 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des );
494 }
495 }
496 }
497 }
478 } 498 }
479 } 499 if ( found )
480 d->mAddressees.append( a ); 500 return;
481 Addressee& addr = d->mAddressees.last(); 501 d->mAddressees.append( a );
482 if ( addr.resource() == 0 ) 502 Addressee& addr = d->mAddressees.last();
483 addr.setResource( standardResource() ); 503 if ( addr.resource() == 0 )
504 addr.setResource( standardResource() );
484 505
485 addr.setChanged( true ); 506 addr.setChanged( true );
486} 507}
@@ -490,8 +511,46 @@ void AddressBook::removeAddressee( const Addressee &a )
490 Iterator it; 511 Iterator it;
512 Iterator it2;
513 bool found = false;
491 for ( it = begin(); it != end(); ++it ) { 514 for ( it = begin(); it != end(); ++it ) {
492 if ( a.uid() == (*it).uid() ) { 515 if ( a.uid() == (*it).uid() ) {
493 removeAddressee( it ); 516 found = true;
494 return; 517 it2 = it;
518 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 );
521 Addressee b = a;
522 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) {
524 QString des = (*it).note();
525 if( des.find( id ) < 0 ) {
526 des += id + ",";
527 (*it).setNote( des );
528 }
529 }
530 }
531
495 } 532 }
496 } 533 }
534
535 if ( found )
536 removeAddressee( it2 );
537
538}
539
540void AddressBook::removeDeletedAddressees()
541{
542 deleteRemovedAddressees();
543 Iterator it = begin();
544 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) {
547 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
549 it2 = it;
550 ++it;
551 removeAddressee( it2 );
552 } else
553 ++it;
554 }
555 deleteRemovedAddressees();
497} 556}
@@ -525,2 +584,3 @@ Addressee AddressBook::findByUid( const QString &uid )
525} 584}
585#if 0
526Addressee::List AddressBook::getExternLastSyncAddressees() 586Addressee::List AddressBook::getExternLastSyncAddressees()
@@ -532,3 +592,3 @@ Addressee::List AddressBook::getExternLastSyncAddressees()
532 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 592 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
533 if ( (*it).familyName().left(3) == "E: " ) 593 if ( (*it).familyName().left(4) == "!E: " )
534 results.append( *it ); 594 results.append( *it );
@@ -539,2 +599,3 @@ Addressee::List AddressBook::getExternLastSyncAddressees()
539} 599}
600#endif
540void AddressBook::resetTempSyncStat() 601void AddressBook::resetTempSyncStat()
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 253de68..2f2678b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -291,5 +291,6 @@ class AddressBook : public QObject
291 // sync stuff 291 // sync stuff
292 Addressee::List getExternLastSyncAddressees(); 292 //Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList(); 294 QStringList uidList();
295 void removeDeletedAddressees();
295 296
@@ -326,2 +327,3 @@ class AddressBook : public QObject
326 AddressBookData *d; 327 AddressBookData *d;
328 bool blockLSEchange;
327}; 329};
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7f04d8f..0f5d605 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -176,2 +176,98 @@ bool Addressee::isEmpty() const
176} 176}
177ulong Addressee::getCsum4List( const QStringList & attList)
178{
179 int max = attList.count();
180 ulong cSum = 0;
181 int j,k,i;
182 int add;
183 for ( i = 0; i < max ; ++i ) {
184 QString s = attList[i];
185 if ( ! s.isEmpty() ){
186 j = s.length();
187 for ( k = 0; k < j; ++k ) {
188 int mul = k +1;
189 add = s[k].unicode ();
190 if ( k < 16 )
191 mul = mul * mul;
192 int ii = i+1;
193 add = add * mul *ii*ii*ii;
194 cSum += add;
195 }
196 }
197
198 }
199 //QString dump = attList.join(",");
200 //qDebug("csum: %d %s", cSum,dump.latin1());
201
202 return cSum;
203
204}
205void Addressee::computeCsum(const QString &dev)
206{
207 QStringList l;
208 if ( !mData->name.isEmpty() ) l.append(mData->name);
209 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
210 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
211 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
212 if ( !mData->additionalName ) l.append( mData->additionalName );
213 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
214 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
215 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
216 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
217 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
218 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
219 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
220 if ( !mData->title .isEmpty() ) l.append( mData->title );
221 if ( !mData->role.isEmpty() ) l.append( mData->role );
222 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
223 if ( !mData->note.isEmpty() ) l.append( mData->note );
224 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
225 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
226 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
227 // if ( !mData->logo.isEmpty() ) l.append( );
228 //if ( !mData->photo.isEmpty() ) l.append( );
229 //if ( !mData->sound.isEmpty() ) l.append( );
230 //if ( !mData->agent.isEmpty() ) l.append( );
231 //if ( mData->url.isValid() ) l.append( );
232#if 0
233 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
234 if ( !mData->addresses.isEmpty() ) l.append( );
235 //if ( !mData->keys.isEmpty() ) l.append( );
236 if ( !mData->emails.isEmpty() ) l.append( );
237 if ( !mData->categories .isEmpty() ) l.append( );
238 if ( !mData->custom.isEmpty() ) l.append( );
239#endif
240 KABC::PhoneNumber::List phoneNumbers;
241 KABC::PhoneNumber::List::Iterator phoneIter;
242
243 QStringList t;
244 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
245 ++phoneIter )
246 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
247 t.sort();
248 uint iii;
249 for ( iii = 0; iii < t.count(); ++iii)
250 l.append( t[iii] );
251 t = mData->emails;
252 t.sort();
253 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] );
255 t = mData->categories;
256 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] );
259 t = mData->custom;
260 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] );
263 KABC::Address::List::Iterator addressIter;
264 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
265 ++addressIter ) {
266 t = (*addressIter).asList();
267 t.sort();
268 for ( iii = 0; iii < t.count(); ++iii)
269 l.append( t[iii] );
270 }
271 setCsum( dev, QString::number (getCsum4List(l)) );
272}
177void Addressee::removeID(const QString &prof) 273void Addressee::removeID(const QString &prof)
@@ -1452,3 +1548,3 @@ void Addressee::insertCustom( const QString &app, const QString &name,
1452 if ( (*it).startsWith( qualifiedName ) ) { 1548 if ( (*it).startsWith( qualifiedName ) ) {
1453 (*it) = qualifiedName + value; 1549 (*it) = qualifiedName + value;
1454 return; 1550 return;
@@ -1456,3 +1552,2 @@ void Addressee::insertCustom( const QString &app, const QString &name,
1456 } 1552 }
1457
1458 mData->custom.append( qualifiedName + value ); 1553 mData->custom.append( qualifiedName + value );
diff --git a/kabc/addressee.h b/kabc/addressee.h
index f098371..0805458 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -108,2 +108,4 @@ class Addressee
108 void removeID(const QString &); 108 void removeID(const QString &);
109 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList);
109 /** 111 /**