diff options
Diffstat (limited to 'apps/plugins/calendar.c')
-rw-r--r-- | apps/plugins/calendar.c | 138 |
1 files changed, 48 insertions, 90 deletions
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 873a09b970..17116fe3e9 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -272,7 +272,7 @@ static int is_leap_year(int yr) | |||
272 | (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400)) ? 1:0 ; | 272 | (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400)) ? 1:0 ; |
273 | } | 273 | } |
274 | 274 | ||
275 | /* searches the weekday of the first day in month, | 275 | /* searches the weekday of the first day in month, |
276 | * relative to the given values */ | 276 | * relative to the given values */ |
277 | static int calc_weekday( struct shown *shown ) | 277 | static int calc_weekday( struct shown *shown ) |
278 | { | 278 | { |
@@ -343,19 +343,9 @@ static void draw_calendar(struct shown *shown) | |||
343 | int x,y,pos,days_per_month,j; | 343 | int x,y,pos,days_per_month,j; |
344 | char buffer[9]; | 344 | char buffer[9]; |
345 | const char *monthname[] = { | 345 | const char *monthname[] = { |
346 | "Jan", | 346 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
347 | "Feb", | 347 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
348 | "Mar", | 348 | }; |
349 | "Apr", | ||
350 | "May", | ||
351 | "Jun", | ||
352 | "Jul", | ||
353 | "Aug", | ||
354 | "Sep", | ||
355 | "Oct", | ||
356 | "Nov", | ||
357 | "Dec" | ||
358 | }; | ||
359 | if(use_system_font) | 349 | if(use_system_font) |
360 | rb->lcd_setfont(FONT_SYSFIXED); | 350 | rb->lcd_setfont(FONT_SYSFIXED); |
361 | rb->lcd_getstringsize("A",&w,&h); | 351 | rb->lcd_getstringsize("A",&w,&h); |
@@ -421,7 +411,7 @@ static int memos_in_shown_memory = 0; | |||
421 | 411 | ||
422 | static void load_memo(struct shown *shown) | 412 | static void load_memo(struct shown *shown) |
423 | { | 413 | { |
424 | int i, k, fp; | 414 | int k, fp; |
425 | bool exit = false; | 415 | bool exit = false; |
426 | char temp_memo1[2]; | 416 | char temp_memo1[2]; |
427 | char temp_memo2[3]; | 417 | char temp_memo2[3]; |
@@ -429,18 +419,6 @@ static void load_memo(struct shown *shown) | |||
429 | temp_memo1[1] = 0; | 419 | temp_memo1[1] = 0; |
430 | temp_memo2[2] = 0; | 420 | temp_memo2[2] = 0; |
431 | temp_memo4[4] = 0; | 421 | temp_memo4[4] = 0; |
432 | for (k = 0; k < memos_in_memory; k++) | ||
433 | { | ||
434 | memos[k].day = 0; | ||
435 | memos[k].month = 0; | ||
436 | memos[k].file_pointer_start = 0; | ||
437 | memos[k].file_pointer_end = 0; | ||
438 | memos[k].year = 0; | ||
439 | memos[k].type = 0; | ||
440 | memos[k].wday = 0; | ||
441 | for (i = 0; i < MAX_CHAR_MEMO_LEN; i++) | ||
442 | memos[k].message[i] = 0; | ||
443 | } | ||
444 | for (k = 1; k < 32; k++) | 422 | for (k = 1; k < 32; k++) |
445 | day_has_memo[k] = false; | 423 | day_has_memo[k] = false; |
446 | for (k = 0; k < 7; k++) | 424 | for (k = 0; k < 7; k++) |
@@ -449,12 +427,13 @@ static void load_memo(struct shown *shown) | |||
449 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY); | 427 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY); |
450 | if (fp > -1) | 428 | if (fp > -1) |
451 | { | 429 | { |
452 | int count = rb->filesize(fp); | ||
453 | rb->lseek(fp, 0, SEEK_SET); | 430 | rb->lseek(fp, 0, SEEK_SET); |
454 | while (!exit) | 431 | while (!exit) |
455 | { | 432 | { |
456 | memos[memos_in_memory].file_pointer_start = rb->lseek(fp, 0, | 433 | bool load_to_memory; |
457 | SEEK_CUR); | 434 | rb->memset(&memos[memos_in_memory].message, 0, MAX_CHAR_MEMO_LEN); |
435 | memos[memos_in_memory].file_pointer_start = | ||
436 | rb->lseek(fp, 0, SEEK_CUR); | ||
458 | if (rb->read(fp, temp_memo2, 2) == 2) | 437 | if (rb->read(fp, temp_memo2, 2) == 2) |
459 | memos[memos_in_memory].day = rb->atoi(&temp_memo2[0]); | 438 | memos[memos_in_memory].day = rb->atoi(&temp_memo2[0]); |
460 | else | 439 | else |
@@ -472,7 +451,7 @@ static void load_memo(struct shown *shown) | |||
472 | if (memos[memos_in_memory].year > (shown->year * 10)) | 451 | if (memos[memos_in_memory].year > (shown->year * 10)) |
473 | memos[memos_in_memory].year = (memos[memos_in_memory].year - | 452 | memos[memos_in_memory].year = (memos[memos_in_memory].year - |
474 | memos[memos_in_memory].month) / | 453 | memos[memos_in_memory].month) / |
475 | 100; | 454 | 100; |
476 | if (rb->read(fp, temp_memo1, 1) == 1) | 455 | if (rb->read(fp, temp_memo1, 1) == 1) |
477 | memos[memos_in_memory].wday = rb->atoi(&temp_memo1[0]); | 456 | memos[memos_in_memory].wday = rb->atoi(&temp_memo1[0]); |
478 | else | 457 | else |
@@ -481,48 +460,16 @@ static void load_memo(struct shown *shown) | |||
481 | memos[memos_in_memory].type = rb->atoi(&temp_memo1[0]); | 460 | memos[memos_in_memory].type = rb->atoi(&temp_memo1[0]); |
482 | else | 461 | else |
483 | memos[memos_in_memory].type = 0; | 462 | memos[memos_in_memory].type = 0; |
484 | for (k = 0; k <= count; k++) | 463 | load_to_memory = ((memos[memos_in_memory].type < 2) || |
464 | ((memos[memos_in_memory].type == 2) && | ||
465 | (memos[memos_in_memory].month == shown->mon)) || | ||
466 | ((memos[memos_in_memory].type > 2) && | ||
467 | (memos[memos_in_memory].month == shown->mon) && | ||
468 | (memos[memos_in_memory].year == shown->year))); | ||
469 | k = 0; | ||
470 | while (1) | ||
485 | { | 471 | { |
486 | if (rb->read(fp, temp_memo1, 1) == 1) | 472 | if (rb->read(fp, temp_memo1, 1) != 1) |
487 | { | ||
488 | if ( | ||
489 | (memos[memos_in_memory].type < 2) | ||
490 | || | ||
491 | ( | ||
492 | (memos[memos_in_memory].type == 2) | ||
493 | && | ||
494 | (memos[memos_in_memory].month == shown->mon) | ||
495 | ) | ||
496 | || | ||
497 | ( | ||
498 | (memos[memos_in_memory].type > 2) | ||
499 | && | ||
500 | (memos[memos_in_memory].month == shown->mon) | ||
501 | && | ||
502 | (memos[memos_in_memory].year == shown->year) | ||
503 | ) | ||
504 | ) | ||
505 | { | ||
506 | if (temp_memo1[0] == '\n') | ||
507 | { | ||
508 | if (memos[memos_in_memory].type > 0) | ||
509 | day_has_memo[memos[memos_in_memory].day] = | ||
510 | true; | ||
511 | else | ||
512 | wday_has_memo[memos[memos_in_memory].wday] = | ||
513 | true; | ||
514 | memos[memos_in_memory++].file_pointer_end = | ||
515 | rb->lseek(fp, 0, SEEK_CUR); | ||
516 | } | ||
517 | else if ( (temp_memo1[0] != '\r') && | ||
518 | (temp_memo1[0] != '\t') && | ||
519 | k < MAX_CHAR_MEMO_LEN-1 ) | ||
520 | memos[memos_in_memory].message[k] = temp_memo1[0]; | ||
521 | } | ||
522 | if (temp_memo1[0] == '\n') | ||
523 | break; | ||
524 | } | ||
525 | else | ||
526 | { | 473 | { |
527 | memos[memos_in_memory].day = 0; | 474 | memos[memos_in_memory].day = 0; |
528 | memos[memos_in_memory].month = 0; | 475 | memos[memos_in_memory].month = 0; |
@@ -535,6 +482,26 @@ static void load_memo(struct shown *shown) | |||
535 | exit = true; | 482 | exit = true; |
536 | break; | 483 | break; |
537 | } | 484 | } |
485 | if (load_to_memory) | ||
486 | { | ||
487 | if (temp_memo1[0] == '\n') | ||
488 | { | ||
489 | if (memos[memos_in_memory].type > 0) | ||
490 | day_has_memo[memos[memos_in_memory].day] = | ||
491 | true; | ||
492 | else | ||
493 | wday_has_memo[memos[memos_in_memory].wday] = | ||
494 | true; | ||
495 | memos[memos_in_memory++].file_pointer_end = | ||
496 | rb->lseek(fp, 0, SEEK_CUR); | ||
497 | } | ||
498 | else if ( (temp_memo1[0] != '\r') && | ||
499 | (temp_memo1[0] != '\t') && | ||
500 | k < MAX_CHAR_MEMO_LEN-1 ) | ||
501 | memos[memos_in_memory].message[k++] = temp_memo1[0]; | ||
502 | } | ||
503 | if (temp_memo1[0] == '\n') | ||
504 | break; | ||
538 | } | 505 | } |
539 | } | 506 | } |
540 | } | 507 | } |
@@ -546,7 +513,7 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
546 | int fp,fq; | 513 | int fp,fq; |
547 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY | O_CREAT); | 514 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY | O_CREAT); |
548 | fq = rb->creat(ROCKBOX_DIR "/~temp"); | 515 | fq = rb->creat(ROCKBOX_DIR "/~temp"); |
549 | if ( (fq != -1) && (fp != -1) ) | 516 | if ( (fq > -1) && (fp > -1) ) |
550 | { | 517 | { |
551 | int i; | 518 | int i; |
552 | char temp[MAX_CHAR_MEMO_LEN]; | 519 | char temp[MAX_CHAR_MEMO_LEN]; |
@@ -578,9 +545,9 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
578 | load_memo(shown); | 545 | load_memo(shown); |
579 | return true; | 546 | return true; |
580 | } | 547 | } |
581 | else if (fp != -1) | 548 | else if (fp > -1) |
582 | rb->close(fp); | 549 | rb->close(fp); |
583 | else if (fq != -1) | 550 | else if (fq > -1) |
584 | rb->close(fq); | 551 | rb->close(fq); |
585 | return false; | 552 | return false; |
586 | } | 553 | } |
@@ -714,7 +681,7 @@ static bool view_events(int selected, struct shown *shown) | |||
714 | rb->gui_synclist_set_nb_items(&gui_memos, memos_in_shown_memory); | 681 | rb->gui_synclist_set_nb_items(&gui_memos, memos_in_shown_memory); |
715 | rb->gui_synclist_select_item(&gui_memos, selected); | 682 | rb->gui_synclist_select_item(&gui_memos, selected); |
716 | rb->gui_synclist_draw(&gui_memos); | 683 | rb->gui_synclist_draw(&gui_memos); |
717 | 684 | ||
718 | while (!exit) | 685 | while (!exit) |
719 | { | 686 | { |
720 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); | 687 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); |
@@ -746,19 +713,10 @@ static void update_memos_shown(struct shown *shown) | |||
746 | int i; | 713 | int i; |
747 | memos_in_shown_memory = 0; | 714 | memos_in_shown_memory = 0; |
748 | for (i = 0; i < memos_in_memory; i++) | 715 | for (i = 0; i < memos_in_memory; i++) |
749 | if ( | 716 | if (((memos[i].type >= 1) && |
750 | ( | 717 | (memos[i].day == shown->mday)) || |
751 | (memos[i].type >= 1) | 718 | ((memos[i].type < 1) && |
752 | && | 719 | (memos[i].wday == shown->wday))) |
753 | (memos[i].day == shown->mday) | ||
754 | ) | ||
755 | || | ||
756 | ( | ||
757 | (memos[i].type < 1) | ||
758 | && | ||
759 | (memos[i].wday == shown->wday) | ||
760 | ) | ||
761 | ) | ||
762 | pointer_array[memos_in_shown_memory++] = i; | 720 | pointer_array[memos_in_shown_memory++] = i; |
763 | } | 721 | } |
764 | 722 | ||
@@ -836,7 +794,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
836 | struct shown shown; | 794 | struct shown shown; |
837 | bool exit = false; | 795 | bool exit = false; |
838 | int button; | 796 | int button; |
839 | 797 | ||
840 | (void)(parameter); | 798 | (void)(parameter); |
841 | 799 | ||
842 | calendar_init(&today, &shown); | 800 | calendar_init(&today, &shown); |