diff options
Diffstat (limited to 'apps/plugins/calendar.c')
-rw-r--r-- | apps/plugins/calendar.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 448c1a824f..233fc096d1 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -46,7 +46,6 @@ struct shown { | |||
46 | int firstday; /* first (w)day of month */ | 46 | int firstday; /* first (w)day of month */ |
47 | int lastday; /* last (w)day of month */ | 47 | int lastday; /* last (w)day of month */ |
48 | }; | 48 | }; |
49 | |||
50 | /* leap year -- account for gregorian reformation in 1752 */ | 49 | /* leap year -- account for gregorian reformation in 1752 */ |
51 | static int is_leap_year(int yr) | 50 | static int is_leap_year(int yr) |
52 | { | 51 | { |
@@ -54,7 +53,8 @@ static int is_leap_year(int yr) | |||
54 | (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400)) ? 1:0 ; | 53 | (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400)) ? 1:0 ; |
55 | } | 54 | } |
56 | 55 | ||
57 | /* searches the weekday of the first day in month, relative to the given values */ | 56 | /* searches the weekday of the first day in month, |
57 | * relative to the given values */ | ||
58 | static int calc_weekday( struct shown *shown ) | 58 | static int calc_weekday( struct shown *shown ) |
59 | { | 59 | { |
60 | return ( shown->wday + 36 - shown->mday ) % 7 ; | 60 | return ( shown->wday + 36 - shown->mday ) % 7 ; |
@@ -64,12 +64,14 @@ static int calc_weekday( struct shown *shown ) | |||
64 | static void calendar_init(struct today *today, struct shown *shown) | 64 | static void calendar_init(struct today *today, struct shown *shown) |
65 | { | 65 | { |
66 | int w,h; | 66 | int w,h; |
67 | #ifdef HAVE_RTC | ||
68 | struct tm *tm; | ||
69 | #endif | ||
67 | rb->lcd_getstringsize("A",&w,&h); | 70 | rb->lcd_getstringsize("A",&w,&h); |
68 | if ( ((w * 14) > LCD_WIDTH) || ((h * 7) > LCD_HEIGHT) ) | 71 | if ( ((w * 14) > LCD_WIDTH) || ((h * 7) > LCD_HEIGHT) ) |
69 | rb->lcd_setfont(FONT_SYSFIXED); | 72 | rb->lcd_setfont(FONT_SYSFIXED); |
70 | rb->lcd_clear_display(); | 73 | rb->lcd_clear_display(); |
71 | #ifdef HAVE_RTC | 74 | #ifdef HAVE_RTC |
72 | struct tm *tm; | ||
73 | tm = rb->get_time(); | 75 | tm = rb->get_time(); |
74 | today->mon = tm->tm_mon +1; | 76 | today->mon = tm->tm_mon +1; |
75 | today->year = 2000+tm->tm_year%100; | 77 | today->year = 2000+tm->tm_year%100; |
@@ -92,9 +94,9 @@ static int space = LCD_WIDTH / 7; | |||
92 | static void draw_headers(void) | 94 | static void draw_headers(void) |
93 | { | 95 | { |
94 | int i,w,h; | 96 | int i,w,h; |
95 | rb->lcd_getstringsize("A",&w,&h); | ||
96 | char *Dayname[7] = {"M","T","W","T","F","S","S"}; | 97 | char *Dayname[7] = {"M","T","W","T","F","S","S"}; |
97 | int ws = 2; | 98 | int ws = 2; |
99 | rb->lcd_getstringsize("A",&w,&h); | ||
98 | for (i = 0; i < 8;) | 100 | for (i = 0; i < 8;) |
99 | { | 101 | { |
100 | rb->lcd_putsxy(ws, 0 , Dayname[i++]); | 102 | rb->lcd_putsxy(ws, 0 , Dayname[i++]); |
@@ -108,7 +110,8 @@ static bool wday_has_memo[6]; | |||
108 | static void draw_calendar(struct shown *shown) | 110 | static void draw_calendar(struct shown *shown) |
109 | { | 111 | { |
110 | int w,h; | 112 | int w,h; |
111 | rb->lcd_getstringsize("A",&w,&h); | 113 | int ws,row,pos,days_per_month,j; |
114 | char buffer[7]; | ||
112 | char *Monthname[] = { | 115 | char *Monthname[] = { |
113 | "Jan", | 116 | "Jan", |
114 | "Feb", | 117 | "Feb", |
@@ -123,16 +126,15 @@ static void draw_calendar(struct shown *shown) | |||
123 | "Nov", | 126 | "Nov", |
124 | "Dec" | 127 | "Dec" |
125 | }; | 128 | }; |
129 | rb->lcd_getstringsize("A",&w,&h); | ||
126 | rb->lcd_clear_display(); | 130 | rb->lcd_clear_display(); |
127 | draw_headers(); | 131 | draw_headers(); |
128 | int row,pos,days_per_month,j; | ||
129 | if (shown->firstday > 6) | 132 | if (shown->firstday > 6) |
130 | shown->firstday -= 7; | 133 | shown->firstday -= 7; |
131 | char buffer[7]; | ||
132 | row = 1; | 134 | row = 1; |
133 | pos = shown->firstday; | 135 | pos = shown->firstday; |
134 | days_per_month = days_in_month[leap_year][shown->mon]; | 136 | days_per_month = days_in_month[leap_year][shown->mon]; |
135 | int ws = 2 + (pos * space); | 137 | ws = 2 + (pos * space); |
136 | for (j = 0; j < days_per_month;) | 138 | for (j = 0; j < days_per_month;) |
137 | { | 139 | { |
138 | if ( (day_has_memo[++j]) || (wday_has_memo[pos]) ) | 140 | if ( (day_has_memo[++j]) || (wday_has_memo[pos]) ) |
@@ -494,11 +496,11 @@ static int start = 0; | |||
494 | 496 | ||
495 | static void show_lines(int selected, struct shown *shown) | 497 | static void show_lines(int selected, struct shown *shown) |
496 | { | 498 | { |
497 | int j = 1,w,h,i,k = 0, pos = 1,m = 0; | 499 | int lines,j = 1,w,h,i,k = 0, pos = 1,m = 0; |
498 | rb->lcd_getstringsize("A",&w,&h); | ||
499 | int lines = (LCD_HEIGHT / h) - 1; | ||
500 | char temp[MAX_CHAR_MEMO_LEN + 12]; | 500 | char temp[MAX_CHAR_MEMO_LEN + 12]; |
501 | 501 | rb->lcd_getstringsize("A",&w,&h); | |
502 | lines = (LCD_HEIGHT / h) - 1; | ||
503 | |||
502 | rb->lcd_clear_display(); | 504 | rb->lcd_clear_display(); |
503 | rb->lcd_puts(0,0,"Events (play : menu)"); | 505 | rb->lcd_puts(0,0,"Events (play : menu)"); |
504 | 506 | ||
@@ -532,9 +534,9 @@ static void show_lines(int selected, struct shown *shown) | |||
532 | 534 | ||
533 | static void update_memos_shown(struct shown *shown) | 535 | static void update_memos_shown(struct shown *shown) |
534 | { | 536 | { |
537 | int i; | ||
535 | memos_in_shown_memory = 0; | 538 | memos_in_shown_memory = 0; |
536 | start = 0; | 539 | start = 0; |
537 | int i; | ||
538 | for (i = 0; i < memos_in_memory; i++) | 540 | for (i = 0; i < memos_in_memory; i++) |
539 | if ( | 541 | if ( |
540 | (memos[i].day == shown->mday) | 542 | (memos[i].day == shown->mday) |
@@ -550,8 +552,9 @@ static void update_memos_shown(struct shown *shown) | |||
550 | 552 | ||
551 | static bool any_events(struct shown *shown, bool force) | 553 | static bool any_events(struct shown *shown, bool force) |
552 | { | 554 | { |
553 | update_memos_shown(shown); | ||
554 | int lines_displayed = 0; | 555 | int lines_displayed = 0; |
556 | bool exit=false; | ||
557 | update_memos_shown(shown); | ||
555 | if (memos_in_shown_memory > 0) | 558 | if (memos_in_shown_memory > 0) |
556 | show_lines(lines_displayed,shown); | 559 | show_lines(lines_displayed,shown); |
557 | else if (force) | 560 | else if (force) |
@@ -559,7 +562,6 @@ static bool any_events(struct shown *shown, bool force) | |||
559 | else | 562 | else |
560 | return false; | 563 | return false; |
561 | rb->lcd_update(); | 564 | rb->lcd_update(); |
562 | bool exit = false; | ||
563 | while (!exit) | 565 | while (!exit) |
564 | { | 566 | { |
565 | switch (rb->button_get(true)) | 567 | switch (rb->button_get(true)) |
@@ -655,18 +657,18 @@ static void prev_day(struct shown *shown, int step) | |||
655 | 657 | ||
656 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 658 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
657 | { | 659 | { |
660 | struct today today; | ||
661 | struct shown shown; | ||
662 | bool exit = false; | ||
658 | TEST_PLUGIN_API(api); | 663 | TEST_PLUGIN_API(api); |
659 | (void)(parameter); | 664 | (void)(parameter); |
665 | |||
660 | rb = api; | 666 | rb = api; |
661 | 667 | ||
662 | struct today today; | ||
663 | struct shown shown; | ||
664 | |||
665 | calendar_init(&today, &shown); | 668 | calendar_init(&today, &shown); |
666 | load_memo(&shown); | 669 | load_memo(&shown); |
667 | any_events(&shown, false); | 670 | any_events(&shown, false); |
668 | draw_calendar(&shown); | 671 | draw_calendar(&shown); |
669 | bool exit = false; | ||
670 | while (!exit) | 672 | while (!exit) |
671 | { | 673 | { |
672 | switch (rb->button_get(true)) | 674 | switch (rb->button_get(true)) |