diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/calendar.c | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 18706c14f6..4ac3128ab0 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <timefuncs.h> | 26 | #include <timefuncs.h> |
27 | #include "lib/playback_control.h" | 27 | #include "lib/playback_control.h" |
28 | #include "lib/configfile.h" | ||
28 | 29 | ||
29 | PLUGIN_HEADER | 30 | PLUGIN_HEADER |
30 | 31 | ||
@@ -252,6 +253,12 @@ CONFIG_KEYPAD == SANSA_M200_PAD | |||
252 | #define CELL_WIDTH (LCD_WIDTH / 7) | 253 | #define CELL_WIDTH (LCD_WIDTH / 7) |
253 | #define CELL_HEIGHT (LCD_HEIGHT / 7) | 254 | #define CELL_HEIGHT (LCD_HEIGHT / 7) |
254 | 255 | ||
256 | #define CFG_FILE "calendar.cfg" | ||
257 | static int first_wday = 0, old_first_wday; | ||
258 | static struct configdata config[] = { | ||
259 | { TYPE_INT, 0, 6, { .int_p = &first_wday }, "first wday", NULL }, | ||
260 | }; | ||
261 | |||
255 | static bool leap_year; | 262 | static bool leap_year; |
256 | /* days_in_month[][0] is for December */ | 263 | /* days_in_month[][0] is for December */ |
257 | static const int days_in_month[2][13] = { | 264 | static const int days_in_month[2][13] = { |
@@ -315,6 +322,7 @@ static void draw_headers(void) | |||
315 | { | 322 | { |
316 | int i, w, h; | 323 | int i, w, h; |
317 | int x = X_OFFSET; | 324 | int x = X_OFFSET; |
325 | int wday; | ||
318 | const char **dayname = dayname_long; | 326 | const char **dayname = dayname_long; |
319 | 327 | ||
320 | for (i = 0; i < 7; i++) | 328 | for (i = 0; i < 7; i++) |
@@ -327,10 +335,12 @@ static void draw_headers(void) | |||
327 | } | 335 | } |
328 | } | 336 | } |
329 | 337 | ||
338 | wday = first_wday; | ||
330 | rb->lcd_getstringsize("A", &w, &h); | 339 | rb->lcd_getstringsize("A", &w, &h); |
331 | for (i = 0; i < 7; i++) | 340 | for (i = 0; i < 7; i++) |
332 | { | 341 | { |
333 | rb->lcd_putsxy(x, 0, dayname[i]); | 342 | if (wday >= 7) wday = 0; |
343 | rb->lcd_putsxy(x, 0, dayname[wday++]); | ||
334 | x += CELL_WIDTH; | 344 | x += CELL_WIDTH; |
335 | } | 345 | } |
336 | rb->lcd_hline(0, LCD_WIDTH-1, h); | 346 | rb->lcd_hline(0, LCD_WIDTH-1, h); |
@@ -342,6 +352,7 @@ static void draw_calendar(struct shown *shown) | |||
342 | { | 352 | { |
343 | int w, h; | 353 | int w, h; |
344 | int x, y, pos, days_per_month, j; | 354 | int x, y, pos, days_per_month, j; |
355 | int wday; | ||
345 | char buffer[12]; | 356 | char buffer[12]; |
346 | const char *monthname[] = { | 357 | const char *monthname[] = { |
347 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 358 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
@@ -354,13 +365,16 @@ static void draw_calendar(struct shown *shown) | |||
354 | rb->lcd_getstringsize("A", &w, &h); | 365 | rb->lcd_getstringsize("A", &w, &h); |
355 | rb->lcd_clear_display(); | 366 | rb->lcd_clear_display(); |
356 | draw_headers(); | 367 | draw_headers(); |
357 | pos = shown->firstday; | 368 | wday = shown->firstday; |
369 | pos = wday + 7 - first_wday; | ||
370 | if (pos >= 7) pos -= 7; | ||
371 | |||
358 | days_per_month = days_in_month[leap_year][shown->mon]; | 372 | days_per_month = days_in_month[leap_year][shown->mon]; |
359 | x = X_OFFSET + (pos * CELL_WIDTH); | 373 | x = X_OFFSET + (pos * CELL_WIDTH); |
360 | y = Y_OFFSET + h; | 374 | y = Y_OFFSET + h; |
361 | for (j = 1; j <= days_per_month; j++) | 375 | for (j = 1; j <= days_per_month; j++) |
362 | { | 376 | { |
363 | if ( (day_has_memo[j]) || (wday_has_memo[pos]) ) | 377 | if ( (day_has_memo[j]) || (wday_has_memo[wday]) ) |
364 | rb->snprintf(buffer, 4, "%02d.", j); | 378 | rb->snprintf(buffer, 4, "%02d.", j); |
365 | else | 379 | else |
366 | rb->snprintf(buffer, 4, "%02d", j); | 380 | rb->snprintf(buffer, 4, "%02d", j); |
@@ -369,7 +383,7 @@ static void draw_calendar(struct shown *shown) | |||
369 | rb->lcd_set_drawmode(DRMODE_SOLID); | 383 | rb->lcd_set_drawmode(DRMODE_SOLID); |
370 | rb->lcd_fillrect(x, y - 1, CELL_WIDTH - 1, CELL_HEIGHT); | 384 | rb->lcd_fillrect(x, y - 1, CELL_WIDTH - 1, CELL_HEIGHT); |
371 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | 385 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
372 | shown->wday = pos; | 386 | shown->wday = wday; |
373 | } | 387 | } |
374 | else | 388 | else |
375 | { | 389 | { |
@@ -377,6 +391,9 @@ static void draw_calendar(struct shown *shown) | |||
377 | } | 391 | } |
378 | rb->lcd_putsxy(x, y, buffer); | 392 | rb->lcd_putsxy(x, y, buffer); |
379 | x += CELL_WIDTH; | 393 | x += CELL_WIDTH; |
394 | wday++; | ||
395 | if (wday >= 7) | ||
396 | wday = 0; | ||
380 | pos++; | 397 | pos++; |
381 | if (pos >= 7) | 398 | if (pos >= 7) |
382 | { | 399 | { |
@@ -385,7 +402,7 @@ static void draw_calendar(struct shown *shown) | |||
385 | y += CELL_HEIGHT; | 402 | y += CELL_HEIGHT; |
386 | } | 403 | } |
387 | } | 404 | } |
388 | shown->lastday = pos; | 405 | shown->lastday = wday; |
389 | rb->lcd_set_drawmode(DRMODE_SOLID); | 406 | rb->lcd_set_drawmode(DRMODE_SOLID); |
390 | rb->lcd_vline(LCD_WIDTH-w*8-10, LCD_HEIGHT-h-3, LCD_HEIGHT-1); | 407 | rb->lcd_vline(LCD_WIDTH-w*8-10, LCD_HEIGHT-h-3, LCD_HEIGHT-1); |
391 | rb->lcd_hline(LCD_WIDTH-w*8-10, LCD_WIDTH-1, LCD_HEIGHT-h-3); | 408 | rb->lcd_hline(LCD_WIDTH-w*8-10, LCD_WIDTH-1, LCD_HEIGHT-h-3); |
@@ -586,10 +603,21 @@ static bool edit_memo(int change, struct shown *shown) | |||
586 | bool exit = false; | 603 | bool exit = false; |
587 | int selected = 0; | 604 | int selected = 0; |
588 | 605 | ||
606 | static const struct opt_items modes[7] = { | ||
607 | { "Mon", -1 }, | ||
608 | { "Tue", -1 }, | ||
609 | { "Wed", -1 }, | ||
610 | { "Thu", -1 }, | ||
611 | { "Fri", -1 }, | ||
612 | { "Sat", -1 }, | ||
613 | { "Sun", -1 }, | ||
614 | }; | ||
615 | |||
589 | MENUITEM_STRINGLIST(edit_menu, "Edit menu", edit_menu_cb, | 616 | MENUITEM_STRINGLIST(edit_menu, "Edit menu", edit_menu_cb, |
590 | "Remove", "Edit", | 617 | "Remove", "Edit", |
591 | "New Weekly", "New Monthly", | 618 | "New Weekly", "New Monthly", |
592 | "New Yearly", "New One off", | 619 | "New Yearly", "New One off", |
620 | "First Day of Week", | ||
593 | "Playback Control"); | 621 | "Playback Control"); |
594 | 622 | ||
595 | while (!exit) | 623 | while (!exit) |
@@ -622,7 +650,12 @@ static bool edit_memo(int change, struct shown *shown) | |||
622 | add_memo(shown, 3); | 650 | add_memo(shown, 3); |
623 | return false; | 651 | return false; |
624 | 652 | ||
625 | case 6: /* playback control */ | 653 | case 6: /* weekday */ |
654 | rb->set_option("First Day of Week", &first_wday, | ||
655 | INT, modes, 7, NULL); | ||
656 | break; | ||
657 | |||
658 | case 7: /* playback control */ | ||
626 | playback_control(NULL); | 659 | playback_control(NULL); |
627 | break; | 660 | break; |
628 | 661 | ||
@@ -785,10 +818,14 @@ enum plugin_status plugin_start(const void* parameter) | |||
785 | 818 | ||
786 | (void)(parameter); | 819 | (void)(parameter); |
787 | 820 | ||
821 | configfile_load(CFG_FILE, config, 1, 0); | ||
822 | old_first_wday = first_wday; | ||
823 | |||
788 | calendar_init(&shown); | 824 | calendar_init(&shown); |
789 | load_memo(&shown); | 825 | load_memo(&shown); |
790 | any_events(&shown, false); | 826 | any_events(&shown, false); |
791 | draw_calendar(&shown); | 827 | draw_calendar(&shown); |
828 | |||
792 | while (!exit) | 829 | while (!exit) |
793 | { | 830 | { |
794 | button = rb->button_get(true); | 831 | button = rb->button_get(true); |
@@ -840,6 +877,9 @@ enum plugin_status plugin_start(const void* parameter) | |||
840 | break; | 877 | break; |
841 | } | 878 | } |
842 | } | 879 | } |
880 | |||
881 | if (old_first_wday != first_wday) | ||
882 | configfile_save(CFG_FILE, config, 1, 0); | ||
843 | return been_in_usb_mode?PLUGIN_USB_CONNECTED:PLUGIN_OK; | 883 | return been_in_usb_mode?PLUGIN_USB_CONNECTED:PLUGIN_OK; |
844 | } | 884 | } |
845 | 885 | ||