summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-11-04 13:03:42 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-11-04 13:03:42 +0000
commitfd8632fa37915008351899960335a67dbf93e4f2 (patch)
tree9f5de1a070252458a354e7fcd86015b74d707ab7
parent139694c7e2c360ec0426acb0d2f261b9cf51c9b3 (diff)
downloadrockbox-fd8632fa37915008351899960335a67dbf93e4f2.tar.gz
rockbox-fd8632fa37915008351899960335a67dbf93e4f2.zip
FS#10649: calendar: make it selectable what day is first day of week.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23516 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/calendar.c52
-rw-r--r--manual/plugins/calendar.tex2
2 files changed, 48 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
29PLUGIN_HEADER 30PLUGIN_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"
257static int first_wday = 0, old_first_wday;
258static struct configdata config[] = {
259 { TYPE_INT, 0, 6, { .int_p = &first_wday }, "first wday", NULL },
260};
261
255static bool leap_year; 262static bool leap_year;
256/* days_in_month[][0] is for December */ 263/* days_in_month[][0] is for December */
257static const int days_in_month[2][13] = { 264static 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
diff --git a/manual/plugins/calendar.tex b/manual/plugins/calendar.tex
index 962d3df964..c45c1e1ed5 100644
--- a/manual/plugins/calendar.tex
+++ b/manual/plugins/calendar.tex
@@ -5,6 +5,8 @@ This is a small and simple calendar application with memo saving function.
5Dots indicate dates with memos. The available memo types are: one off, 5Dots indicate dates with memos. The available memo types are: one off,
6yearly, monthly, and weekly memos. 6yearly, monthly, and weekly memos.
7 7
8You can select what day is first day of week by the setting \setting{First Day of Week} in the menu.
9
8\begin{table} 10\begin{table}
9\begin{btnmap}{}{} 11\begin{btnmap}{}{}
10 \ButtonLeft{} / \ButtonRight{} / 12 \ButtonLeft{} / \ButtonRight{} /