Index: apps/plugins/calendar.c =================================================================== --- apps/plugins/calendar.c (revision 22956) +++ 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,16 @@ #define CELL_WIDTH (LCD_WIDTH / 7) #define CELL_HEIGHT (LCD_HEIGHT / 7) +#define CFG_FILE "calendar.cfg" +enum { + CALENDAR_MODE_EURO, + CALENDAR_MODE_US, +}; +static int calendar_mode = CALENDAR_MODE_EURO; +static struct configdata config[] = { + { TYPE_INT, 0, 1, { .int_p = &calendar_mode }, "calendar mode", NULL }, +}; + static bool leap_year; /* days_in_month[][0] is for December */ static const int days_in_month[2][13] = { @@ -287,7 +298,6 @@ static int calc_weekday( struct shown *shown ) { return ( shown->wday + 36 - shown->mday ) % 7 ; - } static void calendar_init(struct shown *shown) @@ -318,6 +328,7 @@ { int i,w,h; int x = X_OFFSET; + int wday; const char **dayname = (const char**)&dayname_long; for (i = 0; i < 7; i++) @@ -330,12 +341,15 @@ } } - rb->lcd_getstringsize("A",&w,&h); + /* start from Sun if calendar_mode is CALENDAR_MODE_US */ + wday = (calendar_mode == CALENDAR_MODE_EURO)? 0: 6; for (i = 0; i < 7; i++) { - rb->lcd_putsxy(x, 0 , dayname[i]); + if (wday >= 7) wday = 0; + rb->lcd_putsxy(x, 0 , dayname[wday++]); x += CELL_WIDTH; } + rb->lcd_getstringsize("A",&w,&h); rb->lcd_hline(0, LCD_WIDTH-1 ,h); } @@ -345,6 +359,7 @@ { int w,h; int x,y,pos,days_per_month,j; + int wday; char buffer[9]; const char *monthname[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -355,15 +370,19 @@ rb->lcd_getstringsize("A",&w,&h); rb->lcd_clear_display(); draw_headers(); - if (shown->firstday > 6) + if (shown->firstday >= 7) shown->firstday -= 7; - pos = shown->firstday; + wday = shown->firstday; + /* pos needs to be shifted right for US style */ + pos = wday + (calendar_mode == CALENDAR_MODE_EURO? 0: 1); + if (pos >= 7) pos -= 7; + days_per_month = days_in_month[leap_year][shown->mon]; x = X_OFFSET + (pos * CELL_WIDTH); y = Y_OFFSET + h; for (j = 1; j <= days_per_month; j++) { - if ( (day_has_memo[j]) || (wday_has_memo[pos]) ) + if ( (day_has_memo[j]) || (wday_has_memo[wday]) ) rb->snprintf(buffer,4,"%02d.", j); else rb->snprintf(buffer,4,"%02d", j); @@ -372,7 +391,7 @@ rb->lcd_set_drawmode(DRMODE_SOLID); rb->lcd_fillrect(x, y - 1, CELL_WIDTH - 1, CELL_HEIGHT); rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - shown->wday = pos; + shown->wday = wday; } else { @@ -380,6 +399,8 @@ } rb->lcd_putsxy(x, y, buffer); x += CELL_WIDTH; + wday++; + if (wday >= 7) wday = 0; pos++; if (pos >= 7) { @@ -393,7 +414,7 @@ rb->lcd_hline(LCD_WIDTH-w*8-10,LCD_WIDTH-1,LCD_HEIGHT-h-3); rb->snprintf(buffer,9,"%s %04d",monthname[shown->mon-1],shown->year); rb->lcd_putsxy(LCD_WIDTH-w*8-8,LCD_HEIGHT-h-1,buffer); - shown->lastday = pos; + shown->lastday = wday; rb->lcd_update(); } @@ -611,11 +632,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"); + "Calendar Mode", "Playback Control"); while (!exit) { @@ -647,7 +673,12 @@ add_memo(shown,3); return false; - case 6: /* playback control */ + case 6: /* calendar mode: Euro or US */ + rb->set_option("Calendar Mode", &calendar_mode, + INT, modes, 2, NULL); + break; + + case 7: /* playback control */ playback_control(NULL); break; @@ -806,10 +837,13 @@ (void)(parameter); + configfile_load(CFG_FILE, config, 1, 0); + calendar_init(&shown); load_memo(&shown); any_events(&shown, false); draw_calendar(&shown); + while (!exit) { button = rb->button_get(true); @@ -861,6 +895,8 @@ break; } } + + configfile_save(CFG_FILE, config, 1, 0); return been_in_usb_mode?PLUGIN_USB_CONNECTED:PLUGIN_OK; }