Index: apps/plugins/calendar.c =================================================================== --- apps/plugins/calendar.c (revision 22928) +++ apps/plugins/calendar.c (working copy) @@ -25,6 +25,7 @@ #include #include "lib/playback_control.h" +#include "lib/configfile.h" PLUGIN_HEADER @@ -252,6 +253,15 @@ #define CELL_WIDTH (LCD_WIDTH / 7) #define CELL_HEIGHT (LCD_HEIGHT / 7) +#define CFG_FILE "calendar.cfg" +static int calendar_mode; +static struct configdata config[] = { + {TYPE_INT, 0, 1, { .int_p = &calendar_mode }, "Calendar Mode", NULL}, +}; + +#define CALENDAR_MODE_EURO 0 +#define CALENDAR_MODE_US 1 + static bool leap_year; /* days_in_month[][0] is for December */ static const int days_in_month[2][13] = { @@ -259,8 +269,14 @@ {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, }; -static const char *dayname_long[7] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; -static const char *dayname_short[7] = {"M","T","W","T","F","S","S"}; +/* Use this for Euro mode header*/ +static const char *euro_dayname_long[7] = + {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; +static const char *euro_dayname_short[7] = {"M","T","W","T","F","S","S"}; +/* Use this for US mode header */ +static const char *us_dayname_long[7] = + {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; +static const char *us_dayname_short[7] = {"S","M","T","W","T","F","S"}; struct shown { int mday; /* day of the month */ @@ -284,10 +300,13 @@ /* searches the weekday of the first day in month, * relative to the given values */ +/* use for US - return ( shown->wday + 37 - shown->mday ) % 7 ; */ static int calc_weekday( struct shown *shown ) { - return ( shown->wday + 36 - shown->mday ) % 7 ; - + if (calendar_mode == CALENDAR_MODE_EURO) + return ( shown->wday + 36 - shown->mday ) % 7 ; + else + return ( shown->wday + 37 - shown->mday ) % 7 ; } static void calendar_init(struct shown *shown) @@ -318,22 +337,37 @@ { int i,w,h; int x = X_OFFSET; - const char **dayname = (const char**)&dayname_long; + const char **us_dayname = (const char**)&us_dayname_long; + const char **euro_dayname = (const char**)&euro_dayname_long; for (i = 0; i < 7; i++) { - rb->lcd_getstringsize(dayname[i],&w,&h); + if (calendar_mode == CALENDAR_MODE_EURO) + rb->lcd_getstringsize(euro_dayname[i],&w,&h); + else if (calendar_mode == CALENDAR_MODE_US) + rb->lcd_getstringsize(us_dayname[i],&w,&h); if (w > CELL_WIDTH) { - dayname = (const char**)&dayname_short; - break; + if (calendar_mode == CALENDAR_MODE_EURO) + { + euro_dayname = (const char**)&euro_dayname_short; + break; + } + else if (calendar_mode == CALENDAR_MODE_US) + { + us_dayname = (const char**)&us_dayname_short; + break; + } } } rb->lcd_getstringsize("A",&w,&h); for (i = 0; i < 7; i++) { - rb->lcd_putsxy(x, 0 , dayname[i]); + if (calendar_mode == CALENDAR_MODE_EURO) + rb->lcd_putsxy(x, 0 , euro_dayname[i]); + else if (calendar_mode == CALENDAR_MODE_US) + rb->lcd_putsxy(x, 0 , us_dayname[i]); x += CELL_WIDTH; } rb->lcd_hline(0, LCD_WIDTH-1 ,h); @@ -466,10 +500,10 @@ memos[memos_in_memory].type = 0; load_to_memory = ((memos[memos_in_memory].type < 2) || ((memos[memos_in_memory].type == 2) && - (memos[memos_in_memory].month == shown->mon)) || + (memos[memos_in_memory].month == shown->mon)) || ((memos[memos_in_memory].type > 2) && - (memos[memos_in_memory].month == shown->mon) && - (memos[memos_in_memory].year == shown->year))); + (memos[memos_in_memory].month == shown->mon) && + (memos[memos_in_memory].year == shown->year))); k = 0; while (1) { @@ -611,11 +645,16 @@ bool exit = false; int selected = 0; + static const struct opt_items modes[2] = { + { "European Style", -1 }, + { "US style", -1 }, + }; + MENUITEM_STRINGLIST(edit_menu, "Edit menu", edit_menu_cb, "Remove", "Edit", "New Weekly", "New Monthly", "New Yearly", "New One off", - "Playback Control"); + "Playback Control", "Calendar Mode"); while (!exit) { @@ -650,6 +689,12 @@ case 6: /* playback control */ playback_control(NULL); break; + case 7: /* Calendar Mode - Euro or US */ + rb->set_option("Calendar Mode", &calendar_mode, + INT, modes, 2, NULL); + calendar_init(shown); /* reinitialise for the new header */ + load_memo(shown); /* and reload memos */ + return false; case GO_TO_PREVIOUS: return false; @@ -806,6 +851,8 @@ (void)(parameter); + configfile_load(CFG_FILE, config, 1, 0); + calendar_init(&shown); load_memo(&shown); any_events(&shown, false); @@ -861,6 +908,8 @@ break; } } + + configfile_save(CFG_FILE, config, 1, 0); return been_in_usb_mode?PLUGIN_USB_CONNECTED:PLUGIN_OK; }