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