-rw-r--r-- | libkcal/phoneformat.cpp | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 281434e..101db57 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -309,26 +309,33 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | |||
309 | Event* ev = er.first(); | 309 | Event* ev = er.first(); |
310 | qDebug("reading events... "); | 310 | qDebug("reading events... "); |
311 | while ( ev ) { | 311 | while ( ev ) { |
312 | QStringList cat = ev->categories(); | 312 | QStringList cat = ev->categories(); |
313 | if ( cat.contains( "MeetingDEF" )) { | 313 | if ( cat.contains( "MeetingDEF" )) { |
314 | ev->setCategories( QStringList() ); | 314 | ev->setCategories( QStringList() ); |
315 | } else | ||
316 | if ( cat.contains( "Birthday" )) { | ||
317 | ev->setFloats( true ); | ||
318 | QDate da = ev->dtStart().date(); | ||
319 | ev->setDtStart( QDateTime( da) ); | ||
320 | ev->setDtEnd( QDateTime( da.addDays(1)) ); | ||
321 | |||
315 | } | 322 | } |
323 | uint cSum; | ||
324 | cSum = PhoneFormat::getCsumEvent( ev ); | ||
316 | int id = ev->pilotId(); | 325 | int id = ev->pilotId(); |
317 | Event *event; | 326 | Event *event; |
318 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 327 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
319 | if ( event ) { | 328 | if ( event ) { |
320 | event = (Event*)event->clone(); | 329 | event = (Event*)event->clone(); |
321 | copyEvent( event, ev ); | 330 | copyEvent( event, ev ); |
322 | calendar->deleteEvent( ev ); | 331 | calendar->deleteEvent( ev ); |
323 | calendar->addEvent( event); | 332 | calendar->addEvent( event); |
324 | } | 333 | } |
325 | else | 334 | else |
326 | event = ev; | 335 | event = ev; |
327 | uint cSum; | ||
328 | cSum = PhoneFormat::getCsumEvent( event ); | ||
329 | event->setCsum( mProfileName, QString::number( cSum )); | 336 | event->setCsum( mProfileName, QString::number( cSum )); |
330 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 337 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
331 | event->setID( mProfileName,QString::number( id ) ); | 338 | event->setID( mProfileName,QString::number( id ) ); |
332 | ev = er.next(); | 339 | ev = er.next(); |
333 | } | 340 | } |
334 | { | 341 | { |
@@ -339,26 +346,26 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | |||
339 | 346 | ||
340 | QStringList cat = ev->categories(); | 347 | QStringList cat = ev->categories(); |
341 | if ( cat.contains( "MeetingDEF" )) { | 348 | if ( cat.contains( "MeetingDEF" )) { |
342 | ev->setCategories( QStringList() ); | 349 | ev->setCategories( QStringList() ); |
343 | } | 350 | } |
344 | int id = ev->pilotId(); | 351 | int id = ev->pilotId(); |
352 | uint cSum; | ||
353 | cSum = PhoneFormat::getCsumTodo( ev ); | ||
345 | Todo *event; | 354 | Todo *event; |
346 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 355 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
347 | if ( event ) { | 356 | if ( event ) { |
348 | //qDebug("copy todo %s ", event->summary().latin1()); | 357 | //qDebug("copy todo %s ", event->summary().latin1()); |
349 | 358 | ||
350 | event = (Todo*)event->clone(); | 359 | event = (Todo*)event->clone(); |
351 | copyTodo( event, ev ); | 360 | copyTodo( event, ev ); |
352 | calendar->deleteTodo( ev ); | 361 | calendar->deleteTodo( ev ); |
353 | calendar->addTodo( event); | 362 | calendar->addTodo( event); |
354 | } | 363 | } |
355 | else | 364 | else |
356 | event = ev; | 365 | event = ev; |
357 | uint cSum; | ||
358 | cSum = PhoneFormat::getCsumTodo( event ); | ||
359 | event->setCsum( mProfileName, QString::number( cSum )); | 366 | event->setCsum( mProfileName, QString::number( cSum )); |
360 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 367 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
361 | event->setID( mProfileName,QString::number( id ) ); | 368 | event->setID( mProfileName,QString::number( id ) ); |
362 | ev = tr.next(); | 369 | ev = tr.next(); |
363 | } | 370 | } |
364 | } | 371 | } |
@@ -379,17 +386,13 @@ void PhoneFormat::copyEvent( Event* to, Event* from ) | |||
379 | 386 | ||
380 | if ( from->alarms().count() ) { | 387 | if ( from->alarms().count() ) { |
381 | to->clearAlarms(); | 388 | to->clearAlarms(); |
382 | Alarm *a = from->alarms().first(); | 389 | Alarm *a = from->alarms().first(); |
383 | Alarm *b = to->newAlarm( ); | 390 | Alarm *b = to->newAlarm( ); |
384 | b->setEnabled( a->enabled() ); | 391 | b->setEnabled( a->enabled() ); |
385 | if ( a->hasStartOffset() ) { | 392 | b->setStartOffset(Duration( a->offset() ) ); |
386 | b->setStartOffset( a->startOffset() ); | ||
387 | } | ||
388 | if ( a->hasTime() ) | ||
389 | b->setTime( a->time() ); | ||
390 | 393 | ||
391 | } | 394 | } |
392 | QStringList cat = to->categories(); | 395 | QStringList cat = to->categories(); |
393 | QStringList catFrom = from->categories(); | 396 | QStringList catFrom = from->categories(); |
394 | QString nCat; | 397 | QString nCat; |
395 | int iii; | 398 | int iii; |
@@ -398,39 +401,42 @@ void PhoneFormat::copyEvent( Event* to, Event* from ) | |||
398 | if ( !nCat.isEmpty() ) | 401 | if ( !nCat.isEmpty() ) |
399 | if ( !cat.contains( nCat )) { | 402 | if ( !cat.contains( nCat )) { |
400 | cat << nCat; | 403 | cat << nCat; |
401 | } | 404 | } |
402 | } | 405 | } |
403 | to->setCategories( cat ); | 406 | to->setCategories( cat ); |
404 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 407 | if ( from->doesRecur() ) { |
405 | to->setRecurrence( r ) ; | 408 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
409 | to->setRecurrence( r ) ; | ||
410 | } | ||
406 | 411 | ||
407 | 412 | ||
408 | } | 413 | } |
409 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 414 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
410 | { | 415 | { |
411 | if ( from->dtStart().isValid() ) | 416 | if ( from->hasStartDate() ) { |
417 | to->setHasStartDate( true ); | ||
412 | to->setDtStart( from->dtStart() ); | 418 | to->setDtStart( from->dtStart() ); |
413 | if ( from->dtDue().isValid() ) | 419 | } |
420 | if ( from->hasDueDate() ){ | ||
421 | to->setHasDueDate( true ); | ||
414 | to->setDtDue( from->dtDue() ); | 422 | to->setDtDue( from->dtDue() ); |
423 | } | ||
415 | if ( !from->location().isEmpty() ) | 424 | if ( !from->location().isEmpty() ) |
416 | to->setLocation( from->location() ); | 425 | to->setLocation( from->location() ); |
417 | if ( !from->description().isEmpty() ) | 426 | if ( !from->description().isEmpty() ) |
418 | to->setDescription( from->description() ); | 427 | to->setDescription( from->description() ); |
419 | if ( !from->summary().isEmpty() ) | 428 | if ( !from->summary().isEmpty() ) |
420 | to->setSummary( from->summary() ); | 429 | to->setSummary( from->summary() ); |
421 | 430 | ||
422 | if ( from->alarms().count() ) { | 431 | if ( from->alarms().count() ) { |
423 | to->clearAlarms(); | 432 | to->clearAlarms(); |
424 | Alarm *a = from->alarms().first(); | 433 | Alarm *a = from->alarms().first(); |
425 | Alarm *b = to->newAlarm( ); | 434 | Alarm *b = to->newAlarm( ); |
426 | b->setEnabled( a->enabled() ); | 435 | b->setEnabled( a->enabled() ); |
427 | if ( a->hasStartOffset() ) | 436 | b->setStartOffset(Duration( a->offset() ) ); |
428 | b->setStartOffset( a->startOffset() ); | ||
429 | if ( a->hasTime() ) | ||
430 | b->setTime( a->time() ); | ||
431 | } | 437 | } |
432 | 438 | ||
433 | QStringList cat = to->categories(); | 439 | QStringList cat = to->categories(); |
434 | QStringList catFrom = from->categories(); | 440 | QStringList catFrom = from->categories(); |
435 | QString nCat; | 441 | QString nCat; |
436 | int iii; | 442 | int iii; |
@@ -458,32 +464,26 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from ) | |||
458 | else | 464 | else |
459 | to->setPriority(from->priority()); | 465 | to->setPriority(from->priority()); |
460 | 466 | ||
461 | } | 467 | } |
462 | #include <qcstring.h> | 468 | #include <qcstring.h> |
463 | 469 | ||
464 | void PhoneFormat::afterSave( Incidence* inc) | 470 | void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) |
465 | { | 471 | { |
466 | uint csum; | 472 | inc->setID( mProfileName, id ); |
467 | inc->removeID( mProfileName ); | 473 | inc->setCsum( mProfileName, csum); |
468 | if ( inc->type() == "Event") | ||
469 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | ||
470 | else | ||
471 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | ||
472 | inc->setCsum( mProfileName, QString::number( csum )); | ||
473 | |||
474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
475 | 475 | ||
476 | } | 476 | } |
477 | 477 | ||
478 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 478 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
479 | { | 479 | { |
480 | #ifdef _WIN32_ | 480 | #ifdef _WIN32_ |
481 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | 481 | QString fileName = locateLocal("tmp", "phonefile.vcs"); |
482 | #else | 482 | #else |
483 | QString fileName = "/tmp/kdepimtemp.vcs"; | 483 | QString fileName = "/tmp/phonefile.vcs"; |
484 | #endif | 484 | #endif |
485 | 485 | ||
486 | VCalFormat vfsave; | 486 | VCalFormat vfsave; |
487 | vfsave.setLocalTime ( true ); | 487 | vfsave.setLocalTime ( true ); |
488 | QString id = calendar->timeZoneId(); | 488 | QString id = calendar->timeZoneId(); |
489 | calendar->setLocalTime(); | 489 | calendar->setLocalTime(); |
@@ -491,24 +491,13 @@ bool PhoneFormat::writeToPhone( Calendar * calendar) | |||
491 | return false; | 491 | return false; |
492 | calendar->setTimeZoneId( id ); | 492 | calendar->setTimeZoneId( id ); |
493 | return PhoneAccess::writeToPhone( fileName ); | 493 | return PhoneAccess::writeToPhone( fileName ); |
494 | } | 494 | } |
495 | bool PhoneFormat::save( Calendar *calendar) | 495 | bool PhoneFormat::save( Calendar *calendar) |
496 | { | 496 | { |
497 | QLabel status ( i18n(" Opening device ..."), 0 ); | 497 | |
498 | int w = status.sizeHint().width()+20 ; | ||
499 | if ( w < 200 ) w = 230; | ||
500 | int h = status.sizeHint().height()+20 ; | ||
501 | int dw = QApplication::desktop()->width(); | ||
502 | int dh = QApplication::desktop()->height(); | ||
503 | status.setCaption(i18n("Writing to phone...") ); | ||
504 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
505 | status.show(); | ||
506 | status.raise(); | ||
507 | qApp->processEvents(); | ||
508 | QString message; | ||
509 | 498 | ||
510 | // 1 remove events which should be deleted | 499 | // 1 remove events which should be deleted |
511 | QPtrList<Event> er = calendar->rawEvents(); | 500 | QPtrList<Event> er = calendar->rawEvents(); |
512 | Event* ev = er.first(); | 501 | Event* ev = er.first(); |
513 | while ( ev ) { | 502 | while ( ev ) { |
514 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 503 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
@@ -531,13 +520,24 @@ bool PhoneFormat::save( Calendar *calendar) | |||
531 | } | 520 | } |
532 | to = tl.next(); | 521 | to = tl.next(); |
533 | } | 522 | } |
534 | // 3 save file | 523 | // 3 save file |
535 | if ( !writeToPhone( calendar ) ) | 524 | if ( !writeToPhone( calendar ) ) |
536 | return false; | 525 | return false; |
537 | 526 | QLabel status ( i18n(" Opening device ..."), 0 ); | |
527 | int w = status.sizeHint().width()+20 ; | ||
528 | if ( w < 200 ) w = 230; | ||
529 | int h = status.sizeHint().height()+20 ; | ||
530 | int dw = QApplication::desktop()->width(); | ||
531 | int dh = QApplication::desktop()->height(); | ||
532 | status.setCaption(i18n("Writing to phone...") ); | ||
533 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
534 | QString message; | ||
535 | status.show(); | ||
536 | status.raise(); | ||
537 | qApp->processEvents(); | ||
538 | // 5 reread data | 538 | // 5 reread data |
539 | message = i18n(" Rereading all data ... "); | 539 | message = i18n(" Rereading all data ... "); |
540 | status.setText ( message ); | 540 | status.setText ( message ); |
541 | qApp->processEvents(); | 541 | qApp->processEvents(); |
542 | CalendarLocal* calendarTemp = new CalendarLocal(); | 542 | CalendarLocal* calendarTemp = new CalendarLocal(); |
543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
@@ -556,25 +556,17 @@ bool PhoneFormat::save( Calendar *calendar) | |||
556 | Event* ev1; | 556 | Event* ev1; |
557 | int procCount = 0; | 557 | int procCount = 0; |
558 | while ( ev ) { | 558 | while ( ev ) { |
559 | //qDebug("event new ID %s",ev->summary().latin1()); | 559 | //qDebug("event new ID %s",ev->summary().latin1()); |
560 | status.setText ( message + QString::number ( ++procCount ) ); | 560 | status.setText ( message + QString::number ( ++procCount ) ); |
561 | qApp->processEvents(); | 561 | qApp->processEvents(); |
562 | uint csum; | ||
563 | csum = PhoneFormat::getCsumEvent( ev ); | ||
564 | QString cSum = QString::number( csum ); | ||
565 | //ev->setCsum( mProfileName, cSum ); | ||
566 | //qDebug("Event cSum %s ", cSum.latin1()); | ||
567 | ev1 = er1.first(); | 562 | ev1 = er1.first(); |
568 | while ( ev1 ) { | 563 | while ( ev1 ) { |
569 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 564 | if ( ev->contains( ev1 ) ) { |
565 | afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); | ||
570 | er1.remove( ev1 ); | 566 | er1.remove( ev1 ); |
571 | afterSave( ev ); | ||
572 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | ||
573 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | ||
574 | |||
575 | break; | 567 | break; |
576 | } | 568 | } |
577 | ev1 = er1.next(); | 569 | ev1 = er1.next(); |
578 | } | 570 | } |
579 | if ( ! ev1 ) { | 571 | if ( ! ev1 ) { |
580 | // ev->removeID(mProfileName); | 572 | // ev->removeID(mProfileName); |
@@ -591,23 +583,17 @@ bool PhoneFormat::save( Calendar *calendar) | |||
591 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 583 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
592 | Todo* to1 ; | 584 | Todo* to1 ; |
593 | message = i18n(" Comparing todo # "); | 585 | message = i18n(" Comparing todo # "); |
594 | while ( to ) { | 586 | while ( to ) { |
595 | status.setText ( message + QString::number ( ++procCount ) ); | 587 | status.setText ( message + QString::number ( ++procCount ) ); |
596 | qApp->processEvents(); | 588 | qApp->processEvents(); |
597 | uint csum; | ||
598 | csum = PhoneFormat::getCsumTodo( to ); | ||
599 | QString cSum = QString::number( csum ); | ||
600 | //to->setCsum( mProfileName, cSum ); | ||
601 | //qDebug("Todo cSum %s ", cSum.latin1()); | ||
602 | Todo* to1 = tl1.first(); | 589 | Todo* to1 = tl1.first(); |
603 | while ( to1 ) { | 590 | while ( to1 ) { |
604 | if ( to1->getCsum( mProfileName ) == cSum ) { | 591 | if ( to->contains( to1 ) ) { |
592 | afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); | ||
605 | tl1.remove( to1 ); | 593 | tl1.remove( to1 ); |
606 | afterSave( to ); | ||
607 | to->setID(mProfileName, to1->getID(mProfileName) ); | ||
608 | break; | 594 | break; |
609 | } | 595 | } |
610 | to1 = tl1.next(); | 596 | to1 = tl1.next(); |
611 | } | 597 | } |
612 | if ( ! to1 ) { | 598 | if ( ! to1 ) { |
613 | //to->removeID(mProfileName); | 599 | //to->removeID(mProfileName); |