author | zautrix <zautrix> | 2004-08-20 04:35:46 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-20 04:35:46 (UTC) |
commit | b42c4af4200c67802ee0cc57e10e1464903736b7 (patch) (unidiff) | |
tree | 59f35319f3223892e2353bb8a2c72cb9e87ca0f9 | |
parent | 93decd4185adc7197008e8397cf753a5ab674d99 (diff) | |
download | kdepimpi-b42c4af4200c67802ee0cc57e10e1464903736b7.zip kdepimpi-b42c4af4200c67802ee0cc57e10e1464903736b7.tar.gz kdepimpi-b42c4af4200c67802ee0cc57e10e1464903736b7.tar.bz2 |
change reverted
-rw-r--r-- | libkcal/sharpformat.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index 820d068..defdb09 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -318,385 +318,385 @@ class SharpParser : public QObject | |||
318 | 318 | ||
319 | private: | 319 | private: |
320 | Calendar *mCalendar; | 320 | Calendar *mCalendar; |
321 | QStringList * oldCategories; | 321 | QStringList * oldCategories; |
322 | static QString category( const QString &id ) | 322 | static QString category( const QString &id ) |
323 | { | 323 | { |
324 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); | 324 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); |
325 | if ( it == mCategoriesMap.end() ) return id; | 325 | if ( it == mCategoriesMap.end() ) return id; |
326 | else return *it; | 326 | else return *it; |
327 | } | 327 | } |
328 | 328 | ||
329 | static void setCategory( const QString &id, const QString &name ) | 329 | static void setCategory( const QString &id, const QString &name ) |
330 | { | 330 | { |
331 | mCategoriesMap.insert( id, name ); | 331 | mCategoriesMap.insert( id, name ); |
332 | } | 332 | } |
333 | 333 | ||
334 | static QMap<QString,QString> mCategoriesMap; | 334 | static QMap<QString,QString> mCategoriesMap; |
335 | }; | 335 | }; |
336 | 336 | ||
337 | QMap<QString,QString> SharpParser::mCategoriesMap; | 337 | QMap<QString,QString> SharpParser::mCategoriesMap; |
338 | 338 | ||
339 | SharpFormat::SharpFormat() | 339 | SharpFormat::SharpFormat() |
340 | { | 340 | { |
341 | mCategories = 0; | 341 | mCategories = 0; |
342 | } | 342 | } |
343 | 343 | ||
344 | SharpFormat::~SharpFormat() | 344 | SharpFormat::~SharpFormat() |
345 | { | 345 | { |
346 | } | 346 | } |
347 | ulong SharpFormat::getCsum( const QStringList & attList) | 347 | ulong SharpFormat::getCsum( const QStringList & attList) |
348 | { | 348 | { |
349 | int max = attList.count() -1; | 349 | int max = attList.count() -1; |
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 = 1; i < max ; ++i ) { | 353 | for ( i = 1; 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 | add = add * mul *i*i*i; | 362 | add = add * mul *i*i*i; |
363 | cSum += add; | 363 | cSum += add; |
364 | } | 364 | } |
365 | } | 365 | } |
366 | } | 366 | } |
367 | return cSum; | 367 | return cSum; |
368 | 368 | ||
369 | } | 369 | } |
370 | #include <stdlib.h> | 370 | #include <stdlib.h> |
371 | #define DEBUGMODE false | 371 | #define DEBUGMODE false |
372 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | 372 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) |
373 | { | 373 | { |
374 | 374 | ||
375 | 375 | ||
376 | bool debug = DEBUGMODE; | 376 | bool debug = DEBUGMODE; |
377 | //debug = true; | 377 | //debug = true; |
378 | QString text; | 378 | QString text; |
379 | QString codec = "utf8"; | 379 | QString codec = "utf8"; |
380 | QLabel status ( i18n("Reading events ..."), 0 ); | 380 | QLabel status ( i18n("Reading events ..."), 0 ); |
381 | 381 | ||
382 | int w = status.sizeHint().width()+20 ; | 382 | int w = status.sizeHint().width()+20 ; |
383 | if ( w < 200 ) w = 200; | 383 | if ( w < 200 ) w = 200; |
384 | int h = status.sizeHint().height()+20 ; | 384 | int h = status.sizeHint().height()+20 ; |
385 | int dw = QApplication::desktop()->width(); | 385 | int dw = QApplication::desktop()->width(); |
386 | int dh = QApplication::desktop()->height(); | 386 | int dh = QApplication::desktop()->height(); |
387 | status.setCaption(i18n("Reading DTM Data") ); | 387 | status.setCaption(i18n("Reading DTM Data") ); |
388 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 388 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
389 | status.show(); | 389 | status.show(); |
390 | status.raise(); | 390 | status.raise(); |
391 | qApp->processEvents(); | 391 | qApp->processEvents(); |
392 | QString fileName; | 392 | QString fileName; |
393 | if ( ! debug ) { | 393 | if ( ! debug ) { |
394 | fileName = "/tmp/kopitempout"; | 394 | fileName = "/tmp/kopitempout"; |
395 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; | 395 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; |
396 | system ( command.latin1() ); | 396 | system ( command.latin1() ); |
397 | } else { | 397 | } else { |
398 | fileName = "/tmp/events.txt"; | 398 | fileName = "/tmp/events.txt"; |
399 | 399 | ||
400 | } | 400 | } |
401 | QFile file( fileName ); | 401 | QFile file( fileName ); |
402 | if (!file.open( IO_ReadOnly ) ) { | 402 | if (!file.open( IO_ReadOnly ) ) { |
403 | return false; | 403 | return false; |
404 | 404 | ||
405 | } | 405 | } |
406 | QTextStream ts( &file ); | 406 | QTextStream ts( &file ); |
407 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 407 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
408 | text = ts.read(); | 408 | text = ts.read(); |
409 | file.close(); | 409 | file.close(); |
410 | status.setText( i18n("Processing events ...") ); | 410 | status.setText( i18n("Processing events ...") ); |
411 | status.raise(); | 411 | status.raise(); |
412 | qApp->processEvents(); | 412 | qApp->processEvents(); |
413 | fromString2Cal( calendar, existngCal, text, "Event" ); | 413 | fromString2Cal( calendar, existngCal, text, "Event" ); |
414 | status.setText( i18n("Reading todos ...") ); | 414 | status.setText( i18n("Reading todos ...") ); |
415 | qApp->processEvents(); | 415 | qApp->processEvents(); |
416 | if ( ! debug ) { | 416 | if ( ! debug ) { |
417 | fileName = "/tmp/kopitempout"; | 417 | fileName = "/tmp/kopitempout"; |
418 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; | 418 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; |
419 | system ( command.latin1() ); | 419 | system ( command.latin1() ); |
420 | } else { | 420 | } else { |
421 | fileName = "/tmp/todo.txt"; | 421 | fileName = "/tmp/todo.txt"; |
422 | } | 422 | } |
423 | file.setName( fileName ); | 423 | file.setName( fileName ); |
424 | if (!file.open( IO_ReadOnly ) ) { | 424 | if (!file.open( IO_ReadOnly ) ) { |
425 | return false; | 425 | return false; |
426 | 426 | ||
427 | } | 427 | } |
428 | ts.setDevice( &file ); | 428 | ts.setDevice( &file ); |
429 | text = ts.read(); | 429 | text = ts.read(); |
430 | file.close(); | 430 | file.close(); |
431 | 431 | ||
432 | status.setText( i18n("Processing todos ...") ); | 432 | status.setText( i18n("Processing todos ...") ); |
433 | status.raise(); | 433 | status.raise(); |
434 | qApp->processEvents(); | 434 | qApp->processEvents(); |
435 | fromString2Cal( calendar, existngCal, text, "Todo" ); | 435 | fromString2Cal( calendar, existngCal, text, "Todo" ); |
436 | return true; | 436 | return true; |
437 | } | 437 | } |
438 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | 438 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) |
439 | { | 439 | { |
440 | int retval = -1; | 440 | int retval = -1; |
441 | QStringList templist; | 441 | QStringList templist; |
442 | QString tempString; | 442 | QString tempString; |
443 | int start = 0; | 443 | int start = 0; |
444 | int len = answer.length(); | 444 | int len = answer.length(); |
445 | int end = answer.find ("\n",start)+1; | 445 | int end = answer.find ("\n",start)+1; |
446 | bool ok = true; | 446 | bool ok = true; |
447 | start = end; | 447 | start = end; |
448 | int ccc = 0; | 448 | int ccc = 0; |
449 | while ( start > 0 ) { | 449 | while ( start > 0 ) { |
450 | templist.clear(); | 450 | templist.clear(); |
451 | ok = true; | 451 | ok = true; |
452 | int loopCount = 0; | 452 | int loopCount = 0; |
453 | while ( ok ) { | 453 | while ( ok ) { |
454 | ++loopCount; | 454 | ++loopCount; |
455 | if ( loopCount > 25 ) { | 455 | if ( loopCount > 25 ) { |
456 | qDebug("KO: Error in while loop"); | 456 | qDebug("KO: Error in while loop"); |
457 | ok = false; | 457 | ok = false; |
458 | start = 0; | 458 | start = 0; |
459 | break; | 459 | break; |
460 | } | 460 | } |
461 | if ( ok ) | 461 | if ( ok ) |
462 | tempString = getPart( answer, ok, start ); | 462 | tempString = getPart( answer, ok, start ); |
463 | if ( start >= len || start == 0 ) { | 463 | if ( start >= len || start == 0 ) { |
464 | start = 0; | 464 | start = 0; |
465 | ok = false; | 465 | ok = false; |
466 | } | 466 | } |
467 | if ( tempString.right(1) =="\n" ) | 467 | if ( tempString.right(1) =="\n" ) |
468 | tempString = tempString.left( tempString.length()-1); | 468 | tempString = tempString.left( tempString.length()-1); |
469 | 469 | ||
470 | templist.append( tempString ); | 470 | templist.append( tempString ); |
471 | } | 471 | } |
472 | ++ccc; | 472 | ++ccc; |
473 | if ( ccc == 2 && loopCount < 25 ) { | 473 | if ( ccc == 2 && loopCount < 25 ) { |
474 | start = 0; | 474 | start = 0; |
475 | bool ok; | 475 | bool ok; |
476 | int newnum = templist[0].toInt( &ok ); | 476 | int newnum = templist[0].toInt( &ok ); |
477 | if ( ok && newnum > 0) { | 477 | if ( ok && newnum > 0) { |
478 | retval = newnum; | 478 | retval = newnum; |
479 | inc->setID( "Sharp_DTM",templist[0] ); | 479 | inc->setID( "Sharp_DTM",templist[0] ); |
480 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); | 480 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); |
481 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 481 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
482 | } | 482 | } |
483 | } | 483 | } |
484 | } | 484 | } |
485 | //qDebug("getNumFromRecord returning : %d ", retval); | 485 | //qDebug("getNumFromRecord returning : %d ", retval); |
486 | return retval; | 486 | return retval; |
487 | } | 487 | } |
488 | bool SharpFormat::save( Calendar *calendar) | 488 | bool SharpFormat::save( Calendar *calendar) |
489 | { | 489 | { |
490 | 490 | ||
491 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 491 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
492 | int w = status.sizeHint().width()+20 ; | 492 | int w = status.sizeHint().width()+20 ; |
493 | if ( w < 200 ) w = 200; | 493 | if ( w < 200 ) w = 200; |
494 | int h = status.sizeHint().height()+20 ; | 494 | int h = status.sizeHint().height()+20 ; |
495 | int dw = QApplication::desktop()->width(); | 495 | int dw = QApplication::desktop()->width(); |
496 | int dh = QApplication::desktop()->height(); | 496 | int dh = QApplication::desktop()->height(); |
497 | status.setCaption(i18n("Writing DTM Data") ); | 497 | status.setCaption(i18n("Writing DTM Data") ); |
498 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 498 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
499 | status.show(); | 499 | status.show(); |
500 | status.raise(); | 500 | status.raise(); |
501 | qApp->processEvents(); | 501 | qApp->processEvents(); |
502 | bool debug = DEBUGMODE; | 502 | bool debug = DEBUGMODE; |
503 | QString codec = "utf8"; | 503 | QString codec = "utf8"; |
504 | QString answer; | 504 | QString answer; |
505 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; | 505 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; |
506 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; | 506 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; |
507 | QString command; | 507 | QString command; |
508 | QPtrList<Event> er = calendar->rawEvents(); | 508 | QPtrList<Event> er = calendar->rawEvents(); |
509 | Event* ev = er.first(); | 509 | Event* ev = er.first(); |
510 | QString fileName = "/tmp/kdepimtempfile"; | 510 | QString fileName = "/tmp/kopitempout"; |
511 | int i = 0; | 511 | int i = 0; |
512 | QString changeString = ePrefix; | 512 | QString changeString = ePrefix; |
513 | QString deleteString = ePrefix; | 513 | QString deleteString = ePrefix; |
514 | bool deleteEnt = false; | 514 | bool deleteEnt = false; |
515 | bool changeEnt = false; | 515 | bool changeEnt = false; |
516 | QString message = i18n("Processing event # "); | 516 | QString message = i18n("Processing event # "); |
517 | int procCount = 0; | 517 | int procCount = 0; |
518 | while ( ev ) { | 518 | while ( ev ) { |
519 | //qDebug("i %d ", ++i); | 519 | //qDebug("i %d ", ++i); |
520 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 520 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
521 | status.setText ( message + QString::number ( ++procCount ) ); | 521 | status.setText ( message + QString::number ( ++procCount ) ); |
522 | qApp->processEvents(); | 522 | qApp->processEvents(); |
523 | QString eString = getEventString( ev ); | 523 | QString eString = getEventString( ev ); |
524 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 524 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
525 | // deleting empty strings does not work. | 525 | // deleting empty strings does not work. |
526 | // we write first and x and then delete the record with the x | 526 | // we write first and x and then delete the record with the x |
527 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 527 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
528 | changeString += eString + "\n"; | 528 | changeString += eString + "\n"; |
529 | deleteString += eString + "\n"; | 529 | deleteString += eString + "\n"; |
530 | deleteEnt = true; | 530 | deleteEnt = true; |
531 | changeEnt = true; | 531 | changeEnt = true; |
532 | } | 532 | } |
533 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 533 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
534 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 534 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
535 | system ( command.utf8() ); | 535 | system ( command.utf8() ); |
536 | QFile file( fileName ); | 536 | QFile file( fileName ); |
537 | if (!file.open( IO_ReadOnly ) ) { | 537 | if (!file.open( IO_ReadOnly ) ) { |
538 | return false; | 538 | return false; |
539 | 539 | ||
540 | } | 540 | } |
541 | QTextStream ts( &file ); | 541 | QTextStream ts( &file ); |
542 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 542 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
543 | answer = ts.read(); | 543 | answer = ts.read(); |
544 | file.close(); | 544 | file.close(); |
545 | //qDebug("answer \n%s ", answer.latin1()); | 545 | //qDebug("answer \n%s ", answer.latin1()); |
546 | getNumFromRecord( answer, ev ) ; | 546 | getNumFromRecord( answer, ev ) ; |
547 | 547 | ||
548 | } | 548 | } |
549 | else { // change existing | 549 | else { // change existing |
550 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 550 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
551 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 551 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
552 | changeString += eString + "\n"; | 552 | changeString += eString + "\n"; |
553 | changeEnt = true; | 553 | changeEnt = true; |
554 | 554 | ||
555 | } | 555 | } |
556 | } | 556 | } |
557 | ev = er.next(); | 557 | ev = er.next(); |
558 | } | 558 | } |
559 | status.setText ( i18n("Changing events ...") ); | 559 | status.setText ( i18n("Changing events ...") ); |
560 | qApp->processEvents(); | 560 | qApp->processEvents(); |
561 | //qDebug("changing... "); | 561 | //qDebug("changing... "); |
562 | if ( changeEnt ) { | 562 | if ( changeEnt ) { |
563 | QFile file( fileName ); | 563 | QFile file( fileName ); |
564 | if (!file.open( IO_WriteOnly ) ) { | 564 | if (!file.open( IO_WriteOnly ) ) { |
565 | return false; | 565 | return false; |
566 | 566 | ||
567 | } | 567 | } |
568 | QTextStream ts( &file ); | 568 | QTextStream ts( &file ); |
569 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 569 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
570 | ts << changeString ; | 570 | ts << changeString ; |
571 | file.close(); | 571 | file.close(); |
572 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 572 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
573 | system ( command.latin1() ); | 573 | system ( command.latin1() ); |
574 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 574 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
575 | 575 | ||
576 | } | 576 | } |
577 | status.setText ( i18n("Deleting events ...") ); | 577 | status.setText ( i18n("Deleting events ...") ); |
578 | qApp->processEvents(); | 578 | qApp->processEvents(); |
579 | //qDebug("deleting... "); | 579 | //qDebug("deleting... "); |
580 | if ( deleteEnt ) { | 580 | if ( deleteEnt ) { |
581 | QFile file( fileName ); | 581 | QFile file( fileName ); |
582 | if (!file.open( IO_WriteOnly ) ) { | 582 | if (!file.open( IO_WriteOnly ) ) { |
583 | return false; | 583 | return false; |
584 | 584 | ||
585 | } | 585 | } |
586 | QTextStream ts( &file ); | 586 | QTextStream ts( &file ); |
587 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 587 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
588 | ts << deleteString; | 588 | ts << deleteString; |
589 | file.close(); | 589 | file.close(); |
590 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 590 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
591 | system ( command.latin1() ); | 591 | system ( command.latin1() ); |
592 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 592 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
593 | } | 593 | } |
594 | 594 | ||
595 | 595 | ||
596 | changeString = tPrefix; | 596 | changeString = tPrefix; |
597 | deleteString = tPrefix; | 597 | deleteString = tPrefix; |
598 | status.setText ( i18n("Processing todos ...") ); | 598 | status.setText ( i18n("Processing todos ...") ); |
599 | qApp->processEvents(); | 599 | qApp->processEvents(); |
600 | QPtrList<Todo> tl = calendar->rawTodos(); | 600 | QPtrList<Todo> tl = calendar->rawTodos(); |
601 | Todo* to = tl.first(); | 601 | Todo* to = tl.first(); |
602 | i = 0; | 602 | i = 0; |
603 | message = i18n("Processing todo # "); | 603 | message = i18n("Processing todo # "); |
604 | procCount = 0; | 604 | procCount = 0; |
605 | while ( to ) { | 605 | while ( to ) { |
606 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 606 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
607 | status.setText ( message + QString::number ( ++procCount ) ); | 607 | status.setText ( message + QString::number ( ++procCount ) ); |
608 | qApp->processEvents(); | 608 | qApp->processEvents(); |
609 | QString eString = getTodoString( to ); | 609 | QString eString = getTodoString( to ); |
610 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 610 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
611 | // deleting empty strings does not work. | 611 | // deleting empty strings does not work. |
612 | // we write first and x and then delete the record with the x | 612 | // we write first and x and then delete the record with the x |
613 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 613 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
614 | changeString += eString + "\n"; | 614 | changeString += eString + "\n"; |
615 | deleteString += eString + "\n"; | 615 | deleteString += eString + "\n"; |
616 | deleteEnt = true; | 616 | deleteEnt = true; |
617 | changeEnt = true; | 617 | changeEnt = true; |
618 | } | 618 | } |
619 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 619 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new |
620 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; | 620 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; |
621 | system ( command.utf8() ); | 621 | system ( command.utf8() ); |
622 | QFile file( fileName ); | 622 | QFile file( fileName ); |
623 | if (!file.open( IO_ReadOnly ) ) { | 623 | if (!file.open( IO_ReadOnly ) ) { |
624 | return false; | 624 | return false; |
625 | 625 | ||
626 | } | 626 | } |
627 | QTextStream ts( &file ); | 627 | QTextStream ts( &file ); |
628 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 628 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
629 | answer = ts.read(); | 629 | answer = ts.read(); |
630 | file.close(); | 630 | file.close(); |
631 | //qDebug("answer \n%s ", answer.latin1()); | 631 | //qDebug("answer \n%s ", answer.latin1()); |
632 | getNumFromRecord( answer, to ) ; | 632 | getNumFromRecord( answer, to ) ; |
633 | 633 | ||
634 | } | 634 | } |
635 | else { // change existing | 635 | else { // change existing |
636 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); | 636 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); |
637 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 637 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
638 | changeString += eString + "\n"; | 638 | changeString += eString + "\n"; |
639 | changeEnt = true; | 639 | changeEnt = true; |
640 | 640 | ||
641 | } | 641 | } |
642 | } | 642 | } |
643 | 643 | ||
644 | to = tl.next(); | 644 | to = tl.next(); |
645 | } | 645 | } |
646 | status.setText ( i18n("Changing todos ...") ); | 646 | status.setText ( i18n("Changing todos ...") ); |
647 | qApp->processEvents(); | 647 | qApp->processEvents(); |
648 | //qDebug("changing... "); | 648 | //qDebug("changing... "); |
649 | if ( changeEnt ) { | 649 | if ( changeEnt ) { |
650 | QFile file( fileName ); | 650 | QFile file( fileName ); |
651 | if (!file.open( IO_WriteOnly ) ) { | 651 | if (!file.open( IO_WriteOnly ) ) { |
652 | return false; | 652 | return false; |
653 | 653 | ||
654 | } | 654 | } |
655 | QTextStream ts( &file ); | 655 | QTextStream ts( &file ); |
656 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 656 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
657 | ts << changeString ; | 657 | ts << changeString ; |
658 | file.close(); | 658 | file.close(); |
659 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; | 659 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; |
660 | system ( command.latin1() ); | 660 | system ( command.latin1() ); |
661 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 661 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
662 | 662 | ||
663 | } | 663 | } |
664 | status.setText ( i18n("Deleting todos ...") ); | 664 | status.setText ( i18n("Deleting todos ...") ); |
665 | qApp->processEvents(); | 665 | qApp->processEvents(); |
666 | //qDebug("deleting... "); | 666 | //qDebug("deleting... "); |
667 | if ( deleteEnt ) { | 667 | if ( deleteEnt ) { |
668 | QFile file( fileName ); | 668 | QFile file( fileName ); |
669 | if (!file.open( IO_WriteOnly ) ) { | 669 | if (!file.open( IO_WriteOnly ) ) { |
670 | return false; | 670 | return false; |
671 | 671 | ||
672 | } | 672 | } |
673 | QTextStream ts( &file ); | 673 | QTextStream ts( &file ); |
674 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 674 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
675 | ts << deleteString; | 675 | ts << deleteString; |
676 | file.close(); | 676 | file.close(); |
677 | command = "db2file todo -d -c " + codec+ " < "+ fileName; | 677 | command = "db2file todo -d -c " + codec+ " < "+ fileName; |
678 | system ( command.latin1() ); | 678 | system ( command.latin1() ); |
679 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 679 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
680 | } | 680 | } |
681 | 681 | ||
682 | return true; | 682 | return true; |
683 | } | 683 | } |
684 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) | 684 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) |
685 | { | 685 | { |
686 | QString datestr; | 686 | QString datestr; |
687 | QString timestr; | 687 | QString timestr; |
688 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 688 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
689 | QDateTime dt; | 689 | QDateTime dt; |
690 | if (useTZ) | 690 | if (useTZ) |
691 | dt = dti.addSecs ( -(offset*60)); | 691 | dt = dti.addSecs ( -(offset*60)); |
692 | else | 692 | else |
693 | dt = dti; | 693 | dt = dti; |
694 | if(dt.date().isValid()){ | 694 | if(dt.date().isValid()){ |
695 | const QDate& date = dt.date(); | 695 | const QDate& date = dt.date(); |
696 | datestr.sprintf("%04d%02d%02d", | 696 | datestr.sprintf("%04d%02d%02d", |
697 | date.year(), date.month(), date.day()); | 697 | date.year(), date.month(), date.day()); |
698 | } | 698 | } |
699 | if(dt.time().isValid()){ | 699 | if(dt.time().isValid()){ |
700 | const QTime& time = dt.time(); | 700 | const QTime& time = dt.time(); |
701 | timestr.sprintf("T%02d%02d%02d", | 701 | timestr.sprintf("T%02d%02d%02d", |
702 | time.hour(), time.minute(), time.second()); | 702 | time.hour(), time.minute(), time.second()); |