-rw-r--r-- | libkcal/phoneformat.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 99d6a06..c67dc6a 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -323,129 +323,133 @@ ulong PhoneFormat::getCsumEvent( Event* event ) | |||
323 | list.append( "0" ); | 323 | list.append( "0" ); |
324 | list.append( QString() ); | 324 | list.append( QString() ); |
325 | list.append( "0" ); | 325 | list.append( "0" ); |
326 | list.append( "20991231T000000" ); | 326 | list.append( "20991231T000000" ); |
327 | break; | 327 | break; |
328 | } | 328 | } |
329 | if ( writeEndDate ) { | 329 | if ( writeEndDate ) { |
330 | 330 | ||
331 | if ( rec->endDate().isValid() ) { // 15 + 16 | 331 | if ( rec->endDate().isValid() ) { // 15 + 16 |
332 | list.append( "1" ); | 332 | list.append( "1" ); |
333 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 333 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
334 | } else { | 334 | } else { |
335 | list.append( "0" ); | 335 | list.append( "0" ); |
336 | list.append( "20991231T000000" ); | 336 | list.append( "20991231T000000" ); |
337 | } | 337 | } |
338 | 338 | ||
339 | } | 339 | } |
340 | attList << list.join(""); | 340 | attList << list.join(""); |
341 | attList << event->categoriesStr(); | 341 | attList << event->categoriesStr(); |
342 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 342 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
343 | 343 | ||
344 | attList << event->secrecyStr(); | 344 | attList << event->secrecyStr(); |
345 | return PhoneFormat::getCsum(attList ); | 345 | return PhoneFormat::getCsum(attList ); |
346 | } | 346 | } |
347 | ulong PhoneFormat::getCsum( const QStringList & attList) | 347 | ulong PhoneFormat::getCsum( const QStringList & attList) |
348 | { | 348 | { |
349 | int max = attList.count(); | 349 | int max = attList.count(); |
350 | ulong cSum = 0; | 350 | ulong cSum = 0; |
351 | int j,k,i; | 351 | int j,k,i; |
352 | int add; | 352 | int add; |
353 | for ( i = 0; i < max ; ++i ) { | 353 | for ( i = 0; i < max ; ++i ) { |
354 | QString s = attList[i]; | 354 | QString s = attList[i]; |
355 | if ( ! s.isEmpty() ){ | 355 | if ( ! s.isEmpty() ){ |
356 | j = s.length(); | 356 | j = s.length(); |
357 | for ( k = 0; k < j; ++k ) { | 357 | for ( k = 0; k < j; ++k ) { |
358 | int mul = k +1; | 358 | int mul = k +1; |
359 | add = s[k].unicode (); | 359 | add = s[k].unicode (); |
360 | if ( k < 16 ) | 360 | if ( k < 16 ) |
361 | mul = mul * mul; | 361 | mul = mul * mul; |
362 | int ii = i+1; | 362 | int ii = i+1; |
363 | add = add * mul *ii*ii*ii; | 363 | add = add * mul *ii*ii*ii; |
364 | cSum += add; | 364 | cSum += add; |
365 | } | 365 | } |
366 | } | 366 | } |
367 | 367 | ||
368 | } | 368 | } |
369 | //QString dump = attList.join(","); | 369 | //QString dump = attList.join(","); |
370 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 370 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
371 | 371 | ||
372 | return cSum; | 372 | return cSum; |
373 | 373 | ||
374 | } | 374 | } |
375 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 375 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
376 | #include <stdlib.h> | 376 | #include <stdlib.h> |
377 | #define DEBUGMODE false | 377 | #define DEBUGMODE false |
378 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 378 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
379 | { | 379 | { |
380 | 380 | ||
381 | QString fileName; | 381 | QString fileName; |
382 | #ifdef _WIN32_ | 382 | #ifdef _WIN32_ |
383 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 383 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
384 | #else | 384 | #else |
385 | fileName = "/tmp/kdepimtemp.vcs"; | 385 | fileName = "/tmp/kdepimtemp.vcs"; |
386 | #endif | 386 | #endif |
387 | #ifdef DESKTOP_VERSION | ||
387 | QString command ="./kammu --backup " + fileName + " -yes" ; | 388 | QString command ="./kammu --backup " + fileName + " -yes" ; |
389 | #else | ||
390 | QString command ="kammu --backup " + fileName + " -yes" ; | ||
391 | #endif | ||
388 | int ret = system ( command.latin1() ); | 392 | int ret = system ( command.latin1() ); |
389 | if ( ret != 0 ) { | 393 | if ( ret != 0 ) { |
390 | qDebug("Error::command returned %d", ret); | 394 | qDebug("Error::command returned %d", ret); |
391 | return false; | 395 | return false; |
392 | } | 396 | } |
393 | VCalFormat vfload; | 397 | VCalFormat vfload; |
394 | vfload.setLocalTime ( true ); | 398 | vfload.setLocalTime ( true ); |
395 | qDebug("loading file ..."); | 399 | qDebug("loading file ..."); |
396 | 400 | ||
397 | if ( ! vfload.load( calendar, fileName ) ) | 401 | if ( ! vfload.load( calendar, fileName ) ) |
398 | return false; | 402 | return false; |
399 | QPtrList<Event> er = calendar->rawEvents(); | 403 | QPtrList<Event> er = calendar->rawEvents(); |
400 | Event* ev = er.first(); | 404 | Event* ev = er.first(); |
401 | qDebug("reading events... "); | 405 | qDebug("reading events... "); |
402 | while ( ev ) { | 406 | while ( ev ) { |
403 | QStringList cat = ev->categories(); | 407 | QStringList cat = ev->categories(); |
404 | if ( cat.contains( "MeetingDEF" )) { | 408 | if ( cat.contains( "MeetingDEF" )) { |
405 | ev->setCategories( QStringList() ); | 409 | ev->setCategories( QStringList() ); |
406 | } | 410 | } |
407 | int id = ev->pilotId(); | 411 | int id = ev->pilotId(); |
408 | Event *event; | 412 | Event *event; |
409 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 413 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
410 | if ( event ) { | 414 | if ( event ) { |
411 | event = (Event*)event->clone(); | 415 | event = (Event*)event->clone(); |
412 | copyEvent( event, ev ); | 416 | copyEvent( event, ev ); |
413 | calendar->deleteEvent( ev ); | 417 | calendar->deleteEvent( ev ); |
414 | calendar->addEvent( event); | 418 | calendar->addEvent( event); |
415 | } | 419 | } |
416 | else | 420 | else |
417 | event = ev; | 421 | event = ev; |
418 | uint cSum; | 422 | uint cSum; |
419 | cSum = PhoneFormat::getCsumEvent( event ); | 423 | cSum = PhoneFormat::getCsumEvent( event ); |
420 | event->setCsum( mProfileName, QString::number( cSum )); | 424 | event->setCsum( mProfileName, QString::number( cSum )); |
421 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 425 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
422 | event->setID( mProfileName,QString::number( id ) ); | 426 | event->setID( mProfileName,QString::number( id ) ); |
423 | ev = er.next(); | 427 | ev = er.next(); |
424 | } | 428 | } |
425 | { | 429 | { |
426 | qDebug("reading todos... "); | 430 | qDebug("reading todos... "); |
427 | QPtrList<Todo> tr = calendar->rawTodos(); | 431 | QPtrList<Todo> tr = calendar->rawTodos(); |
428 | Todo* ev = tr.first(); | 432 | Todo* ev = tr.first(); |
429 | while ( ev ) { | 433 | while ( ev ) { |
430 | 434 | ||
431 | QStringList cat = ev->categories(); | 435 | QStringList cat = ev->categories(); |
432 | if ( cat.contains( "MeetingDEF" )) { | 436 | if ( cat.contains( "MeetingDEF" )) { |
433 | ev->setCategories( QStringList() ); | 437 | ev->setCategories( QStringList() ); |
434 | } | 438 | } |
435 | int id = ev->pilotId(); | 439 | int id = ev->pilotId(); |
436 | Todo *event; | 440 | Todo *event; |
437 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 441 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
438 | if ( event ) { | 442 | if ( event ) { |
439 | //qDebug("copy todo %s ", event->summary().latin1()); | 443 | //qDebug("copy todo %s ", event->summary().latin1()); |
440 | 444 | ||
441 | event = (Todo*)event->clone(); | 445 | event = (Todo*)event->clone(); |
442 | copyTodo( event, ev ); | 446 | copyTodo( event, ev ); |
443 | calendar->deleteTodo( ev ); | 447 | calendar->deleteTodo( ev ); |
444 | calendar->addTodo( event); | 448 | calendar->addTodo( event); |
445 | } | 449 | } |
446 | else | 450 | else |
447 | event = ev; | 451 | event = ev; |
448 | uint cSum; | 452 | uint cSum; |
449 | cSum = PhoneFormat::getCsumTodo( event ); | 453 | cSum = PhoneFormat::getCsumTodo( event ); |
450 | event->setCsum( mProfileName, QString::number( cSum )); | 454 | event->setCsum( mProfileName, QString::number( cSum )); |
451 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 455 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
@@ -554,129 +558,133 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from ) | |||
554 | 558 | ||
555 | void PhoneFormat::afterSave( Incidence* inc) | 559 | void PhoneFormat::afterSave( Incidence* inc) |
556 | { | 560 | { |
557 | uint csum; | 561 | uint csum; |
558 | inc->removeID( mProfileName ); | 562 | inc->removeID( mProfileName ); |
559 | if ( inc->type() == "Event") | 563 | if ( inc->type() == "Event") |
560 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 564 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
561 | else | 565 | else |
562 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 566 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
563 | inc->setCsum( mProfileName, QString::number( csum )); | 567 | inc->setCsum( mProfileName, QString::number( csum )); |
564 | 568 | ||
565 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 569 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
566 | 570 | ||
567 | } | 571 | } |
568 | bool PhoneFormat::save( Calendar *calendar) | 572 | bool PhoneFormat::save( Calendar *calendar) |
569 | { | 573 | { |
570 | QLabel status ( i18n(" Opening device ..."), 0 ); | 574 | QLabel status ( i18n(" Opening device ..."), 0 ); |
571 | int w = status.sizeHint().width()+20 ; | 575 | int w = status.sizeHint().width()+20 ; |
572 | if ( w < 200 ) w = 230; | 576 | if ( w < 200 ) w = 230; |
573 | int h = status.sizeHint().height()+20 ; | 577 | int h = status.sizeHint().height()+20 ; |
574 | int dw = QApplication::desktop()->width(); | 578 | int dw = QApplication::desktop()->width(); |
575 | int dh = QApplication::desktop()->height(); | 579 | int dh = QApplication::desktop()->height(); |
576 | status.setCaption(i18n("Writing to phone...") ); | 580 | status.setCaption(i18n("Writing to phone...") ); |
577 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 581 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
578 | status.show(); | 582 | status.show(); |
579 | status.raise(); | 583 | status.raise(); |
580 | qApp->processEvents(); | 584 | qApp->processEvents(); |
581 | QString message; | 585 | QString message; |
582 | #ifdef _WIN32_ | 586 | #ifdef _WIN32_ |
583 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 587 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
584 | #else | 588 | #else |
585 | QString fileName = "/tmp/kdepimtemp.vcs"; | 589 | QString fileName = "/tmp/kdepimtemp.vcs"; |
586 | #endif | 590 | #endif |
587 | 591 | ||
588 | // 1 remove events which should be deleted | 592 | // 1 remove events which should be deleted |
589 | QPtrList<Event> er = calendar->rawEvents(); | 593 | QPtrList<Event> er = calendar->rawEvents(); |
590 | Event* ev = er.first(); | 594 | Event* ev = er.first(); |
591 | while ( ev ) { | 595 | while ( ev ) { |
592 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 596 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
593 | calendar->deleteEvent( ev ); | 597 | calendar->deleteEvent( ev ); |
594 | } else { | 598 | } else { |
595 | 599 | ||
596 | } | 600 | } |
597 | ev = er.next(); | 601 | ev = er.next(); |
598 | } | 602 | } |
599 | // 2 remove todos which should be deleted | 603 | // 2 remove todos which should be deleted |
600 | QPtrList<Todo> tl = calendar->rawTodos(); | 604 | QPtrList<Todo> tl = calendar->rawTodos(); |
601 | Todo* to = tl.first(); | 605 | Todo* to = tl.first(); |
602 | while ( to ) { | 606 | while ( to ) { |
603 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 607 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
604 | calendar->deleteTodo( to ); | 608 | calendar->deleteTodo( to ); |
605 | } else { | 609 | } else { |
606 | if ( to->isCompleted()) { | 610 | if ( to->isCompleted()) { |
607 | calendar->deleteTodo( to ); | 611 | calendar->deleteTodo( to ); |
608 | } | 612 | } |
609 | } | 613 | } |
610 | to = tl.next(); | 614 | to = tl.next(); |
611 | } | 615 | } |
612 | // 3 save file | 616 | // 3 save file |
613 | VCalFormat vfsave; | 617 | VCalFormat vfsave; |
614 | vfsave.setLocalTime ( true ); | 618 | vfsave.setLocalTime ( true ); |
615 | if ( ! vfsave.save( calendar, fileName ) ) | 619 | if ( ! vfsave.save( calendar, fileName ) ) |
616 | return false; | 620 | return false; |
617 | // 4 call kammu | 621 | // 4 call kammu |
622 | #ifdef DESKTOP_VERSION | ||
618 | QString command ="./kammu --restore " + fileName ; | 623 | QString command ="./kammu --restore " + fileName ; |
624 | #else | ||
625 | QString command ="kammu --restore " + fileName ; | ||
626 | #endif | ||
619 | int ret; | 627 | int ret; |
620 | while ( (ret = system ( command.latin1())) != 0 ) { | 628 | while ( (ret = system ( command.latin1())) != 0 ) { |
621 | qDebug("Error S::command returned %d. asking users", ret); | 629 | qDebug("Error S::command returned %d. asking users", ret); |
622 | int retval = KMessageBox::warningContinueCancel(0, | 630 | int retval = KMessageBox::warningContinueCancel(0, |
623 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); | 631 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); |
624 | if ( retval != KMessageBox::Continue ) | 632 | if ( retval != KMessageBox::Continue ) |
625 | return false; | 633 | return false; |
626 | } | 634 | } |
627 | 635 | ||
628 | // 5 reread data | 636 | // 5 reread data |
629 | message = i18n(" Rereading all data ... "); | 637 | message = i18n(" Rereading all data ... "); |
630 | status.setText ( message ); | 638 | status.setText ( message ); |
631 | qApp->processEvents(); | 639 | qApp->processEvents(); |
632 | CalendarLocal* calendarTemp = new CalendarLocal(); | 640 | CalendarLocal* calendarTemp = new CalendarLocal(); |
633 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 641 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
634 | if ( ! load( calendarTemp,calendar) ){ | 642 | if ( ! load( calendarTemp,calendar) ){ |
635 | qDebug("error reloading calendar "); | 643 | qDebug("error reloading calendar "); |
636 | delete calendarTemp; | 644 | delete calendarTemp; |
637 | return false; | 645 | return false; |
638 | } | 646 | } |
639 | // 6 compare data | 647 | // 6 compare data |
640 | 648 | ||
641 | //algo 6 compare event | 649 | //algo 6 compare event |
642 | er = calendar->rawEvents(); | 650 | er = calendar->rawEvents(); |
643 | ev = er.first(); | 651 | ev = er.first(); |
644 | message = i18n(" Comparing event # "); | 652 | message = i18n(" Comparing event # "); |
645 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 653 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
646 | Event* ev1; | 654 | Event* ev1; |
647 | int procCount = 0; | 655 | int procCount = 0; |
648 | while ( ev ) { | 656 | while ( ev ) { |
649 | //qDebug("event new ID %s",ev->summary().latin1()); | 657 | //qDebug("event new ID %s",ev->summary().latin1()); |
650 | status.setText ( message + QString::number ( ++procCount ) ); | 658 | status.setText ( message + QString::number ( ++procCount ) ); |
651 | qApp->processEvents(); | 659 | qApp->processEvents(); |
652 | uint csum; | 660 | uint csum; |
653 | csum = PhoneFormat::getCsumEvent( ev ); | 661 | csum = PhoneFormat::getCsumEvent( ev ); |
654 | QString cSum = QString::number( csum ); | 662 | QString cSum = QString::number( csum ); |
655 | //ev->setCsum( mProfileName, cSum ); | 663 | //ev->setCsum( mProfileName, cSum ); |
656 | //qDebug("Event cSum %s ", cSum.latin1()); | 664 | //qDebug("Event cSum %s ", cSum.latin1()); |
657 | ev1 = er1.first(); | 665 | ev1 = er1.first(); |
658 | while ( ev1 ) { | 666 | while ( ev1 ) { |
659 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 667 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
660 | er1.remove( ev1 ); | 668 | er1.remove( ev1 ); |
661 | afterSave( ev ); | 669 | afterSave( ev ); |
662 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 670 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
663 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | 671 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); |
664 | 672 | ||
665 | break; | 673 | break; |
666 | } | 674 | } |
667 | ev1 = er1.next(); | 675 | ev1 = er1.next(); |
668 | } | 676 | } |
669 | if ( ! ev1 ) { | 677 | if ( ! ev1 ) { |
670 | // ev->removeID(mProfileName); | 678 | // ev->removeID(mProfileName); |
671 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 679 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
672 | } | 680 | } |
673 | 681 | ||
674 | 682 | ||
675 | ev = er.next(); | 683 | ev = er.next(); |
676 | } | 684 | } |
677 | //algo 6 compare todo | 685 | //algo 6 compare todo |
678 | tl = calendar->rawTodos(); | 686 | tl = calendar->rawTodos(); |
679 | to = tl.first(); | 687 | to = tl.first(); |
680 | procCount = 0; | 688 | procCount = 0; |
681 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 689 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
682 | Todo* to1 ; | 690 | Todo* to1 ; |