summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp31
-rw-r--r--kabc/addressee.cpp19
-rw-r--r--kabc/addressee.h1
-rw-r--r--kabc/stdaddressbook.cpp7
-rw-r--r--kaddressbook/kabcore.cpp27
-rw-r--r--korganizer/calendarview.cpp2
6 files changed, 59 insertions, 28 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index ec9f893..46a9cf4 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -314,88 +314,98 @@ void AddressBook::init(const QString &config, const QString &family )
314 addCustomField( i18n( "Children" ), KABC::Field::Personal, 314 addCustomField( i18n( "Children" ), KABC::Field::Personal,
315 "X-Children", "KADDRESSBOOK" ); 315 "X-Children", "KADDRESSBOOK" );
316 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 316 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
317 "X-FreeBusyUrl", "KADDRESSBOOK" ); 317 "X-FreeBusyUrl", "KADDRESSBOOK" );
318 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 318 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
319 "X-ExternalID", "KADDRESSBOOK" ); 319 "X-ExternalID", "KADDRESSBOOK" );
320} 320}
321 321
322AddressBook::~AddressBook() 322AddressBook::~AddressBook()
323{ 323{
324 delete d->mConfig; d->mConfig = 0; 324 delete d->mConfig; d->mConfig = 0;
325 delete d->mManager; d->mManager = 0; 325 delete d->mManager; d->mManager = 0;
326//US delete d->mErrorHandler; d->mErrorHandler = 0; 326//US delete d->mErrorHandler; d->mErrorHandler = 0;
327 delete d; d = 0; 327 delete d; d = 0;
328} 328}
329 329
330bool AddressBook::load() 330bool AddressBook::load()
331{ 331{
332 332
333 333
334 clear(); 334 clear();
335 335
336 KRES::Manager<Resource>::ActiveIterator it; 336 KRES::Manager<Resource>::ActiveIterator it;
337 bool ok = true; 337 bool ok = true;
338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
339 if ( !(*it)->load() ) { 339 if ( !(*it)->load() ) {
340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
341 ok = false; 341 ok = false;
342 } 342 }
343 343
344 // mark all addressees as unchanged 344 // mark all addressees as unchanged
345 Addressee::List::Iterator addrIt; 345 Addressee::List::Iterator addrIt;
346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
347 (*addrIt).setChanged( false ); 347 (*addrIt).setChanged( false );
348 348 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
349 if ( !id.isEmpty() ) {
350 //qDebug("setId aa %s ", id.latin1());
351 (*addrIt).setIDStr(id );
352 }
353 }
349 blockLSEchange = true; 354 blockLSEchange = true;
350 return ok; 355 return ok;
351} 356}
352 357
353bool AddressBook::save( Ticket *ticket ) 358bool AddressBook::save( Ticket *ticket )
354{ 359{
355 kdDebug(5700) << "AddressBook::save()"<< endl; 360 kdDebug(5700) << "AddressBook::save()"<< endl;
356 361
357 if ( ticket->resource() ) { 362 if ( ticket->resource() ) {
358 deleteRemovedAddressees(); 363 deleteRemovedAddressees();
359 return ticket->resource()->save( ticket ); 364 return ticket->resource()->save( ticket );
360 } 365 }
361 366
362 return false; 367 return false;
363} 368}
364bool AddressBook::saveAB() 369bool AddressBook::saveAB()
365{ 370{
366 bool ok = true; 371 bool ok = true;
367 372
368 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
369 374 Iterator ait;
375 for ( ait = begin(); ait != end(); ++ait ) {
376 if ( !(*ait).IDStr().isEmpty() ) {
377 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
378 }
379 }
370 KRES::Manager<Resource>::ActiveIterator it; 380 KRES::Manager<Resource>::ActiveIterator it;
371 KRES::Manager<Resource> *manager = d->mManager; 381 KRES::Manager<Resource> *manager = d->mManager;
372 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 382 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
373 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 383 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
374 Ticket *ticket = requestSaveTicket( *it ); 384 Ticket *ticket = requestSaveTicket( *it );
375// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 385// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
376 if ( !ticket ) { 386 if ( !ticket ) {
377 error( i18n( "Unable to save to resource '%1'. It is locked." ) 387 error( i18n( "Unable to save to resource '%1'. It is locked." )
378 .arg( (*it)->resourceName() ) ); 388 .arg( (*it)->resourceName() ) );
379 return false; 389 return false;
380 } 390 }
381 391
382 //if ( !save( ticket ) ) 392 //if ( !save( ticket ) )
383 if ( ticket->resource() ) { 393 if ( ticket->resource() ) {
384 if ( ! ticket->resource()->save( ticket ) ) 394 if ( ! ticket->resource()->save( ticket ) )
385 ok = false; 395 ok = false;
386 } else 396 } else
387 ok = false; 397 ok = false;
388 398
389 } 399 }
390 } 400 }
391 return ok; 401 return ok;
392} 402}
393 403
394AddressBook::Iterator AddressBook::begin() 404AddressBook::Iterator AddressBook::begin()
395{ 405{
396 Iterator it = Iterator(); 406 Iterator it = Iterator();
397 it.d->mIt = d->mAddressees.begin(); 407 it.d->mIt = d->mAddressees.begin();
398 return it; 408 return it;
399} 409}
400 410
401AddressBook::ConstIterator AddressBook::begin() const 411AddressBook::ConstIterator AddressBook::begin() const
@@ -421,165 +431,172 @@ AddressBook::ConstIterator AddressBook::end() const
421 431
422void AddressBook::clear() 432void AddressBook::clear()
423{ 433{
424 d->mAddressees.clear(); 434 d->mAddressees.clear();
425} 435}
426 436
427Ticket *AddressBook::requestSaveTicket( Resource *resource ) 437Ticket *AddressBook::requestSaveTicket( Resource *resource )
428{ 438{
429 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 439 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
430 440
431 if ( !resource ) 441 if ( !resource )
432 { 442 {
433 qDebug("AddressBook::requestSaveTicket no resource" ); 443 qDebug("AddressBook::requestSaveTicket no resource" );
434 resource = standardResource(); 444 resource = standardResource();
435 } 445 }
436 446
437 KRES::Manager<Resource>::ActiveIterator it; 447 KRES::Manager<Resource>::ActiveIterator it;
438 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 448 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
439 if ( (*it) == resource ) { 449 if ( (*it) == resource ) {
440 if ( (*it)->readOnly() || !(*it)->isOpen() ) 450 if ( (*it)->readOnly() || !(*it)->isOpen() )
441 return 0; 451 return 0;
442 else 452 else
443 return (*it)->requestSaveTicket(); 453 return (*it)->requestSaveTicket();
444 } 454 }
445 } 455 }
446 456
447 return 0; 457 return 0;
448} 458}
449 459
450void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 460void AddressBook::insertAddressee( const Addressee &a, bool setRev )
451{ 461{
452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 462 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
463 //qDebug("block insert ");
453 return; 464 return;
454 } 465 }
466 //qDebug("inserting.... %s ",a.uid().latin1() );
455 bool found = false; 467 bool found = false;
456 Addressee::List::Iterator it; 468 Addressee::List::Iterator it;
457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 469 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
458 if ( a.uid() == (*it).uid() ) { 470 if ( a.uid() == (*it).uid() ) {
459 471
460 bool changed = false; 472 bool changed = false;
461 Addressee addr = a; 473 Addressee addr = a;
462 if ( addr != (*it) ) 474 if ( addr != (*it) )
463 changed = true; 475 changed = true;
464 476
465 (*it) = a; 477 (*it) = a;
466 if ( (*it).resource() == 0 ) 478 if ( (*it).resource() == 0 )
467 (*it).setResource( standardResource() ); 479 (*it).setResource( standardResource() );
468 480
469 if ( changed ) { 481 if ( changed ) {
470 if ( setRev ) { 482 if ( setRev ) {
471 483
472 // get rid of micro seconds 484 // get rid of micro seconds
473 QDateTime dt = QDateTime::currentDateTime(); 485 QDateTime dt = QDateTime::currentDateTime();
474 QTime t = dt.time(); 486 QTime t = dt.time();
475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 487 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
476 (*it).setRevision( dt ); 488 (*it).setRevision( dt );
477 } 489 }
478 (*it).setChanged( true ); 490 (*it).setChanged( true );
479 } 491 }
480 492
481 found = true; 493 found = true;
482 } else { 494 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) { 495 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 ); 496 QString name = (*it).uid().mid( 19 );
485 Addressee b = a; 497 Addressee b = a;
486 QString id = b.getID( name ); 498 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) { 499 if ( ! id.isEmpty() ) {
488 QString des = (*it).note(); 500 QString des = (*it).note();
489 int startN; 501 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) { 502 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 ); 503 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 ); 504 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des ); 505 (*it).setNote( des );
494 } 506 }
495 } 507 }
496 } 508 }
497 } 509 }
498 } 510 }
499 if ( found ) 511 if ( found )
500 return; 512 return;
501 d->mAddressees.append( a ); 513 d->mAddressees.append( a );
502 Addressee& addr = d->mAddressees.last(); 514 Addressee& addr = d->mAddressees.last();
503 if ( addr.resource() == 0 ) 515 if ( addr.resource() == 0 )
504 addr.setResource( standardResource() ); 516 addr.setResource( standardResource() );
505 517
506 addr.setChanged( true ); 518 addr.setChanged( true );
507} 519}
508 520
509void AddressBook::removeAddressee( const Addressee &a ) 521void AddressBook::removeAddressee( const Addressee &a )
510{ 522{
511 Iterator it; 523 Iterator it;
512 Iterator it2; 524 Iterator it2;
513 bool found = false; 525 bool found = false;
514 for ( it = begin(); it != end(); ++it ) { 526 for ( it = begin(); it != end(); ++it ) {
515 if ( a.uid() == (*it).uid() ) { 527 if ( a.uid() == (*it).uid() ) {
516 found = true; 528 found = true;
517 it2 = it; 529 it2 = it;
518 } else { 530 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) { 531 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 ); 532 QString name = (*it).uid().mid( 19 );
521 Addressee b = a; 533 Addressee b = a;
522 QString id = b.getID( name ); 534 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) { 535 if ( ! id.isEmpty() ) {
524 QString des = (*it).note(); 536 QString des = (*it).note();
525 if( des.find( id ) < 0 ) { 537 if( des.find( id ) < 0 ) {
526 des += id + ","; 538 des += id + ",";
527 (*it).setNote( des ); 539 (*it).setNote( des );
528 } 540 }
529 } 541 }
530 } 542 }
531 543
532 } 544 }
533 } 545 }
534 546
535 if ( found ) 547 if ( found )
536 removeAddressee( it2 ); 548 removeAddressee( it2 );
537 549
538} 550}
539 551
540void AddressBook::removeDeletedAddressees() 552void AddressBook::removeDeletedAddressees()
541{ 553{
542 deleteRemovedAddressees(); 554 deleteRemovedAddressees();
543 Iterator it = begin(); 555 Iterator it = begin();
544 Iterator it2 ; 556 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) ); 557 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) { 558 while ( it != end() ) {
547 (*it).setRevision( dt ); 559 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 560 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
561 (*it).setIDStr("");
562 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
549 it2 = it; 563 it2 = it;
564 //qDebug("removing %s ",(*it).uid().latin1() );
550 ++it; 565 ++it;
551 removeAddressee( it2 ); 566 removeAddressee( it2 );
552 } else 567 } else {
568 //qDebug("skipping %s ",(*it).uid().latin1() );
553 ++it; 569 ++it;
570 }
554 } 571 }
555 deleteRemovedAddressees(); 572 deleteRemovedAddressees();
556} 573}
557 574
558void AddressBook::removeAddressee( const Iterator &it ) 575void AddressBook::removeAddressee( const Iterator &it )
559{ 576{
560 d->mRemovedAddressees.append( (*it) ); 577 d->mRemovedAddressees.append( (*it) );
561 d->mAddressees.remove( it.d->mIt ); 578 d->mAddressees.remove( it.d->mIt );
562} 579}
563 580
564AddressBook::Iterator AddressBook::find( const Addressee &a ) 581AddressBook::Iterator AddressBook::find( const Addressee &a )
565{ 582{
566 Iterator it; 583 Iterator it;
567 for ( it = begin(); it != end(); ++it ) { 584 for ( it = begin(); it != end(); ++it ) {
568 if ( a.uid() == (*it).uid() ) { 585 if ( a.uid() == (*it).uid() ) {
569 return it; 586 return it;
570 } 587 }
571 } 588 }
572 return end(); 589 return end();
573} 590}
574 591
575Addressee AddressBook::findByUid( const QString &uid ) 592Addressee AddressBook::findByUid( const QString &uid )
576{ 593{
577 Iterator it; 594 Iterator it;
578 for ( it = begin(); it != end(); ++it ) { 595 for ( it = begin(); it != end(); ++it ) {
579 if ( uid == (*it).uid() ) { 596 if ( uid == (*it).uid() ) {
580 return *it; 597 return *it;
581 } 598 }
582 } 599 }
583 return Addressee(); 600 return Addressee();
584} 601}
585#if 0 602#if 0
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 0f5d605..d6b70c4 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -50,90 +50,89 @@ struct Addressee::AddresseeData : public KShared
50 QString name; 50 QString name;
51 QString formattedName; 51 QString formattedName;
52 QString familyName; 52 QString familyName;
53 QString givenName; 53 QString givenName;
54 QString additionalName; 54 QString additionalName;
55 QString prefix; 55 QString prefix;
56 QString suffix; 56 QString suffix;
57 QString nickName; 57 QString nickName;
58 QDateTime birthday; 58 QDateTime birthday;
59 QString mailer; 59 QString mailer;
60 TimeZone timeZone; 60 TimeZone timeZone;
61 Geo geo; 61 Geo geo;
62 QString title; 62 QString title;
63 QString role; 63 QString role;
64 QString organization; 64 QString organization;
65 QString note; 65 QString note;
66 QString productId; 66 QString productId;
67 QDateTime revision; 67 QDateTime revision;
68 QString sortString; 68 QString sortString;
69 KURL url; 69 KURL url;
70 Secrecy secrecy; 70 Secrecy secrecy;
71 Picture logo; 71 Picture logo;
72 Picture photo; 72 Picture photo;
73 Sound sound; 73 Sound sound;
74 Agent agent; 74 Agent agent;
75 QString mExternalId; 75 QString mExternalId;
76 PhoneNumber::List phoneNumbers; 76 PhoneNumber::List phoneNumbers;
77 Address::List addresses; 77 Address::List addresses;
78 Key::List keys; 78 Key::List keys;
79 QStringList emails; 79 QStringList emails;
80 QStringList categories; 80 QStringList categories;
81 QStringList custom; 81 QStringList custom;
82 82 int mTempSyncStat;
83 Resource *resource; 83 Resource *resource;
84 84
85 bool empty :1; 85 bool empty :1;
86 bool changed :1; 86 bool changed :1;
87}; 87};
88 88
89Addressee::Addressee() 89Addressee::Addressee()
90{ 90{
91 mData = new AddresseeData; 91 mData = new AddresseeData;
92 mData->empty = true; 92 mData->empty = true;
93 mData->changed = false; 93 mData->changed = false;
94 mData->resource = 0; 94 mData->resource = 0;
95 mData->mExternalId = ":"; 95 mData->mExternalId = ":";
96 mData->revision = QDateTime ( QDate( 2004,1,1)); 96 mData->revision = QDateTime ( QDate( 2004,1,1));
97 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 97 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
98} 98}
99 99
100Addressee::~Addressee() 100Addressee::~Addressee()
101{ 101{
102} 102}
103 103
104Addressee::Addressee( const Addressee &a ) 104Addressee::Addressee( const Addressee &a )
105{ 105{
106 mData = a.mData; 106 mData = a.mData;
107 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
108} 107}
109 108
110Addressee &Addressee::operator=( const Addressee &a ) 109Addressee &Addressee::operator=( const Addressee &a )
111{ 110{
112 mData = a.mData; 111 mData = a.mData;
113 return (*this); 112 return (*this);
114} 113}
115 114
116Addressee Addressee::copy() 115Addressee Addressee::copy()
117{ 116{
118 Addressee a; 117 Addressee a;
119 *(a.mData) = *mData; 118 *(a.mData) = *mData;
120 return a; 119 return a;
121} 120}
122 121
123void Addressee::detach() 122void Addressee::detach()
124{ 123{
125 if ( mData.count() == 1 ) return; 124 if ( mData.count() == 1 ) return;
126 *this = copy(); 125 *this = copy();
127} 126}
128 127
129bool Addressee::operator==( const Addressee &a ) const 128bool Addressee::operator==( const Addressee &a ) const
130{ 129{
131 if ( uid() != a.uid() ) return false; 130 if ( uid() != a.uid() ) return false;
132 if ( mData->name != a.mData->name ) return false; 131 if ( mData->name != a.mData->name ) return false;
133 if ( mData->formattedName != a.mData->formattedName ) return false; 132 if ( mData->formattedName != a.mData->formattedName ) return false;
134 if ( mData->familyName != a.mData->familyName ) return false; 133 if ( mData->familyName != a.mData->familyName ) return false;
135 if ( mData->givenName != a.mData->givenName ) return false; 134 if ( mData->givenName != a.mData->givenName ) return false;
136 if ( mData->additionalName != a.mData->additionalName ) return false; 135 if ( mData->additionalName != a.mData->additionalName ) return false;
137 if ( mData->prefix != a.mData->prefix ) return false; 136 if ( mData->prefix != a.mData->prefix ) return false;
138 if ( mData->suffix != a.mData->suffix ) return false; 137 if ( mData->suffix != a.mData->suffix ) return false;
139 if ( mData->nickName != a.mData->nickName ) return false; 138 if ( mData->nickName != a.mData->nickName ) return false;
@@ -239,95 +238,103 @@ void Addressee::computeCsum(const QString &dev)
239#endif 238#endif
240 KABC::PhoneNumber::List phoneNumbers; 239 KABC::PhoneNumber::List phoneNumbers;
241 KABC::PhoneNumber::List::Iterator phoneIter; 240 KABC::PhoneNumber::List::Iterator phoneIter;
242 241
243 QStringList t; 242 QStringList t;
244 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 243 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
245 ++phoneIter ) 244 ++phoneIter )
246 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 245 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
247 t.sort(); 246 t.sort();
248 uint iii; 247 uint iii;
249 for ( iii = 0; iii < t.count(); ++iii) 248 for ( iii = 0; iii < t.count(); ++iii)
250 l.append( t[iii] ); 249 l.append( t[iii] );
251 t = mData->emails; 250 t = mData->emails;
252 t.sort(); 251 t.sort();
253 for ( iii = 0; iii < t.count(); ++iii) 252 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] ); 253 l.append( t[iii] );
255 t = mData->categories; 254 t = mData->categories;
256 t.sort(); 255 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii) 256 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] ); 257 l.append( t[iii] );
259 t = mData->custom; 258 t = mData->custom;
260 t.sort(); 259 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii) 260 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] ); 261 l.append( t[iii] );
263 KABC::Address::List::Iterator addressIter; 262 KABC::Address::List::Iterator addressIter;
264 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 263 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
265 ++addressIter ) { 264 ++addressIter ) {
266 t = (*addressIter).asList(); 265 t = (*addressIter).asList();
267 t.sort(); 266 t.sort();
268 for ( iii = 0; iii < t.count(); ++iii) 267 for ( iii = 0; iii < t.count(); ++iii)
269 l.append( t[iii] ); 268 l.append( t[iii] );
270 } 269 }
271 setCsum( dev, QString::number (getCsum4List(l)) ); 270 uint cs = getCsum4List(l);
271 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
272 setCsum( dev, QString::number (cs ));
272} 273}
273void Addressee::removeID(const QString &prof) 274void Addressee::removeID(const QString &prof)
274{ 275{
275 detach(); 276 detach();
276 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 277 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
277 278
278} 279}
279void Addressee::setID( const QString & prof , const QString & id ) 280void Addressee::setID( const QString & prof , const QString & id )
280{ 281{
281 detach(); 282 detach();
283 qDebug("setID1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
282 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 284 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
285 qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
283} 286}
284void Addressee::setTempSyncStat( int id ) 287void Addressee::setTempSyncStat( int id )
285{ 288{
286 mTempSyncStat = id; 289 if ( mData->mTempSyncStat == id ) return;
290 detach();
291 mData->mTempSyncStat = id;
287} 292}
288int Addressee::tempSyncStat() const 293int Addressee::tempSyncStat() const
289{ 294{
290 return mTempSyncStat; 295 return mData->mTempSyncStat;
291} 296}
292 297
293QString Addressee::getID( const QString & prof) 298QString Addressee::getID( const QString & prof)
294{ 299{
295 return KIdManager::getId ( mData->mExternalId, prof ); 300 return KIdManager::getId ( mData->mExternalId, prof );
296} 301}
297 302
298void Addressee::setCsum( const QString & prof , const QString & id ) 303void Addressee::setCsum( const QString & prof , const QString & id )
299{ 304{
300 detach(); 305 detach();
306 qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
301 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 307 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
308 qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
302} 309}
303 310
304QString Addressee::getCsum( const QString & prof) 311QString Addressee::getCsum( const QString & prof)
305{ 312{
306 return KIdManager::getCsum ( mData->mExternalId, prof ); 313 return KIdManager::getCsum ( mData->mExternalId, prof );
307} 314}
308 315
309void Addressee::setIDStr( const QString & s ) 316void Addressee::setIDStr( const QString & s )
310{ 317{
311 detach(); 318 detach();
312 mData->mExternalId = s; 319 mData->mExternalId = s;
313} 320}
314 321
315QString Addressee::IDStr() const 322QString Addressee::IDStr() const
316{ 323{
317 return mData->mExternalId; 324 return mData->mExternalId;
318} 325}
319 326
320 327
321void Addressee::setUid( const QString &id ) 328void Addressee::setUid( const QString &id )
322{ 329{
323 if ( id == mData->uid ) return; 330 if ( id == mData->uid ) return;
324 detach(); 331 detach();
325 mData->empty = false; 332 mData->empty = false;
326 mData->uid = id; 333 mData->uid = id;
327} 334}
328 335
329QString Addressee::uid() const 336QString Addressee::uid() const
330{ 337{
331 if ( mData->uid.isEmpty() ) 338 if ( mData->uid.isEmpty() )
332 mData->uid = KApplication::randomString( 10 ); 339 mData->uid = KApplication::randomString( 10 );
333 340
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0805458..bfb0840 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -797,44 +797,43 @@ class Addressee
797 */ 797 */
798 QString asString() const; 798 QString asString() const;
799 799
800 /** 800 /**
801 Set resource where the addressee is from. 801 Set resource where the addressee is from.
802 */ 802 */
803 void setResource( Resource *resource ); 803 void setResource( Resource *resource );
804 804
805 /** 805 /**
806 Return pointer to resource. 806 Return pointer to resource.
807 */ 807 */
808 Resource *resource() const; 808 Resource *resource() const;
809 809
810 /** 810 /**
811 Return resourcelabel. 811 Return resourcelabel.
812 */ 812 */
813 //US 813 //US
814 static QString resourceLabel(); 814 static QString resourceLabel();
815 815
816 /** 816 /**
817 Mark addressee as changed. 817 Mark addressee as changed.
818 */ 818 */
819 void setChanged( bool value ); 819 void setChanged( bool value );
820 820
821 /** 821 /**
822 Return whether the addressee is changed. 822 Return whether the addressee is changed.
823 */ 823 */
824 bool changed() const; 824 bool changed() const;
825 825
826 private: 826 private:
827 Addressee copy(); 827 Addressee copy();
828 void detach(); 828 void detach();
829 int mTempSyncStat;
830 829
831 struct AddresseeData; 830 struct AddresseeData;
832 mutable KSharedPtr<AddresseeData> mData; 831 mutable KSharedPtr<AddresseeData> mData;
833}; 832};
834 833
835QDataStream &operator<<( QDataStream &, const Addressee & ); 834QDataStream &operator<<( QDataStream &, const Addressee & );
836QDataStream &operator>>( QDataStream &, Addressee & ); 835QDataStream &operator>>( QDataStream &, Addressee & );
837 836
838} 837}
839 838
840#endif 839#endif
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index ec47a4e..181a09e 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -136,65 +136,70 @@ void StdAddressBook::init( bool )
136 136
137 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 137 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
138 (*it)->setAddressBook( this ); 138 (*it)->setAddressBook( this );
139 if ( !(*it)->open() ) 139 if ( !(*it)->open() )
140 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 140 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
141 } 141 }
142 142
143 Resource *res = standardResource(); 143 Resource *res = standardResource();
144 if ( !res ) { 144 if ( !res ) {
145 res = manager->createResource( "file" ); 145 res = manager->createResource( "file" );
146 if ( res ) 146 if ( res )
147 { 147 {
148 addResource( res ); 148 addResource( res );
149 } 149 }
150 else 150 else
151 qDebug(" No resource available!!!"); 151 qDebug(" No resource available!!!");
152 } 152 }
153 153
154 setStandardResource( res ); 154 setStandardResource( res );
155 manager->writeConfig(); 155 manager->writeConfig();
156 156
157 load(); 157 load();
158} 158}
159 159
160bool StdAddressBook::save() 160bool StdAddressBook::save()
161{ 161{
162 kdDebug(5700) << "StdAddressBook::save()" << endl; 162 kdDebug(5700) << "StdAddressBook::save()" << endl;
163 163
164 bool ok = true; 164 bool ok = true;
165 AddressBook *ab = self(); 165 AddressBook *ab = self();
166 166
167 ab->deleteRemovedAddressees(); 167 ab->deleteRemovedAddressees();
168 168 Iterator ait;
169 for ( ait = ab->begin(); ait != ab->end(); ++ait ) {
170 if ( !(*ait).IDStr().isEmpty() ) {
171 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
172 }
173 }
169 KRES::Manager<Resource>::ActiveIterator it; 174 KRES::Manager<Resource>::ActiveIterator it;
170 KRES::Manager<Resource> *manager = ab->resourceManager(); 175 KRES::Manager<Resource> *manager = ab->resourceManager();
171 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 176 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
172 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 177 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
173 Ticket *ticket = ab->requestSaveTicket( *it ); 178 Ticket *ticket = ab->requestSaveTicket( *it );
174// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 179// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
175 if ( !ticket ) { 180 if ( !ticket ) {
176 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 181 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
177 .arg( (*it)->resourceName() ) ); 182 .arg( (*it)->resourceName() ) );
178 return false; 183 return false;
179 } 184 }
180 185
181 if ( !ab->save( ticket ) ) 186 if ( !ab->save( ticket ) )
182 ok = false; 187 ok = false;
183 } 188 }
184 } 189 }
185 190
186 return ok; 191 return ok;
187} 192}
188 193
189void StdAddressBook::close() 194void StdAddressBook::close()
190{ 195{
191//US destructObject is not defined on my system???. Is setObject(0) the same ??? 196//US destructObject is not defined on my system???. Is setObject(0) the same ???
192//US addressBookDeleter.destructObject(); 197//US addressBookDeleter.destructObject();
193 addressBookDeleter.setObject(0); 198 addressBookDeleter.setObject(0);
194 199
195} 200}
196 201
197void StdAddressBook::setAutomaticSave( bool enable ) 202void StdAddressBook::setAutomaticSave( bool enable )
198{ 203{
199 mAutomaticSave = enable; 204 mAutomaticSave = enable;
200} 205}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 8776b53..56f6af2 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2497,99 +2497,101 @@ QString KABCore::getPassword( )
2497 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2498 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2499 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2500 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2501 lay.setMargin(7); 2501 lay.setMargin(7);
2502 lay.setSpacing(7); 2502 lay.setSpacing(7);
2503 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2504 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2505 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2506 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2507 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2509 dia.show(); 2509 dia.show();
2510 int res = dia.exec(); 2510 int res = dia.exec();
2511 if ( res ) 2511 if ( res )
2512 retfile = lab.text(); 2512 retfile = lab.text();
2513 dia.hide(); 2513 dia.hide();
2514 qApp->processEvents(); 2514 qApp->processEvents();
2515 return retfile; 2515 return retfile;
2516 2516
2517} 2517}
2518#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2519 2519
2520KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2521{ 2521{
2522 Addressee lse; 2522 Addressee lse;
2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2525 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2526 qDebug("Creating new last-syncAddressee "); 2526 qDebug("Creating new last-syncAddressee ");
2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2528 QString sum = ""; 2528 QString sum = "";
2529 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2530 sum = "E: "; 2530 sum = "E: ";
2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2532 lse.setRevision( mLastAddressbookSync ); 2532 lse.setRevision( mLastAddressbookSync );
2533 lse.setCategories( i18n("SyncEvent") ); 2533 lse.setCategories( i18n("SyncEvent") );
2534 mAddressBook->insertAddressee( lse ); 2534 mAddressBook->insertAddressee( lse );
2535 } 2535 }
2536 return lse; 2536 return lse;
2537} 2537}
2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2539{ 2539{
2540 2540
2541 //void setZaurusId(int id); 2541 //void setZaurusId(int id);
2542 // int zaurusId() const; 2542 // int zaurusId() const;
2543 // void setZaurusUid(int id); 2543 // void setZaurusUid(int id);
2544 // int zaurusUid() const; 2544 // int zaurusUid() const;
2545 // void setZaurusStat(int id); 2545 // void setZaurusStat(int id);
2546 // int zaurusStat() const; 2546 // int zaurusStat() const;
2547 // 0 equal 2547 // 0 equal
2548 // 1 take local 2548 // 1 take local
2549 // 2 take remote 2549 // 2 take remote
2550 // 3 cancel 2550 // 3 cancel
2551 QDateTime lastSync = mLastAddressbookSync; 2551 QDateTime lastSync = mLastAddressbookSync;
2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2553 bool remCh, locCh; 2553 bool remCh, locCh;
2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2555 //if ( remCh ) 2555 if ( remCh )
2556 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2556 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2557 locCh = ( local->revision() > mLastAddressbookSync ); 2557 locCh = ( local->revision() > mLastAddressbookSync );
2558 if ( !remCh && ! locCh ) { 2558 if ( !remCh && ! locCh ) {
2559 //qDebug("both not changed "); 2559 qDebug("both not changed ");
2560 lastSync = local->revision().addDays(1); 2560 lastSync = local->revision().addDays(1);
2561 if ( mode <= SYNC_PREF_ASK )
2562 return 0;
2561 } else { 2563 } else {
2562 if ( locCh ) { 2564 if ( locCh ) {
2563 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); 2565 qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1());
2564 lastSync = local->revision().addDays( -1 ); 2566 lastSync = local->revision().addDays( -1 );
2565 if ( !remCh ) 2567 if ( !remCh )
2566 remote->setRevision( lastSync.addDays( -1 ) ); 2568 remote->setRevision( lastSync.addDays( -1 ) );
2567 } else { 2569 } else {
2568 //qDebug(" not loc changed "); 2570 //qDebug(" not loc changed ");
2569 lastSync = local->revision().addDays( 1 ); 2571 lastSync = local->revision().addDays( 1 );
2570 if ( remCh ) 2572 if ( remCh )
2571 remote->setRevision( lastSync.addDays( 1 ) ); 2573 remote->setRevision( lastSync.addDays( 1 ) );
2572 2574
2573 } 2575 }
2574 } 2576 }
2575 full = true; 2577 full = true;
2576 if ( mode < SYNC_PREF_ASK ) 2578 if ( mode < SYNC_PREF_ASK )
2577 mode = SYNC_PREF_ASK; 2579 mode = SYNC_PREF_ASK;
2578 } else { 2580 } else {
2579 if ( local->revision() == remote->revision() ) 2581 if ( local->revision() == remote->revision() )
2580 return 0; 2582 return 0;
2581 2583
2582 } 2584 }
2583 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2585 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2584 2586
2585 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 2587 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
2586 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2588 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2587 //full = true; //debug only 2589 //full = true; //debug only
2588 if ( full ) { 2590 if ( full ) {
2589 bool equ = ( (*local) == (*remote) ); 2591 bool equ = ( (*local) == (*remote) );
2590 if ( equ ) { 2592 if ( equ ) {
2591 //qDebug("equal "); 2593 //qDebug("equal ");
2592 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2594 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2593 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2595 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2594 } 2596 }
2595 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2597 if ( mode < SYNC_PREF_FORCE_LOCAL )
@@ -2761,211 +2763,210 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2761 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2763 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2762 //qDebug("take %d %s ", take, inL.summary().latin1()); 2764 //qDebug("take %d %s ", take, inL.summary().latin1());
2763 if ( take == 3 ) 2765 if ( take == 3 )
2764 return false; 2766 return false;
2765 if ( take == 1 ) {// take local 2767 if ( take == 1 ) {// take local
2766 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2768 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2767 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2769 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2768 local->insertAddressee( inL, false ); 2770 local->insertAddressee( inL, false );
2769 } 2771 }
2770 else 2772 else
2771 idS = inR.IDStr(); 2773 idS = inR.IDStr();
2772 remote->removeAddressee( inR ); 2774 remote->removeAddressee( inR );
2773 inR = inL; 2775 inR = inL;
2774 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2776 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2775 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2777 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2776 inR.setIDStr( idS ); 2778 inR.setIDStr( idS );
2777 inR.setResource( 0 ); 2779 inR.setResource( 0 );
2778 remote->insertAddressee( inR , false); 2780 remote->insertAddressee( inR , false);
2779 ++changedRemote; 2781 ++changedRemote;
2780 } else { 2782 } else {
2781 idS = inL.IDStr(); 2783 idS = inL.IDStr();
2782 local->removeAddressee( inL ); 2784 local->removeAddressee( inL );
2783 inL = inR; 2785 inL = inR;
2784 inL.setIDStr( idS ); 2786 inL.setIDStr( idS );
2785 inL.setResource( 0 ); 2787 inL.setResource( 0 );
2786 local->insertAddressee( inL , false ); 2788 local->insertAddressee( inL , false );
2787 ++changedLocal; 2789 ++changedLocal;
2788 } 2790 }
2789 } 2791 }
2790 } else { // no conflict 2792 } else { // no conflict
2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2793 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2792 QString des = addresseeLSync.note(); 2794 QString des = addresseeLSync.note();
2793 QString pref = "a"; 2795 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2794 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2795 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2796 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2797 remote->insertAddressee( inR, false );
2796 ++deletedAddresseeR; 2798 ++deletedAddresseeR;
2797 } else { 2799 } else {
2798 inR.setRevision( modifiedCalendar ); 2800 inR.setRevision( modifiedCalendar );
2799 remote->insertAddressee( inR, false ); 2801 remote->insertAddressee( inR, false );
2800 inL = inR; 2802 inL = inR;
2801 inL.setResource( 0 ); 2803 inL.setResource( 0 );
2802 local->insertAddressee( inL , false); 2804 local->insertAddressee( inL , false);
2803 ++addedAddressee; 2805 ++addedAddressee;
2804 } 2806 }
2805 } else { 2807 } else {
2806 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2808 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2807 inR.setRevision( modifiedCalendar ); 2809 inR.setRevision( modifiedCalendar );
2808 remote->insertAddressee( inR, false ); 2810 remote->insertAddressee( inR, false );
2809 inR.setResource( 0 ); 2811 inR.setResource( 0 );
2810 local->insertAddressee( inR, false ); 2812 local->insertAddressee( inR, false );
2811 ++addedAddressee; 2813 ++addedAddressee;
2812 } else { 2814 } else {
2813 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2815 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2814 remote->removeAddressee( inR ); 2816 remote->removeAddressee( inR );
2815 ++deletedAddresseeR; 2817 ++deletedAddresseeR;
2816 } 2818 }
2817 } 2819 }
2818 } 2820 }
2819 } 2821 }
2820 ++incCounter; 2822 ++incCounter;
2821 } 2823 }
2822 er.clear(); 2824 er.clear();
2823 QStringList el = remote->uidList(); 2825 QStringList el = local->uidList();
2824 modulo = (el.count()/10)+1; 2826 modulo = (el.count()/10)+1;
2825 bar.setCaption (i18n("Add / remove addressees") ); 2827 bar.setCaption (i18n("Add / remove addressees") );
2826 bar.setTotalSteps ( el.count() ) ; 2828 bar.setTotalSteps ( el.count() ) ;
2827 bar.show(); 2829 bar.show();
2828 incCounter = 0; 2830 incCounter = 0;
2829 while ( incCounter < el.count()) { 2831 while ( incCounter < el.count()) {
2830
2831 qApp->processEvents(); 2832 qApp->processEvents();
2832 if ( ! bar.isVisible() ) 2833 if ( ! bar.isVisible() )
2833 return false; 2834 return false;
2834 if ( incCounter % modulo == 0 ) 2835 if ( incCounter % modulo == 0 )
2835 bar.setProgress( incCounter ); 2836 bar.setProgress( incCounter );
2836 uid = el[ incCounter ]; 2837 uid = el[ incCounter ];
2837 bool skipIncidence = false; 2838 bool skipIncidence = false;
2838 if ( uid.left(19) == QString("last-syncAddressee-") ) 2839 if ( uid.left(19) == QString("last-syncAddressee-") )
2839 skipIncidence = true; 2840 skipIncidence = true;
2840 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2841 skipIncidence = true;
2842 if ( !skipIncidence ) { 2841 if ( !skipIncidence ) {
2843 inL = local->findByUid( uid ); 2842 inL = local->findByUid( uid );
2844 inR = remote->findByUid( uid ); 2843 inR = remote->findByUid( uid );
2845 if ( inR.isEmpty() ) { 2844 if ( inR.isEmpty() ) {
2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2845 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2847 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2846 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2848 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2847 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2849 local->removeAddressee( inL ); 2848 local->removeAddressee( inL );
2850 ++deletedAddresseeL; 2849 ++deletedAddresseeL;
2851 } else { 2850 } else {
2852 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2851 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2853 inL.removeID(mCurrentSyncDevice ); 2852 inL.removeID(mCurrentSyncDevice );
2854 ++addedAddresseeR; 2853 ++addedAddresseeR;
2855 //qDebug("remote added Incidence %s ", inL.summary().latin1());
2856 inL.setRevision( modifiedCalendar ); 2854 inL.setRevision( modifiedCalendar );
2857 local->insertAddressee( inL, false ); 2855 local->insertAddressee( inL, false );
2858 inR = inL; 2856 inR = inL;
2859 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2857 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2860 inR.setResource( 0 ); 2858 inR.setResource( 0 );
2861 remote->insertAddressee( inR, false ); 2859 remote->insertAddressee( inR, false );
2862 } 2860 }
2863 } 2861 }
2864 } else { 2862 } else {
2865 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2863 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2866 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2864 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2867 local->removeAddressee( inL ); 2865 local->removeAddressee( inL );
2868 ++deletedAddresseeL; 2866 ++deletedAddresseeL;
2869 } else { 2867 } else {
2870 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2868 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2871 ++addedAddresseeR; 2869 ++addedAddresseeR;
2872 inL.setRevision( modifiedCalendar ); 2870 inL.setRevision( modifiedCalendar );
2873 local->insertAddressee( inL, false ); 2871 local->insertAddressee( inL, false );
2874 inR = inL; 2872 inR = inL;
2875 inR.setResource( 0 ); 2873 inR.setResource( 0 );
2876 remote->insertAddressee( inR, false ); 2874 remote->insertAddressee( inR, false );
2877 } 2875 }
2878 } 2876 }
2879 } 2877 }
2880 } 2878 }
2881 } 2879 }
2882 ++incCounter; 2880 ++incCounter;
2883 } 2881 }
2884 el.clear(); 2882 el.clear();
2885 bar.hide(); 2883 bar.hide();
2886 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2884 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2887 // get rid of micro seconds 2885 // get rid of micro seconds
2888 QTime t = mLastAddressbookSync.time(); 2886 QTime t = mLastAddressbookSync.time();
2889 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2887 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2890 addresseeLSync.setRevision( mLastAddressbookSync ); 2888 addresseeLSync.setRevision( mLastAddressbookSync );
2891 addresseeRSync.setRevision( mLastAddressbookSync ); 2889 addresseeRSync.setRevision( mLastAddressbookSync );
2892 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2890 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2893 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2891 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2894 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2892 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2895 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2893 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2896 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2894 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2897 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2895 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2896 addresseeRSync.setNote( "" ) ;
2897 addresseeLSync.setNote( "" );
2898 2898
2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2900 remote->insertAddressee( addresseeRSync, false ); 2900 remote->insertAddressee( addresseeRSync, false );
2901 local->insertAddressee( addresseeLSync, false ); 2901 local->insertAddressee( addresseeLSync, false );
2902 QString mes; 2902 QString mes;
2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2904 if ( KABPrefs::instance()->mShowSyncSummary ) { 2904 if ( KABPrefs::instance()->mShowSyncSummary ) {
2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2906 } 2906 }
2907 qDebug( mes ); 2907 qDebug( mes );
2908 return syncOK; 2908 return syncOK;
2909} 2909}
2910 2910
2911bool KABCore::syncAB(QString filename, int mode) 2911bool KABCore::syncAB(QString filename, int mode)
2912{ 2912{
2913 2913
2914 //pending prepare addresseeview for output 2914 //pending prepare addresseeview for output
2915 //pending detect, if remote file has REV field. if not switch to external sync 2915 //pending detect, if remote file has REV field. if not switch to external sync
2916 mGlobalSyncMode = SYNC_MODE_NORMAL; 2916 mGlobalSyncMode = SYNC_MODE_NORMAL;
2917 AddressBook abLocal(filename,"syncContact"); 2917 AddressBook abLocal(filename,"syncContact");
2918 bool syncOK = false; 2918 bool syncOK = false;
2919 if ( abLocal.load() ) { 2919 if ( abLocal.load() ) {
2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2921 bool external = false; 2921 bool external = false;
2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2923 if ( ! lse.isEmpty() ) { 2923 if ( ! lse.isEmpty() ) {
2924 if ( lse.familyName().left(4) == "!E: " ) 2924 if ( lse.familyName().left(4) == "!E: " )
2925 external = true; 2925 external = true;
2926 } else { 2926 } else {
2927 bool found = false; 2927 bool found = false;
2928 QDateTime dt( QDate( 2004,1,1)); 2928 QDateTime dt( QDate( 2004,1,1));
2929 AddressBook::Iterator it; 2929 AddressBook::Iterator it;
2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2931 if ( (*it).revision() != dt ) { 2931 if ( (*it).revision() != dt ) {
2932 found = true; 2932 found = true;
2933 break; 2933 break;
2934 } 2934 }
2935 } 2935 }
2936 external = ! found; 2936 external = ! found;
2937 } 2937 }
2938 2938
2939 if ( external ) { 2939 if ( external ) {
2940 qDebug("**********Setting vcf mode to external ");
2940 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2941 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2941 AddressBook::Iterator it; 2942 AddressBook::Iterator it;
2942 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2943 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2943 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2944 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2944 (*it).computeCsum( mCurrentSyncDevice ); 2945 (*it).computeCsum( mCurrentSyncDevice );
2945 } 2946 }
2946 } 2947 }
2947 //AddressBook::Iterator it; 2948 //AddressBook::Iterator it;
2948 //QStringList vcards; 2949 //QStringList vcards;
2949 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2950 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2950 // qDebug("Name %s ", (*it).familyName().latin1()); 2951 // qDebug("Name %s ", (*it).familyName().latin1());
2951 //} 2952 //}
2952 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2953 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2953 if ( syncOK ) { 2954 if ( syncOK ) {
2954 if ( KABPrefs::instance()->mWriteBackFile ) 2955 if ( KABPrefs::instance()->mWriteBackFile )
2955 { 2956 {
2956 if ( external ) 2957 if ( external )
2957 abLocal.removeDeletedAddressees(); 2958 abLocal.removeDeletedAddressees();
2958 qDebug("saving remote AB "); 2959 qDebug("saving remote AB ");
2959 abLocal.saveAB(); 2960 abLocal.saveAB();
2960 } 2961 }
2961 } 2962 }
2962 setModified(); 2963 setModified();
2963 2964
2964 } 2965 }
2965 if ( syncOK ) 2966 if ( syncOK )
2966 mViewManager->refreshView(); 2967 mViewManager->refreshView();
2967 return syncOK; 2968 return syncOK;
2968#if 0 2969#if 0
2969 2970
2970 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2971 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2971 getEventViewerDialog()->setSyncMode( true ); 2972 getEventViewerDialog()->setSyncMode( true );
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 56b3fb0..0c75632 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -706,64 +706,66 @@ void CalendarView::confSync()
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
730 bool remCh, locCh; 730 bool remCh, locCh;
731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
732 //if ( remCh ) 732 //if ( remCh )
733 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 733 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
734 locCh = ( local->lastModified() > mLastCalendarSync ); 734 locCh = ( local->lastModified() > mLastCalendarSync );
735 if ( !remCh && ! locCh ) { 735 if ( !remCh && ! locCh ) {
736 //qDebug("both not changed "); 736 //qDebug("both not changed ");
737 lastSync = local->lastModified().addDays(1); 737 lastSync = local->lastModified().addDays(1);
738 if ( mode <= SYNC_PREF_ASK )
739 return 0;
738 } else { 740 } else {
739 if ( locCh ) { 741 if ( locCh ) {
740 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); 742 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
741 lastSync = local->lastModified().addDays( -1 ); 743 lastSync = local->lastModified().addDays( -1 );
742 if ( !remCh ) 744 if ( !remCh )
743 remote->setLastModified( lastSync.addDays( -1 ) ); 745 remote->setLastModified( lastSync.addDays( -1 ) );
744 } else { 746 } else {
745 //qDebug(" not loc changed "); 747 //qDebug(" not loc changed ");
746 lastSync = local->lastModified().addDays( 1 ); 748 lastSync = local->lastModified().addDays( 1 );
747 if ( remCh ) 749 if ( remCh )
748 remote->setLastModified( lastSync.addDays( 1 ) ); 750 remote->setLastModified( lastSync.addDays( 1 ) );
749 751
750 } 752 }
751 } 753 }
752 full = true; 754 full = true;
753 if ( mode < SYNC_PREF_ASK ) 755 if ( mode < SYNC_PREF_ASK )
754 mode = SYNC_PREF_ASK; 756 mode = SYNC_PREF_ASK;
755 } else { 757 } else {
756 if ( local->lastModified() == remote->lastModified() ) 758 if ( local->lastModified() == remote->lastModified() )
757 if ( local->revision() == remote->revision() ) 759 if ( local->revision() == remote->revision() )
758 return 0; 760 return 0;
759 761
760 } 762 }
761 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 763 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
762 764
763 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 765 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
764 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 766 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
765 //full = true; //debug only 767 //full = true; //debug only
766 if ( full ) { 768 if ( full ) {
767 bool equ = false; 769 bool equ = false;
768 if ( local->type() == "Event" ) { 770 if ( local->type() == "Event" ) {
769 equ = (*((Event*) local) == *((Event*) remote)); 771 equ = (*((Event*) local) == *((Event*) remote));