summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/sharpformat.cpp18
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
@@ -228,564 +228,580 @@ class SharpParser : public QObject
228 228
229 229
230 230
231 QString hasDateStr = attList[3]; // due 231 QString hasDateStr = attList[3]; // due
232 if ( !hasDateStr.isEmpty() ) { 232 if ( !hasDateStr.isEmpty() ) {
233 if ( hasDateStr.right(6) == "000000" ) { 233 if ( hasDateStr.right(6) == "000000" ) {
234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
235 todo->setFloats( true ); 235 todo->setFloats( true );
236 } 236 }
237 else { 237 else {
238 todo->setDtDue( fromString( hasDateStr ) ); 238 todo->setDtDue( fromString( hasDateStr ) );
239 todo->setFloats( false ); 239 todo->setFloats( false );
240 } 240 }
241 241
242 todo->setHasDueDate( true ); 242 todo->setHasDueDate( true );
243 } 243 }
244 hasDateStr = attList[2];//start 244 hasDateStr = attList[2];//start
245 if ( !hasDateStr.isEmpty() ) { 245 if ( !hasDateStr.isEmpty() ) {
246 246
247 todo->setDtStart( fromString( hasDateStr ) ); 247 todo->setDtStart( fromString( hasDateStr ) );
248 todo->setHasStartDate( true); 248 todo->setHasStartDate( true);
249 } else 249 } else
250 todo->setHasStartDate( false ); 250 todo->setHasStartDate( false );
251 hasDateStr = attList[4];//completed 251 hasDateStr = attList[4];//completed
252 if ( !hasDateStr.isEmpty() ) { 252 if ( !hasDateStr.isEmpty() ) {
253 todo->setCompleted(fromString( hasDateStr ) ); 253 todo->setCompleted(fromString( hasDateStr ) );
254 } 254 }
255 QString completedStr = attList[5]; 255 QString completedStr = attList[5];
256 if ( completedStr == "0" ) 256 if ( completedStr == "0" )
257 todo->setCompleted( true ); 257 todo->setCompleted( true );
258 else 258 else
259 todo->setCompleted( false ); 259 todo->setCompleted( false );
260 mCalendar->addTodo( todo ); 260 mCalendar->addTodo( todo );
261 261
262 } else if ( qName == "Category" ) { 262 } else if ( qName == "Category" ) {
263 /* 263 /*
264 QString id = attributes.value( "id" ); 264 QString id = attributes.value( "id" );
265 QString name = attributes.value( "name" ); 265 QString name = attributes.value( "name" );
266 setCategory( id, name ); 266 setCategory( id, name );
267 */ 267 */
268 } 268 }
269 //qDebug("end "); 269 //qDebug("end ");
270 return true; 270 return true;
271 } 271 }
272 272
273 273
274 void setCategoriesList ( QStringList * c ) 274 void setCategoriesList ( QStringList * c )
275 { 275 {
276 oldCategories = c; 276 oldCategories = c;
277 } 277 }
278 278
279 QDateTime fromString ( QString s, bool useTz = true ) { 279 QDateTime fromString ( QString s, bool useTz = true ) {
280 QDateTime dt; 280 QDateTime dt;
281 int y,m,t,h,min,sec; 281 int y,m,t,h,min,sec;
282 y = s.mid(0,4).toInt(); 282 y = s.mid(0,4).toInt();
283 m = s.mid(4,2).toInt(); 283 m = s.mid(4,2).toInt();
284 t = s.mid(6,2).toInt(); 284 t = s.mid(6,2).toInt();
285 h = s.mid(9,2).toInt(); 285 h = s.mid(9,2).toInt();
286 min = s.mid(11,2).toInt(); 286 min = s.mid(11,2).toInt();
287 sec = s.mid(13,2).toInt(); 287 sec = s.mid(13,2).toInt();
288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
289 int offset = KGlobal::locale()->localTimeOffset( dt ); 289 int offset = KGlobal::locale()->localTimeOffset( dt );
290 if ( useTz ) 290 if ( useTz )
291 dt = dt.addSecs ( offset*60); 291 dt = dt.addSecs ( offset*60);
292 return dt; 292 return dt;
293 293
294 } 294 }
295 protected: 295 protected:
296 QDateTime toDateTime( const QString &value ) 296 QDateTime toDateTime( const QString &value )
297 { 297 {
298 QDateTime dt; 298 QDateTime dt;
299 dt.setTime_t( value.toUInt() ); 299 dt.setTime_t( value.toUInt() );
300 300
301 return dt; 301 return dt;
302 } 302 }
303 303
304 QStringList lookupCategories( const QString &categoryList ) 304 QStringList lookupCategories( const QString &categoryList )
305 { 305 {
306 QStringList categoryIds = QStringList::split( ";", categoryList ); 306 QStringList categoryIds = QStringList::split( ";", categoryList );
307 QStringList categories; 307 QStringList categories;
308 QStringList::ConstIterator it; 308 QStringList::ConstIterator it;
309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
310 QString cate = category( *it ); 310 QString cate = category( *it );
311 if ( oldCategories ) { 311 if ( oldCategories ) {
312 if ( ! oldCategories->contains( cate ) ) 312 if ( ! oldCategories->contains( cate ) )
313 oldCategories->append( cate ); 313 oldCategories->append( cate );
314 } 314 }
315 categories.append(cate ); 315 categories.append(cate );
316 } 316 }
317 return categories; 317 return categories;
318 } 318 }
319 319
320 private: 320 private:
321 Calendar *mCalendar; 321 Calendar *mCalendar;
322 QStringList * oldCategories; 322 QStringList * oldCategories;
323 static QString category( const QString &id ) 323 static QString category( const QString &id )
324 { 324 {
325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
326 if ( it == mCategoriesMap.end() ) return id; 326 if ( it == mCategoriesMap.end() ) return id;
327 else return *it; 327 else return *it;
328 } 328 }
329 329
330 static void setCategory( const QString &id, const QString &name ) 330 static void setCategory( const QString &id, const QString &name )
331 { 331 {
332 mCategoriesMap.insert( id, name ); 332 mCategoriesMap.insert( id, name );
333 } 333 }
334 334
335 static QMap<QString,QString> mCategoriesMap; 335 static QMap<QString,QString> mCategoriesMap;
336}; 336};
337 337
338QMap<QString,QString> SharpParser::mCategoriesMap; 338QMap<QString,QString> SharpParser::mCategoriesMap;
339 339
340SharpFormat::SharpFormat() 340SharpFormat::SharpFormat()
341{ 341{
342 mCategories = 0; 342 mCategories = 0;
343} 343}
344 344
345SharpFormat::~SharpFormat() 345SharpFormat::~SharpFormat()
346{ 346{
347} 347}
348ulong SharpFormat::getCsum( const QStringList & attList) 348ulong SharpFormat::getCsum( const QStringList & attList)
349{ 349{
350 int max = attList.count() -1; 350 int max = attList.count() -1;
351 ulong cSum = 0; 351 ulong cSum = 0;
352 int j,k,i; 352 int j,k,i;
353 int add; 353 int add;
354 for ( i = 1; i < max ; ++i ) { 354 for ( i = 1; i < max ; ++i ) {
355 QString s = attList[i]; 355 QString s = attList[i];
356 if ( ! s.isEmpty() ){ 356 if ( ! s.isEmpty() ){
357 j = s.length(); 357 j = s.length();
358 for ( k = 0; k < j; ++k ) { 358 for ( k = 0; k < j; ++k ) {
359 int mul = k +1; 359 int mul = k +1;
360 add = s[k].unicode (); 360 add = s[k].unicode ();
361 if ( k < 16 ) 361 if ( k < 16 )
362 mul = mul * mul; 362 mul = mul * mul;
363 add = add * mul *i*i*i; 363 add = add * mul *i*i*i;
364 cSum += add; 364 cSum += add;
365 } 365 }
366 } 366 }
367 } 367 }
368 return cSum; 368 return cSum;
369 369
370} 370}
371#include <stdlib.h> 371#include <stdlib.h>
372#define DEBUGMODE false 372#define DEBUGMODE false
373//#define DEBUGMODE true 373//#define DEBUGMODE true
374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
375{ 375{
376 376
377 377
378 bool debug = DEBUGMODE; 378 bool debug = DEBUGMODE;
379 QString text; 379 QString text;
380 QString codec = "utf8"; 380 QString codec = "utf8";
381 QLabel status ( i18n("Reading events ..."), 0 ); 381 QLabel status ( i18n("Reading events ..."), 0 );
382 382
383 int w = status.sizeHint().width()+20 ; 383 int w = status.sizeHint().width()+20 ;
384 if ( w < 200 ) w = 200; 384 if ( w < 200 ) w = 200;
385 int h = status.sizeHint().height()+20 ; 385 int h = status.sizeHint().height()+20 ;
386 int dw = QApplication::desktop()->width(); 386 int dw = QApplication::desktop()->width();
387 int dh = QApplication::desktop()->height(); 387 int dh = QApplication::desktop()->height();
388 status.setCaption(i18n("Reading DTM Data") ); 388 status.setCaption(i18n("Reading DTM Data") );
389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
390 status.show(); 390 status.show();
391 status.raise(); 391 status.raise();
392 qApp->processEvents(); 392 qApp->processEvents();
393 QString fileName; 393 QString fileName;
394 if ( ! debug ) { 394 if ( ! debug ) {
395 fileName = "/tmp/kopitempout"; 395 fileName = "/tmp/kopitempout";
396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
397 system ( command.latin1() ); 397 system ( command.latin1() );
398 } else { 398 } else {
399 fileName = "/tmp/events.txt"; 399 fileName = "/tmp/events.txt";
400 400
401 } 401 }
402 QFile file( fileName ); 402 QFile file( fileName );
403 if (!file.open( IO_ReadOnly ) ) { 403 if (!file.open( IO_ReadOnly ) ) {
404 return false; 404 return false;
405 405
406 } 406 }
407 QTextStream ts( &file ); 407 QTextStream ts( &file );
408 ts.setCodec( QTextCodec::codecForName("utf8") ); 408 ts.setCodec( QTextCodec::codecForName("utf8") );
409 text = ts.read(); 409 text = ts.read();
410 file.close(); 410 file.close();
411 status.setText( i18n("Processing events ...") ); 411 status.setText( i18n("Processing events ...") );
412 status.raise(); 412 status.raise();
413 qApp->processEvents(); 413 qApp->processEvents();
414 fromString2Cal( calendar, existngCal, text, "Event" ); 414 fromString2Cal( calendar, existngCal, text, "Event" );
415 status.setText( i18n("Reading todos ...") ); 415 status.setText( i18n("Reading todos ...") );
416 qApp->processEvents(); 416 qApp->processEvents();
417 if ( ! debug ) { 417 if ( ! debug ) {
418 fileName = "/tmp/kopitempout"; 418 fileName = "/tmp/kopitempout";
419 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 419 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
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}
439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 439int 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}
489bool SharpFormat::save( Calendar *calendar) 492bool 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 ...") );
600 qApp->processEvents(); 616 qApp->processEvents();
601 QPtrList<Todo> tl = calendar->rawTodos(); 617 QPtrList<Todo> tl = calendar->rawTodos();
602 Todo* to = tl.first(); 618 Todo* to = tl.first();
603 i = 0; 619 i = 0;
604 message = i18n("Processing todo # "); 620 message = i18n("Processing todo # ");
605 procCount = 0; 621 procCount = 0;
606 while ( to ) { 622 while ( to ) {
607 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 623 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
608 status.setText ( message + QString::number ( ++procCount ) ); 624 status.setText ( message + QString::number ( ++procCount ) );
609 qApp->processEvents(); 625 qApp->processEvents();
610 QString eString = getTodoString( to ); 626 QString eString = getTodoString( to );
611 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 627 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
612 // deleting empty strings does not work. 628 // deleting empty strings does not work.
613 // 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
614 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 630 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
615 changeString += eString + "\n"; 631 changeString += eString + "\n";
616 deleteString += eString + "\n"; 632 deleteString += eString + "\n";
617 deleteEnt = true; 633 deleteEnt = true;
618 changeEnt = true; 634 changeEnt = true;
619 } 635 }
620 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 636 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
621 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 637 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
622 system ( command.utf8() ); 638 system ( command.utf8() );
623 QFile file( fileName ); 639 QFile file( fileName );
624 if (!file.open( IO_ReadOnly ) ) { 640 if (!file.open( IO_ReadOnly ) ) {
625 return false; 641 return false;
626 642
627 } 643 }
628 QTextStream ts( &file ); 644 QTextStream ts( &file );
629 ts.setCodec( QTextCodec::codecForName("utf8") ); 645 ts.setCodec( QTextCodec::codecForName("utf8") );
630 answer = ts.read(); 646 answer = ts.read();
631 file.close(); 647 file.close();
632 //qDebug("answer \n%s ", answer.latin1()); 648 //qDebug("answer \n%s ", answer.latin1());
633 getNumFromRecord( answer, to ) ; 649 getNumFromRecord( answer, to ) ;
634 650
635 } 651 }
636 else { // change existing 652 else { // change existing
637 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 653 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
638 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 654 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
639 changeString += eString + "\n"; 655 changeString += eString + "\n";
640 changeEnt = true; 656 changeEnt = true;
641 657
642 } 658 }
643 } 659 }
644 660
645 to = tl.next(); 661 to = tl.next();
646 } 662 }
647 status.setText ( i18n("Changing todos ...") ); 663 status.setText ( i18n("Changing todos ...") );
648 qApp->processEvents(); 664 qApp->processEvents();
649 //qDebug("changing... "); 665 //qDebug("changing... ");
650 if ( changeEnt ) { 666 if ( changeEnt ) {
651 QFile file( fileName ); 667 QFile file( fileName );
652 if (!file.open( IO_WriteOnly ) ) { 668 if (!file.open( IO_WriteOnly ) ) {
653 return false; 669 return false;
654 670
655 } 671 }
656 QTextStream ts( &file ); 672 QTextStream ts( &file );
657 ts.setCodec( QTextCodec::codecForName("utf8") ); 673 ts.setCodec( QTextCodec::codecForName("utf8") );
658 ts << changeString ; 674 ts << changeString ;
659 file.close(); 675 file.close();
660 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 676 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
661 system ( command.latin1() ); 677 system ( command.latin1() );
662 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 678 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
663 679
664 } 680 }
665 status.setText ( i18n("Deleting todos ...") ); 681 status.setText ( i18n("Deleting todos ...") );
666 qApp->processEvents(); 682 qApp->processEvents();
667 //qDebug("deleting... "); 683 //qDebug("deleting... ");
668 if ( deleteEnt ) { 684 if ( deleteEnt ) {
669 QFile file( fileName ); 685 QFile file( fileName );
670 if (!file.open( IO_WriteOnly ) ) { 686 if (!file.open( IO_WriteOnly ) ) {
671 return false; 687 return false;
672 688
673 } 689 }
674 QTextStream ts( &file ); 690 QTextStream ts( &file );
675 ts.setCodec( QTextCodec::codecForName("utf8") ); 691 ts.setCodec( QTextCodec::codecForName("utf8") );
676 ts << deleteString; 692 ts << deleteString;
677 file.close(); 693 file.close();
678 command = "db2file todo -d -c " + codec+ " < "+ fileName; 694 command = "db2file todo -d -c " + codec+ " < "+ fileName;
679 system ( command.latin1() ); 695 system ( command.latin1() );
680 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 696 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
681 } 697 }
682 698
683 return true; 699 return true;
684} 700}
685QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 701QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
686{ 702{
687 QString datestr; 703 QString datestr;
688 QString timestr; 704 QString timestr;
689 int offset = KGlobal::locale()->localTimeOffset( dti ); 705 int offset = KGlobal::locale()->localTimeOffset( dti );
690 QDateTime dt; 706 QDateTime dt;
691 if (useTZ) 707 if (useTZ)
692 dt = dti.addSecs ( -(offset*60)); 708 dt = dti.addSecs ( -(offset*60));
693 else 709 else
694 dt = dti; 710 dt = dti;
695 if(dt.date().isValid()){ 711 if(dt.date().isValid()){
696 const QDate& date = dt.date(); 712 const QDate& date = dt.date();
697 datestr.sprintf("%04d%02d%02d", 713 datestr.sprintf("%04d%02d%02d",
698 date.year(), date.month(), date.day()); 714 date.year(), date.month(), date.day());
699 } 715 }
700 if(dt.time().isValid()){ 716 if(dt.time().isValid()){
701 const QTime& time = dt.time(); 717 const QTime& time = dt.time();
702 timestr.sprintf("T%02d%02d%02d", 718 timestr.sprintf("T%02d%02d%02d",
703 time.hour(), time.minute(), time.second()); 719 time.hour(), time.minute(), time.second());
704 } 720 }
705 return datestr + timestr; 721 return datestr + timestr;
706} 722}
707QString SharpFormat::getEventString( Event* event ) 723QString SharpFormat::getEventString( Event* event )
708{ 724{
709 QStringList list; 725 QStringList list;
710 list.append( event->getID("Sharp_DTM") ); 726 list.append( event->getID("Sharp_DTM") );
711 list.append( event->categories().join(",") ); 727 list.append( event->categories().join(",") );
712 if ( !event->summary().isEmpty() ) 728 if ( !event->summary().isEmpty() )
713 list.append( event->summary() ); 729 list.append( event->summary() );
714 else 730 else
715 list.append("" ); 731 list.append("" );
716 if ( !event->location().isEmpty() ) 732 if ( !event->location().isEmpty() )
717 list.append( event->location() ); 733 list.append( event->location() );
718 else 734 else
719 list.append("" ); 735 list.append("" );
720 if ( !event->description().isEmpty() ) 736 if ( !event->description().isEmpty() )
721 list.append( event->description() ); 737 list.append( event->description() );
722 else 738 else
723 list.append( "" ); 739 list.append( "" );
724 if ( event->doesFloat () ) { 740 if ( event->doesFloat () ) {
725 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 741 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
726 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 742 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
727 list.append( "1" ); 743 list.append( "1" );
728 744
729 } 745 }
730 else { 746 else {
731 list.append( dtToString( event->dtStart()) ); 747 list.append( dtToString( event->dtStart()) );
732 list.append( dtToString( event->dtEnd()) ); //6 748 list.append( dtToString( event->dtEnd()) ); //6
733 list.append( "0" ); 749 list.append( "0" );
734 } 750 }
735 bool noAlarm = true; 751 bool noAlarm = true;
736 if ( event->alarms().count() > 0 ) { 752 if ( event->alarms().count() > 0 ) {
737 Alarm * al = event->alarms().first(); 753 Alarm * al = event->alarms().first();
738 if ( al->enabled() ) { 754 if ( al->enabled() ) {
739 noAlarm = false; 755 noAlarm = false;
740 list.append( "0" ); // yes, 0 == alarm 756 list.append( "0" ); // yes, 0 == alarm
741 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 757 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
742 if ( al->type() == Alarm::Audio ) 758 if ( al->type() == Alarm::Audio )
743 list.append( "1" ); // type audio 759 list.append( "1" ); // type audio
744 else 760 else
745 list.append( "0" ); // type silent 761 list.append( "0" ); // type silent
746 } 762 }
747 } 763 }
748 if ( noAlarm ) { 764 if ( noAlarm ) {
749 list.append( "1" ); // yes, 1 == no alarm 765 list.append( "1" ); // yes, 1 == no alarm
750 list.append( "0" ); // no alarm offset 766 list.append( "0" ); // no alarm offset
751 list.append( "1" ); // type 767 list.append( "1" ); // type
752 } 768 }
753 // next is: 11 769 // next is: 11
754 // next is: 11-16 are recurrence 770 // next is: 11-16 are recurrence
755 Recurrence* rec = event->recurrence(); 771 Recurrence* rec = event->recurrence();
756 772
757 bool writeEndDate = false; 773 bool writeEndDate = false;
758 switch ( rec->doesRecur() ) 774 switch ( rec->doesRecur() )
759 { 775 {
760 case Recurrence::rDaily: // 0 776 case Recurrence::rDaily: // 0
761 list.append( "0" ); 777 list.append( "0" );
762 list.append( QString::number( rec->frequency() ));//12 778 list.append( QString::number( rec->frequency() ));//12
763 list.append( "0" ); 779 list.append( "0" );
764 list.append( "0" ); 780 list.append( "0" );
765 writeEndDate = true; 781 writeEndDate = true;
766 break; 782 break;
767 case Recurrence::rWeekly:// 1 783 case Recurrence::rWeekly:// 1
768 list.append( "1" ); 784 list.append( "1" );
769 list.append( QString::number( rec->frequency()) );//12 785 list.append( QString::number( rec->frequency()) );//12
770 list.append( "0" ); 786 list.append( "0" );
771 { 787 {
772 int days = 0; 788 int days = 0;
773 QBitArray weekDays = rec->days(); 789 QBitArray weekDays = rec->days();
774 int i; 790 int i;
775 for( i = 1; i <= 7; ++i ) { 791 for( i = 1; i <= 7; ++i ) {
776 if ( weekDays[i-1] ) { 792 if ( weekDays[i-1] ) {
777 days += 1 << (i-1); 793 days += 1 << (i-1);
778 } 794 }
779 } 795 }
780 list.append( QString::number( days ) ); 796 list.append( QString::number( days ) );
781 } 797 }
782 //pending weekdays 798 //pending weekdays
783 writeEndDate = true; 799 writeEndDate = true;
784 800
785 break; 801 break;
786 case Recurrence::rMonthlyPos:// 2 802 case Recurrence::rMonthlyPos:// 2
787 list.append( "2" ); 803 list.append( "2" );
788 list.append( QString::number( rec->frequency()) );//12 804 list.append( QString::number( rec->frequency()) );//12
789 805
790 writeEndDate = true; 806 writeEndDate = true;
791 { 807 {