author | zautrix <zautrix> | 2004-10-28 13:13:08 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-28 13:13:08 (UTC) |
commit | 12068392f1d131c3f599b8854fe131dd9291a5ea (patch) (unidiff) | |
tree | bd49e43036eefde4aa2bdaa9b167b6b8d0e216b0 | |
parent | 849ad402a00e2fe7bfd37c4c452b205767dab3d2 (diff) | |
download | kdepimpi-12068392f1d131c3f599b8854fe131dd9291a5ea.zip kdepimpi-12068392f1d131c3f599b8854fe131dd9291a5ea.tar.gz kdepimpi-12068392f1d131c3f599b8854fe131dd9291a5ea.tar.bz2 |
fixed todo DTM sync
-rw-r--r-- | libkcal/sharpformat.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index d56eab6..b88e729 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -445,390 +445,401 @@ int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | |||
445 | int len = answer.length(); | 445 | int len = answer.length(); |
446 | int end = answer.find ("\n",start)+1; | 446 | int end = answer.find ("\n",start)+1; |
447 | bool ok = true; | 447 | bool ok = true; |
448 | start = end; | 448 | start = end; |
449 | int ccc = 0; | 449 | int ccc = 0; |
450 | while ( start > 0 ) { | 450 | while ( start > 0 ) { |
451 | templist.clear(); | 451 | templist.clear(); |
452 | ok = true; | 452 | ok = true; |
453 | int loopCount = 0; | 453 | int loopCount = 0; |
454 | while ( ok ) { | 454 | while ( ok ) { |
455 | ++loopCount; | 455 | ++loopCount; |
456 | if ( loopCount > 25 ) { | 456 | if ( loopCount > 25 ) { |
457 | qDebug("KO: Error in while loop"); | 457 | qDebug("KO: Error in while loop"); |
458 | ok = false; | 458 | ok = false; |
459 | start = 0; | 459 | start = 0; |
460 | break; | 460 | break; |
461 | } | 461 | } |
462 | if ( ok ) | 462 | if ( ok ) |
463 | tempString = getPart( answer, ok, start ); | 463 | tempString = getPart( answer, ok, start ); |
464 | if ( start >= len || start == 0 ) { | 464 | if ( start >= len || start == 0 ) { |
465 | start = 0; | 465 | start = 0; |
466 | ok = false; | 466 | ok = false; |
467 | } | 467 | } |
468 | if ( tempString.right(1) =="\n" ) | 468 | if ( tempString.right(1) =="\n" ) |
469 | tempString = tempString.left( tempString.length()-1); | 469 | tempString = tempString.left( tempString.length()-1); |
470 | 470 | ||
471 | templist.append( tempString ); | 471 | templist.append( tempString ); |
472 | } | 472 | } |
473 | ++ccc; | 473 | ++ccc; |
474 | if ( ccc == 2 && loopCount < 25 ) { | 474 | if ( ccc == 2 && loopCount < 25 ) { |
475 | start = 0; | 475 | start = 0; |
476 | bool ok; | 476 | bool ok; |
477 | int newnum = templist[0].toInt( &ok ); | 477 | int newnum = templist[0].toInt( &ok ); |
478 | if ( ok && newnum > 0) { | 478 | if ( ok && newnum > 0) { |
479 | retval = newnum; | 479 | retval = newnum; |
480 | inc->setID( "Sharp_DTM",templist[0] ); | 480 | inc->setID( "Sharp_DTM",templist[0] ); |
481 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); | 481 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); |
482 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 482 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
483 | } | 483 | } |
484 | if ( ok && newnum == -1 ) { | 484 | if ( ok && newnum == -1 ) { |
485 | qDebug("Error writing back %s ", inc->summary().latin1()); | 485 | qDebug("Error writing back %s ", inc->summary().latin1()); |
486 | } | 486 | } |
487 | } | 487 | } |
488 | } | 488 | } |
489 | //qDebug("getNumFromRecord returning : %d ", retval); | 489 | //qDebug("getNumFromRecord returning : %d ", retval); |
490 | return retval; | 490 | return retval; |
491 | } | 491 | } |
492 | bool SharpFormat::save( Calendar *calendar) | 492 | bool SharpFormat::save( Calendar *calendar) |
493 | { | 493 | { |
494 | 494 | ||
495 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 495 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
496 | int w = status.sizeHint().width()+20 ; | 496 | int w = status.sizeHint().width()+20 ; |
497 | if ( w < 200 ) w = 200; | 497 | if ( w < 200 ) w = 200; |
498 | int h = status.sizeHint().height()+20 ; | 498 | int h = status.sizeHint().height()+20 ; |
499 | int dw = QApplication::desktop()->width(); | 499 | int dw = QApplication::desktop()->width(); |
500 | int dh = QApplication::desktop()->height(); | 500 | int dh = QApplication::desktop()->height(); |
501 | status.setCaption(i18n("Writing DTM Data") ); | 501 | status.setCaption(i18n("Writing DTM Data") ); |
502 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 502 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
503 | status.show(); | 503 | status.show(); |
504 | status.raise(); | 504 | status.raise(); |
505 | qApp->processEvents(); | 505 | qApp->processEvents(); |
506 | bool debug = DEBUGMODE; | 506 | bool debug = DEBUGMODE; |
507 | QString codec = "utf8"; | 507 | QString codec = "utf8"; |
508 | QString answer; | 508 | QString answer; |
509 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; | 509 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; |
510 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; | 510 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; |
511 | QString command; | 511 | QString command; |
512 | QPtrList<Event> er = calendar->rawEvents(); | 512 | QPtrList<Event> er = calendar->rawEvents(); |
513 | Event* ev = er.first(); | 513 | Event* ev = er.first(); |
514 | QString fileName = "/tmp/kopitempout"; | 514 | QString fileName = "/tmp/kopitempout"; |
515 | int i = 0; | 515 | int i = 0; |
516 | QString changeString = ePrefix; | 516 | QString changeString = ePrefix; |
517 | QString deleteString = ePrefix; | 517 | QString deleteString = ePrefix; |
518 | bool deleteEnt = false; | 518 | bool deleteEnt = false; |
519 | bool changeEnt = false; | 519 | bool changeEnt = false; |
520 | QString message = i18n("Processing event # "); | 520 | QString message = i18n("Processing event # "); |
521 | int procCount = 0; | 521 | int procCount = 0; |
522 | while ( ev ) { | 522 | while ( ev ) { |
523 | //qDebug("i %d ", ++i); | 523 | //qDebug("i %d ", ++i); |
524 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 524 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
525 | status.setText ( message + QString::number ( ++procCount ) ); | 525 | status.setText ( message + QString::number ( ++procCount ) ); |
526 | qApp->processEvents(); | 526 | qApp->processEvents(); |
527 | QString eString = getEventString( ev ); | 527 | QString eString = getEventString( ev ); |
528 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 528 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
529 | // deleting empty strings does not work. | 529 | // deleting empty strings does not work. |
530 | // we write first and x and then delete the record with the x | 530 | // we write first and x and then delete the record with the x |
531 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 531 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
532 | changeString += eString + "\n"; | 532 | changeString += eString + "\n"; |
533 | deleteString += eString + "\n"; | 533 | deleteString += eString + "\n"; |
534 | deleteEnt = true; | 534 | deleteEnt = true; |
535 | changeEnt = true; | 535 | changeEnt = true; |
536 | } | 536 | } |
537 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 537 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
538 | QString fileNameIn = "/tmp/kopitempin"; | 538 | QString fileNameIn = "/tmp/kopitempin"; |
539 | QFile fileIn( fileNameIn ); | 539 | QFile fileIn( fileNameIn ); |
540 | if (!fileIn.open( IO_WriteOnly ) ) { | 540 | if (!fileIn.open( IO_WriteOnly ) ) { |
541 | return false; | 541 | return false; |
542 | } | 542 | } |
543 | QTextStream tsIn( &fileIn ); | 543 | QTextStream tsIn( &fileIn ); |
544 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 544 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
545 | tsIn << ePrefix << eString ; | 545 | tsIn << ePrefix << eString ; |
546 | fileIn.close(); | 546 | fileIn.close(); |
547 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 547 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
548 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; | 548 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; |
549 | //qDebug("command ++++++++ "); | 549 | //qDebug("command ++++++++ "); |
550 | //qDebug("%s ",command.latin1()); | 550 | //qDebug("%s ",command.latin1()); |
551 | //qDebug("command -------- "); | 551 | //qDebug("command -------- "); |
552 | system ( command.utf8() ); | 552 | system ( command.utf8() ); |
553 | QFile file( fileName ); | 553 | QFile file( fileName ); |
554 | if (!file.open( IO_ReadOnly ) ) { | 554 | if (!file.open( IO_ReadOnly ) ) { |
555 | return false; | 555 | return false; |
556 | 556 | ||
557 | } | 557 | } |
558 | QTextStream ts( &file ); | 558 | QTextStream ts( &file ); |
559 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 559 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
560 | answer = ts.read(); | 560 | answer = ts.read(); |
561 | file.close(); | 561 | file.close(); |
562 | //qDebug("answer \n%s ", answer.latin1()); | 562 | //qDebug("answer \n%s ", answer.latin1()); |
563 | getNumFromRecord( answer, ev ) ; | 563 | getNumFromRecord( answer, ev ) ; |
564 | 564 | ||
565 | } | 565 | } |
566 | else { // change existing | 566 | else { // change existing |
567 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 567 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
568 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 568 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
569 | changeString += eString + "\n"; | 569 | changeString += eString + "\n"; |
570 | changeEnt = true; | 570 | changeEnt = true; |
571 | 571 | ||
572 | } | 572 | } |
573 | } | 573 | } |
574 | ev = er.next(); | 574 | ev = er.next(); |
575 | } | 575 | } |
576 | status.setText ( i18n("Changing events ...") ); | 576 | status.setText ( i18n("Changing events ...") ); |
577 | qApp->processEvents(); | 577 | qApp->processEvents(); |
578 | //qDebug("changing... "); | 578 | //qDebug("changing... "); |
579 | if ( changeEnt ) { | 579 | if ( changeEnt ) { |
580 | QFile file( fileName ); | 580 | QFile file( fileName ); |
581 | if (!file.open( IO_WriteOnly ) ) { | 581 | if (!file.open( IO_WriteOnly ) ) { |
582 | return false; | 582 | return false; |
583 | 583 | ||
584 | } | 584 | } |
585 | QTextStream ts( &file ); | 585 | QTextStream ts( &file ); |
586 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 586 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
587 | ts << changeString ; | 587 | ts << changeString ; |
588 | file.close(); | 588 | file.close(); |
589 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 589 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
590 | system ( command.latin1() ); | 590 | system ( command.latin1() ); |
591 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 591 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
592 | 592 | ||
593 | } | 593 | } |
594 | status.setText ( i18n("Deleting events ...") ); | 594 | status.setText ( i18n("Deleting events ...") ); |
595 | qApp->processEvents(); | 595 | qApp->processEvents(); |
596 | //qDebug("deleting... "); | 596 | //qDebug("deleting... "); |
597 | if ( deleteEnt ) { | 597 | if ( deleteEnt ) { |
598 | QFile file( fileName ); | 598 | QFile file( fileName ); |
599 | if (!file.open( IO_WriteOnly ) ) { | 599 | if (!file.open( IO_WriteOnly ) ) { |
600 | return false; | 600 | return false; |
601 | 601 | ||
602 | } | 602 | } |
603 | QTextStream ts( &file ); | 603 | QTextStream ts( &file ); |
604 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 604 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
605 | ts << deleteString; | 605 | ts << deleteString; |
606 | file.close(); | 606 | file.close(); |
607 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 607 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
608 | system ( command.latin1() ); | 608 | system ( command.latin1() ); |
609 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 609 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
610 | } | 610 | } |
611 | 611 | ||
612 | 612 | ||
613 | changeString = tPrefix; | 613 | changeString = tPrefix; |
614 | deleteString = tPrefix; | 614 | deleteString = tPrefix; |
615 | status.setText ( i18n("Processing todos ...") ); | 615 | status.setText ( i18n("Processing todos ...") ); |
616 | qApp->processEvents(); | 616 | qApp->processEvents(); |
617 | QPtrList<Todo> tl = calendar->rawTodos(); | 617 | QPtrList<Todo> tl = calendar->rawTodos(); |
618 | Todo* to = tl.first(); | 618 | Todo* to = tl.first(); |
619 | i = 0; | 619 | i = 0; |
620 | message = i18n("Processing todo # "); | 620 | message = i18n("Processing todo # "); |
621 | procCount = 0; | 621 | procCount = 0; |
622 | while ( to ) { | 622 | while ( to ) { |
623 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 623 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
624 | status.setText ( message + QString::number ( ++procCount ) ); | 624 | status.setText ( message + QString::number ( ++procCount ) ); |
625 | qApp->processEvents(); | 625 | qApp->processEvents(); |
626 | QString eString = getTodoString( to ); | 626 | QString eString = getTodoString( to ); |
627 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 627 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
628 | // deleting empty strings does not work. | 628 | // deleting empty strings does not work. |
629 | // we write first and x and then delete the record with the x | 629 | // we write first and x and then delete the record with the x |
630 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 630 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
631 | changeString += eString + "\n"; | 631 | changeString += eString + "\n"; |
632 | deleteString += eString + "\n"; | 632 | deleteString += eString + "\n"; |
633 | deleteEnt = true; | 633 | deleteEnt = true; |
634 | changeEnt = true; | 634 | changeEnt = true; |
635 | } | 635 | } |
636 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 636 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new |
637 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; | 637 | |
638 | |||
639 | |||
640 | QString fileNameIn = "/tmp/kopitempin"; | ||
641 | QFile fileIn( fileNameIn ); | ||
642 | if (!fileIn.open( IO_WriteOnly ) ) { | ||
643 | return false; | ||
644 | } | ||
645 | QTextStream tsIn( &fileIn ); | ||
646 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | ||
647 | tsIn << tPrefix << eString ; | ||
648 | fileIn.close(); | ||
649 | command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; | ||
638 | system ( command.utf8() ); | 650 | system ( command.utf8() ); |
639 | QFile file( fileName ); | 651 | QFile file( fileName ); |
640 | if (!file.open( IO_ReadOnly ) ) { | 652 | if (!file.open( IO_ReadOnly ) ) { |
641 | return false; | 653 | return false; |
642 | |||
643 | } | 654 | } |
644 | QTextStream ts( &file ); | 655 | QTextStream ts( &file ); |
645 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 656 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
646 | answer = ts.read(); | 657 | answer = ts.read(); |
647 | file.close(); | 658 | file.close(); |
648 | //qDebug("answer \n%s ", answer.latin1()); | 659 | //qDebug("answer \n%s ", answer.latin1()); |
649 | getNumFromRecord( answer, to ) ; | 660 | getNumFromRecord( answer, to ) ; |
650 | 661 | ||
651 | } | 662 | } |
652 | else { // change existing | 663 | else { // change existing |
653 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); | 664 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); |
654 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 665 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
655 | changeString += eString + "\n"; | 666 | changeString += eString + "\n"; |
656 | changeEnt = true; | 667 | changeEnt = true; |
657 | 668 | ||
658 | } | 669 | } |
659 | } | 670 | } |
660 | 671 | ||
661 | to = tl.next(); | 672 | to = tl.next(); |
662 | } | 673 | } |
663 | status.setText ( i18n("Changing todos ...") ); | 674 | status.setText ( i18n("Changing todos ...") ); |
664 | qApp->processEvents(); | 675 | qApp->processEvents(); |
665 | //qDebug("changing... "); | 676 | //qDebug("changing... "); |
666 | if ( changeEnt ) { | 677 | if ( changeEnt ) { |
667 | QFile file( fileName ); | 678 | QFile file( fileName ); |
668 | if (!file.open( IO_WriteOnly ) ) { | 679 | if (!file.open( IO_WriteOnly ) ) { |
669 | return false; | 680 | return false; |
670 | 681 | ||
671 | } | 682 | } |
672 | QTextStream ts( &file ); | 683 | QTextStream ts( &file ); |
673 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 684 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
674 | ts << changeString ; | 685 | ts << changeString ; |
675 | file.close(); | 686 | file.close(); |
676 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; | 687 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; |
677 | system ( command.latin1() ); | 688 | system ( command.latin1() ); |
678 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 689 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
679 | 690 | ||
680 | } | 691 | } |
681 | status.setText ( i18n("Deleting todos ...") ); | 692 | status.setText ( i18n("Deleting todos ...") ); |
682 | qApp->processEvents(); | 693 | qApp->processEvents(); |
683 | //qDebug("deleting... "); | 694 | //qDebug("deleting... "); |
684 | if ( deleteEnt ) { | 695 | if ( deleteEnt ) { |
685 | QFile file( fileName ); | 696 | QFile file( fileName ); |
686 | if (!file.open( IO_WriteOnly ) ) { | 697 | if (!file.open( IO_WriteOnly ) ) { |
687 | return false; | 698 | return false; |
688 | 699 | ||
689 | } | 700 | } |
690 | QTextStream ts( &file ); | 701 | QTextStream ts( &file ); |
691 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 702 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
692 | ts << deleteString; | 703 | ts << deleteString; |
693 | file.close(); | 704 | file.close(); |
694 | command = "db2file todo -d -c " + codec+ " < "+ fileName; | 705 | command = "db2file todo -d -c " + codec+ " < "+ fileName; |
695 | system ( command.latin1() ); | 706 | system ( command.latin1() ); |
696 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 707 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
697 | } | 708 | } |
698 | 709 | ||
699 | return true; | 710 | return true; |
700 | } | 711 | } |
701 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) | 712 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) |
702 | { | 713 | { |
703 | QString datestr; | 714 | QString datestr; |
704 | QString timestr; | 715 | QString timestr; |
705 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 716 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
706 | QDateTime dt; | 717 | QDateTime dt; |
707 | if (useTZ) | 718 | if (useTZ) |
708 | dt = dti.addSecs ( -(offset*60)); | 719 | dt = dti.addSecs ( -(offset*60)); |
709 | else | 720 | else |
710 | dt = dti; | 721 | dt = dti; |
711 | if(dt.date().isValid()){ | 722 | if(dt.date().isValid()){ |
712 | const QDate& date = dt.date(); | 723 | const QDate& date = dt.date(); |
713 | datestr.sprintf("%04d%02d%02d", | 724 | datestr.sprintf("%04d%02d%02d", |
714 | date.year(), date.month(), date.day()); | 725 | date.year(), date.month(), date.day()); |
715 | } | 726 | } |
716 | if(dt.time().isValid()){ | 727 | if(dt.time().isValid()){ |
717 | const QTime& time = dt.time(); | 728 | const QTime& time = dt.time(); |
718 | timestr.sprintf("T%02d%02d%02d", | 729 | timestr.sprintf("T%02d%02d%02d", |
719 | time.hour(), time.minute(), time.second()); | 730 | time.hour(), time.minute(), time.second()); |
720 | } | 731 | } |
721 | return datestr + timestr; | 732 | return datestr + timestr; |
722 | } | 733 | } |
723 | QString SharpFormat::getEventString( Event* event ) | 734 | QString SharpFormat::getEventString( Event* event ) |
724 | { | 735 | { |
725 | QStringList list; | 736 | QStringList list; |
726 | list.append( event->getID("Sharp_DTM") ); | 737 | list.append( event->getID("Sharp_DTM") ); |
727 | list.append( event->categories().join(",") ); | 738 | list.append( event->categories().join(",") ); |
728 | if ( !event->summary().isEmpty() ) | 739 | if ( !event->summary().isEmpty() ) |
729 | list.append( event->summary() ); | 740 | list.append( event->summary() ); |
730 | else | 741 | else |
731 | list.append("" ); | 742 | list.append("" ); |
732 | if ( !event->location().isEmpty() ) | 743 | if ( !event->location().isEmpty() ) |
733 | list.append( event->location() ); | 744 | list.append( event->location() ); |
734 | else | 745 | else |
735 | list.append("" ); | 746 | list.append("" ); |
736 | if ( !event->description().isEmpty() ) | 747 | if ( !event->description().isEmpty() ) |
737 | list.append( event->description() ); | 748 | list.append( event->description() ); |
738 | else | 749 | else |
739 | list.append( "" ); | 750 | list.append( "" ); |
740 | if ( event->doesFloat () ) { | 751 | if ( event->doesFloat () ) { |
741 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 752 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
742 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 753 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
743 | list.append( "1" ); | 754 | list.append( "1" ); |
744 | 755 | ||
745 | } | 756 | } |
746 | else { | 757 | else { |
747 | list.append( dtToString( event->dtStart()) ); | 758 | list.append( dtToString( event->dtStart()) ); |
748 | list.append( dtToString( event->dtEnd()) ); //6 | 759 | list.append( dtToString( event->dtEnd()) ); //6 |
749 | list.append( "0" ); | 760 | list.append( "0" ); |
750 | } | 761 | } |
751 | bool noAlarm = true; | 762 | bool noAlarm = true; |
752 | if ( event->alarms().count() > 0 ) { | 763 | if ( event->alarms().count() > 0 ) { |
753 | Alarm * al = event->alarms().first(); | 764 | Alarm * al = event->alarms().first(); |
754 | if ( al->enabled() ) { | 765 | if ( al->enabled() ) { |
755 | noAlarm = false; | 766 | noAlarm = false; |
756 | list.append( "0" ); // yes, 0 == alarm | 767 | list.append( "0" ); // yes, 0 == alarm |
757 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | 768 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); |
758 | if ( al->type() == Alarm::Audio ) | 769 | if ( al->type() == Alarm::Audio ) |
759 | list.append( "1" ); // type audio | 770 | list.append( "1" ); // type audio |
760 | else | 771 | else |
761 | list.append( "0" ); // type silent | 772 | list.append( "0" ); // type silent |
762 | } | 773 | } |
763 | } | 774 | } |
764 | if ( noAlarm ) { | 775 | if ( noAlarm ) { |
765 | list.append( "1" ); // yes, 1 == no alarm | 776 | list.append( "1" ); // yes, 1 == no alarm |
766 | list.append( "0" ); // no alarm offset | 777 | list.append( "0" ); // no alarm offset |
767 | list.append( "1" ); // type | 778 | list.append( "1" ); // type |
768 | } | 779 | } |
769 | // next is: 11 | 780 | // next is: 11 |
770 | // next is: 11-16 are recurrence | 781 | // next is: 11-16 are recurrence |
771 | Recurrence* rec = event->recurrence(); | 782 | Recurrence* rec = event->recurrence(); |
772 | 783 | ||
773 | bool writeEndDate = false; | 784 | bool writeEndDate = false; |
774 | switch ( rec->doesRecur() ) | 785 | switch ( rec->doesRecur() ) |
775 | { | 786 | { |
776 | case Recurrence::rDaily: // 0 | 787 | case Recurrence::rDaily: // 0 |
777 | list.append( "0" ); | 788 | list.append( "0" ); |
778 | list.append( QString::number( rec->frequency() ));//12 | 789 | list.append( QString::number( rec->frequency() ));//12 |
779 | list.append( "0" ); | 790 | list.append( "0" ); |
780 | list.append( "0" ); | 791 | list.append( "0" ); |
781 | writeEndDate = true; | 792 | writeEndDate = true; |
782 | break; | 793 | break; |
783 | case Recurrence::rWeekly:// 1 | 794 | case Recurrence::rWeekly:// 1 |
784 | list.append( "1" ); | 795 | list.append( "1" ); |
785 | list.append( QString::number( rec->frequency()) );//12 | 796 | list.append( QString::number( rec->frequency()) );//12 |
786 | list.append( "0" ); | 797 | list.append( "0" ); |
787 | { | 798 | { |
788 | int days = 0; | 799 | int days = 0; |
789 | QBitArray weekDays = rec->days(); | 800 | QBitArray weekDays = rec->days(); |
790 | int i; | 801 | int i; |
791 | for( i = 1; i <= 7; ++i ) { | 802 | for( i = 1; i <= 7; ++i ) { |
792 | if ( weekDays[i-1] ) { | 803 | if ( weekDays[i-1] ) { |
793 | days += 1 << (i-1); | 804 | days += 1 << (i-1); |
794 | } | 805 | } |
795 | } | 806 | } |
796 | list.append( QString::number( days ) ); | 807 | list.append( QString::number( days ) ); |
797 | } | 808 | } |
798 | //pending weekdays | 809 | //pending weekdays |
799 | writeEndDate = true; | 810 | writeEndDate = true; |
800 | 811 | ||
801 | break; | 812 | break; |
802 | case Recurrence::rMonthlyPos:// 2 | 813 | case Recurrence::rMonthlyPos:// 2 |
803 | list.append( "2" ); | 814 | list.append( "2" ); |
804 | list.append( QString::number( rec->frequency()) );//12 | 815 | list.append( QString::number( rec->frequency()) );//12 |
805 | 816 | ||
806 | writeEndDate = true; | 817 | writeEndDate = true; |
807 | { | 818 | { |
808 | int count = 1; | 819 | int count = 1; |
809 | QPtrList<Recurrence::rMonthPos> rmp; | 820 | QPtrList<Recurrence::rMonthPos> rmp; |
810 | rmp = rec->monthPositions(); | 821 | rmp = rec->monthPositions(); |
811 | if ( rmp.first()->negative ) | 822 | if ( rmp.first()->negative ) |
812 | count = 5 - rmp.first()->rPos - 1; | 823 | count = 5 - rmp.first()->rPos - 1; |
813 | else | 824 | else |
814 | count = rmp.first()->rPos - 1; | 825 | count = rmp.first()->rPos - 1; |
815 | list.append( QString::number( count ) ); | 826 | list.append( QString::number( count ) ); |
816 | 827 | ||
817 | } | 828 | } |
818 | 829 | ||
819 | list.append( "0" ); | 830 | list.append( "0" ); |
820 | break; | 831 | break; |
821 | case Recurrence::rMonthlyDay:// 3 | 832 | case Recurrence::rMonthlyDay:// 3 |
822 | list.append( "3" ); | 833 | list.append( "3" ); |
823 | list.append( QString::number( rec->frequency()) );//12 | 834 | list.append( QString::number( rec->frequency()) );//12 |
824 | list.append( "0" ); | 835 | list.append( "0" ); |
825 | list.append( "0" ); | 836 | list.append( "0" ); |
826 | writeEndDate = true; | 837 | writeEndDate = true; |
827 | break; | 838 | break; |
828 | case Recurrence::rYearlyMonth://4 | 839 | case Recurrence::rYearlyMonth://4 |
829 | list.append( "4" ); | 840 | list.append( "4" ); |
830 | list.append( QString::number( rec->frequency()) );//12 | 841 | list.append( QString::number( rec->frequency()) );//12 |
831 | list.append( "0" ); | 842 | list.append( "0" ); |
832 | list.append( "0" ); | 843 | list.append( "0" ); |
833 | writeEndDate = true; | 844 | writeEndDate = true; |
834 | break; | 845 | break; |