summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-09-20 00:12:42 (UTC)
committer zautrix <zautrix>2004-09-20 00:12:42 (UTC)
commitb01b669d88fa195261d29ecf73b1c69e608a5ebc (patch) (unidiff)
treec0e79d45242a764b49470d07a9c95be156c121cc /kabc
parent3da2cfeab2edbe64a17251662e56668fe143f7a3 (diff)
downloadkdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.zip
kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.gz
kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.bz2
more AB sync
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp27
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kabc/addressee.cpp6
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp2
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp79
5 files changed, 98 insertions, 19 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 86dc7c2..17b9ba2 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -553,7 +553,6 @@ void AddressBook::removeAddressee( const Addressee &a )
553} 553}
554 554
555void AddressBook::removeDeletedAddressees() 555void AddressBook::removeSyncAddressees( bool removeDeleted )
556{ 556{
557 deleteRemovedAddressees();
558 Iterator it = begin(); 557 Iterator it = begin();
559 Iterator it2 ; 558 Iterator it2 ;
@@ -563,10 +562,10 @@ void AddressBook::removeDeletedAddressees()
563 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 562 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
564 (*it).setIDStr(""); 563 (*it).setIDStr("");
565 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 564 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
566 it2 = it; 565 it2 = it;
567 //qDebug("removing %s ",(*it).uid().latin1() ); 566 //qDebug("removing %s ",(*it).uid().latin1() );
568 ++it; 567 ++it;
569 removeAddressee( it2 ); 568 removeAddressee( it2 );
570 } else { 569 } else {
571 //qDebug("skipping %s ",(*it).uid().latin1() ); 570 //qDebug("skipping %s ",(*it).uid().latin1() );
572 ++it; 571 ++it;
@@ -618,9 +617,10 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
618 AddressBook::Iterator it; 617 AddressBook::Iterator it;
619 for ( it = begin(); it != end(); ++it ) { 618 for ( it = begin(); it != end(); ++it ) {
619 qDebug("check uid %s ", (*it).uid().latin1() );
620 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 620 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
621 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 621 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
622 Addressee ad = aBook->findByUid( ( (*it).uid() )); 622 Addressee ad = aBook->findByUid( ( (*it).uid() ));
623 if ( ad.isEmpty() ) { 623 if ( ad.isEmpty() ) {
624 qDebug("ERROR ad empty "); 624 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
625 } else { 625 } else {
626 (*it).computeCsum( csd ); 626 (*it).computeCsum( csd );
@@ -634,5 +634,13 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
634} 634}
635 635
636 636bool AddressBook::containsExternalUid( const QString& uid )
637{
638 Iterator it;
639 for ( it = begin(); it != end(); ++it ) {
640 if ( uid == (*it).externalUID( ) )
641 return true;
642 }
643 return false;
644}
637Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 645Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
638{ 646{
@@ -654,4 +662,11 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
654 } 662 }
655 } 663 }
664#if 0
665 // test only
666 for ( it = begin(); it != end(); ++it ) {
667
668 qDebug("uid %s ", (*it).uid().latin1());
669 }
670#endif
656} 671}
657 672
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 157dc56..8f62f0d 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -293,7 +293,8 @@ class AddressBook : public QObject
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList(); 294 QStringList uidList();
295 void removeDeletedAddressees(); 295 void removeSyncAddressees( bool removeDeleted = false );
296 void mergeAB( AddressBook *aBook, const QString& profile ); 296 void mergeAB( AddressBook *aBook, const QString& profile );
297 Addressee findByExternUid( const QString& uid , const QString& profile ); 297 Addressee findByExternUid( const QString& uid , const QString& profile );
298 bool containsExternalUid( const QString& uid );
298 299
299 void preExternSync( AddressBook* aBook, const QString& csd ); 300 void preExternSync( AddressBook* aBook, const QString& csd );
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index fda62f1..e241281 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -96,5 +96,5 @@ Addressee::Addressee()
96 mData->resource = 0; 96 mData->resource = 0;
97 mData->mExternalId = ":"; 97 mData->mExternalId = ":";
98 mData->revision = QDateTime ( QDate( 2004,1,1)); 98 mData->revision = QDateTime ( QDate( 2003,1,1));
99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
100} 100}
@@ -309,4 +309,6 @@ void Addressee::mergeContact( const Addressee& ad )
309 // merging custom; 309 // merging custom;
310 // merging keys 310 // merging keys
311 qDebug("merge contact %s ", ad.uid().latin1());
312 setUid( ad.uid() );
311} 313}
312 314
@@ -380,4 +382,5 @@ void Addressee::setOriginalExternalUID( const QString &id )
380 detach(); 382 detach();
381 mData->empty = false; 383 mData->empty = false;
384 qDebug("*******Set orig uid %s ", id.latin1());
382 mData->originalExternalUID = id; 385 mData->originalExternalUID = id;
383} 386}
@@ -392,4 +395,5 @@ void Addressee::setUid( const QString &id )
392 if ( id == mData->uid ) return; 395 if ( id == mData->uid ) return;
393 detach(); 396 detach();
397 qDebug("****setuid %s ", id.latin1());
394 mData->empty = false; 398 mData->empty = false;
395 mData->uid = id; 399 mData->uid = id;
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index de45e63..430c7b3 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -87,5 +87,5 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a
87 exuid = exuid.left( ente-1 ); 87 exuid = exuid.left( ente-1 );
88 addr.setExternalUID( exuid ); 88 addr.setExternalUID( exuid );
89 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); 89 qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() );
90 90
91 // email 91 // email
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 935a1cf..1f90fcb 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -198,32 +198,87 @@ bool ResourceQtopia::save( Ticket *ticket )
198 KABC::AddressBook::Iterator it; 198 KABC::AddressBook::Iterator it;
199 bool res; 199 bool res;
200 200 KABC::Addressee::List changedAddressees;
201 QStringList addedUID;
201 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 202 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
202 //KABC::Addressee addressee = (*it); 203 //KABC::Addressee addressee = (*it);
204 // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
203 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 205 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
204 QUuid uid( (*it).originalExternalUID() ); 206 QUuid uid( (*it).originalExternalUID() );
205 bool ok; 207 bool ok;
206 PimContact c = mAccess->contactForId( uid, &ok ); 208 PimContact c = mAccess->contactForId( uid, &ok );
209 qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
207 res = mConverter->addresseeToQtopia( *it, c ); 210 res = mConverter->addresseeToQtopia( *it, c );
208 if (res == true) { 211 if (res == true) {
209 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 212 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
210 mAccess->addContact(c); 213 qDebug("skipping adding of contact ");
211 KABC::Addressee addressee; 214 continue;
212 mConverter->qtopiaToAddressee( c, addressee ); 215 PimContact e;
213 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 216 AddressBookAccess Access2;
214 addressBook()->insertAddressee( addressee ); 217 Access2.addContact(e);
218 const PimContact* contact;
219 bool res;
220 QString uid2, Ouid;
221 AddressBookIterator itt(Access2);
222 for (contact=itt.toFirst(); itt.current(); ++itt)
223 {
224 contact = itt.current();
225 QString exuid = contact->uid().toString();
226 Ouid =exuid;
227 int ente = exuid.find( "-0000");
228 if ( exuid.left(1) == "{" )
229 exuid = exuid.mid(1);
230 if ( ente > -1 )
231 exuid = exuid.left( ente-1 );
232 uid2 = exuid;
233 qDebug("trying find uid ");
234 if ( !addressBook()->containsExternalUid( uid2 ) ) {
235 qDebug("ab not contains ");
236 if ( !addedUID.contains( uid2 )) {
237 qDebug("list not contains ");
238 break;
239 }
240 }
241
242 }
243 if ( !itt.current()) {
244 qDebug("ERROR uid ");
245 continue;
246 }
247 else
248 qDebug("ADD uid detected ");
249
250
251 QUuid uid3( Ouid);
252 PimContact d = Access2.contactForId( uid3, &ok );
253 if ( ! ok ) {
254 qDebug("ADD: Error getting new uid ");
255 } else {
256 qDebug("NEW UID found ");
257 PimContact g = mAccess->contactForId( c.uid(), &ok );
258 KABC::Addressee addressee;
259 mConverter->qtopiaToAddressee( g, addressee );
260 addressee.setUid((*it).uid() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 changedAddressees.append( addressee );
263 addedUID.append( uid2 );
264 }
265
215 266
216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 267 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
268 qDebug("Remove contact ");
217 if ( ok ) 269 if ( ok )
218 mAccess->removeContact(c); 270 mAccess->removeContact(c);
219 else 271 else
220 qDebug("Error revoe contact from qtopia "); 272 qDebug("Error remove contact from qtopia ");
221 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 273 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
222 if ( ok ) { 274 if ( ok ) {
275 qDebug("Update contact ");
223 mAccess->updateContact(c); 276 mAccess->updateContact(c);
277 PimContact g = mAccess->contactForId( c.uid(), &ok );
224 KABC::Addressee addressee; 278 KABC::Addressee addressee;
225 mConverter->qtopiaToAddressee( c, addressee ); 279 mConverter->qtopiaToAddressee( g, addressee );
280 addressee.setUid((*it).uid() );
226 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 281 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
227 addressBook()->insertAddressee( addressee ); 282 changedAddressees.append( addressee );
228 } 283 }
229 else 284 else
@@ -238,5 +293,9 @@ bool ResourceQtopia::save( Ticket *ticket )
238 } 293 }
239 294
240 // mAccess->addressBookUpdated(); 295 KABC::Addressee::List::Iterator it2;
296 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
297 addressBook()->insertAddressee((*it2));
298
299
241 300
242 mDirWatch.startScan(); 301 mDirWatch.startScan();