-rw-r--r-- | gammu/emb/common/service/gsmcal.c | 4 | ||||
-rw-r--r-- | gammu/emb/gammu/gammu.c | 6 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 42 |
3 files changed, 36 insertions, 16 deletions
diff --git a/gammu/emb/common/service/gsmcal.c b/gammu/emb/common/service/gsmcal.c index ddf9790..0ea8e06 100644 --- a/gammu/emb/common/service/gsmcal.c +++ b/gammu/emb/common/service/gsmcal.c | |||
@@ -349,164 +349,164 @@ GSM_Error GSM_EncodeVTODO(char *Buffer, int *Length, GSM_ToDoEntry *note, bool h | |||
349 | 349 | ||
350 | if (header) { | 350 | if (header) { |
351 | *Length+=sprintf(Buffer+(*Length), "END:VCALENDAR%c%c",13,10); | 351 | *Length+=sprintf(Buffer+(*Length), "END:VCALENDAR%c%c",13,10); |
352 | } | 352 | } |
353 | return ERR_NONE; | 353 | return ERR_NONE; |
354 | } | 354 | } |
355 | 355 | ||
356 | GSM_Error GSM_DecodeVCALENDAR_VTODO(unsigned char *Buffer, int *Pos, GSM_CalendarEntry *Calendar, GSM_ToDoEntry *ToDo, GSM_VCalendarVersion CalVer, GSM_VToDoVersion ToDoVer) | 356 | GSM_Error GSM_DecodeVCALENDAR_VTODO(unsigned char *Buffer, int *Pos, GSM_CalendarEntry *Calendar, GSM_ToDoEntry *ToDo, GSM_VCalendarVersion CalVer, GSM_VToDoVersion ToDoVer) |
357 | { | 357 | { |
358 | unsigned char Line[2000],Buff[2000]; | 358 | unsigned char Line[2000],Buff[2000]; |
359 | int Level = 0; | 359 | int Level = 0; |
360 | 360 | ||
361 | Calendar->EntriesNum = 0; | 361 | Calendar->EntriesNum = 0; |
362 | ToDo->EntriesNum = 0; | 362 | ToDo->EntriesNum = 0; |
363 | 363 | ||
364 | while (1) { | 364 | while (1) { |
365 | MyGetLine(Buffer, Pos, Line, strlen(Buffer)); | 365 | MyGetLine(Buffer, Pos, Line, strlen(Buffer)); |
366 | if (strlen(Line) == 0) break; | 366 | if (strlen(Line) == 0) break; |
367 | switch (Level) { | 367 | switch (Level) { |
368 | case 0: | 368 | case 0: |
369 | if (strstr(Line,"BEGIN:VEVENT")) { | 369 | if (strstr(Line,"BEGIN:VEVENT")) { |
370 | Calendar->Type = GSM_CAL_MEMO; | 370 | Calendar->Type = GSM_CAL_MEMO; |
371 | Level = 1; | 371 | Level = 1; |
372 | } | 372 | } |
373 | if (strstr(Line,"BEGIN:VTODO")) { | 373 | if (strstr(Line,"BEGIN:VTODO")) { |
374 | ToDo->Priority = GSM_Priority_Medium; | 374 | ToDo->Priority = GSM_Priority_Medium; |
375 | Level = 2; | 375 | Level = 2; |
376 | } | 376 | } |
377 | break; | 377 | break; |
378 | case 1: /* Calendar note */ | 378 | case 1: /* Calendar note */ |
379 | if (strstr(Line,"END:VEVENT")) { | 379 | if (strstr(Line,"END:VEVENT")) { |
380 | if (Calendar->EntriesNum == 0) return ERR_EMPTY; | 380 | if (Calendar->EntriesNum == 0) return ERR_EMPTY; |
381 | return ERR_NONE; | 381 | return ERR_NONE; |
382 | } | 382 | } |
383 | Calendar->Type = GSM_CAL_MEETING; | 383 | Calendar->Type = GSM_CAL_MEETING; |
384 | if (strstr(Line,"CATEGORIES:Reminder")) Calendar->Type = GSM_CAL_REMINDER; | 384 | if (strstr(Line,"CATEGORIES:Reminder")) Calendar->Type = GSM_CAL_REMINDER; |
385 | if (strstr(Line,"CATEGORIES:Date")) Calendar->Type = GSM_CAL_REMINDER;//SE | 385 | if (strstr(Line,"CATEGORIES:Date")) Calendar->Type = GSM_CAL_REMINDER;//SE |
386 | if (strstr(Line,"CATEGORIES:Travel")) Calendar->Type = GSM_CAL_TRAVEL; //SE | 386 | if (strstr(Line,"CATEGORIES:Travel")) Calendar->Type = GSM_CAL_TRAVEL; //SE |
387 | if (strstr(Line,"CATEGORIES:Vacation")) Calendar->Type = GSM_CAL_VACATION;//SE | 387 | if (strstr(Line,"CATEGORIES:Vacation")) Calendar->Type = GSM_CAL_VACATION;//SE |
388 | if (strstr(Line,"CATEGORIES:Miscellaneous")) Calendar->Type = GSM_CAL_MEMO; | 388 | if (strstr(Line,"CATEGORIES:Miscellaneous")) Calendar->Type = GSM_CAL_MEMO; |
389 | if (strstr(Line,"CATEGORIES:Phone Call")) Calendar->Type = GSM_CAL_CALL; | 389 | if (strstr(Line,"CATEGORIES:Phone Call")) Calendar->Type = GSM_CAL_CALL; |
390 | if (strstr(Line,"CATEGORIES:Special Occasion")) Calendar->Type = GSM_CAL_BIRTHDAY; | 390 | if (strstr(Line,"CATEGORIES:Special Occasion")) Calendar->Type = GSM_CAL_BIRTHDAY; |
391 | if (strstr(Line,"CATEGORIES:Anniversary")) Calendar->Type = GSM_CAL_BIRTHDAY; | 391 | if (strstr(Line,"CATEGORIES:Anniversary")) Calendar->Type = GSM_CAL_BIRTHDAY; |
392 | if (strstr(Line,"CATEGORIES:Meeting")) Calendar->Type = GSM_CAL_MEETING; | 392 | if (strstr(Line,"CATEGORIES:Meeting")) Calendar->Type = GSM_CAL_MEETING; |
393 | if (strstr(Line,"CATEGORIES:Appointment")) Calendar->Type = GSM_CAL_MEETING; | 393 | if (strstr(Line,"CATEGORIES:Appointment")) Calendar->Type = GSM_CAL_MEETING; |
394 | if (strstr(Line,"RRULE:D1")) { | 394 | if (strstr(Line,"RRULE:D1")) { |
395 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; | 395 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; |
396 | Calendar->Entries[Calendar->EntriesNum].Number = 1*24; | 396 | Calendar->Entries[Calendar->EntriesNum].Number = 1*24; |
397 | Calendar->EntriesNum++; | 397 | Calendar->EntriesNum++; |
398 | } | 398 | } |
399 | if ((strstr(Line,"RRULE:W1")) || (strstr(Line,"RRULE:D7"))) { | 399 | if ((strstr(Line,"RRULE:W1")) || (strstr(Line,"RRULE:D7"))) { |
400 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; | 400 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; |
401 | Calendar->Entries[Calendar->EntriesNum].Number = 7*24; | 401 | Calendar->Entries[Calendar->EntriesNum].Number = 7*24; |
402 | Calendar->EntriesNum++; | 402 | Calendar->EntriesNum++; |
403 | } | 403 | } |
404 | if (strstr(Line,"RRULE:W2")) { | 404 | if (strstr(Line,"RRULE:W2")) { |
405 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; | 405 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; |
406 | Calendar->Entries[Calendar->EntriesNum].Number = 14*24; | 406 | Calendar->Entries[Calendar->EntriesNum].Number = 14*24; |
407 | Calendar->EntriesNum++; | 407 | Calendar->EntriesNum++; |
408 | } | 408 | } |
409 | if (strstr(Line,"RRULE:MD1")) { | 409 | if (strstr(Line,"RRULE:MD1")) { |
410 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; | 410 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; |
411 | Calendar->Entries[Calendar->EntriesNum].Number = 30*24; | 411 | Calendar->Entries[Calendar->EntriesNum].Number = 30*24; |
412 | Calendar->EntriesNum++; | 412 | Calendar->EntriesNum++; |
413 | } | 413 | } |
414 | if (strstr(Line,"RRULE:YD1")) { | 414 | if (strstr(Line,"RRULE:YD1")) { |
415 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; | 415 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; |
416 | Calendar->Entries[Calendar->EntriesNum].Number = 365*24; | 416 | Calendar->Entries[Calendar->EntriesNum].Number = 365*24; |
417 | Calendar->EntriesNum++; | 417 | Calendar->EntriesNum++; |
418 | } | 418 | } |
419 | if ((ReadVCALText(Line, "SUMMARY", Buff)) || (ReadVCALText(Line, "DESCRIPTION", Buff))) { | 419 | if ((ReadVCALText(Line, "SUMMARY", Buff)) || (ReadVCALText(Line, "DESCRIPTION", Buff))) { |
420 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_TEXT; | 420 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_TEXT; |
421 | CopyUnicodeString(Calendar->Entries[Calendar->EntriesNum].Text,Buff); | 421 | CopyUnicodeString(Calendar->Entries[Calendar->EntriesNum].Text,Buff); |
422 | Calendar->EntriesNum++; | 422 | Calendar->EntriesNum++; |
423 | } | 423 | } |
424 | if (ReadVCALText(Line, "LOCATION", Buff)) { | 424 | if (ReadVCALText(Line, "LOCATION", Buff)) { |
425 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_LOCATION; | 425 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_LOCATION; |
426 | CopyUnicodeString(Calendar->Entries[Calendar->EntriesNum].Text,Buff); | 426 | CopyUnicodeString(Calendar->Entries[Calendar->EntriesNum].Text,Buff); |
427 | Calendar->EntriesNum++; | 427 | Calendar->EntriesNum++; |
428 | } | 428 | } |
429 | if (ReadVCALText(Line, "DTSTART", Buff)) { | 429 | if (ReadVCALText(Line, "DTSTART", Buff)) { |
430 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_START_DATETIME; | 430 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_START_DATETIME; |
431 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); | 431 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); |
432 | Calendar->EntriesNum++; | 432 | Calendar->EntriesNum++; |
433 | } | 433 | } |
434 | if (ReadVCALText(Line, "DTEND", Buff)) { | 434 | if (ReadVCALText(Line, "DTEND", Buff)) { |
435 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_END_DATETIME; | 435 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_END_DATETIME; |
436 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); | 436 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); |
437 | Calendar->EntriesNum++; | 437 | Calendar->EntriesNum++; |
438 | } | 438 | } |
439 | if (ReadVCALText(Line, "DALARM", Buff)) { | 439 | if (ReadVCALText(Line, "DALARM", Buff)) { |
440 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME; | 440 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME; |
441 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); | 441 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); |
442 | Calendar->EntriesNum++; | 442 | Calendar->EntriesNum++; |
443 | } | 443 | } |
444 | if (ReadVCALText(Line, "AALARM", Buff)) { | 444 | if (ReadVCALText(Line, "AALARM", Buff)) { |
445 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_ALARM_DATETIME; | 445 | Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_ALARM_DATETIME; |
446 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); | 446 | ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); |
447 | Calendar->EntriesNum++; | 447 | Calendar->EntriesNum++; |
448 | } | 448 | } |
449 | break; | 449 | break; |
450 | case 2: /* ToDo note */ | 450 | case 2: /* ToDo note */ |
451 | if (strstr(Line,"END:VTODO")) { | 451 | if (strstr(Line,"END:VTODO")) { |
452 | if (ToDo->EntriesNum == 0) return ERR_EMPTY; | 452 | if (ToDo->EntriesNum == 0) return ERR_EMPTY; |
453 | return ERR_NONE; | 453 | return ERR_NONE; |
454 | } | 454 | } |
455 | if (ReadVCALText(Line, "DUE", Buff)) { | 455 | if (ReadVCALText(Line, "DUE", Buff)) { |
456 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_END_DATETIME; | 456 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_END_DATETIME; |
457 | ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); | 457 | ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); |
458 | ToDo->EntriesNum++; | 458 | ToDo->EntriesNum++; |
459 | } | 459 | } |
460 | if (ReadVCALText(Line, "DALARM", Buff)) { | 460 | if (ReadVCALText(Line, "DALARM", Buff)) { |
461 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME; | 461 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME; |
462 | ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); | 462 | ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); |
463 | ToDo->EntriesNum++; | 463 | ToDo->EntriesNum++; |
464 | } | 464 | } |
465 | if (ReadVCALText(Line, "AALARM", Buff)) { | 465 | if (ReadVCALText(Line, "AALARM", Buff)) { |
466 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_ALARM_DATETIME; | 466 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_ALARM_DATETIME; |
467 | ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); | 467 | ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); |
468 | ToDo->EntriesNum++; | 468 | ToDo->EntriesNum++; |
469 | } | 469 | } |
470 | if (ReadVCALText(Line, "SUMMARY", Buff)) { | 470 | if (ReadVCALText(Line, "SUMMARY", Buff)) { |
471 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_TEXT; | 471 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_TEXT; |
472 | CopyUnicodeString(ToDo->Entries[ToDo->EntriesNum].Text,Buff); | 472 | CopyUnicodeString(ToDo->Entries[ToDo->EntriesNum].Text,Buff); |
473 | ToDo->EntriesNum++; | 473 | ToDo->EntriesNum++; |
474 | } | 474 | } |
475 | if (ReadVCALText(Line, "PRIORITY", Buff)) { | 475 | if (ReadVCALText(Line, "PRIORITY", Buff)) { |
476 | if (ToDoVer == SonyEricsson_VToDo) { | 476 | if (ToDoVer == SonyEricsson_VToDo) { |
477 | ToDo->Priority = GSM_Priority_Low; | 477 | ToDo->Priority = GSM_Priority_Medium; |
478 | if (atoi(DecodeUnicodeString(Buff))>3) ToDo->Priority = GSM_Priority_Low; | 478 | if (atoi(DecodeUnicodeString(Buff))>3) ToDo->Priority = GSM_Priority_Low; |
479 | if (atoi(DecodeUnicodeString(Buff))<3) ToDo->Priority = GSM_Priority_High; | 479 | if (atoi(DecodeUnicodeString(Buff))<3) ToDo->Priority = GSM_Priority_High; |
480 | dbgprintf("atoi is %i %s\n",atoi(DecodeUnicodeString(Buff)),DecodeUnicodeString(Buff)); | 480 | dbgprintf("atoi is %i %s\n",atoi(DecodeUnicodeString(Buff)),DecodeUnicodeString(Buff)); |
481 | } else if (ToDoVer == Nokia_VToDo) { | 481 | } else if (ToDoVer == Nokia_VToDo) { |
482 | ToDo->Priority = GSM_Priority_Low; | 482 | ToDo->Priority = GSM_Priority_Medium; |
483 | if (atoi(DecodeUnicodeString(Buff))>3) ToDo->Priority = GSM_Priority_Low; | 483 | if (atoi(DecodeUnicodeString(Buff))>3) ToDo->Priority = GSM_Priority_Low; |
484 | if (atoi(DecodeUnicodeString(Buff))<3) ToDo->Priority = GSM_Priority_High; | 484 | if (atoi(DecodeUnicodeString(Buff))<3) ToDo->Priority = GSM_Priority_High; |
485 | } | 485 | } |
486 | } | 486 | } |
487 | if (strstr(Line,"PERCENT-COMPLETE:100")) { | 487 | if (strstr(Line,"PERCENT-COMPLETE:100")) { |
488 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_COMPLETED; | 488 | ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_COMPLETED; |
489 | ToDo->Entries[ToDo->EntriesNum].Number = 1; | 489 | ToDo->Entries[ToDo->EntriesNum].Number = 1; |
490 | ToDo->EntriesNum++; | 490 | ToDo->EntriesNum++; |
491 | } | 491 | } |
492 | break; | 492 | break; |
493 | } | 493 | } |
494 | } | 494 | } |
495 | 495 | ||
496 | if (Calendar->EntriesNum == 0 && ToDo->EntriesNum == 0) return ERR_EMPTY; | 496 | if (Calendar->EntriesNum == 0 && ToDo->EntriesNum == 0) return ERR_EMPTY; |
497 | return ERR_NONE; | 497 | return ERR_NONE; |
498 | } | 498 | } |
499 | 499 | ||
500 | GSM_Error GSM_EncodeVNTFile(unsigned char *Buffer, int *Length, GSM_NoteEntry *Note) | 500 | GSM_Error GSM_EncodeVNTFile(unsigned char *Buffer, int *Length, GSM_NoteEntry *Note) |
501 | { | 501 | { |
502 | *Length+=sprintf(Buffer+(*Length), "BEGIN:VNOTE%c%c",13,10); | 502 | *Length+=sprintf(Buffer+(*Length), "BEGIN:VNOTE%c%c",13,10); |
503 | *Length+=sprintf(Buffer+(*Length), "VERSION:1.1%c%c",13,10); | 503 | *Length+=sprintf(Buffer+(*Length), "VERSION:1.1%c%c",13,10); |
504 | SaveVCALText(Buffer, Length, Note->Text, "BODY"); | 504 | SaveVCALText(Buffer, Length, Note->Text, "BODY"); |
505 | *Length+=sprintf(Buffer+(*Length), "END:VNOTE%c%c",13,10); | 505 | *Length+=sprintf(Buffer+(*Length), "END:VNOTE%c%c",13,10); |
506 | 506 | ||
507 | return ERR_NONE; | 507 | return ERR_NONE; |
508 | } | 508 | } |
509 | 509 | ||
510 | /* How should editor hadle tabs in this file? Add editor commands here. | 510 | /* How should editor hadle tabs in this file? Add editor commands here. |
511 | * vim: noexpandtab sw=8 ts=8 sts=8: | 511 | * vim: noexpandtab sw=8 ts=8 sts=8: |
512 | */ | 512 | */ |
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c index a3b93a8..997485a 100644 --- a/gammu/emb/gammu/gammu.c +++ b/gammu/emb/gammu/gammu.c | |||
@@ -4502,317 +4502,322 @@ static void Restore(int argc, char *argv[]) | |||
4502 | bool Found, DoRestore; | 4502 | bool Found, DoRestore; |
4503 | 4503 | ||
4504 | error=GSM_ReadBackupFile(argv[2],&Backup); | 4504 | error=GSM_ReadBackupFile(argv[2],&Backup); |
4505 | Print_Error(error); | 4505 | Print_Error(error); |
4506 | 4506 | ||
4507 | signal(SIGINT, interrupt); | 4507 | signal(SIGINT, interrupt); |
4508 | printmsgerr("Press Ctrl+C to break...\n"); | 4508 | printmsgerr("Press Ctrl+C to break...\n"); |
4509 | 4509 | ||
4510 | if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); | 4510 | if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); |
4511 | if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); | 4511 | if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); |
4512 | if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); | 4512 | if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); |
4513 | 4513 | ||
4514 | if (Backup.MD5Calculated[0]!=0) { | 4514 | if (Backup.MD5Calculated[0]!=0) { |
4515 | dbgprintf("\"%s\"\n",Backup.MD5Original); | 4515 | dbgprintf("\"%s\"\n",Backup.MD5Original); |
4516 | dbgprintf("\"%s\"\n",Backup.MD5Calculated); | 4516 | dbgprintf("\"%s\"\n",Backup.MD5Calculated); |
4517 | if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { | 4517 | if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { |
4518 | if (!answer_yes("Checksum in backup file do not match. Continue")) return; | 4518 | if (!answer_yes("Checksum in backup file do not match. Continue")) return; |
4519 | } | 4519 | } |
4520 | } | 4520 | } |
4521 | 4521 | ||
4522 | GSM_Init(true); | 4522 | GSM_Init(true); |
4523 | 4523 | ||
4524 | DoRestore = false; | 4524 | DoRestore = false; |
4525 | if (Backup.PhonePhonebook[0] != NULL) { | 4525 | if (Backup.PhonePhonebook[0] != NULL) { |
4526 | MemStatus.MemoryType = MEM_ME; | 4526 | MemStatus.MemoryType = MEM_ME; |
4527 | error=Phone->GetMemoryStatus(&s, &MemStatus); | 4527 | error=Phone->GetMemoryStatus(&s, &MemStatus); |
4528 | if (error==ERR_NONE) { | 4528 | if (error==ERR_NONE) { |
4529 | max = 0; | 4529 | max = 0; |
4530 | while (Backup.PhonePhonebook[max]!=NULL) max++; | 4530 | while (Backup.PhonePhonebook[max]!=NULL) max++; |
4531 | printmsgerr("%i entries in backup file\n",max); | 4531 | printmsgerr("%i entries in backup file\n",max); |
4532 | if (answer_yes("Restore phone phonebook")) DoRestore = true; | 4532 | if (answer_yes("Restore phone phonebook")) DoRestore = true; |
4533 | } | 4533 | } |
4534 | } | 4534 | } |
4535 | if (DoRestore) { | 4535 | if (DoRestore) { |
4536 | used = 0; | 4536 | used = 0; |
4537 | for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { | 4537 | for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { |
4538 | Pbk.MemoryType = MEM_ME; | 4538 | Pbk.MemoryType = MEM_ME; |
4539 | Pbk.Location= i + 1; | 4539 | Pbk.Location= i + 1; |
4540 | Pbk.EntriesNum= 0; | 4540 | Pbk.EntriesNum= 0; |
4541 | if (used<max) { | 4541 | if (used<max) { |
4542 | if (Backup.PhonePhonebook[used]->Location == Pbk.Location) { | 4542 | if (Backup.PhonePhonebook[used]->Location == Pbk.Location) { |
4543 | Pbk = *Backup.PhonePhonebook[used]; | 4543 | Pbk = *Backup.PhonePhonebook[used]; |
4544 | used++; | 4544 | used++; |
4545 | dbgprintf("Location %i\n",Pbk.Location); | 4545 | dbgprintf("Location %i\n",Pbk.Location); |
4546 | if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); | 4546 | if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); |
4547 | } | 4547 | } |
4548 | } | 4548 | } |
4549 | if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); | 4549 | if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); |
4550 | Print_Error(error); | 4550 | Print_Error(error); |
4551 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); | 4551 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); |
4552 | if (gshutdown) { | 4552 | if (gshutdown) { |
4553 | GSM_Terminate(); | 4553 | GSM_Terminate(); |
4554 | exit(0); | 4554 | exit(0); |
4555 | } | 4555 | } |
4556 | } | 4556 | } |
4557 | printmsgerr("\n"); | 4557 | printmsgerr("\n"); |
4558 | } | 4558 | } |
4559 | 4559 | ||
4560 | DoRestore = false; | 4560 | DoRestore = false; |
4561 | if (Backup.SIMPhonebook[0] != NULL) { | 4561 | if (Backup.SIMPhonebook[0] != NULL) { |
4562 | MemStatus.MemoryType = MEM_SM; | 4562 | MemStatus.MemoryType = MEM_SM; |
4563 | error=Phone->GetMemoryStatus(&s, &MemStatus); | 4563 | error=Phone->GetMemoryStatus(&s, &MemStatus); |
4564 | if (error==ERR_NONE) { | 4564 | if (error==ERR_NONE) { |
4565 | max = 0; | 4565 | max = 0; |
4566 | while (Backup.SIMPhonebook[max]!=NULL) max++; | 4566 | while (Backup.SIMPhonebook[max]!=NULL) max++; |
4567 | printmsgerr("%i entries in backup file\n",max); | 4567 | printmsgerr("%i entries in backup file\n",max); |
4568 | if (answer_yes("Restore SIM phonebook")) DoRestore = true; | 4568 | if (answer_yes("Restore SIM phonebook")) DoRestore = true; |
4569 | } | 4569 | } |
4570 | } | 4570 | } |
4571 | if (DoRestore) { | 4571 | if (DoRestore) { |
4572 | used = 0; | 4572 | used = 0; |
4573 | for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { | 4573 | for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { |
4574 | Pbk.MemoryType = MEM_SM; | 4574 | Pbk.MemoryType = MEM_SM; |
4575 | Pbk.Location= i + 1; | 4575 | Pbk.Location= i + 1; |
4576 | Pbk.EntriesNum= 0; | 4576 | Pbk.EntriesNum= 0; |
4577 | if (used<max) { | 4577 | if (used<max) { |
4578 | if (Backup.SIMPhonebook[used]->Location == Pbk.Location) { | 4578 | if (Backup.SIMPhonebook[used]->Location == Pbk.Location) { |
4579 | Pbk = *Backup.SIMPhonebook[used]; | 4579 | Pbk = *Backup.SIMPhonebook[used]; |
4580 | used++; | 4580 | used++; |
4581 | dbgprintf("Location %i\n",Pbk.Location); | 4581 | dbgprintf("Location %i\n",Pbk.Location); |
4582 | if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); | 4582 | if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); |
4583 | } | 4583 | } |
4584 | } | 4584 | } |
4585 | if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); | 4585 | if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); |
4586 | Print_Error(error); | 4586 | Print_Error(error); |
4587 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); | 4587 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); |
4588 | if (gshutdown) { | 4588 | if (gshutdown) { |
4589 | GSM_Terminate(); | 4589 | GSM_Terminate(); |
4590 | exit(0); | 4590 | exit(0); |
4591 | } | 4591 | } |
4592 | } | 4592 | } |
4593 | printmsgerr("\n"); | 4593 | printmsgerr("\n"); |
4594 | } | 4594 | } |
4595 | 4595 | ||
4596 | DoRestore = false; | 4596 | DoRestore = false; |
4597 | if (Backup.CallerLogos[0] != NULL) { | 4597 | if (Backup.CallerLogos[0] != NULL) { |
4598 | Bitmap.Type = GSM_CallerGroupLogo; | 4598 | Bitmap.Type = GSM_CallerGroupLogo; |
4599 | Bitmap.Location = 1; | 4599 | Bitmap.Location = 1; |
4600 | error=Phone->GetBitmap(&s,&Bitmap); | 4600 | error=Phone->GetBitmap(&s,&Bitmap); |
4601 | if (error == ERR_NONE) { | 4601 | if (error == ERR_NONE) { |
4602 | if (answer_yes("Restore caller groups and logos")) DoRestore = true; | 4602 | if (answer_yes("Restore caller groups and logos")) DoRestore = true; |
4603 | } | 4603 | } |
4604 | } | 4604 | } |
4605 | if (DoRestore) { | 4605 | if (DoRestore) { |
4606 | max = 0; | 4606 | max = 0; |
4607 | while (Backup.CallerLogos[max]!=NULL) max++; | 4607 | while (Backup.CallerLogos[max]!=NULL) max++; |
4608 | for (i=0;i<max;i++) { | 4608 | for (i=0;i<max;i++) { |
4609 | error=Phone->SetBitmap(&s,Backup.CallerLogos[i]); | 4609 | error=Phone->SetBitmap(&s,Backup.CallerLogos[i]); |
4610 | Print_Error(error); | 4610 | Print_Error(error); |
4611 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); | 4611 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); |
4612 | if (gshutdown) { | 4612 | if (gshutdown) { |
4613 | GSM_Terminate(); | 4613 | GSM_Terminate(); |
4614 | exit(0); | 4614 | exit(0); |
4615 | } | 4615 | } |
4616 | } | 4616 | } |
4617 | printmsgerr("\n"); | 4617 | printmsgerr("\n"); |
4618 | } | 4618 | } |
4619 | 4619 | ||
4620 | if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { | 4620 | if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { |
4621 | if (/*answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/ true ) { | 4621 | if (/*answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/ true ) { |
4622 | GSM_GetCurrentDateTime(&date_time); | 4622 | GSM_GetCurrentDateTime(&date_time); |
4623 | 4623 | ||
4624 | error=Phone->SetDateTime(&s, &date_time); | 4624 | error=Phone->SetDateTime(&s, &date_time); |
4625 | Print_Error(error); | 4625 | Print_Error(error); |
4626 | } | 4626 | } |
4627 | } | 4627 | } |
4628 | DoRestore = false; | 4628 | DoRestore = false; |
4629 | if (Backup.Calendar[0] != NULL) { | 4629 | if (Backup.Calendar[0] != NULL) { |
4630 | DoRestore = true; | ||
4630 | /* N6110 doesn't support getting calendar status */ | 4631 | /* N6110 doesn't support getting calendar status */ |
4631 | error = Phone->GetNextCalendar(&s,&Calendar,true); | 4632 | error = Phone->GetNextCalendar(&s,&Calendar,true); |
4632 | if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { | 4633 | if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { |
4633 | max = 0; | 4634 | max = 0; |
4634 | while (Backup.Calendar[max] != NULL) max++; | 4635 | while (Backup.Calendar[max] != NULL) max++; |
4635 | printmsgerr("%i entries in backup file\n",max); | 4636 | printmsgerr("%i entries in backup file\n",max); |
4636 | DoRestore = true; | 4637 | DoRestore = true; |
4637 | /* | 4638 | /* |
4638 | if (answer_yes("Restore calendar notes")) { | 4639 | if (answer_yes("Restore calendar notes")) { |
4639 | Past = answer_yes("Restore notes from the past"); | 4640 | Past = answer_yes("Restore notes from the past"); |
4640 | DoRestore = true; | 4641 | DoRestore = true; |
4641 | } | 4642 | } |
4642 | */ | 4643 | */ |
4643 | } | 4644 | } |
4644 | } | 4645 | } |
4645 | if (DoRestore) { | 4646 | if (DoRestore) { |
4646 | printmsgerr("Deleting old notes: "); | 4647 | printmsgerr("Deleting old notes: "); |
4647 | error = Phone->DeleteAllCalendar(&s); | 4648 | error = Phone->DeleteAllCalendar(&s); |
4648 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | 4649 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { |
4649 | while (1) { | 4650 | while (1) { |
4650 | error = Phone->GetNextCalendar(&s,&Calendar,true); | 4651 | error = Phone->GetNextCalendar(&s,&Calendar,true); |
4651 | if (error != ERR_NONE) break; | 4652 | if (error != ERR_NONE) break; |
4652 | error = Phone->DeleteCalendar(&s,&Calendar); | 4653 | error = Phone->DeleteCalendar(&s,&Calendar); |
4653 | Print_Error(error); | 4654 | Print_Error(error); |
4654 | printmsgerr("*"); | 4655 | printmsgerr("*"); |
4655 | } | 4656 | } |
4656 | printmsgerr("\n"); | 4657 | printmsgerr("\n"); |
4657 | } else { | 4658 | } else { |
4658 | printmsgerr("Done\n"); | 4659 | printmsgerr("Done\n"); |
4659 | Print_Error(error); | 4660 | Print_Error(error); |
4660 | } | 4661 | } |
4661 | 4662 | ||
4662 | for (i=0;i<max;i++) { | 4663 | for (i=0;i<max;i++) { |
4663 | if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue; | 4664 | if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue; |
4664 | 4665 | ||
4665 | Calendar = *Backup.Calendar[i]; | 4666 | Calendar = *Backup.Calendar[i]; |
4666 | error=Phone->AddCalendar(&s,&Calendar); | 4667 | error=Phone->AddCalendar(&s,&Calendar); |
4667 | Print_Error(error); | 4668 | Print_Error(error); |
4668 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); | 4669 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); |
4669 | if (gshutdown) { | 4670 | if (gshutdown) { |
4670 | GSM_Terminate(); | 4671 | GSM_Terminate(); |
4671 | exit(0); | 4672 | exit(0); |
4672 | } | 4673 | } |
4673 | } | 4674 | } |
4674 | printmsgerr("\n"); | 4675 | printmsgerr("\n"); |
4675 | } | 4676 | } |
4676 | 4677 | ||
4677 | DoRestore = false; | 4678 | DoRestore = false; |
4678 | if (Backup.ToDo[0] != NULL) { | 4679 | if (Backup.ToDo[0] != NULL) { |
4679 | error = Phone->GetToDoStatus(&s,&ToDoStatus); | 4680 | error = Phone->GetToDoStatus(&s,&ToDoStatus); |
4680 | if (error == ERR_NONE) { | 4681 | if (error == ERR_NONE) { |
4682 | error == ERR_NOTSUPPORTED; | ||
4683 | DoRestore = true; | ||
4681 | max = 0; | 4684 | max = 0; |
4682 | while (Backup.ToDo[max]!=NULL) max++; | 4685 | while (Backup.ToDo[max]!=NULL) max++; |
4683 | printmsgerr("%i entries in backup file\n",max); | 4686 | printmsgerr("%i entries in backup file\n",max); |
4684 | 4687 | ||
4685 | /*if (answer_yes("Restore ToDo")) */DoRestore = true; | 4688 | /*if (answer_yes("Restore ToDo")) */DoRestore = true; |
4686 | } | 4689 | } |
4687 | } | 4690 | } |
4688 | if (DoRestore) { | 4691 | if (DoRestore) { |
4692 | if ( max > 0 ) { | ||
4689 | ToDo = *Backup.ToDo[0]; | 4693 | ToDo = *Backup.ToDo[0]; |
4690 | error = Phone->SetToDo(&s,&ToDo); | 4694 | error = Phone->SetToDo(&s,&ToDo); |
4695 | } | ||
4691 | } | 4696 | } |
4692 | if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { | 4697 | if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { |
4693 | printmsgerr("Deleting old ToDo: "); | 4698 | printmsgerr("Deleting old ToDo: "); |
4694 | error=Phone->DeleteAllToDo(&s); | 4699 | error=Phone->DeleteAllToDo(&s); |
4695 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | 4700 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { |
4696 | while (1) { | 4701 | while (1) { |
4697 | error = Phone->GetNextToDo(&s,&ToDo,true); | 4702 | error = Phone->GetNextToDo(&s,&ToDo,true); |
4698 | if (error != ERR_NONE) break; | 4703 | if (error != ERR_NONE) break; |
4699 | error = Phone->DeleteToDo(&s,&ToDo); | 4704 | error = Phone->DeleteToDo(&s,&ToDo); |
4700 | Print_Error(error); | 4705 | Print_Error(error); |
4701 | printmsgerr("*"); | 4706 | printmsgerr("*"); |
4702 | } | 4707 | } |
4703 | printmsgerr("\n"); | 4708 | printmsgerr("\n"); |
4704 | } else { | 4709 | } else { |
4705 | printmsgerr("Done\n"); | 4710 | printmsgerr("Done\n"); |
4706 | Print_Error(error); | 4711 | Print_Error(error); |
4707 | } | 4712 | } |
4708 | 4713 | ||
4709 | for (i=0;i<max;i++) { | 4714 | for (i=0;i<max;i++) { |
4710 | ToDo = *Backup.ToDo[i]; | 4715 | ToDo = *Backup.ToDo[i]; |
4711 | ToDo.Location = 0; | 4716 | ToDo.Location = 0; |
4712 | error=Phone->AddToDo(&s,&ToDo); | 4717 | error=Phone->AddToDo(&s,&ToDo); |
4713 | Print_Error(error); | 4718 | Print_Error(error); |
4714 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); | 4719 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); |
4715 | if (gshutdown) { | 4720 | if (gshutdown) { |
4716 | GSM_Terminate(); | 4721 | GSM_Terminate(); |
4717 | exit(0); | 4722 | exit(0); |
4718 | } | 4723 | } |
4719 | } | 4724 | } |
4720 | printmsgerr("\n"); | 4725 | printmsgerr("\n"); |
4721 | } else if (DoRestore) { | 4726 | } else if (DoRestore) { |
4722 | /* At first delete entries, that were deleted */ | 4727 | /* At first delete entries, that were deleted */ |
4723 | used = 0; | 4728 | used = 0; |
4724 | error = Phone->GetNextToDo(&s,&ToDo,true); | 4729 | error = Phone->GetNextToDo(&s,&ToDo,true); |
4725 | while (error == ERR_NONE) { | 4730 | while (error == ERR_NONE) { |
4726 | used++; | 4731 | used++; |
4727 | Found = false; | 4732 | Found = false; |
4728 | for (i=0;i<max;i++) { | 4733 | for (i=0;i<max;i++) { |
4729 | if (Backup.ToDo[i]->Location == ToDo.Location) { | 4734 | if (Backup.ToDo[i]->Location == ToDo.Location) { |
4730 | Found = true; | 4735 | Found = true; |
4731 | break; | 4736 | break; |
4732 | } | 4737 | } |
4733 | } | 4738 | } |
4734 | if (!Found) { | 4739 | if (!Found) { |
4735 | error=Phone->DeleteToDo(&s,&ToDo); | 4740 | error=Phone->DeleteToDo(&s,&ToDo); |
4736 | Print_Error(error); | 4741 | Print_Error(error); |
4737 | } | 4742 | } |
4738 | error = Phone->GetNextToDo(&s,&ToDo,false); | 4743 | error = Phone->GetNextToDo(&s,&ToDo,false); |
4739 | printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used); | 4744 | printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used); |
4740 | if (gshutdown) { | 4745 | if (gshutdown) { |
4741 | GSM_Terminate(); | 4746 | GSM_Terminate(); |
4742 | exit(0); | 4747 | exit(0); |
4743 | } | 4748 | } |
4744 | } | 4749 | } |
4745 | printmsgerr("\n"); | 4750 | printmsgerr("\n"); |
4746 | 4751 | ||
4747 | /* Now write modified/new entries */ | 4752 | /* Now write modified/new entries */ |
4748 | for (i=0;i<max;i++) { | 4753 | for (i=0;i<max;i++) { |
4749 | ToDo = *Backup.ToDo[i]; | 4754 | ToDo = *Backup.ToDo[i]; |
4750 | error = Phone->SetToDo(&s,&ToDo); | 4755 | error = Phone->SetToDo(&s,&ToDo); |
4751 | Print_Error(error); | 4756 | Print_Error(error); |
4752 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); | 4757 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); |
4753 | if (gshutdown) { | 4758 | if (gshutdown) { |
4754 | GSM_Terminate(); | 4759 | GSM_Terminate(); |
4755 | exit(0); | 4760 | exit(0); |
4756 | } | 4761 | } |
4757 | } | 4762 | } |
4758 | printmsgerr("\n"); | 4763 | printmsgerr("\n"); |
4759 | } | 4764 | } |
4760 | 4765 | ||
4761 | if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) { | 4766 | if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) { |
4762 | max = 0; | 4767 | max = 0; |
4763 | while (Backup.SMSC[max]!=NULL) max++; | 4768 | while (Backup.SMSC[max]!=NULL) max++; |
4764 | for (i=0;i<max;i++) { | 4769 | for (i=0;i<max;i++) { |
4765 | error=Phone->SetSMSC(&s,Backup.SMSC[i]); | 4770 | error=Phone->SetSMSC(&s,Backup.SMSC[i]); |
4766 | Print_Error(error); | 4771 | Print_Error(error); |
4767 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); | 4772 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); |
4768 | if (gshutdown) { | 4773 | if (gshutdown) { |
4769 | GSM_Terminate(); | 4774 | GSM_Terminate(); |
4770 | exit(0); | 4775 | exit(0); |
4771 | } | 4776 | } |
4772 | } | 4777 | } |
4773 | printmsgerr("\n"); | 4778 | printmsgerr("\n"); |
4774 | } | 4779 | } |
4775 | if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) { | 4780 | if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) { |
4776 | error=Phone->SetBitmap(&s,Backup.StartupLogo); | 4781 | error=Phone->SetBitmap(&s,Backup.StartupLogo); |
4777 | Print_Error(error); | 4782 | Print_Error(error); |
4778 | } | 4783 | } |
4779 | if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) { | 4784 | if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) { |
4780 | error=Phone->SetBitmap(&s,Backup.OperatorLogo); | 4785 | error=Phone->SetBitmap(&s,Backup.OperatorLogo); |
4781 | Print_Error(error); | 4786 | Print_Error(error); |
4782 | } | 4787 | } |
4783 | DoRestore = false; | 4788 | DoRestore = false; |
4784 | if (Backup.WAPBookmark[0] != NULL) { | 4789 | if (Backup.WAPBookmark[0] != NULL) { |
4785 | Bookmark.Location = 1; | 4790 | Bookmark.Location = 1; |
4786 | error = Phone->GetWAPBookmark(&s,&Bookmark); | 4791 | error = Phone->GetWAPBookmark(&s,&Bookmark); |
4787 | if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { | 4792 | if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { |
4788 | if (answer_yes("Restore WAP bookmarks")) DoRestore = true; | 4793 | if (answer_yes("Restore WAP bookmarks")) DoRestore = true; |
4789 | } | 4794 | } |
4790 | } | 4795 | } |
4791 | if (DoRestore) { | 4796 | if (DoRestore) { |
4792 | printmsgerr("Deleting old bookmarks: "); | 4797 | printmsgerr("Deleting old bookmarks: "); |
4793 | /* One thing to explain: DCT4 phones seems to have bug here. | 4798 | /* One thing to explain: DCT4 phones seems to have bug here. |
4794 | * When delete for example first bookmark, phone change | 4799 | * When delete for example first bookmark, phone change |
4795 | * numeration for getting frame, not for deleting. So, we try to | 4800 | * numeration for getting frame, not for deleting. So, we try to |
4796 | * get 1'st bookmark. Inside frame is "correct" location. We use | 4801 | * get 1'st bookmark. Inside frame is "correct" location. We use |
4797 | * it later | 4802 | * it later |
4798 | */ | 4803 | */ |
4799 | while (error==ERR_NONE) { | 4804 | while (error==ERR_NONE) { |
4800 | error = Phone->DeleteWAPBookmark(&s,&Bookmark); | 4805 | error = Phone->DeleteWAPBookmark(&s,&Bookmark); |
4801 | Bookmark.Location = 1; | 4806 | Bookmark.Location = 1; |
4802 | error = Phone->GetWAPBookmark(&s,&Bookmark); | 4807 | error = Phone->GetWAPBookmark(&s,&Bookmark); |
4803 | printmsgerr("*"); | 4808 | printmsgerr("*"); |
4804 | } | 4809 | } |
4805 | printmsgerr("\n"); | 4810 | printmsgerr("\n"); |
4806 | max = 0; | 4811 | max = 0; |
4807 | while (Backup.WAPBookmark[max]!=NULL) max++; | 4812 | while (Backup.WAPBookmark[max]!=NULL) max++; |
4808 | for (i=0;i<max;i++) { | 4813 | for (i=0;i<max;i++) { |
4809 | Bookmark = *Backup.WAPBookmark[i]; | 4814 | Bookmark = *Backup.WAPBookmark[i]; |
4810 | Bookmark.Location = 0; | 4815 | Bookmark.Location = 0; |
4811 | error=Phone->SetWAPBookmark(&s,&Bookmark); | 4816 | error=Phone->SetWAPBookmark(&s,&Bookmark); |
4812 | Print_Error(error); | 4817 | Print_Error(error); |
4813 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); | 4818 | printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); |
4814 | if (gshutdown) { | 4819 | if (gshutdown) { |
4815 | GSM_Terminate(); | 4820 | GSM_Terminate(); |
4816 | exit(0); | 4821 | exit(0); |
4817 | } | 4822 | } |
4818 | } | 4823 | } |
@@ -8249,180 +8254,179 @@ int main(int argc, char *argv[]) | |||
8249 | #if 0 | 8254 | #if 0 |
8250 | GSM_ReadConfig(NULL, &s.Config[0], 0); | 8255 | GSM_ReadConfig(NULL, &s.Config[0], 0); |
8251 | s.ConfigNum = 1; | 8256 | s.ConfigNum = 1; |
8252 | GSM_Config *con = &s.Config[0]; | 8257 | GSM_Config *con = &s.Config[0]; |
8253 | 8258 | ||
8254 | char* tempC; | 8259 | char* tempC; |
8255 | tempC = argv[argc-1]+2; | 8260 | tempC = argv[argc-1]+2; |
8256 | if ( *tempC != 0 ) { | 8261 | if ( *tempC != 0 ) { |
8257 | fprintf(stderr,"Using model %s \n",tempC); | 8262 | fprintf(stderr,"Using model %s \n",tempC); |
8258 | strcpy(con->Model,tempC ); | 8263 | strcpy(con->Model,tempC ); |
8259 | } | 8264 | } |
8260 | tempC = argv[argc-2]+2; | 8265 | tempC = argv[argc-2]+2; |
8261 | if ( *tempC != 0 ) { | 8266 | if ( *tempC != 0 ) { |
8262 | fprintf(stderr,"Using device %s \n",tempC); | 8267 | fprintf(stderr,"Using device %s \n",tempC); |
8263 | con->Device = strdup(tempC); | 8268 | con->Device = strdup(tempC); |
8264 | con->DefaultDevice = false; | 8269 | con->DefaultDevice = false; |
8265 | } | 8270 | } |
8266 | tempC = argv[argc-3]+2; | 8271 | tempC = argv[argc-3]+2; |
8267 | if ( *tempC != 0 ) { | 8272 | if ( *tempC != 0 ) { |
8268 | fprintf(stderr,"Using connection %s \n",tempC); | 8273 | fprintf(stderr,"Using connection %s \n",tempC); |
8269 | con->Connection = strdup(tempC); | 8274 | con->Connection = strdup(tempC); |
8270 | con->DefaultConnection = false; | 8275 | con->DefaultConnection = false; |
8271 | } | 8276 | } |
8272 | argc = argc-3; | 8277 | argc = argc-3; |
8273 | //#if 0 | 8278 | //#if 0 |
8274 | if ( ! mConnection.isEmpty() ) { | 8279 | if ( ! mConnection.isEmpty() ) { |
8275 | cfg->Connection = strdup(mConnection.latin1()); | 8280 | cfg->Connection = strdup(mConnection.latin1()); |
8276 | cfg->DefaultConnection = false; | 8281 | cfg->DefaultConnection = false; |
8277 | qDebug("Connection set %s ", cfg->Connection ); | 8282 | qDebug("Connection set %s ", cfg->Connection ); |
8278 | 8283 | ||
8279 | } | 8284 | } |
8280 | if ( ! mDevice.isEmpty() ) { | 8285 | if ( ! mDevice.isEmpty() ) { |
8281 | cfg->Device = strdup(mDevice.latin1()); | 8286 | cfg->Device = strdup(mDevice.latin1()); |
8282 | cfg->DefaultDevice = false; | 8287 | cfg->DefaultDevice = false; |
8283 | qDebug("Device set %s ", cfg->Device); | 8288 | qDebug("Device set %s ", cfg->Device); |
8284 | 8289 | ||
8285 | } | 8290 | } |
8286 | if ( ! mModel.isEmpty() ) { | 8291 | if ( ! mModel.isEmpty() ) { |
8287 | strcpy(cfg->Model,mModel.latin1() ); | 8292 | strcpy(cfg->Model,mModel.latin1() ); |
8288 | cfg->DefaultModel = false; | 8293 | cfg->DefaultModel = false; |
8289 | qDebug("Model set %s ",cfg->Model ); | 8294 | qDebug("Model set %s ",cfg->Model ); |
8290 | } | 8295 | } |
8291 | 8296 | ||
8292 | #endif | 8297 | #endif |
8293 | 8298 | ||
8294 | 8299 | ||
8295 | cfg=GSM_FindGammuRC(); | 8300 | cfg=GSM_FindGammuRC(); |
8296 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { | 8301 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { |
8297 | if (cfg!=NULL) { | 8302 | if (cfg!=NULL) { |
8298 | cp = INI_GetValue(cfg, "gammu", "gammucoding", false); | 8303 | cp = INI_GetValue(cfg, "gammu", "gammucoding", false); |
8299 | if (cp) di.coding = cp; | 8304 | if (cp) di.coding = cp; |
8300 | 8305 | ||
8301 | s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); | 8306 | s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); |
8302 | if (s.Config[i].Localize) { | 8307 | if (s.Config[i].Localize) { |
8303 | s.msg=INI_ReadFile(s.Config[i].Localize, true); | 8308 | s.msg=INI_ReadFile(s.Config[i].Localize, true); |
8304 | } else { | 8309 | } else { |
8305 | #if !defined(WIN32) && defined(LOCALE_PATH) | 8310 | #if !defined(WIN32) && defined(LOCALE_PATH) |
8306 | locale = setlocale(LC_MESSAGES, NULL); | 8311 | locale = setlocale(LC_MESSAGES, NULL); |
8307 | if (locale != NULL) { | 8312 | if (locale != NULL) { |
8308 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", | 8313 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", |
8309 | LOCALE_PATH, | 8314 | LOCALE_PATH, |
8310 | tolower(locale[0]), | 8315 | tolower(locale[0]), |
8311 | tolower(locale[1])); | 8316 | tolower(locale[1])); |
8312 | s.msg = INI_ReadFile(locale_file, true); | 8317 | s.msg = INI_ReadFile(locale_file, true); |
8313 | } | 8318 | } |
8314 | #endif | 8319 | #endif |
8315 | } | 8320 | } |
8316 | } | 8321 | } |
8317 | 8322 | ||
8318 | /* Wanted user specific configuration? */ | 8323 | /* Wanted user specific configuration? */ |
8319 | 8324 | ||
8320 | if (only_config != -1) { | 8325 | if (only_config != -1) { |
8321 | /* Here we get only in first for loop */ | 8326 | /* Here we get only in first for loop */ |
8322 | if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; | 8327 | if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; |
8323 | } else { | 8328 | } else { |
8324 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; | 8329 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; |
8325 | } | 8330 | } |
8326 | s.ConfigNum++; | 8331 | s.ConfigNum++; |
8327 | 8332 | ||
8328 | /* We want to use only one file descriptor for global and state machine debug output */ | 8333 | /* We want to use only one file descriptor for global and state machine debug output */ |
8329 | s.Config[i].UseGlobalDebugFile = true; | 8334 | s.Config[i].UseGlobalDebugFile = true; |
8330 | 8335 | ||
8331 | /* It makes no sense to open several debug logs... */ | 8336 | /* It makes no sense to open several debug logs... */ |
8332 | if (i != 0) { | 8337 | if (i != 0) { |
8333 | strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); | 8338 | strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); |
8334 | free(s.Config[i].DebugFile); | 8339 | free(s.Config[i].DebugFile); |
8335 | s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); | 8340 | s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); |
8336 | } else { | 8341 | } else { |
8337 | /* Just for first config */ | 8342 | /* Just for first config */ |
8338 | /* When user gave debug level on command line */ | 8343 | /* When user gave debug level on command line */ |
8339 | if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { | 8344 | if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { |
8340 | /* Debug level from command line will be used with phone too */ | 8345 | /* Debug level from command line will be used with phone too */ |
8341 | strcpy(s.Config[i].DebugLevel,argv[1 + start]); | 8346 | strcpy(s.Config[i].DebugLevel,argv[1 + start]); |
8342 | start++; | 8347 | start++; |
8343 | } else { | 8348 | } else { |
8344 | /* Try to set debug level from config file */ | 8349 | /* Try to set debug level from config file */ |
8345 | GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); | 8350 | GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); |
8346 | } | 8351 | } |
8347 | /* If user gave debug file in gammurc, we will use it */ | 8352 | /* If user gave debug file in gammurc, we will use it */ |
8348 | error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); | 8353 | error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); |
8349 | Print_Error(error); | 8354 | Print_Error(error); |
8350 | } | 8355 | } |
8351 | 8356 | ||
8352 | /* We wanted to read just user specified configuration. */ | 8357 | /* We wanted to read just user specified configuration. */ |
8353 | if (only_config != -1) {break;} | 8358 | if (only_config != -1) {break;} |
8354 | } | 8359 | } |
8355 | #if 0 | 8360 | #if 0 |
8356 | GSM_Config *con = &s.Config[0]; | 8361 | GSM_Config *con = &s.Config[0]; |
8357 | 8362 | ||
8358 | char* tempC; | 8363 | char* tempC; |
8359 | tempC = argv[argc-1]+2; | 8364 | tempC = argv[argc-1]+2; |
8360 | if ( *tempC != 0 ) { | 8365 | if ( *tempC != 0 ) { |
8361 | fprintf(stderr,"Using model %s \n",tempC); | 8366 | fprintf(stderr,"Using model %s \n",tempC); |
8362 | strcpy(con->Model,tempC ); | 8367 | strcpy(con->Model,tempC ); |
8363 | } | 8368 | } |
8364 | tempC = argv[argc-2]+2; | 8369 | tempC = argv[argc-2]+2; |
8365 | if ( *tempC != 0 ) { | 8370 | if ( *tempC != 0 ) { |
8366 | fprintf(stderr,"Using device %s \n",tempC); | 8371 | fprintf(stderr,"Using device %s \n",tempC); |
8367 | con->Device = strdup(tempC); | 8372 | con->Device = strdup(tempC); |
8368 | con->DefaultDevice = false; | 8373 | con->DefaultDevice = false; |
8369 | } | 8374 | } |
8370 | tempC = argv[argc-3]+2; | 8375 | tempC = argv[argc-3]+2; |
8371 | if ( *tempC != 0 ) { | 8376 | if ( *tempC != 0 ) { |
8372 | fprintf(stderr,"Using connection %s \n",tempC); | 8377 | fprintf(stderr,"Using connection %s \n",tempC); |
8373 | con->Connection = strdup(tempC); | 8378 | con->Connection = strdup(tempC); |
8374 | con->DefaultConnection = false; | 8379 | con->DefaultConnection = false; |
8375 | } | 8380 | } |
8376 | #endif | 8381 | #endif |
8377 | argc = argc-3; | ||
8378 | 8382 | ||
8379 | 8383 | ||
8380 | /* Do we have enough parameters? */ | 8384 | /* Do we have enough parameters? */ |
8381 | if (argc == 1 + start) { | 8385 | if (argc == 1 + start) { |
8382 | HelpGeneral(); | 8386 | HelpGeneral(); |
8383 | printmsg("Too few parameters!\n"); | 8387 | printmsg("Too few parameters!\n"); |
8384 | exit(-2); | 8388 | exit(-2); |
8385 | } | 8389 | } |
8386 | 8390 | ||
8387 | /* Check used version vs. compiled */ | 8391 | /* Check used version vs. compiled */ |
8388 | if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { | 8392 | if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { |
8389 | printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", | 8393 | printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", |
8390 | GetGammuVersion(),VERSION); | 8394 | GetGammuVersion(),VERSION); |
8391 | exit(-1); | 8395 | exit(-1); |
8392 | } | 8396 | } |
8393 | 8397 | ||
8394 | /* Check parameters */ | 8398 | /* Check parameters */ |
8395 | while (Parameters[z].Function != NULL) { | 8399 | while (Parameters[z].Function != NULL) { |
8396 | if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { | 8400 | if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { |
8397 | if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { | 8401 | if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { |
8398 | fprintf(stderr,"Executing \n"); | 8402 | fprintf(stderr,"Executing \n"); |
8399 | Parameters[z].Function(argc - start, argv + start); | 8403 | Parameters[z].Function(argc - start, argv + start); |
8400 | break; | 8404 | break; |
8401 | } else { | 8405 | } else { |
8402 | count_failed = true; | 8406 | count_failed = true; |
8403 | } | 8407 | } |
8404 | } | 8408 | } |
8405 | z++; | 8409 | z++; |
8406 | } | 8410 | } |
8407 | 8411 | ||
8408 | /* Tell user when we did nothing */ | 8412 | /* Tell user when we did nothing */ |
8409 | if (Parameters[z].Function == NULL) { | 8413 | if (Parameters[z].Function == NULL) { |
8410 | HelpGeneral(); | 8414 | HelpGeneral(); |
8411 | if (count_failed) { | 8415 | if (count_failed) { |
8412 | printmsg("Bad parameter count!\n"); | 8416 | printmsg("Bad parameter count!\n"); |
8413 | } else { | 8417 | } else { |
8414 | printmsg("Bad option!\n"); | 8418 | printmsg("Bad option!\n"); |
8415 | } | 8419 | } |
8416 | } | 8420 | } |
8417 | 8421 | ||
8418 | /* Close debug output if opened */ | 8422 | /* Close debug output if opened */ |
8419 | if (di.df!=stdout) fclose(di.df); | 8423 | if (di.df!=stdout) fclose(di.df); |
8420 | //#endif // 0 | 8424 | //#endif // 0 |
8421 | fprintf(stderr,"kammu: Success. End. \n"); | 8425 | fprintf(stderr,"kammu: Success. End. \n"); |
8422 | exit(0); | 8426 | exit(0); |
8423 | } | 8427 | } |
8424 | 8428 | ||
8425 | /* How should editor hadle tabs in this file? Add editor commands here. | 8429 | /* How should editor hadle tabs in this file? Add editor commands here. |
8426 | * vim: noexpandtab sw=8 ts=8 sts=8: | 8430 | * vim: noexpandtab sw=8 ts=8 sts=8: |
8427 | */ | 8431 | */ |
8428 | 8432 | ||
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 6df639f..ef69bce 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -4,617 +4,633 @@ | |||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qxml.h> | 32 | #include <qxml.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kglobal.h> | 37 | #include <kglobal.h> |
38 | #include <kmessagebox.h> | 38 | #include <kmessagebox.h> |
39 | 39 | ||
40 | #include "calendar.h" | 40 | #include "calendar.h" |
41 | #include "alarm.h" | 41 | #include "alarm.h" |
42 | #include "recurrence.h" | 42 | #include "recurrence.h" |
43 | #include "calendarlocal.h" | 43 | #include "calendarlocal.h" |
44 | 44 | ||
45 | #include "phoneformat.h" | 45 | #include "phoneformat.h" |
46 | #include "syncdefines.h" | 46 | #include "syncdefines.h" |
47 | 47 | ||
48 | using namespace KCal; | 48 | using namespace KCal; |
49 | class PhoneParser : public QObject | 49 | class PhoneParser : public QObject |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | PhoneParser( ) { | 52 | PhoneParser( ) { |
53 | ; | 53 | ; |
54 | } | 54 | } |
55 | 55 | ||
56 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 56 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
57 | { | 57 | { |
58 | QString datestr; | 58 | QString datestr; |
59 | QString timestr; | 59 | QString timestr; |
60 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 60 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
61 | QDateTime dt; | 61 | QDateTime dt; |
62 | if (useTZ) | 62 | if (useTZ) |
63 | dt = dti.addSecs ( -(offset*60)); | 63 | dt = dti.addSecs ( -(offset*60)); |
64 | else | 64 | else |
65 | dt = dti; | 65 | dt = dti; |
66 | if(dt.date().isValid()){ | 66 | if(dt.date().isValid()){ |
67 | const QDate& date = dt.date(); | 67 | const QDate& date = dt.date(); |
68 | datestr.sprintf("%04d%02d%02d", | 68 | datestr.sprintf("%04d%02d%02d", |
69 | date.year(), date.month(), date.day()); | 69 | date.year(), date.month(), date.day()); |
70 | } | 70 | } |
71 | if(dt.time().isValid()){ | 71 | if(dt.time().isValid()){ |
72 | const QTime& time = dt.time(); | 72 | const QTime& time = dt.time(); |
73 | timestr.sprintf("T%02d%02d%02d", | 73 | timestr.sprintf("T%02d%02d%02d", |
74 | time.hour(), time.minute(), time.second()); | 74 | time.hour(), time.minute(), time.second()); |
75 | } | 75 | } |
76 | return datestr + timestr; | 76 | return datestr + timestr; |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | }; | 80 | }; |
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
85 | { | 85 | { |
86 | mProfileName = profileName; | 86 | mProfileName = profileName; |
87 | mDevice = device; | 87 | mDevice = device; |
88 | mConnection = connection; | 88 | mConnection = connection; |
89 | mModel = model; | 89 | mModel = model; |
90 | } | 90 | } |
91 | 91 | ||
92 | PhoneFormat::~PhoneFormat() | 92 | PhoneFormat::~PhoneFormat() |
93 | { | 93 | { |
94 | } | 94 | } |
95 | #if 0 | 95 | #if 0 |
96 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 96 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
97 | { | 97 | { |
98 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 98 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
99 | s->ConfigNum = 1; | 99 | s->ConfigNum = 1; |
100 | GSM_Config *cfg = &s->Config[0]; | 100 | GSM_Config *cfg = &s->Config[0]; |
101 | if ( ! mConnection.isEmpty() ) { | 101 | if ( ! mConnection.isEmpty() ) { |
102 | cfg->Connection = strdup(mConnection.latin1()); | 102 | cfg->Connection = strdup(mConnection.latin1()); |
103 | cfg->DefaultConnection = false; | 103 | cfg->DefaultConnection = false; |
104 | qDebug("Connection set %s ", cfg->Connection ); | 104 | qDebug("Connection set %s ", cfg->Connection ); |
105 | 105 | ||
106 | } | 106 | } |
107 | if ( ! mDevice.isEmpty() ) { | 107 | if ( ! mDevice.isEmpty() ) { |
108 | cfg->Device = strdup(mDevice.latin1()); | 108 | cfg->Device = strdup(mDevice.latin1()); |
109 | cfg->DefaultDevice = false; | 109 | cfg->DefaultDevice = false; |
110 | qDebug("Device set %s ", cfg->Device); | 110 | qDebug("Device set %s ", cfg->Device); |
111 | 111 | ||
112 | } | 112 | } |
113 | if ( ! mModel.isEmpty() ) { | 113 | if ( ! mModel.isEmpty() ) { |
114 | strcpy(cfg->Model,mModel.latin1() ); | 114 | strcpy(cfg->Model,mModel.latin1() ); |
115 | cfg->DefaultModel = false; | 115 | cfg->DefaultModel = false; |
116 | qDebug("Model set %s ",cfg->Model ); | 116 | qDebug("Model set %s ",cfg->Model ); |
117 | } | 117 | } |
118 | int error=GSM_InitConnection(s,3); | 118 | int error=GSM_InitConnection(s,3); |
119 | return error; | 119 | return error; |
120 | } | 120 | } |
121 | #endif | 121 | #endif |
122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
123 | { | 123 | { |
124 | QStringList attList; | 124 | QStringList attList; |
125 | if ( todo->hasDueDate() ) | 125 | if ( todo->hasDueDate() ) |
126 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 126 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
127 | attList << todo->summary(); | 127 | attList << todo->summary(); |
128 | QString completedString = "no"; | 128 | QString completedString = "no"; |
129 | if ( todo->isCompleted() ) | 129 | if ( todo->isCompleted() ) |
130 | completedString = "yes"; | 130 | completedString = "yes"; |
131 | attList << completedString; | 131 | attList << completedString; |
132 | attList << QString::number( todo->priority() ); | 132 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | ||
134 | if (prio == 4 ) prio = 5 ; | ||
135 | attList << QString::number( prio ); | ||
133 | QString alarmString = "na"; | 136 | QString alarmString = "na"; |
134 | Alarm *alarm; | 137 | Alarm *alarm; |
135 | if ( todo->alarms().count() > 0 ) { | 138 | if ( todo->alarms().count() > 0 ) { |
136 | alarm = todo->alarms().first(); | 139 | alarm = todo->alarms().first(); |
137 | if ( alarm->enabled() ) { | 140 | if ( alarm->enabled() ) { |
138 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 141 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
139 | } | 142 | } |
140 | } | 143 | } |
141 | attList << alarmString; | 144 | attList << alarmString; |
142 | attList << todo->categoriesStr(); | 145 | attList << todo->categoriesStr(); |
143 | attList << todo->secrecyStr(); | 146 | attList << todo->secrecyStr(); |
144 | return PhoneFormat::getCsum(attList ); | 147 | return PhoneFormat::getCsum(attList ); |
145 | 148 | ||
146 | } | 149 | } |
147 | ulong PhoneFormat::getCsumEvent( Event* event ) | 150 | ulong PhoneFormat::getCsumEvent( Event* event ) |
148 | { | 151 | { |
149 | QStringList attList; | 152 | QStringList attList; |
150 | attList << PhoneParser::dtToString ( event->dtStart() ); | 153 | attList << PhoneParser::dtToString ( event->dtStart() ); |
151 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 154 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
152 | attList << event->summary(); | 155 | attList << event->summary(); |
153 | attList << event->location(); | 156 | attList << event->location(); |
154 | QString alarmString = "na"; | 157 | QString alarmString = "na"; |
155 | Alarm *alarm; | 158 | Alarm *alarm; |
156 | if ( event->alarms().count() > 0 ) { | 159 | if ( event->alarms().count() > 0 ) { |
157 | alarm = event->alarms().first(); | 160 | alarm = event->alarms().first(); |
158 | if ( alarm->enabled() ) { | 161 | if ( alarm->enabled() ) { |
159 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 162 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
160 | } | 163 | } |
161 | } | 164 | } |
162 | attList << alarmString; | 165 | attList << alarmString; |
163 | Recurrence* rec = event->recurrence(); | 166 | Recurrence* rec = event->recurrence(); |
164 | QStringList list; | 167 | QStringList list; |
165 | bool writeEndDate = false; | 168 | bool writeEndDate = false; |
166 | switch ( rec->doesRecur() ) | 169 | switch ( rec->doesRecur() ) |
167 | { | 170 | { |
168 | case Recurrence::rDaily: // 0 | 171 | case Recurrence::rDaily: // 0 |
169 | list.append( "0" ); | 172 | list.append( "0" ); |
170 | list.append( QString::number( rec->frequency() ));//12 | 173 | list.append( QString::number( rec->frequency() ));//12 |
171 | list.append( "0" ); | 174 | list.append( "0" ); |
172 | list.append( "0" ); | 175 | list.append( "0" ); |
173 | writeEndDate = true; | 176 | writeEndDate = true; |
174 | break; | 177 | break; |
175 | case Recurrence::rWeekly:// 1 | 178 | case Recurrence::rWeekly:// 1 |
176 | list.append( "1" ); | 179 | list.append( "1" ); |
177 | list.append( QString::number( rec->frequency()) );//12 | 180 | list.append( QString::number( rec->frequency()) );//12 |
178 | list.append( "0" ); | 181 | list.append( "0" ); |
179 | { | 182 | { |
180 | int days = 0; | 183 | int days = 0; |
181 | QBitArray weekDays = rec->days(); | 184 | QBitArray weekDays = rec->days(); |
182 | int i; | 185 | int i; |
183 | for( i = 1; i <= 7; ++i ) { | 186 | for( i = 1; i <= 7; ++i ) { |
184 | if ( weekDays[i-1] ) { | 187 | if ( weekDays[i-1] ) { |
185 | days += 1 << (i-1); | 188 | days += 1 << (i-1); |
186 | } | 189 | } |
187 | } | 190 | } |
188 | list.append( QString::number( days ) ); | 191 | list.append( QString::number( days ) ); |
189 | } | 192 | } |
190 | //pending weekdays | 193 | //pending weekdays |
191 | writeEndDate = true; | 194 | writeEndDate = true; |
192 | 195 | ||
193 | break; | 196 | break; |
194 | case Recurrence::rMonthlyPos:// 2 | 197 | case Recurrence::rMonthlyPos:// 2 |
195 | list.append( "2" ); | 198 | list.append( "2" ); |
196 | list.append( QString::number( rec->frequency()) );//12 | 199 | list.append( QString::number( rec->frequency()) );//12 |
197 | 200 | ||
198 | writeEndDate = true; | 201 | writeEndDate = true; |
199 | { | 202 | { |
200 | int count = 1; | 203 | int count = 1; |
201 | QPtrList<Recurrence::rMonthPos> rmp; | 204 | QPtrList<Recurrence::rMonthPos> rmp; |
202 | rmp = rec->monthPositions(); | 205 | rmp = rec->monthPositions(); |
203 | if ( rmp.first()->negative ) | 206 | if ( rmp.first()->negative ) |
204 | count = 5 - rmp.first()->rPos - 1; | 207 | count = 5 - rmp.first()->rPos - 1; |
205 | else | 208 | else |
206 | count = rmp.first()->rPos - 1; | 209 | count = rmp.first()->rPos - 1; |
207 | list.append( QString::number( count ) ); | 210 | list.append( QString::number( count ) ); |
208 | 211 | ||
209 | } | 212 | } |
210 | 213 | ||
211 | list.append( "0" ); | 214 | list.append( "0" ); |
212 | break; | 215 | break; |
213 | case Recurrence::rMonthlyDay:// 3 | 216 | case Recurrence::rMonthlyDay:// 3 |
214 | list.append( "3" ); | 217 | list.append( "3" ); |
215 | list.append( QString::number( rec->frequency()) );//12 | 218 | list.append( QString::number( rec->frequency()) );//12 |
216 | list.append( "0" ); | 219 | list.append( "0" ); |
217 | list.append( "0" ); | 220 | list.append( "0" ); |
218 | writeEndDate = true; | 221 | writeEndDate = true; |
219 | break; | 222 | break; |
220 | case Recurrence::rYearlyMonth://4 | 223 | case Recurrence::rYearlyMonth://4 |
221 | list.append( "4" ); | 224 | list.append( "4" ); |
222 | list.append( QString::number( rec->frequency()) );//12 | 225 | list.append( QString::number( rec->frequency()) );//12 |
223 | list.append( "0" ); | 226 | list.append( "0" ); |
224 | list.append( "0" ); | 227 | list.append( "0" ); |
225 | writeEndDate = true; | 228 | writeEndDate = true; |
226 | break; | 229 | break; |
227 | 230 | ||
228 | default: | 231 | default: |
229 | list.append( "255" ); | 232 | list.append( "255" ); |
230 | list.append( QString() ); | 233 | list.append( QString() ); |
231 | list.append( "0" ); | 234 | list.append( "0" ); |
232 | list.append( QString() ); | 235 | list.append( QString() ); |
233 | list.append( "0" ); | 236 | list.append( "0" ); |
234 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
235 | break; | 238 | break; |
236 | } | 239 | } |
237 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
238 | 241 | ||
239 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
240 | list.append( "1" ); | 243 | list.append( "1" ); |
241 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
242 | } else { | 245 | } else { |
243 | list.append( "0" ); | 246 | list.append( "0" ); |
244 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
245 | } | 248 | } |
246 | 249 | ||
247 | } | 250 | } |
248 | attList << list.join(""); | 251 | attList << list.join(""); |
249 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
250 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
251 | 254 | ||
252 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
253 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
254 | } | 257 | } |
255 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
256 | { | 259 | { |
257 | int max = attList.count() -1; | 260 | int max = attList.count(); |
258 | ulong cSum = 0; | 261 | ulong cSum = 0; |
259 | int j,k,i; | 262 | int j,k,i; |
260 | int add; | 263 | int add; |
261 | for ( i = 1; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
262 | QString s = attList[i]; | 265 | QString s = attList[i]; |
263 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
264 | j = s.length(); | 267 | j = s.length(); |
265 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
266 | int mul = k +1; | 269 | int mul = k +1; |
267 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
268 | if ( k < 16 ) | 271 | if ( k < 16 ) |
269 | mul = mul * mul; | 272 | mul = mul * mul; |
270 | add = add * mul *i*i*i; | 273 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | ||
271 | cSum += add; | 275 | cSum += add; |
272 | } | 276 | } |
273 | } | 277 | } |
278 | if ( i == 0 ) | ||
279 | qDebug("csum: i == 0 %d ", cSum); | ||
280 | |||
274 | } | 281 | } |
275 | //QString dump = attList.join(","); | 282 | QString dump = attList.join(","); |
276 | //qDebug("csum: %s", dump.latin1()); | 283 | qDebug("csum: %d %s", cSum,dump.latin1()); |
277 | 284 | ||
278 | return cSum; | 285 | return cSum; |
279 | 286 | ||
280 | } | 287 | } |
281 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 288 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
282 | #include <stdlib.h> | 289 | #include <stdlib.h> |
283 | #define DEBUGMODE false | 290 | #define DEBUGMODE false |
284 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 291 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
285 | { | 292 | { |
286 | 293 | ||
287 | QString fileName; | 294 | QString fileName; |
288 | #ifdef _WIN32_ | 295 | #ifdef _WIN32_ |
289 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 296 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
290 | #else | 297 | #else |
291 | fileName = "/tmp/kdepimtemp.vcs"; | 298 | fileName = "/tmp/kdepimtemp.vcs"; |
292 | #endif | 299 | #endif |
293 | QString command ="./kammu --backup " + fileName + " -yes -C" + | 300 | QString command ="./kammu --backup " + fileName + " -yes" ; |
294 | mConnection +" -D" + mDevice +" -M" + mModel; | ||
295 | int ret = system ( command.latin1() ); | 301 | int ret = system ( command.latin1() ); |
296 | if ( ret != 0 ) { | 302 | if ( ret != 0 ) { |
297 | qDebug("Error::command returned %d", ret); | 303 | qDebug("Error::command returned %d", ret); |
298 | return false; | 304 | return false; |
299 | } | 305 | } |
300 | qDebug("Command returned %d", ret); | 306 | qDebug("Command returned %d", ret); |
301 | VCalFormat vfload; | 307 | VCalFormat vfload; |
302 | vfload.setLocalTime ( true ); | 308 | vfload.setLocalTime ( true ); |
303 | qDebug("loading file ..."); | 309 | qDebug("loading file ..."); |
304 | 310 | ||
305 | if ( ! vfload.load( calendar, fileName ) ) | 311 | if ( ! vfload.load( calendar, fileName ) ) |
306 | return false; | 312 | return false; |
307 | QPtrList<Event> er = calendar->rawEvents(); | 313 | QPtrList<Event> er = calendar->rawEvents(); |
308 | Event* ev = er.first(); | 314 | Event* ev = er.first(); |
309 | qDebug("reading events... "); | 315 | qDebug("reading events... "); |
310 | while ( ev ) { | 316 | while ( ev ) { |
311 | QStringList cat = ev->categories(); | 317 | QStringList cat = ev->categories(); |
312 | if ( cat.contains( "MeetingDEF" )) { | 318 | if ( cat.contains( "MeetingDEF" )) { |
313 | ev->setCategories( QStringList() ); | 319 | ev->setCategories( QStringList() ); |
314 | } | 320 | } |
315 | int id = ev->pilotId(); | 321 | int id = ev->pilotId(); |
316 | Event *event; | 322 | Event *event; |
317 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 323 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
318 | if ( event ) { | 324 | if ( event ) { |
319 | event = (Event*)event->clone(); | 325 | event = (Event*)event->clone(); |
320 | copyEvent( event, ev ); | 326 | copyEvent( event, ev ); |
321 | calendar->deleteEvent( ev ); | 327 | calendar->deleteEvent( ev ); |
322 | calendar->addEvent( event); | 328 | calendar->addEvent( event); |
323 | } | 329 | } |
324 | else | 330 | else |
325 | event = ev; | 331 | event = ev; |
326 | uint cSum; | 332 | uint cSum; |
327 | cSum = PhoneFormat::getCsumEvent( event ); | 333 | cSum = PhoneFormat::getCsumEvent( event ); |
328 | event->setCsum( mProfileName, QString::number( cSum )); | 334 | event->setCsum( mProfileName, QString::number( cSum )); |
329 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 335 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
330 | event->setID( mProfileName,QString::number( id ) ); | 336 | event->setID( mProfileName,QString::number( id ) ); |
331 | ev = er.next(); | 337 | ev = er.next(); |
332 | } | 338 | } |
333 | { | 339 | { |
334 | qDebug("reading todos... "); | 340 | qDebug("reading todos... "); |
335 | QPtrList<Todo> tr = calendar->rawTodos(); | 341 | QPtrList<Todo> tr = calendar->rawTodos(); |
336 | Todo* ev = tr.first(); | 342 | Todo* ev = tr.first(); |
337 | while ( ev ) { | 343 | while ( ev ) { |
338 | 344 | ||
339 | QStringList cat = ev->categories(); | 345 | QStringList cat = ev->categories(); |
340 | if ( cat.contains( "MeetingDEF" )) { | 346 | if ( cat.contains( "MeetingDEF" )) { |
341 | ev->setCategories( QStringList() ); | 347 | ev->setCategories( QStringList() ); |
342 | } | 348 | } |
343 | int id = ev->pilotId(); | 349 | int id = ev->pilotId(); |
344 | Todo *event; | 350 | Todo *event; |
345 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 351 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
346 | if ( event ) { | 352 | if ( event ) { |
353 | qDebug("copy todo %s ", event->summary().latin1()); | ||
354 | |||
347 | event = (Todo*)event->clone(); | 355 | event = (Todo*)event->clone(); |
348 | copyTodo( event, ev ); | 356 | copyTodo( event, ev ); |
349 | calendar->deleteTodo( ev ); | 357 | calendar->deleteTodo( ev ); |
350 | calendar->addTodo( event); | 358 | calendar->addTodo( event); |
351 | } | 359 | } |
352 | else | 360 | else |
353 | event = ev; | 361 | event = ev; |
354 | uint cSum; | 362 | uint cSum; |
355 | cSum = PhoneFormat::getCsumTodo( event ); | 363 | cSum = PhoneFormat::getCsumTodo( event ); |
356 | event->setCsum( mProfileName, QString::number( cSum )); | 364 | event->setCsum( mProfileName, QString::number( cSum )); |
357 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 365 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
358 | event->setID( mProfileName,QString::number( id ) ); | 366 | event->setID( mProfileName,QString::number( id ) ); |
359 | ev = tr.next(); | 367 | ev = tr.next(); |
360 | } | 368 | } |
361 | } | 369 | } |
362 | return true; | 370 | return true; |
363 | } | 371 | } |
364 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 372 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
365 | { | 373 | { |
366 | if ( from->dtStart().isValid() ) | 374 | if ( from->dtStart().isValid() ) |
367 | to->setDtStart( from->dtStart() ); | 375 | to->setDtStart( from->dtStart() ); |
368 | if ( from->dtEnd().isValid() ) | 376 | if ( from->dtEnd().isValid() ) |
369 | to->setDtEnd( from->dtEnd() ); | 377 | to->setDtEnd( from->dtEnd() ); |
370 | if ( !from->location().isEmpty() ) | 378 | if ( !from->location().isEmpty() ) |
371 | to->setLocation( from->location() ); | 379 | to->setLocation( from->location() ); |
372 | if ( !from->description().isEmpty() ) | 380 | if ( !from->description().isEmpty() ) |
373 | to->setDescription( from->description() ); | 381 | to->setDescription( from->description() ); |
374 | if ( !from->summary().isEmpty() ) | 382 | if ( !from->summary().isEmpty() ) |
375 | to->setSummary( from->summary() ); | 383 | to->setSummary( from->summary() ); |
376 | 384 | ||
377 | QPtrListIterator<Alarm> it( from->alarms() ); | 385 | QPtrListIterator<Alarm> it( from->alarms() ); |
378 | to->clearAlarms(); | 386 | if ( it.current() ) |
387 | to->clearAlarms(); | ||
379 | const Alarm *a; | 388 | const Alarm *a; |
380 | while( (a = it.current()) ) { | 389 | while( (a = it.current()) ) { |
381 | Alarm *b = new Alarm( *a ); | 390 | Alarm *b = new Alarm( *a ); |
382 | b->setParent( to ); | 391 | b->setParent( to ); |
383 | to->addAlarm( b ); | 392 | to->addAlarm( b ); |
384 | ++it; | 393 | ++it; |
385 | } | 394 | } |
386 | QStringList cat = to->categories(); | 395 | QStringList cat = to->categories(); |
387 | QStringList catFrom = from->categories(); | 396 | QStringList catFrom = from->categories(); |
388 | QString nCat; | 397 | QString nCat; |
389 | int iii; | 398 | int iii; |
390 | for ( iii = 0; iii < catFrom.count();++iii ) { | 399 | for ( iii = 0; iii < catFrom.count();++iii ) { |
391 | nCat = catFrom[iii]; | 400 | nCat = catFrom[iii]; |
392 | if ( !nCat.isEmpty() ) | 401 | if ( !nCat.isEmpty() ) |
393 | if ( !cat.contains( nCat )) { | 402 | if ( !cat.contains( nCat )) { |
394 | cat << nCat; | 403 | cat << nCat; |
395 | } | 404 | } |
396 | } | 405 | } |
397 | to->setCategories( cat ); | 406 | to->setCategories( cat ); |
398 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 407 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
399 | to->setRecurrence( r ) ; | 408 | to->setRecurrence( r ) ; |
400 | 409 | ||
401 | 410 | ||
402 | } | 411 | } |
403 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 412 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
404 | { | 413 | { |
405 | if ( from->dtStart().isValid() ) | 414 | if ( from->dtStart().isValid() ) |
406 | to->setDtStart( from->dtStart() ); | 415 | to->setDtStart( from->dtStart() ); |
407 | if ( from->dtDue().isValid() ) | 416 | if ( from->dtDue().isValid() ) |
408 | to->setDtDue( from->dtDue() ); | 417 | to->setDtDue( from->dtDue() ); |
409 | if ( !from->location().isEmpty() ) | 418 | if ( !from->location().isEmpty() ) |
410 | to->setLocation( from->location() ); | 419 | to->setLocation( from->location() ); |
411 | if ( !from->description().isEmpty() ) | 420 | if ( !from->description().isEmpty() ) |
412 | to->setDescription( from->description() ); | 421 | to->setDescription( from->description() ); |
413 | if ( !from->summary().isEmpty() ) | 422 | if ( !from->summary().isEmpty() ) |
414 | to->setSummary( from->summary() ); | 423 | to->setSummary( from->summary() ); |
415 | 424 | ||
416 | QPtrListIterator<Alarm> it( from->alarms() ); | 425 | QPtrListIterator<Alarm> it( from->alarms() ); |
417 | to->clearAlarms(); | 426 | if ( it.current() ) |
427 | to->clearAlarms(); | ||
418 | const Alarm *a; | 428 | const Alarm *a; |
419 | while( (a = it.current()) ) { | 429 | while( (a = it.current()) ) { |
420 | Alarm *b = new Alarm( *a ); | 430 | Alarm *b = new Alarm( *a ); |
421 | b->setParent( to ); | 431 | b->setParent( to ); |
422 | to->addAlarm( b ); | 432 | to->addAlarm( b ); |
423 | ++it; | 433 | ++it; |
424 | } | 434 | } |
425 | QStringList cat = to->categories(); | 435 | QStringList cat = to->categories(); |
426 | QStringList catFrom = from->categories(); | 436 | QStringList catFrom = from->categories(); |
427 | QString nCat; | 437 | QString nCat; |
428 | int iii; | 438 | int iii; |
429 | for ( iii = 0; iii < catFrom.count();++iii ) { | 439 | for ( iii = 0; iii < catFrom.count();++iii ) { |
430 | nCat = catFrom[iii]; | 440 | nCat = catFrom[iii]; |
431 | if ( !nCat.isEmpty() ) | 441 | if ( !nCat.isEmpty() ) |
432 | if ( !cat.contains( nCat )) { | 442 | if ( !cat.contains( nCat )) { |
433 | cat << nCat; | 443 | cat << nCat; |
434 | } | 444 | } |
435 | } | 445 | } |
436 | to->setCategories( cat ); | 446 | to->setCategories( cat ); |
437 | if ( from->isCompleted() ) { | 447 | if ( from->isCompleted() ) { |
438 | to->setCompleted( true ); | 448 | to->setCompleted( true ); |
439 | if( from->completed().isValid() ) | 449 | if( from->completed().isValid() ) |
440 | to->setCompleted( from->completed() ); | 450 | to->setCompleted( from->completed() ); |
441 | } else { | 451 | } else { |
442 | // set percentcomplete only, if to->isCompleted() | 452 | // set percentcomplete only, if to->isCompleted() |
443 | if ( to->isCompleted() ) | 453 | if ( to->isCompleted() ) |
444 | to->setPercentComplete(from->percentComplete()); | 454 | to->setPercentComplete(from->percentComplete()); |
445 | } | 455 | } |
446 | to->setPriority(from->priority()); | 456 | if( to->priority() == 2 && from->priority() == 1 ) |
457 | ; //skip | ||
458 | else if (to->priority() == 4 && from->priority() == 5 ) | ||
459 | ; | ||
460 | else | ||
461 | to->setPriority(from->priority()); | ||
447 | 462 | ||
448 | } | 463 | } |
449 | #include <qcstring.h> | 464 | #include <qcstring.h> |
450 | 465 | ||
451 | void PhoneFormat::afterSave( Incidence* inc) | 466 | void PhoneFormat::afterSave( Incidence* inc) |
452 | { | 467 | { |
453 | uint csum; | 468 | uint csum; |
454 | inc->removeID( mProfileName ); | 469 | inc->removeID( mProfileName ); |
470 | #if 0 | ||
455 | if ( inc->type() == "Event") | 471 | if ( inc->type() == "Event") |
456 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 472 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
457 | else | 473 | else |
458 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 474 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
459 | inc->setCsum( mProfileName, QString::number( csum )); | 475 | inc->setCsum( mProfileName, QString::number( csum )); |
476 | #endif | ||
460 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 477 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
461 | 478 | ||
462 | } | 479 | } |
463 | bool PhoneFormat::save( Calendar *calendar) | 480 | bool PhoneFormat::save( Calendar *calendar) |
464 | { | 481 | { |
465 | QLabel status ( i18n(" Opening device ..."), 0 ); | 482 | QLabel status ( i18n(" Opening device ..."), 0 ); |
466 | int w = status.sizeHint().width()+20 ; | 483 | int w = status.sizeHint().width()+20 ; |
467 | if ( w < 200 ) w = 230; | 484 | if ( w < 200 ) w = 230; |
468 | int h = status.sizeHint().height()+20 ; | 485 | int h = status.sizeHint().height()+20 ; |
469 | int dw = QApplication::desktop()->width(); | 486 | int dw = QApplication::desktop()->width(); |
470 | int dh = QApplication::desktop()->height(); | 487 | int dh = QApplication::desktop()->height(); |
471 | status.setCaption(i18n("Writing to phone...") ); | 488 | status.setCaption(i18n("Writing to phone...") ); |
472 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 489 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
473 | status.show(); | 490 | status.show(); |
474 | status.raise(); | 491 | status.raise(); |
475 | qApp->processEvents(); | 492 | qApp->processEvents(); |
476 | QString message; | 493 | QString message; |
477 | #ifdef _WIN32_ | 494 | #ifdef _WIN32_ |
478 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 495 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
479 | #else | 496 | #else |
480 | QString fileName = "/tmp/kdepimtemp.vcs"; | 497 | QString fileName = "/tmp/kdepimtemp.vcs"; |
481 | #endif | 498 | #endif |
482 | 499 | ||
483 | // 1 remove events which should be deleted | 500 | // 1 remove events which should be deleted |
484 | QPtrList<Event> er = calendar->rawEvents(); | 501 | QPtrList<Event> er = calendar->rawEvents(); |
485 | Event* ev = er.first(); | 502 | Event* ev = er.first(); |
486 | while ( ev ) { | 503 | while ( ev ) { |
487 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 504 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
488 | calendar->deleteEvent( ev ); | 505 | calendar->deleteEvent( ev ); |
489 | } else { | 506 | } else { |
490 | 507 | ||
491 | } | 508 | } |
492 | ev = er.next(); | 509 | ev = er.next(); |
493 | } | 510 | } |
494 | // 2 remove todos which should be deleted | 511 | // 2 remove todos which should be deleted |
495 | QPtrList<Todo> tl = calendar->rawTodos(); | 512 | QPtrList<Todo> tl = calendar->rawTodos(); |
496 | Todo* to = tl.first(); | 513 | Todo* to = tl.first(); |
497 | while ( to ) { | 514 | while ( to ) { |
498 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 515 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
499 | calendar->deleteTodo( to ); | 516 | calendar->deleteTodo( to ); |
500 | } | 517 | } |
501 | to = tl.next(); | 518 | to = tl.next(); |
502 | } | 519 | } |
503 | // 3 save file | 520 | // 3 save file |
504 | VCalFormat vfsave; | 521 | VCalFormat vfsave; |
505 | vfsave.setLocalTime ( true ); | 522 | vfsave.setLocalTime ( true ); |
506 | if ( ! vfsave.save( calendar, fileName ) ) | 523 | if ( ! vfsave.save( calendar, fileName ) ) |
507 | return false; | 524 | return false; |
508 | // 4 call kammu | 525 | // 4 call kammu |
509 | QString command ="./kammu --restore " + fileName + " -C" + | 526 | QString command ="./kammu --restore " + fileName ; |
510 | mConnection +" -D" + mDevice +" -M" + mModel; | ||
511 | int ret; | 527 | int ret; |
512 | while ( (ret = system ( command.latin1())) != 0 ) { | 528 | while ( (ret = system ( command.latin1())) != 0 ) { |
513 | qDebug("Error S::command returned %d. asking users", ret); | 529 | qDebug("Error S::command returned %d. asking users", ret); |
514 | int retval = KMessageBox::warningContinueCancel(0, | 530 | int retval = KMessageBox::warningContinueCancel(0, |
515 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); | 531 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); |
516 | if ( retval != KMessageBox::Continue ) | 532 | if ( retval != KMessageBox::Continue ) |
517 | return false; | 533 | return false; |
518 | } | 534 | } |
519 | if ( ret != 0 ) { | 535 | if ( ret != 0 ) { |
520 | qDebug("Error S::command returned %d", ret); | 536 | qDebug("Error S::command returned %d", ret); |
521 | return false; | 537 | return false; |
522 | } | 538 | } |
523 | // 5 reread data | 539 | // 5 reread data |
524 | message = i18n(" Rereading all data ... "); | 540 | message = i18n(" Rereading all data ... "); |
525 | status.setText ( message ); | 541 | status.setText ( message ); |
526 | qApp->processEvents(); | 542 | qApp->processEvents(); |
527 | CalendarLocal* calendarTemp = new CalendarLocal(); | 543 | CalendarLocal* calendarTemp = new CalendarLocal(); |
528 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 544 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
529 | if ( ! load( calendarTemp,calendar) ){ | 545 | if ( ! load( calendarTemp,calendar) ){ |
530 | qDebug("error reloading calendar "); | 546 | qDebug("error reloading calendar "); |
531 | delete calendarTemp; | 547 | delete calendarTemp; |
532 | return false; | 548 | return false; |
533 | } | 549 | } |
534 | // 6 compare data | 550 | // 6 compare data |
535 | 551 | ||
536 | //algo 6 compare event | 552 | //algo 6 compare event |
537 | er = calendar->rawEvents(); | 553 | er = calendar->rawEvents(); |
538 | ev = er.first(); | 554 | ev = er.first(); |
539 | message = i18n(" Comparing event # "); | 555 | message = i18n(" Comparing event # "); |
540 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 556 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
541 | Event* ev1; | 557 | Event* ev1; |
542 | int procCount = 0; | 558 | int procCount = 0; |
543 | while ( ev ) { | 559 | while ( ev ) { |
544 | //qDebug("event new ID %s",ev->summary().latin1()); | 560 | //qDebug("event new ID %s",ev->summary().latin1()); |
545 | status.setText ( message + QString::number ( ++procCount ) ); | 561 | status.setText ( message + QString::number ( ++procCount ) ); |
546 | qApp->processEvents(); | 562 | qApp->processEvents(); |
547 | uint csum; | 563 | uint csum; |
548 | csum = PhoneFormat::getCsumEvent( ev ); | 564 | csum = PhoneFormat::getCsumEvent( ev ); |
549 | QString cSum = QString::number( csum ); | 565 | QString cSum = QString::number( csum ); |
550 | ev->setCsum( mProfileName, cSum ); | 566 | ev->setCsum( mProfileName, cSum ); |
551 | //qDebug("Event cSum %s ", cSum.latin1()); | 567 | //qDebug("Event cSum %s ", cSum.latin1()); |
552 | ev1 = er1.first(); | 568 | ev1 = er1.first(); |
553 | while ( ev1 ) { | 569 | while ( ev1 ) { |
554 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 570 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
555 | er1.remove( ev1 ); | 571 | er1.remove( ev1 ); |
556 | afterSave( ev ); | 572 | afterSave( ev ); |
557 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 573 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
558 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | 574 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); |
559 | 575 | ||
560 | break; | 576 | break; |
561 | } | 577 | } |
562 | ev1 = er1.next(); | 578 | ev1 = er1.next(); |
563 | } | 579 | } |
564 | if ( ! ev1 ) { | 580 | if ( ! ev1 ) { |
565 | ev->removeID(mProfileName); | 581 | ev->removeID(mProfileName); |
566 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 582 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
567 | } | 583 | } |
568 | 584 | ||
569 | 585 | ||
570 | ev = er.next(); | 586 | ev = er.next(); |
571 | } | 587 | } |
572 | //algo 6 compare todo | 588 | //algo 6 compare todo |
573 | tl = calendar->rawTodos(); | 589 | tl = calendar->rawTodos(); |
574 | to = tl.first(); | 590 | to = tl.first(); |
575 | procCount = 0; | 591 | procCount = 0; |
576 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 592 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
577 | Todo* to1 ; | 593 | Todo* to1 ; |
578 | message = i18n(" Comparing todo # "); | 594 | message = i18n(" Comparing todo # "); |
579 | while ( to ) { | 595 | while ( to ) { |
580 | qDebug("todo2 %d ", procCount); | 596 | qDebug("todo2 %d ", procCount); |
581 | status.setText ( message + QString::number ( ++procCount ) ); | 597 | status.setText ( message + QString::number ( ++procCount ) ); |
582 | qApp->processEvents(); | 598 | qApp->processEvents(); |
583 | uint csum; | 599 | uint csum; |
584 | csum = PhoneFormat::getCsumTodo( to ); | 600 | csum = PhoneFormat::getCsumTodo( to ); |
585 | QString cSum = QString::number( csum ); | 601 | QString cSum = QString::number( csum ); |
586 | to->setCsum( mProfileName, cSum ); | 602 | to->setCsum( mProfileName, cSum ); |
587 | qDebug("Todo cSum %s ", cSum.latin1()); | 603 | qDebug("Todo cSum %s ", cSum.latin1()); |
588 | Todo* to1 = tl1.first(); | 604 | Todo* to1 = tl1.first(); |
589 | while ( to1 ) { | 605 | while ( to1 ) { |
590 | if ( to1->getCsum( mProfileName ) == cSum ) { | 606 | if ( to1->getCsum( mProfileName ) == cSum ) { |
591 | tl1.remove( to1 ); | 607 | tl1.remove( to1 ); |
592 | afterSave( to ); | 608 | afterSave( to ); |
593 | to->setID(mProfileName, to1->getID(mProfileName) ); | 609 | to->setID(mProfileName, to1->getID(mProfileName) ); |
594 | break; | 610 | break; |
595 | } | 611 | } |
596 | to1 = tl1.next(); | 612 | to1 = tl1.next(); |
597 | } | 613 | } |
598 | if ( ! to1 ) { | 614 | if ( ! to1 ) { |
599 | to->removeID(mProfileName); | 615 | to->removeID(mProfileName); |
600 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 616 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
601 | } | 617 | } |
602 | 618 | ||
603 | to = tl.next(); | 619 | to = tl.next(); |
604 | } | 620 | } |
605 | delete calendarTemp; | 621 | delete calendarTemp; |
606 | return true; | 622 | return true; |
607 | 623 | ||
608 | 624 | ||
609 | 625 | ||
610 | } | 626 | } |
611 | 627 | ||
612 | 628 | ||
613 | QString PhoneFormat::toString( Calendar * ) | 629 | QString PhoneFormat::toString( Calendar * ) |
614 | { | 630 | { |
615 | return QString::null; | 631 | return QString::null; |
616 | } | 632 | } |
617 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 633 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
618 | { | 634 | { |
619 | return false; | 635 | return false; |
620 | } | 636 | } |