diff options
author | Nils Wallménius <nils@rockbox.org> | 2008-10-24 08:40:48 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2008-10-24 08:40:48 +0000 |
commit | be00a109b398ca2597ba05908aea89df06d6a92d (patch) | |
tree | 799b1f5069deedf9ef1a9c3633573cdbc4ec8e60 /apps/plugins | |
parent | 3ff2f14f9e7e62cbc4a9a09f6e5a7c5f4d0ed618 (diff) | |
download | rockbox-be00a109b398ca2597ba05908aea89df06d6a92d.tar.gz rockbox-be00a109b398ca2597ba05908aea89df06d6a92d.zip |
FS#9487 fixes and improvements of the calendar plugin by Teruaki Kawashima
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18870 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/calendar.c | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 8fb9b7a61a..f7e4ffe786 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -30,9 +30,10 @@ PLUGIN_HEADER | |||
30 | static const struct plugin_api* rb; | 30 | static const struct plugin_api* rb; |
31 | 31 | ||
32 | static bool leap_year; | 32 | static bool leap_year; |
33 | /* days_in_month[][0] is for December */ | ||
33 | static const int days_in_month[2][13] = { | 34 | static const int days_in_month[2][13] = { |
34 | {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, | 35 | {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, |
35 | {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, | 36 | {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, |
36 | }; | 37 | }; |
37 | 38 | ||
38 | struct today { | 39 | struct today { |
@@ -104,12 +105,12 @@ static int space = LCD_WIDTH / 7; | |||
104 | static void draw_headers(void) | 105 | static void draw_headers(void) |
105 | { | 106 | { |
106 | int i,w,h; | 107 | int i,w,h; |
107 | const char *Dayname[7] = {"M","T","W","T","F","S","S"}; | 108 | const char *dayname[7] = {"M","T","W","T","F","S","S"}; |
108 | int ws = 2; | 109 | int ws = 2; |
109 | rb->lcd_getstringsize("A",&w,&h); | 110 | rb->lcd_getstringsize("A",&w,&h); |
110 | for (i = 0; i < 7; i++) | 111 | for (i = 0; i < 7; i++) |
111 | { | 112 | { |
112 | rb->lcd_putsxy(ws, 0 , Dayname[i]); | 113 | rb->lcd_putsxy(ws, 0 , dayname[i]); |
113 | ws += space; | 114 | ws += space; |
114 | } | 115 | } |
115 | rb->lcd_hline(0, LCD_WIDTH-1 ,h); | 116 | rb->lcd_hline(0, LCD_WIDTH-1 ,h); |
@@ -122,7 +123,7 @@ static void draw_calendar(struct shown *shown) | |||
122 | int w,h; | 123 | int w,h; |
123 | int ws,row,pos,days_per_month,j; | 124 | int ws,row,pos,days_per_month,j; |
124 | char buffer[9]; | 125 | char buffer[9]; |
125 | const char *Monthname[] = { | 126 | const char *monthname[] = { |
126 | "Jan", | 127 | "Jan", |
127 | "Feb", | 128 | "Feb", |
128 | "Mar", | 129 | "Mar", |
@@ -170,14 +171,14 @@ static void draw_calendar(struct shown *shown) | |||
170 | } | 171 | } |
171 | rb->lcd_vline(60,LCD_HEIGHT-h-3,LCD_HEIGHT-1); | 172 | rb->lcd_vline(60,LCD_HEIGHT-h-3,LCD_HEIGHT-1); |
172 | rb->lcd_hline(60,LCD_WIDTH-1,LCD_HEIGHT-h-3); | 173 | rb->lcd_hline(60,LCD_WIDTH-1,LCD_HEIGHT-h-3); |
173 | rb->snprintf(buffer,9,"%s %04d",Monthname[shown->mon-1],shown->year); | 174 | rb->snprintf(buffer,9,"%s %04d",monthname[shown->mon-1],shown->year); |
174 | rb->lcd_putsxy(62,(LCD_HEIGHT-h-1),buffer); | 175 | rb->lcd_putsxy(62,(LCD_HEIGHT-h-1),buffer); |
175 | shown->lastday = pos; | 176 | shown->lastday = pos; |
176 | rb->lcd_update(); | 177 | rb->lcd_update(); |
177 | } | 178 | } |
178 | 179 | ||
179 | #define MAX_CHAR_MEMO_LEN 63 | 180 | #define MAX_CHAR_MEMO_LEN 64 |
180 | #define MAX_MEMOS_IN_A_MONTH 127 | 181 | #define MAX_MEMOS_IN_A_MONTH 128 |
181 | struct memo { | 182 | struct memo { |
182 | char message[MAX_CHAR_MEMO_LEN]; | 183 | char message[MAX_CHAR_MEMO_LEN]; |
183 | int day; | 184 | int day; |
@@ -199,6 +200,9 @@ static void load_memo(struct shown *shown) | |||
199 | char temp_memo1[2]; | 200 | char temp_memo1[2]; |
200 | char temp_memo2[3]; | 201 | char temp_memo2[3]; |
201 | char temp_memo4[5]; | 202 | char temp_memo4[5]; |
203 | temp_memo1[1] = 0; | ||
204 | temp_memo2[2] = 0; | ||
205 | temp_memo4[4] = 0; | ||
202 | for (k = 0; k < memos_in_memory; k++) | 206 | for (k = 0; k < memos_in_memory; k++) |
203 | { | 207 | { |
204 | memos[k].day = 0; | 208 | memos[k].day = 0; |
@@ -208,8 +212,8 @@ static void load_memo(struct shown *shown) | |||
208 | memos[k].year = 0; | 212 | memos[k].year = 0; |
209 | memos[k].type = 0; | 213 | memos[k].type = 0; |
210 | memos[k].wday = 0; | 214 | memos[k].wday = 0; |
211 | for (i = 0; i <= MAX_CHAR_MEMO_LEN; i++) | 215 | for (i = 0; i < MAX_CHAR_MEMO_LEN; i++) |
212 | rb->strcpy(&memos[k].message[i],""); | 216 | memos[k].message[i] = 0; |
213 | } | 217 | } |
214 | for (k = 1; k < 32; k++) | 218 | for (k = 1; k < 32; k++) |
215 | day_has_memo[k] = false; | 219 | day_has_memo[k] = false; |
@@ -262,7 +266,7 @@ static void load_memo(struct shown *shown) | |||
262 | (memos[memos_in_memory].type == 2) | 266 | (memos[memos_in_memory].type == 2) |
263 | && | 267 | && |
264 | (memos[memos_in_memory].month == shown->mon) | 268 | (memos[memos_in_memory].month == shown->mon) |
265 | ) | 269 | ) |
266 | || | 270 | || |
267 | ( | 271 | ( |
268 | (memos[memos_in_memory].type > 2) | 272 | (memos[memos_in_memory].type > 2) |
@@ -270,8 +274,8 @@ static void load_memo(struct shown *shown) | |||
270 | (memos[memos_in_memory].month == shown->mon) | 274 | (memos[memos_in_memory].month == shown->mon) |
271 | && | 275 | && |
272 | (memos[memos_in_memory].year == shown->year) | 276 | (memos[memos_in_memory].year == shown->year) |
273 | ) | ||
274 | ) | 277 | ) |
278 | ) | ||
275 | { | 279 | { |
276 | if (temp_memo1[0] == '\n') | 280 | if (temp_memo1[0] == '\n') |
277 | { | 281 | { |
@@ -285,7 +289,8 @@ static void load_memo(struct shown *shown) | |||
285 | rb->lseek(fp, 0, SEEK_CUR); | 289 | rb->lseek(fp, 0, SEEK_CUR); |
286 | } | 290 | } |
287 | else if ( (temp_memo1[0] != '\r') && | 291 | else if ( (temp_memo1[0] != '\r') && |
288 | (temp_memo1[0] != '\t') ) | 292 | (temp_memo1[0] != '\t') && |
293 | k < MAX_CHAR_MEMO_LEN-1 ) | ||
289 | memos[memos_in_memory].message[k] = temp_memo1[0]; | 294 | memos[memos_in_memory].message[k] = temp_memo1[0]; |
290 | } | 295 | } |
291 | if (temp_memo1[0] == '\n') | 296 | if (temp_memo1[0] == '\n') |
@@ -300,7 +305,7 @@ static void load_memo(struct shown *shown) | |||
300 | memos[memos_in_memory].year = 0; | 305 | memos[memos_in_memory].year = 0; |
301 | memos[memos_in_memory].type = 0; | 306 | memos[memos_in_memory].type = 0; |
302 | memos[memos_in_memory].wday = 0; | 307 | memos[memos_in_memory].wday = 0; |
303 | rb->strcpy(&memos[memos_in_memory].message[0], ""); | 308 | memos[memos_in_memory].message[0] = 0; |
304 | exit = true; | 309 | exit = true; |
305 | break; | 310 | break; |
306 | } | 311 | } |
@@ -318,7 +323,7 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
318 | if ( (fq != -1) && (fp != -1) ) | 323 | if ( (fq != -1) && (fp != -1) ) |
319 | { | 324 | { |
320 | int i; | 325 | int i; |
321 | char temp[MAX_CHAR_MEMO_LEN + 1]; | 326 | char temp[MAX_CHAR_MEMO_LEN]; |
322 | rb->lseek(fp, 0, SEEK_SET); | 327 | rb->lseek(fp, 0, SEEK_SET); |
323 | for (i = 0; i < memos[changed].file_pointer_start; i++) | 328 | for (i = 0; i < memos[changed].file_pointer_start; i++) |
324 | { | 329 | { |
@@ -336,24 +341,14 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
336 | memos[changed].message); | 341 | memos[changed].message); |
337 | } | 342 | } |
338 | rb->lseek(fp, memos[changed].file_pointer_end, SEEK_SET); | 343 | rb->lseek(fp, memos[changed].file_pointer_end, SEEK_SET); |
339 | for (i = memos[changed].file_pointer_end; | 344 | while(rb->read(fp, temp, 1) == 1) |
340 | i < rb->filesize(fp); i++) | ||
341 | { | 345 | { |
342 | rb->read(fp, temp, 1); | ||
343 | rb->write(fq,temp,1); | 346 | rb->write(fq,temp,1); |
344 | } | 347 | } |
345 | rb->close(fp); | 348 | rb->close(fp); |
346 | fp = rb->creat(ROCKBOX_DIR "/.memo"); | ||
347 | rb->lseek(fp, 0, SEEK_SET); | ||
348 | rb->lseek(fq, 0, SEEK_SET); | ||
349 | for (i = 0; i < rb->filesize(fq); i++) | ||
350 | { | ||
351 | rb->read(fq, temp, 1); | ||
352 | rb->write(fp,temp,1); | ||
353 | } | ||
354 | rb->close(fp); | ||
355 | rb->close(fq); | 349 | rb->close(fq); |
356 | rb->remove(ROCKBOX_DIR "/~temp"); | 350 | rb->remove(ROCKBOX_DIR "/.memo"); |
351 | rb->rename(ROCKBOX_DIR "/~temp", ROCKBOX_DIR "/.memo"); | ||
357 | load_memo(shown); | 352 | load_memo(shown); |
358 | return true; | 353 | return true; |
359 | } | 354 | } |
@@ -371,7 +366,7 @@ static void add_memo(struct shown *shown, int type) | |||
371 | sizeof memos[memos_in_memory].message) != -1) | 366 | sizeof memos[memos_in_memory].message) != -1) |
372 | { | 367 | { |
373 | if (rb->strlen(memos[memos_in_memory].message)) | 368 | if (rb->strlen(memos[memos_in_memory].message)) |
374 | { | 369 | { |
375 | memos[memos_in_memory].file_pointer_start = 0; | 370 | memos[memos_in_memory].file_pointer_start = 0; |
376 | memos[memos_in_memory].file_pointer_end = 0; | 371 | memos[memos_in_memory].file_pointer_end = 0; |
377 | memos[memos_in_memory].day = shown->mday; | 372 | memos[memos_in_memory].day = shown->mday; |
@@ -382,7 +377,6 @@ static void add_memo(struct shown *shown, int type) | |||
382 | if (save_memo(memos_in_memory,true,shown)) | 377 | if (save_memo(memos_in_memory,true,shown)) |
383 | { | 378 | { |
384 | saved = true; | 379 | saved = true; |
385 | memos_in_memory++; | ||
386 | } | 380 | } |
387 | else | 381 | else |
388 | { | 382 | { |
@@ -534,7 +528,11 @@ static void update_memos_shown(struct shown *shown) | |||
534 | start = 0; | 528 | start = 0; |
535 | for (i = 0; i < memos_in_memory; i++) | 529 | for (i = 0; i < memos_in_memory; i++) |
536 | if ( | 530 | if ( |
537 | (memos[i].day == shown->mday) | 531 | ( |
532 | (memos[i].type >= 1) | ||
533 | && | ||
534 | (memos[i].day == shown->mday) | ||
535 | ) | ||
538 | || | 536 | || |
539 | ( | 537 | ( |
540 | (memos[i].type < 1) | 538 | (memos[i].type < 1) |
@@ -612,7 +610,7 @@ static void next_month(struct shown *shown, int step) | |||
612 | shown->year++; | 610 | shown->year++; |
613 | leap_year = is_leap_year(shown->year); | 611 | leap_year = is_leap_year(shown->year); |
614 | } | 612 | } |
615 | else if (step > 0) | 613 | if (step > 0) |
616 | shown->mday = shown->mday - days_in_month[leap_year][shown->mon-1]; | 614 | shown->mday = shown->mday - days_in_month[leap_year][shown->mon-1]; |
617 | else if (shown->mday > days_in_month[leap_year][shown->mon]) | 615 | else if (shown->mday > days_in_month[leap_year][shown->mon]) |
618 | shown->mday = days_in_month[leap_year][shown->mon]; | 616 | shown->mday = days_in_month[leap_year][shown->mon]; |