-rw-r--r-- | libkcal/phoneformat.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 3555dc6..281434e 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -235,131 +235,129 @@ ulong PhoneFormat::getCsumEvent( Event* event ) | |||
235 | list.append( QString() ); | 235 | list.append( QString() ); |
236 | list.append( "0" ); | 236 | list.append( "0" ); |
237 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
238 | break; | 238 | break; |
239 | } | 239 | } |
240 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
241 | 241 | ||
242 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
243 | list.append( "1" ); | 243 | list.append( "1" ); |
244 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
245 | } else { | 245 | } else { |
246 | list.append( "0" ); | 246 | list.append( "0" ); |
247 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
248 | } | 248 | } |
249 | 249 | ||
250 | } | 250 | } |
251 | attList << list.join(""); | 251 | attList << list.join(""); |
252 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
254 | 254 | ||
255 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
256 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
257 | } | 257 | } |
258 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
259 | { | 259 | { |
260 | int max = attList.count(); | 260 | int max = attList.count(); |
261 | ulong cSum = 0; | 261 | ulong cSum = 0; |
262 | int j,k,i; | 262 | int j,k,i; |
263 | int add; | 263 | int add; |
264 | for ( i = 0; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
265 | QString s = attList[i]; | 265 | QString s = attList[i]; |
266 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
267 | j = s.length(); | 267 | j = s.length(); |
268 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
269 | int mul = k +1; | 269 | int mul = k +1; |
270 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
271 | if ( k < 16 ) | 271 | if ( k < 16 ) |
272 | mul = mul * mul; | 272 | mul = mul * mul; |
273 | int ii = i+1; | 273 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | 274 | add = add * mul *ii*ii*ii; |
275 | cSum += add; | 275 | cSum += add; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | } | 279 | } |
280 | //QString dump = attList.join(","); | 280 | //QString dump = attList.join(","); |
281 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 281 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
282 | 282 | ||
283 | return cSum; | 283 | return cSum; |
284 | 284 | ||
285 | } | 285 | } |
286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
287 | #include <stdlib.h> | 287 | #include <stdlib.h> |
288 | #define DEBUGMODE false | 288 | #define DEBUGMODE false |
289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
290 | { | 290 | { |
291 | 291 | ||
292 | QString fileName; | 292 | QString fileName; |
293 | #ifdef _WIN32_ | 293 | #ifdef _WIN32_ |
294 | fileName = locateLocal("tmp", "phonefile.vcs"); | 294 | fileName = locateLocal("tmp", "phonefile.vcs"); |
295 | #else | 295 | #else |
296 | fileName = "/tmp/phonefile.vcs"; | 296 | fileName = "/tmp/phonefile.vcs"; |
297 | #endif | 297 | #endif |
298 | QString command; | 298 | QString command; |
299 | int ret = PhoneAccess::readFromPhone( fileName ); | 299 | if ( ! PhoneAccess::readFromPhone( fileName )) { |
300 | if ( ret != 0 ) { | ||
301 | qDebug("Error::command returned %d", ret); | ||
302 | return false; | 300 | return false; |
303 | } | 301 | } |
304 | VCalFormat vfload; | 302 | VCalFormat vfload; |
305 | vfload.setLocalTime ( true ); | 303 | vfload.setLocalTime ( true ); |
306 | qDebug("loading file ..."); | 304 | qDebug("loading file ..."); |
307 | 305 | ||
308 | if ( ! vfload.load( calendar, fileName ) ) | 306 | if ( ! vfload.load( calendar, fileName ) ) |
309 | return false; | 307 | return false; |
310 | QPtrList<Event> er = calendar->rawEvents(); | 308 | QPtrList<Event> er = calendar->rawEvents(); |
311 | Event* ev = er.first(); | 309 | Event* ev = er.first(); |
312 | qDebug("reading events... "); | 310 | qDebug("reading events... "); |
313 | while ( ev ) { | 311 | while ( ev ) { |
314 | QStringList cat = ev->categories(); | 312 | QStringList cat = ev->categories(); |
315 | if ( cat.contains( "MeetingDEF" )) { | 313 | if ( cat.contains( "MeetingDEF" )) { |
316 | ev->setCategories( QStringList() ); | 314 | ev->setCategories( QStringList() ); |
317 | } | 315 | } |
318 | int id = ev->pilotId(); | 316 | int id = ev->pilotId(); |
319 | Event *event; | 317 | Event *event; |
320 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 318 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
321 | if ( event ) { | 319 | if ( event ) { |
322 | event = (Event*)event->clone(); | 320 | event = (Event*)event->clone(); |
323 | copyEvent( event, ev ); | 321 | copyEvent( event, ev ); |
324 | calendar->deleteEvent( ev ); | 322 | calendar->deleteEvent( ev ); |
325 | calendar->addEvent( event); | 323 | calendar->addEvent( event); |
326 | } | 324 | } |
327 | else | 325 | else |
328 | event = ev; | 326 | event = ev; |
329 | uint cSum; | 327 | uint cSum; |
330 | cSum = PhoneFormat::getCsumEvent( event ); | 328 | cSum = PhoneFormat::getCsumEvent( event ); |
331 | event->setCsum( mProfileName, QString::number( cSum )); | 329 | event->setCsum( mProfileName, QString::number( cSum )); |
332 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 330 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
333 | event->setID( mProfileName,QString::number( id ) ); | 331 | event->setID( mProfileName,QString::number( id ) ); |
334 | ev = er.next(); | 332 | ev = er.next(); |
335 | } | 333 | } |
336 | { | 334 | { |
337 | qDebug("reading todos... "); | 335 | qDebug("reading todos... "); |
338 | QPtrList<Todo> tr = calendar->rawTodos(); | 336 | QPtrList<Todo> tr = calendar->rawTodos(); |
339 | Todo* ev = tr.first(); | 337 | Todo* ev = tr.first(); |
340 | while ( ev ) { | 338 | while ( ev ) { |
341 | 339 | ||
342 | QStringList cat = ev->categories(); | 340 | QStringList cat = ev->categories(); |
343 | if ( cat.contains( "MeetingDEF" )) { | 341 | if ( cat.contains( "MeetingDEF" )) { |
344 | ev->setCategories( QStringList() ); | 342 | ev->setCategories( QStringList() ); |
345 | } | 343 | } |
346 | int id = ev->pilotId(); | 344 | int id = ev->pilotId(); |
347 | Todo *event; | 345 | Todo *event; |
348 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 346 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
349 | if ( event ) { | 347 | if ( event ) { |
350 | //qDebug("copy todo %s ", event->summary().latin1()); | 348 | //qDebug("copy todo %s ", event->summary().latin1()); |
351 | 349 | ||
352 | event = (Todo*)event->clone(); | 350 | event = (Todo*)event->clone(); |
353 | copyTodo( event, ev ); | 351 | copyTodo( event, ev ); |
354 | calendar->deleteTodo( ev ); | 352 | calendar->deleteTodo( ev ); |
355 | calendar->addTodo( event); | 353 | calendar->addTodo( event); |
356 | } | 354 | } |
357 | else | 355 | else |
358 | event = ev; | 356 | event = ev; |
359 | uint cSum; | 357 | uint cSum; |
360 | cSum = PhoneFormat::getCsumTodo( event ); | 358 | cSum = PhoneFormat::getCsumTodo( event ); |
361 | event->setCsum( mProfileName, QString::number( cSum )); | 359 | event->setCsum( mProfileName, QString::number( cSum )); |
362 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 360 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
363 | event->setID( mProfileName,QString::number( id ) ); | 361 | event->setID( mProfileName,QString::number( id ) ); |
364 | ev = tr.next(); | 362 | ev = tr.next(); |
365 | } | 363 | } |
@@ -426,130 +424,133 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from ) | |||
426 | Alarm *a = from->alarms().first(); | 424 | Alarm *a = from->alarms().first(); |
427 | Alarm *b = to->newAlarm( ); | 425 | Alarm *b = to->newAlarm( ); |
428 | b->setEnabled( a->enabled() ); | 426 | b->setEnabled( a->enabled() ); |
429 | if ( a->hasStartOffset() ) | 427 | if ( a->hasStartOffset() ) |
430 | b->setStartOffset( a->startOffset() ); | 428 | b->setStartOffset( a->startOffset() ); |
431 | if ( a->hasTime() ) | 429 | if ( a->hasTime() ) |
432 | b->setTime( a->time() ); | 430 | b->setTime( a->time() ); |
433 | } | 431 | } |
434 | 432 | ||
435 | QStringList cat = to->categories(); | 433 | QStringList cat = to->categories(); |
436 | QStringList catFrom = from->categories(); | 434 | QStringList catFrom = from->categories(); |
437 | QString nCat; | 435 | QString nCat; |
438 | int iii; | 436 | int iii; |
439 | for ( iii = 0; iii < catFrom.count();++iii ) { | 437 | for ( iii = 0; iii < catFrom.count();++iii ) { |
440 | nCat = catFrom[iii]; | 438 | nCat = catFrom[iii]; |
441 | if ( !nCat.isEmpty() ) | 439 | if ( !nCat.isEmpty() ) |
442 | if ( !cat.contains( nCat )) { | 440 | if ( !cat.contains( nCat )) { |
443 | cat << nCat; | 441 | cat << nCat; |
444 | } | 442 | } |
445 | } | 443 | } |
446 | to->setCategories( cat ); | 444 | to->setCategories( cat ); |
447 | if ( from->isCompleted() ) { | 445 | if ( from->isCompleted() ) { |
448 | to->setCompleted( true ); | 446 | to->setCompleted( true ); |
449 | if( from->completed().isValid() ) | 447 | if( from->completed().isValid() ) |
450 | to->setCompleted( from->completed() ); | 448 | to->setCompleted( from->completed() ); |
451 | } else { | 449 | } else { |
452 | // set percentcomplete only, if to->isCompleted() | 450 | // set percentcomplete only, if to->isCompleted() |
453 | if ( to->isCompleted() ) | 451 | if ( to->isCompleted() ) |
454 | to->setPercentComplete(from->percentComplete()); | 452 | to->setPercentComplete(from->percentComplete()); |
455 | } | 453 | } |
456 | if( to->priority() == 2 && from->priority() == 1 ) | 454 | if( to->priority() == 2 && from->priority() == 1 ) |
457 | ; //skip | 455 | ; //skip |
458 | else if (to->priority() == 4 && from->priority() == 5 ) | 456 | else if (to->priority() == 4 && from->priority() == 5 ) |
459 | ; | 457 | ; |
460 | else | 458 | else |
461 | to->setPriority(from->priority()); | 459 | to->setPriority(from->priority()); |
462 | 460 | ||
463 | } | 461 | } |
464 | #include <qcstring.h> | 462 | #include <qcstring.h> |
465 | 463 | ||
466 | void PhoneFormat::afterSave( Incidence* inc) | 464 | void PhoneFormat::afterSave( Incidence* inc) |
467 | { | 465 | { |
468 | uint csum; | 466 | uint csum; |
469 | inc->removeID( mProfileName ); | 467 | inc->removeID( mProfileName ); |
470 | if ( inc->type() == "Event") | 468 | if ( inc->type() == "Event") |
471 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 469 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
472 | else | 470 | else |
473 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 471 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
474 | inc->setCsum( mProfileName, QString::number( csum )); | 472 | inc->setCsum( mProfileName, QString::number( csum )); |
475 | 473 | ||
476 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
477 | 475 | ||
478 | } | 476 | } |
479 | 477 | ||
480 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 478 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
481 | { | 479 | { |
482 | #ifdef _WIN32_ | 480 | #ifdef _WIN32_ |
483 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | 481 | QString fileName = locateLocal("tmp", "tempfile.vcs"); |
484 | #else | 482 | #else |
485 | QString fileName = "/tmp/kdepimtemp.vcs"; | 483 | QString fileName = "/tmp/kdepimtemp.vcs"; |
486 | #endif | 484 | #endif |
487 | 485 | ||
488 | VCalFormat vfsave; | 486 | VCalFormat vfsave; |
489 | vfsave.setLocalTime ( true ); | 487 | vfsave.setLocalTime ( true ); |
488 | QString id = calendar->timeZoneId(); | ||
489 | calendar->setLocalTime(); | ||
490 | if ( ! vfsave.save( calendar, fileName ) ) | 490 | if ( ! vfsave.save( calendar, fileName ) ) |
491 | return false; | 491 | return false; |
492 | calendar->setTimeZoneId( id ); | ||
492 | return PhoneAccess::writeToPhone( fileName ); | 493 | return PhoneAccess::writeToPhone( fileName ); |
493 | } | 494 | } |
494 | bool PhoneFormat::save( Calendar *calendar) | 495 | bool PhoneFormat::save( Calendar *calendar) |
495 | { | 496 | { |
496 | QLabel status ( i18n(" Opening device ..."), 0 ); | 497 | QLabel status ( i18n(" Opening device ..."), 0 ); |
497 | int w = status.sizeHint().width()+20 ; | 498 | int w = status.sizeHint().width()+20 ; |
498 | if ( w < 200 ) w = 230; | 499 | if ( w < 200 ) w = 230; |
499 | int h = status.sizeHint().height()+20 ; | 500 | int h = status.sizeHint().height()+20 ; |
500 | int dw = QApplication::desktop()->width(); | 501 | int dw = QApplication::desktop()->width(); |
501 | int dh = QApplication::desktop()->height(); | 502 | int dh = QApplication::desktop()->height(); |
502 | status.setCaption(i18n("Writing to phone...") ); | 503 | status.setCaption(i18n("Writing to phone...") ); |
503 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 504 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
504 | status.show(); | 505 | status.show(); |
505 | status.raise(); | 506 | status.raise(); |
506 | qApp->processEvents(); | 507 | qApp->processEvents(); |
507 | QString message; | 508 | QString message; |
508 | 509 | ||
509 | // 1 remove events which should be deleted | 510 | // 1 remove events which should be deleted |
510 | QPtrList<Event> er = calendar->rawEvents(); | 511 | QPtrList<Event> er = calendar->rawEvents(); |
511 | Event* ev = er.first(); | 512 | Event* ev = er.first(); |
512 | while ( ev ) { | 513 | while ( ev ) { |
513 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 514 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
514 | calendar->deleteEvent( ev ); | 515 | calendar->deleteEvent( ev ); |
515 | } else { | 516 | } else { |
516 | 517 | ||
517 | } | 518 | } |
518 | ev = er.next(); | 519 | ev = er.next(); |
519 | } | 520 | } |
520 | // 2 remove todos which should be deleted | 521 | // 2 remove todos which should be deleted |
521 | QPtrList<Todo> tl = calendar->rawTodos(); | 522 | QPtrList<Todo> tl = calendar->rawTodos(); |
522 | Todo* to = tl.first(); | 523 | Todo* to = tl.first(); |
523 | while ( to ) { | 524 | while ( to ) { |
524 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 525 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
525 | calendar->deleteTodo( to ); | 526 | calendar->deleteTodo( to ); |
526 | } else { | 527 | } else { |
527 | if ( to->isCompleted()) { | 528 | if ( to->isCompleted()) { |
528 | calendar->deleteTodo( to ); | 529 | calendar->deleteTodo( to ); |
529 | } | 530 | } |
530 | } | 531 | } |
531 | to = tl.next(); | 532 | to = tl.next(); |
532 | } | 533 | } |
533 | // 3 save file | 534 | // 3 save file |
534 | if ( !writeToPhone( calendar ) ) | 535 | if ( !writeToPhone( calendar ) ) |
535 | return false; | 536 | return false; |
536 | 537 | ||
537 | // 5 reread data | 538 | // 5 reread data |
538 | message = i18n(" Rereading all data ... "); | 539 | message = i18n(" Rereading all data ... "); |
539 | status.setText ( message ); | 540 | status.setText ( message ); |
540 | qApp->processEvents(); | 541 | qApp->processEvents(); |
541 | CalendarLocal* calendarTemp = new CalendarLocal(); | 542 | CalendarLocal* calendarTemp = new CalendarLocal(); |
542 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
543 | if ( ! load( calendarTemp,calendar) ){ | 544 | if ( ! load( calendarTemp,calendar) ){ |
544 | qDebug("error reloading calendar "); | 545 | qDebug("error reloading calendar "); |
545 | delete calendarTemp; | 546 | delete calendarTemp; |
546 | return false; | 547 | return false; |
547 | } | 548 | } |
548 | // 6 compare data | 549 | // 6 compare data |
549 | 550 | ||
550 | //algo 6 compare event | 551 | //algo 6 compare event |
551 | er = calendar->rawEvents(); | 552 | er = calendar->rawEvents(); |
552 | ev = er.first(); | 553 | ev = er.first(); |
553 | message = i18n(" Comparing event # "); | 554 | message = i18n(" Comparing event # "); |
554 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 555 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
555 | Event* ev1; | 556 | Event* ev1; |