diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/SOURCES | 2 | ||||
-rw-r--r-- | apps/plugins/calendar.c | 103 |
2 files changed, 88 insertions, 17 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 4b60562af4..6edb73415a 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES | |||
@@ -58,6 +58,7 @@ flipit.c | |||
58 | #ifdef HAVE_LCD_BITMAP /* Not for the Player */ | 58 | #ifdef HAVE_LCD_BITMAP /* Not for the Player */ |
59 | rockblox1d.c | 59 | rockblox1d.c |
60 | brickmania.c | 60 | brickmania.c |
61 | calendar.c | ||
61 | maze.c | 62 | maze.c |
62 | mazezam.c | 63 | mazezam.c |
63 | text_editor.c | 64 | text_editor.c |
@@ -102,7 +103,6 @@ vu_meter.c | |||
102 | wormlet.c | 103 | wormlet.c |
103 | 104 | ||
104 | #if CONFIG_RTC | 105 | #if CONFIG_RTC |
105 | calendar.c | ||
106 | #endif /* CONFIG_RTC */ | 106 | #endif /* CONFIG_RTC */ |
107 | 107 | ||
108 | #if (MEMORYSIZE <= 8) && !defined(SIMULATOR) /* loaders, only needed for Archos */ | 108 | #if (MEMORYSIZE <= 8) && !defined(SIMULATOR) /* loaders, only needed for Archos */ |
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 0c3a4020ed..a7063b1f5b 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -21,8 +21,6 @@ | |||
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | 23 | ||
24 | #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) | ||
25 | |||
26 | #include <timefuncs.h> | 24 | #include <timefuncs.h> |
27 | #include "lib/playback_control.h" | 25 | #include "lib/playback_control.h" |
28 | #include "lib/configfile.h" | 26 | #include "lib/configfile.h" |
@@ -49,6 +47,16 @@ PLUGIN_HEADER | |||
49 | #define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN) | 47 | #define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN) |
50 | #define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP) | 48 | #define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP) |
51 | 49 | ||
50 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
51 | #define CALENDAR_QUIT BUTTON_OFF | ||
52 | #define CALENDAR_SELECT (BUTTON_MENU|BUTTON_REL) | ||
53 | #define CALENDAR_NEXT_WEEK BUTTON_DOWN | ||
54 | #define CALENDAR_PREV_WEEK BUTTON_UP | ||
55 | #define CALENDAR_NEXT_DAY BUTTON_RIGHT | ||
56 | #define CALENDAR_PREV_DAY BUTTON_LEFT | ||
57 | #define CALENDAR_NEXT_MONTH (BUTTON_MENU|BUTTON_DOWN) | ||
58 | #define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_UP) | ||
59 | |||
52 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | 60 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ |
53 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | 61 | (CONFIG_KEYPAD == IRIVER_H300_PAD) |
54 | #define CALENDAR_QUIT BUTTON_OFF | 62 | #define CALENDAR_QUIT BUTTON_OFF |
@@ -92,6 +100,16 @@ PLUGIN_HEADER | |||
92 | #define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN | 100 | #define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN |
93 | #define CALENDAR_PREV_MONTH BUTTON_VOL_UP | 101 | #define CALENDAR_PREV_MONTH BUTTON_VOL_UP |
94 | 102 | ||
103 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD | ||
104 | #define CALENDAR_QUIT BUTTON_PLAY | ||
105 | #define CALENDAR_SELECT BUTTON_SELECT | ||
106 | #define CALENDAR_NEXT_WEEK BUTTON_DOWN | ||
107 | #define CALENDAR_PREV_WEEK BUTTON_UP | ||
108 | #define CALENDAR_NEXT_DAY BUTTON_RIGHT | ||
109 | #define CALENDAR_PREV_DAY BUTTON_LEFT | ||
110 | #define CALENDAR_NEXT_MONTH BUTTON_MODE | ||
111 | #define CALENDAR_PREV_MONTH BUTTON_EQ | ||
112 | |||
95 | #elif CONFIG_KEYPAD == SANSA_E200_PAD | 113 | #elif CONFIG_KEYPAD == SANSA_E200_PAD |
96 | #define CALENDAR_QUIT BUTTON_POWER | 114 | #define CALENDAR_QUIT BUTTON_POWER |
97 | #define CALENDAR_SELECT BUTTON_SELECT | 115 | #define CALENDAR_SELECT BUTTON_SELECT |
@@ -112,9 +130,9 @@ PLUGIN_HEADER | |||
112 | #define CALENDAR_NEXT_MONTH BUTTON_DOWN | 130 | #define CALENDAR_NEXT_MONTH BUTTON_DOWN |
113 | #define CALENDAR_PREV_MONTH BUTTON_UP | 131 | #define CALENDAR_PREV_MONTH BUTTON_UP |
114 | 132 | ||
115 | #elif CONFIG_KEYPAD == SANSA_C200_PAD || \ | 133 | #elif (CONFIG_KEYPAD == SANSA_C200_PAD) || \ |
116 | CONFIG_KEYPAD == SANSA_CLIP_PAD || \ | 134 | (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \ |
117 | CONFIG_KEYPAD == SANSA_M200_PAD | 135 | (CONFIG_KEYPAD == SANSA_M200_PAD) |
118 | #define CALENDAR_QUIT BUTTON_POWER | 136 | #define CALENDAR_QUIT BUTTON_POWER |
119 | #define CALENDAR_SELECT BUTTON_SELECT | 137 | #define CALENDAR_SELECT BUTTON_SELECT |
120 | #define CALENDAR_NEXT_WEEK BUTTON_DOWN | 138 | #define CALENDAR_NEXT_WEEK BUTTON_DOWN |
@@ -174,6 +192,16 @@ CONFIG_KEYPAD == SANSA_M200_PAD | |||
174 | #define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT | 192 | #define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT |
175 | #define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT | 193 | #define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT |
176 | 194 | ||
195 | #elif CONFIG_KEYPAD == CREATIVEZVM_PAD | ||
196 | #define CALENDAR_QUIT BUTTON_BACK | ||
197 | #define CALENDAR_SELECT BUTTON_SELECT | ||
198 | #define CALENDAR_NEXT_WEEK BUTTON_DOWN | ||
199 | #define CALENDAR_PREV_WEEK BUTTON_UP | ||
200 | #define CALENDAR_NEXT_DAY BUTTON_RIGHT | ||
201 | #define CALENDAR_PREV_DAY BUTTON_LEFT | ||
202 | #define CALENDAR_NEXT_MONTH BUTTON_CUSTOM | ||
203 | #define CALENDAR_PREV_MONTH BUTTON_PLAY | ||
204 | |||
177 | #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD | 205 | #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD |
178 | #define CALENDAR_QUIT BUTTON_POWER | 206 | #define CALENDAR_QUIT BUTTON_POWER |
179 | #define CALENDAR_SELECT BUTTON_SELECT | 207 | #define CALENDAR_SELECT BUTTON_SELECT |
@@ -264,9 +292,20 @@ CONFIG_KEYPAD == SANSA_M200_PAD | |||
264 | #define CELL_HEIGHT (LCD_HEIGHT / 7) | 292 | #define CELL_HEIGHT (LCD_HEIGHT / 7) |
265 | 293 | ||
266 | #define CFG_FILE "calendar.cfg" | 294 | #define CFG_FILE "calendar.cfg" |
267 | static int first_wday = 0, old_first_wday; | 295 | struct info { |
296 | int first_wday; | ||
297 | #if (CONFIG_RTC == 0) | ||
298 | int last_mon; | ||
299 | int last_year; | ||
300 | #endif | ||
301 | }; | ||
302 | static struct info info = { .first_wday = 0 }, old_info; | ||
268 | static struct configdata config[] = { | 303 | static struct configdata config[] = { |
269 | { TYPE_INT, 0, 6, { .int_p = &first_wday }, "first wday", NULL }, | 304 | { TYPE_INT, 0, 6, { .int_p = &(info.first_wday) }, "first wday", NULL }, |
305 | #if (CONFIG_RTC == 0) | ||
306 | { TYPE_INT, 1, 12, { .int_p = &(info.last_mon) }, "last mon", NULL }, | ||
307 | { TYPE_INT, 1, 3000, { .int_p = &(info.last_year) }, "last year", NULL }, | ||
308 | #endif | ||
270 | }; | 309 | }; |
271 | 310 | ||
272 | static bool leap_year; | 311 | static bool leap_year; |
@@ -306,6 +345,20 @@ static int calc_weekday( struct shown *shown ) | |||
306 | return ( shown->wday + 36 - shown->mday ) % 7 ; | 345 | return ( shown->wday + 36 - shown->mday ) % 7 ; |
307 | } | 346 | } |
308 | 347 | ||
348 | #if (CONFIG_RTC == 0) | ||
349 | /* from timefunc.c */ | ||
350 | static void my_set_day_of_week(struct shown *shown) | ||
351 | { | ||
352 | int y = shown->year; | ||
353 | int d = shown->mday; | ||
354 | int m = shown->mon-1; | ||
355 | static const char mo[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; | ||
356 | |||
357 | if(m == 0 || m == 1) y--; | ||
358 | shown->wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7 - 1; | ||
359 | } | ||
360 | #endif | ||
361 | |||
309 | static void calendar_init(struct shown *shown) | 362 | static void calendar_init(struct shown *shown) |
310 | { | 363 | { |
311 | int w, h; | 364 | int w, h; |
@@ -323,6 +376,21 @@ static void calendar_init(struct shown *shown) | |||
323 | shown->mon = tm->tm_mon + 1; | 376 | shown->mon = tm->tm_mon + 1; |
324 | shown->year = 2000 + (tm->tm_year%100); | 377 | shown->year = 2000 + (tm->tm_year%100); |
325 | shown->wday = tm->tm_wday - 1; | 378 | shown->wday = tm->tm_wday - 1; |
379 | #else | ||
380 | #define S100(x) 1 ## x | ||
381 | #define C2DIG2DEC(x) (S100(x)-100) | ||
382 | if(info.last_mon == 0 || info.last_year == 0) | ||
383 | { | ||
384 | shown->mon = C2DIG2DEC(MONTH); | ||
385 | shown->year = YEAR; | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | shown->mon = info.last_mon; | ||
390 | shown->year = info.last_year; | ||
391 | } | ||
392 | shown->mday = 1; | ||
393 | my_set_day_of_week(shown); | ||
326 | #endif | 394 | #endif |
327 | shown->firstday = calc_weekday(shown); | 395 | shown->firstday = calc_weekday(shown); |
328 | leap_year = is_leap_year(shown->year); | 396 | leap_year = is_leap_year(shown->year); |
@@ -345,7 +413,7 @@ static void draw_headers(void) | |||
345 | } | 413 | } |
346 | } | 414 | } |
347 | 415 | ||
348 | wday = first_wday; | 416 | wday = info.first_wday; |
349 | rb->lcd_getstringsize("A", &w, &h); | 417 | rb->lcd_getstringsize("A", &w, &h); |
350 | for (i = 0; i < 7; i++) | 418 | for (i = 0; i < 7; i++) |
351 | { | 419 | { |
@@ -376,7 +444,7 @@ static void draw_calendar(struct shown *shown) | |||
376 | rb->lcd_clear_display(); | 444 | rb->lcd_clear_display(); |
377 | draw_headers(); | 445 | draw_headers(); |
378 | wday = shown->firstday; | 446 | wday = shown->firstday; |
379 | pos = wday + 7 - first_wday; | 447 | pos = wday + 7 - info.first_wday; |
380 | if (pos >= 7) pos -= 7; | 448 | if (pos >= 7) pos -= 7; |
381 | 449 | ||
382 | days_per_month = days_in_month[leap_year][shown->mon]; | 450 | days_per_month = days_in_month[leap_year][shown->mon]; |
@@ -661,7 +729,7 @@ static bool edit_memo(int change, struct shown *shown) | |||
661 | return false; | 729 | return false; |
662 | 730 | ||
663 | case 6: /* weekday */ | 731 | case 6: /* weekday */ |
664 | rb->set_option("First Day of Week", &first_wday, | 732 | rb->set_option("First Day of Week", &info.first_wday, |
665 | INT, modes, 7, NULL); | 733 | INT, modes, 7, NULL); |
666 | break; | 734 | break; |
667 | 735 | ||
@@ -828,8 +896,8 @@ enum plugin_status plugin_start(const void* parameter) | |||
828 | 896 | ||
829 | (void)(parameter); | 897 | (void)(parameter); |
830 | 898 | ||
831 | configfile_load(CFG_FILE, config, 1, 0); | 899 | configfile_load(CFG_FILE, config, ARRAYLEN(config), 0); |
832 | old_first_wday = first_wday; | 900 | rb->memcpy(&old_info, &info, sizeof(struct info)); |
833 | 901 | ||
834 | calendar_init(&shown); | 902 | calendar_init(&shown); |
835 | load_memo(&shown); | 903 | load_memo(&shown); |
@@ -888,9 +956,12 @@ enum plugin_status plugin_start(const void* parameter) | |||
888 | } | 956 | } |
889 | } | 957 | } |
890 | 958 | ||
891 | if (old_first_wday != first_wday) | ||
892 | configfile_save(CFG_FILE, config, 1, 0); | ||
893 | return been_in_usb_mode?PLUGIN_USB_CONNECTED:PLUGIN_OK; | ||
894 | } | ||
895 | 959 | ||
960 | #if (CONFIG_RTC == 0) | ||
961 | info.last_mon = shown.mon; | ||
962 | info.last_year = shown.year; | ||
896 | #endif | 963 | #endif |
964 | if (rb->memcmp(&old_info, &info, sizeof(struct info))) | ||
965 | configfile_save(CFG_FILE, config, ARRAYLEN(config), 0); | ||
966 | return been_in_usb_mode?PLUGIN_USB_CONNECTED:PLUGIN_OK; | ||
967 | } | ||