author | zautrix <zautrix> | 2004-09-14 03:13:52 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-14 03:13:52 (UTC) |
commit | f1f43030eefa765950cb501aece6cc71fb4e9859 (patch) (unidiff) | |
tree | d7396ac13ab052ee38e2e8e139854cc88a289a43 /libkcal | |
parent | 5060b0737c0c279859cac3bcfb73d2ac21c6a79e (diff) | |
download | kdepimpi-f1f43030eefa765950cb501aece6cc71fb4e9859.zip kdepimpi-f1f43030eefa765950cb501aece6cc71fb4e9859.tar.gz kdepimpi-f1f43030eefa765950cb501aece6cc71fb4e9859.tar.bz2 |
More fixes
-rw-r--r-- | libkcal/sharpformat.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index a53b3f8..e7fc670 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -420,180 +420,196 @@ bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | |||
420 | system ( command.latin1() ); | 420 | system ( command.latin1() ); |
421 | } else { | 421 | } else { |
422 | fileName = "/tmp/todo.txt"; | 422 | fileName = "/tmp/todo.txt"; |
423 | } | 423 | } |
424 | file.setName( fileName ); | 424 | file.setName( fileName ); |
425 | if (!file.open( IO_ReadOnly ) ) { | 425 | if (!file.open( IO_ReadOnly ) ) { |
426 | return false; | 426 | return false; |
427 | 427 | ||
428 | } | 428 | } |
429 | ts.setDevice( &file ); | 429 | ts.setDevice( &file ); |
430 | text = ts.read(); | 430 | text = ts.read(); |
431 | file.close(); | 431 | file.close(); |
432 | 432 | ||
433 | status.setText( i18n("Processing todos ...") ); | 433 | status.setText( i18n("Processing todos ...") ); |
434 | status.raise(); | 434 | status.raise(); |
435 | qApp->processEvents(); | 435 | qApp->processEvents(); |
436 | fromString2Cal( calendar, existngCal, text, "Todo" ); | 436 | fromString2Cal( calendar, existngCal, text, "Todo" ); |
437 | return true; | 437 | return true; |
438 | } | 438 | } |
439 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | 439 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) |
440 | { | 440 | { |
441 | int retval = -1; | 441 | int retval = -1; |
442 | QStringList templist; | 442 | QStringList templist; |
443 | QString tempString; | 443 | QString tempString; |
444 | int start = 0; | 444 | int start = 0; |
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 ) { | ||
485 | qDebug("Error writing back %s ", inc->summary().latin1()); | ||
486 | } | ||
484 | } | 487 | } |
485 | } | 488 | } |
486 | //qDebug("getNumFromRecord returning : %d ", retval); | 489 | //qDebug("getNumFromRecord returning : %d ", retval); |
487 | return retval; | 490 | return retval; |
488 | } | 491 | } |
489 | bool SharpFormat::save( Calendar *calendar) | 492 | bool SharpFormat::save( Calendar *calendar) |
490 | { | 493 | { |
491 | 494 | ||
492 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 495 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
493 | int w = status.sizeHint().width()+20 ; | 496 | int w = status.sizeHint().width()+20 ; |
494 | if ( w < 200 ) w = 200; | 497 | if ( w < 200 ) w = 200; |
495 | int h = status.sizeHint().height()+20 ; | 498 | int h = status.sizeHint().height()+20 ; |
496 | int dw = QApplication::desktop()->width(); | 499 | int dw = QApplication::desktop()->width(); |
497 | int dh = QApplication::desktop()->height(); | 500 | int dh = QApplication::desktop()->height(); |
498 | status.setCaption(i18n("Writing DTM Data") ); | 501 | status.setCaption(i18n("Writing DTM Data") ); |
499 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 502 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
500 | status.show(); | 503 | status.show(); |
501 | status.raise(); | 504 | status.raise(); |
502 | qApp->processEvents(); | 505 | qApp->processEvents(); |
503 | bool debug = DEBUGMODE; | 506 | bool debug = DEBUGMODE; |
504 | QString codec = "utf8"; | 507 | QString codec = "utf8"; |
505 | QString answer; | 508 | QString answer; |
506 | 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"; |
507 | 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"; |
508 | QString command; | 511 | QString command; |
509 | QPtrList<Event> er = calendar->rawEvents(); | 512 | QPtrList<Event> er = calendar->rawEvents(); |
510 | Event* ev = er.first(); | 513 | Event* ev = er.first(); |
511 | QString fileName = "/tmp/kopitempout"; | 514 | QString fileName = "/tmp/kopitempout"; |
512 | int i = 0; | 515 | int i = 0; |
513 | QString changeString = ePrefix; | 516 | QString changeString = ePrefix; |
514 | QString deleteString = ePrefix; | 517 | QString deleteString = ePrefix; |
515 | bool deleteEnt = false; | 518 | bool deleteEnt = false; |
516 | bool changeEnt = false; | 519 | bool changeEnt = false; |
517 | QString message = i18n("Processing event # "); | 520 | QString message = i18n("Processing event # "); |
518 | int procCount = 0; | 521 | int procCount = 0; |
519 | while ( ev ) { | 522 | while ( ev ) { |
520 | //qDebug("i %d ", ++i); | 523 | //qDebug("i %d ", ++i); |
521 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 524 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
522 | status.setText ( message + QString::number ( ++procCount ) ); | 525 | status.setText ( message + QString::number ( ++procCount ) ); |
523 | qApp->processEvents(); | 526 | qApp->processEvents(); |
524 | QString eString = getEventString( ev ); | 527 | QString eString = getEventString( ev ); |
525 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 528 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
526 | // deleting empty strings does not work. | 529 | // deleting empty strings does not work. |
527 | // 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 |
528 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 531 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
529 | changeString += eString + "\n"; | 532 | changeString += eString + "\n"; |
530 | deleteString += eString + "\n"; | 533 | deleteString += eString + "\n"; |
531 | deleteEnt = true; | 534 | deleteEnt = true; |
532 | changeEnt = true; | 535 | changeEnt = true; |
533 | } | 536 | } |
534 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 537 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
535 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 538 | QString fileNameIn = "/tmp/kopitempin"; |
539 | QFile fileIn( fileNameIn ); | ||
540 | if (!fileIn.open( IO_WriteOnly ) ) { | ||
541 | return false; | ||
542 | } | ||
543 | QTextStream tsIn( &fileIn ); | ||
544 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | ||
545 | tsIn << ePrefix << eString ; | ||
546 | fileIn.close(); | ||
547 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | ||
548 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; | ||
549 | qDebug("command ++++++++ "); | ||
550 | qDebug("%s ",command.latin1()); | ||
551 | qDebug("command -------- "); | ||
536 | system ( command.utf8() ); | 552 | system ( command.utf8() ); |
537 | QFile file( fileName ); | 553 | QFile file( fileName ); |
538 | if (!file.open( IO_ReadOnly ) ) { | 554 | if (!file.open( IO_ReadOnly ) ) { |
539 | return false; | 555 | return false; |
540 | 556 | ||
541 | } | 557 | } |
542 | QTextStream ts( &file ); | 558 | QTextStream ts( &file ); |
543 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 559 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
544 | answer = ts.read(); | 560 | answer = ts.read(); |
545 | file.close(); | 561 | file.close(); |
546 | //qDebug("answer \n%s ", answer.latin1()); | 562 | //qDebug("answer \n%s ", answer.latin1()); |
547 | getNumFromRecord( answer, ev ) ; | 563 | getNumFromRecord( answer, ev ) ; |
548 | 564 | ||
549 | } | 565 | } |
550 | else { // change existing | 566 | else { // change existing |
551 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 567 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
552 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 568 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
553 | changeString += eString + "\n"; | 569 | changeString += eString + "\n"; |
554 | changeEnt = true; | 570 | changeEnt = true; |
555 | 571 | ||
556 | } | 572 | } |
557 | } | 573 | } |
558 | ev = er.next(); | 574 | ev = er.next(); |
559 | } | 575 | } |
560 | status.setText ( i18n("Changing events ...") ); | 576 | status.setText ( i18n("Changing events ...") ); |
561 | qApp->processEvents(); | 577 | qApp->processEvents(); |
562 | //qDebug("changing... "); | 578 | //qDebug("changing... "); |
563 | if ( changeEnt ) { | 579 | if ( changeEnt ) { |
564 | QFile file( fileName ); | 580 | QFile file( fileName ); |
565 | if (!file.open( IO_WriteOnly ) ) { | 581 | if (!file.open( IO_WriteOnly ) ) { |
566 | return false; | 582 | return false; |
567 | 583 | ||
568 | } | 584 | } |
569 | QTextStream ts( &file ); | 585 | QTextStream ts( &file ); |
570 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 586 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
571 | ts << changeString ; | 587 | ts << changeString ; |
572 | file.close(); | 588 | file.close(); |
573 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 589 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
574 | system ( command.latin1() ); | 590 | system ( command.latin1() ); |
575 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 591 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
576 | 592 | ||
577 | } | 593 | } |
578 | status.setText ( i18n("Deleting events ...") ); | 594 | status.setText ( i18n("Deleting events ...") ); |
579 | qApp->processEvents(); | 595 | qApp->processEvents(); |
580 | //qDebug("deleting... "); | 596 | //qDebug("deleting... "); |
581 | if ( deleteEnt ) { | 597 | if ( deleteEnt ) { |
582 | QFile file( fileName ); | 598 | QFile file( fileName ); |
583 | if (!file.open( IO_WriteOnly ) ) { | 599 | if (!file.open( IO_WriteOnly ) ) { |
584 | return false; | 600 | return false; |
585 | 601 | ||
586 | } | 602 | } |
587 | QTextStream ts( &file ); | 603 | QTextStream ts( &file ); |
588 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 604 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
589 | ts << deleteString; | 605 | ts << deleteString; |
590 | file.close(); | 606 | file.close(); |
591 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 607 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
592 | system ( command.latin1() ); | 608 | system ( command.latin1() ); |
593 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 609 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
594 | } | 610 | } |
595 | 611 | ||
596 | 612 | ||
597 | changeString = tPrefix; | 613 | changeString = tPrefix; |
598 | deleteString = tPrefix; | 614 | deleteString = tPrefix; |
599 | status.setText ( i18n("Processing todos ...") ); | 615 | status.setText ( i18n("Processing todos ...") ); |