1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * (based upon 1.1 by calpefrosch) updated by www.HuwSy.ukhackers.net
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
24 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
26 #include <timefuncs.h>
27 #include "lib/playback_control.h"
31 #if CONFIG_KEYPAD == RECORDER_PAD
32 #define CALENDAR_QUIT BUTTON_OFF
33 #define CALENDAR_SELECT BUTTON_PLAY
34 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
35 #define CALENDAR_PREV_WEEK BUTTON_UP
36 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
37 #define CALENDAR_PREV_DAY BUTTON_LEFT
38 #define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN)
39 #define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP)
41 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
42 #define CALENDAR_QUIT BUTTON_OFF
43 #define CALENDAR_SELECT BUTTON_SELECT
44 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
45 #define CALENDAR_PREV_WEEK BUTTON_UP
46 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
47 #define CALENDAR_PREV_DAY BUTTON_LEFT
48 #define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN)
49 #define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP)
51 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
52 (CONFIG_KEYPAD == IRIVER_H300_PAD)
53 #define CALENDAR_QUIT BUTTON_OFF
54 #define CALENDAR_SELECT BUTTON_SELECT
55 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
56 #define CALENDAR_PREV_WEEK BUTTON_UP
57 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
58 #define CALENDAR_PREV_DAY BUTTON_LEFT
59 #define CALENDAR_NEXT_MONTH BUTTON_MODE
60 #define CALENDAR_PREV_MONTH BUTTON_REC
62 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
63 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
64 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
65 #define CALENDAR_QUIT (BUTTON_SELECT|BUTTON_MENU)
66 #define CALENDAR_SELECT (BUTTON_SELECT|BUTTON_REL)
67 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD
68 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK
69 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
70 #define CALENDAR_PREV_DAY BUTTON_LEFT
71 #define CALENDAR_NEXT_MONTH BUTTON_PLAY
72 #define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_REL)
74 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
75 #define CALENDAR_QUIT BUTTON_POWER
76 #define CALENDAR_SELECT BUTTON_SELECT
77 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
78 #define CALENDAR_PREV_WEEK BUTTON_UP
79 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
80 #define CALENDAR_PREV_DAY BUTTON_LEFT
81 #define CALENDAR_NEXT_MONTH BUTTON_PLAY
82 #define CALENDAR_PREV_MONTH BUTTON_REC
84 #elif CONFIG_KEYPAD == GIGABEAT_PAD
85 #define CALENDAR_QUIT BUTTON_POWER
86 #define CALENDAR_SELECT BUTTON_SELECT
87 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
88 #define CALENDAR_PREV_WEEK BUTTON_UP
89 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
90 #define CALENDAR_PREV_DAY BUTTON_LEFT
91 #define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN
92 #define CALENDAR_PREV_MONTH BUTTON_VOL_UP
94 #elif CONFIG_KEYPAD == SANSA_E200_PAD
95 #define CALENDAR_QUIT BUTTON_POWER
96 #define CALENDAR_SELECT BUTTON_SELECT
97 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD
98 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK
99 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
100 #define CALENDAR_PREV_DAY BUTTON_LEFT
101 #define CALENDAR_NEXT_MONTH BUTTON_DOWN
102 #define CALENDAR_PREV_MONTH BUTTON_UP
104 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
105 #define CALENDAR_QUIT (BUTTON_HOME|BUTTON_REPEAT)
106 #define CALENDAR_SELECT BUTTON_SELECT
107 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD
108 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK
109 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
110 #define CALENDAR_PREV_DAY BUTTON_LEFT
111 #define CALENDAR_NEXT_MONTH BUTTON_DOWN
112 #define CALENDAR_PREV_MONTH BUTTON_UP
114 #elif CONFIG_KEYPAD == SANSA_C200_PAD || \
115 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
116 CONFIG_KEYPAD == SANSA_M200_PAD
117 #define CALENDAR_QUIT BUTTON_POWER
118 #define CALENDAR_SELECT BUTTON_SELECT
119 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
120 #define CALENDAR_PREV_WEEK BUTTON_UP
121 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
122 #define CALENDAR_PREV_DAY BUTTON_LEFT
123 #define CALENDAR_NEXT_MONTH BUTTON_VOL_UP
124 #define CALENDAR_PREV_MONTH BUTTON_VOL_DOWN
126 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
127 #define CALENDAR_QUIT BUTTON_POWER
128 #define CALENDAR_SELECT BUTTON_PLAY
129 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_DOWN
130 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_UP
131 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
132 #define CALENDAR_PREV_DAY BUTTON_LEFT
133 #define CALENDAR_NEXT_MONTH BUTTON_FF
134 #define CALENDAR_PREV_MONTH BUTTON_REW
136 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
137 #define CALENDAR_QUIT BUTTON_BACK
138 #define CALENDAR_SELECT BUTTON_SELECT
139 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
140 #define CALENDAR_PREV_WEEK BUTTON_UP
141 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
142 #define CALENDAR_PREV_DAY BUTTON_LEFT
143 #define CALENDAR_NEXT_MONTH BUTTON_NEXT
144 #define CALENDAR_PREV_MONTH BUTTON_PREV
146 #elif CONFIG_KEYPAD == MROBE100_PAD
147 #define CALENDAR_QUIT BUTTON_POWER
148 #define CALENDAR_SELECT BUTTON_SELECT
149 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
150 #define CALENDAR_PREV_WEEK BUTTON_UP
151 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
152 #define CALENDAR_PREV_DAY BUTTON_LEFT
153 #define CALENDAR_NEXT_MONTH (BUTTON_MENU|BUTTON_DOWN)
154 #define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_UP)
156 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
157 #define CALENDAR_QUIT BUTTON_RC_REC
158 #define CALENDAR_SELECT BUTTON_RC_PLAY
159 #define CALENDAR_NEXT_WEEK BUTTON_RC_VOL_DOWN
160 #define CALENDAR_PREV_WEEK BUTTON_RC_VOL_UP
161 #define CALENDAR_NEXT_DAY BUTTON_RC_FF
162 #define CALENDAR_PREV_DAY BUTTON_RC_REW
163 #define CALENDAR_NEXT_MONTH BUTTON_RC_MODE
164 #define CALENDAR_PREV_MONTH BUTTON_RC_MENU
166 #elif (CONFIG_KEYPAD == COWOND2_PAD)
167 #define CALENDAR_QUIT BUTTON_POWER
168 #define CALENDAR_SELECT BUTTON_CENTER
169 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
170 #define CALENDAR_PREV_WEEK BUTTON_UP
171 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
172 #define CALENDAR_PREV_DAY BUTTON_LEFT
173 #define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT
174 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT
176 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
177 #define CALENDAR_QUIT BUTTON_POWER
178 #define CALENDAR_SELECT BUTTON_SELECT
179 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
180 #define CALENDAR_PREV_WEEK BUTTON_UP
181 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
182 #define CALENDAR_PREV_DAY BUTTON_LEFT
183 #define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN
184 #define CALENDAR_PREV_MONTH BUTTON_VOL_UP
186 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
187 #define CALENDAR_QUIT BUTTON_POWER
188 #define CALENDAR_SELECT BUTTON_MENU
189 #define CALENDAR_NEXT_WEEK BUTTON_VOL_DOWN
190 #define CALENDAR_PREV_WEEK BUTTON_VOL_UP
191 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
192 #define CALENDAR_PREV_DAY BUTTON_LEFT
193 #define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT
194 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT
196 #elif CONFIG_KEYPAD == MROBE500_PAD
197 #define CALENDAR_QUIT BUTTON_POWER
199 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
200 #define CALENDAR_QUIT BUTTON_REC
201 #define CALENDAR_SELECT BUTTON_PLAY
202 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
203 #define CALENDAR_PREV_WEEK BUTTON_UP
204 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
205 #define CALENDAR_PREV_DAY BUTTON_LEFT
206 #define CALENDAR_NEXT_MONTH BUTTON_FFWD
207 #define CALENDAR_PREV_MONTH BUTTON_REW
210 #error "No keypad setting."
213 #ifdef HAVE_TOUCHSCREEN
214 #ifndef CALENDAR_QUIT
215 #define CALENDAR_QUIT BUTTON_MIDLEFT
217 #ifndef CALENDAR_SELECT
218 #define CALENDAR_SELECT BUTTON_CENTER
220 #ifndef CALENDAR_NEXT_DAY
221 #define CALENDAR_NEXT_DAY BUTTON_TOPLEFT
223 #ifndef CALENDAR_PREV_DAY
224 #define CALENDAR_PREV_DAY BUTTON_BOTTOMLEFT
226 #ifndef CALENDAR_NEXT_WEEK
227 #define CALENDAR_NEXT_WEEK BUTTON_TOPMIDDLE
229 #ifndef CALENDAR_PREV_WEEK
230 #define CALENDAR_PREV_WEEK BUTTON_BOTTOMMIDDLE
232 #ifndef CALENDAR_NEXT_MONTH
233 #define CALENDAR_NEXT_MONTH BUTTON_TOPRIGHT
235 #ifndef CALENDAR_PREV_MONTH
236 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMRIGHT
240 #define X_OFFSET ((LCD_WIDTH%7)/2)
246 #define CELL_WIDTH (LCD_WIDTH / 7)
247 #define CELL_HEIGHT (LCD_HEIGHT / 7)
249 static bool leap_year
;
250 /* days_in_month[][0] is for December */
251 static const int days_in_month
[2][13] = {
252 {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
253 {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
256 static const char *dayname_long
[7] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
257 static const char *dayname_short
[7] = {"M","T","W","T","F","S","S"};
260 int mday
; /* day of the month */
262 int year
; /* year since 1900 */
263 int wday
; /* day of the week */
267 int mday
; /* day of the month */
269 int year
; /* year since 1900 */
270 int wday
; /* day of the week */
271 int firstday
; /* first (w)day of month */
272 int lastday
; /* last (w)day of month */
275 static bool use_system_font
= false;
277 static bool been_in_usb_mode
= false;
279 /* leap year -- account for gregorian reformation in 1752 */
280 static int is_leap_year(int yr
)
282 return ((yr
) <= 1752 ? !((yr
) % 4) : \
283 (!((yr
) % 4) && ((yr
) % 100)) || !((yr
) % 400)) ? 1:0 ;
286 /* searches the weekday of the first day in month,
287 * relative to the given values */
288 static int calc_weekday( struct shown
*shown
)
290 return ( shown
->wday
+ 36 - shown
->mday
) % 7 ;
294 static void calendar_init(struct today
*today
, struct shown
*shown
)
302 rb
->lcd_getstringsize("A",&w
,&h
);
303 if ( ((w
* 14) > LCD_WIDTH
) || ((h
* 7) > LCD_HEIGHT
) )
305 rb
->lcd_setfont(FONT_SYSFIXED
);
306 use_system_font
= true;
308 rb
->lcd_clear_display();
311 today
->mon
= tm
->tm_mon
+1;
312 today
->year
= 2000+tm
->tm_year
%100;
313 today
->wday
= tm
->tm_wday
-1;
314 today
->mday
= tm
->tm_mday
;
315 shown
->mday
= today
->mday
;
316 shown
->mon
= today
->mon
;
317 shown
->year
= today
->year
;
318 shown
->wday
= today
->wday
;
320 shown
->firstday
= calc_weekday(shown
);
321 leap_year
= is_leap_year(shown
->year
);
324 static void draw_headers(void)
328 const char **dayname
= (const char**)&dayname_long
;
330 for (i
= 0; i
< 7; i
++)
332 rb
->lcd_getstringsize(dayname
[i
],&w
,&h
);
335 dayname
= (const char**)&dayname_short
;
340 rb
->lcd_getstringsize("A",&w
,&h
);
341 for (i
= 0; i
< 7; i
++)
343 rb
->lcd_putsxy(x
, 0 , dayname
[i
]);
346 rb
->lcd_hline(0, LCD_WIDTH
-1 ,h
);
349 static bool day_has_memo
[32];
350 static bool wday_has_memo
[7];
351 static void draw_calendar(struct shown
*shown
)
354 int x
,y
,pos
,days_per_month
,j
;
356 const char *monthname
[] = {
357 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
358 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
361 rb
->lcd_setfont(FONT_SYSFIXED
);
362 rb
->lcd_getstringsize("A",&w
,&h
);
363 rb
->lcd_clear_display();
365 if (shown
->firstday
> 6)
366 shown
->firstday
-= 7;
367 pos
= shown
->firstday
;
368 days_per_month
= days_in_month
[leap_year
][shown
->mon
];
369 x
= X_OFFSET
+ (pos
* CELL_WIDTH
);
371 for (j
= 1; j
<= days_per_month
; j
++)
373 if ( (day_has_memo
[j
]) || (wday_has_memo
[pos
]) )
374 rb
->snprintf(buffer
,4,"%02d.", j
);
376 rb
->snprintf(buffer
,4,"%02d", j
);
377 if (shown
->mday
== j
)
379 rb
->lcd_set_drawmode(DRMODE_SOLID
);
380 rb
->lcd_fillrect(x
, y
- 1, CELL_WIDTH
- 1, CELL_HEIGHT
);
381 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
386 rb
->lcd_set_drawmode(DRMODE_SOLID
);
388 rb
->lcd_putsxy(x
, y
, buffer
);
398 rb
->lcd_set_drawmode(DRMODE_SOLID
);
399 rb
->lcd_vline(LCD_WIDTH
-w
*8-10,LCD_HEIGHT
-h
-3,LCD_HEIGHT
-1);
400 rb
->lcd_hline(LCD_WIDTH
-w
*8-10,LCD_WIDTH
-1,LCD_HEIGHT
-h
-3);
401 rb
->snprintf(buffer
,9,"%s %04d",monthname
[shown
->mon
-1],shown
->year
);
402 rb
->lcd_putsxy(LCD_WIDTH
-w
*8-8,LCD_HEIGHT
-h
-1,buffer
);
403 shown
->lastday
= pos
;
407 #define MAX_CHAR_MEMO_LEN 64
408 #define MAX_MEMOS_IN_A_MONTH 128
410 char message
[MAX_CHAR_MEMO_LEN
];
413 int file_pointer_start
;
414 int file_pointer_end
;
418 } memos
[MAX_MEMOS_IN_A_MONTH
];
419 static int pointer_array
[MAX_MEMOS_IN_A_MONTH
];
420 static int memos_in_memory
= 0;
421 static int memos_in_shown_memory
= 0;
423 static void load_memo(struct shown
*shown
)
433 for (k
= 1; k
< 32; k
++)
434 day_has_memo
[k
] = false;
435 for (k
= 0; k
< 7; k
++)
436 wday_has_memo
[k
] = false;
438 fp
= rb
->open(ROCKBOX_DIR
"/.memo",O_RDONLY
);
441 rb
->lseek(fp
, 0, SEEK_SET
);
445 rb
->memset(&memos
[memos_in_memory
].message
, 0, MAX_CHAR_MEMO_LEN
);
446 memos
[memos_in_memory
].file_pointer_start
=
447 rb
->lseek(fp
, 0, SEEK_CUR
);
448 if (rb
->read(fp
, temp_memo2
, 2) == 2)
449 memos
[memos_in_memory
].day
= rb
->atoi(&temp_memo2
[0]);
451 memos
[memos_in_memory
].day
= 0;
452 if (rb
->read(fp
, temp_memo2
, 2) == 2)
453 memos
[memos_in_memory
].month
= rb
->atoi(&temp_memo2
[0]);
455 memos
[memos_in_memory
].month
= 0;
456 if (rb
->read(fp
, temp_memo4
, 4) == 4)
457 memos
[memos_in_memory
].year
= rb
->atoi(&temp_memo4
[0]);
459 memos
[memos_in_memory
].year
= 0;
460 /* as the year returned is sometimes yearmonth, ie if yr should =
461 2003, and month = 06, then it returns 200306 */
462 if (memos
[memos_in_memory
].year
> (shown
->year
* 10))
463 memos
[memos_in_memory
].year
= (memos
[memos_in_memory
].year
-
464 memos
[memos_in_memory
].month
) /
466 if (rb
->read(fp
, temp_memo1
, 1) == 1)
467 memos
[memos_in_memory
].wday
= rb
->atoi(&temp_memo1
[0]);
469 memos
[memos_in_memory
].wday
= 0;
470 if (rb
->read(fp
, temp_memo1
, 1) == 1)
471 memos
[memos_in_memory
].type
= rb
->atoi(&temp_memo1
[0]);
473 memos
[memos_in_memory
].type
= 0;
474 load_to_memory
= ((memos
[memos_in_memory
].type
< 2) ||
475 ((memos
[memos_in_memory
].type
== 2) &&
476 (memos
[memos_in_memory
].month
== shown
->mon
)) ||
477 ((memos
[memos_in_memory
].type
> 2) &&
478 (memos
[memos_in_memory
].month
== shown
->mon
) &&
479 (memos
[memos_in_memory
].year
== shown
->year
)));
483 if (rb
->read(fp
, temp_memo1
, 1) != 1)
485 memos
[memos_in_memory
].day
= 0;
486 memos
[memos_in_memory
].month
= 0;
487 memos
[memos_in_memory
].file_pointer_start
= 0;
488 memos
[memos_in_memory
].file_pointer_end
= 0;
489 memos
[memos_in_memory
].year
= 0;
490 memos
[memos_in_memory
].type
= 0;
491 memos
[memos_in_memory
].wday
= 0;
492 memos
[memos_in_memory
].message
[0] = 0;
498 if (temp_memo1
[0] == '\n')
500 if (memos
[memos_in_memory
].type
> 0)
501 day_has_memo
[memos
[memos_in_memory
].day
] =
504 wday_has_memo
[memos
[memos_in_memory
].wday
] =
506 memos
[memos_in_memory
++].file_pointer_end
=
507 rb
->lseek(fp
, 0, SEEK_CUR
);
509 else if ( (temp_memo1
[0] != '\r') &&
510 (temp_memo1
[0] != '\t') &&
511 k
< MAX_CHAR_MEMO_LEN
-1 )
512 memos
[memos_in_memory
].message
[k
++] = temp_memo1
[0];
514 if (temp_memo1
[0] == '\n')
522 static bool save_memo(int changed
, bool new_mod
, struct shown
*shown
)
525 /* use O_RDWR|O_CREAT so that file is created if it doesn't exist. */
526 fp
= rb
->open(ROCKBOX_DIR
"/.memo", O_RDWR
|O_CREAT
);
527 fq
= rb
->creat(ROCKBOX_DIR
"/~temp");
528 if ( (fq
> -1) && (fp
> -1) )
531 char temp
[MAX_CHAR_MEMO_LEN
];
532 rb
->lseek(fp
, 0, SEEK_SET
);
533 for (i
= 0; i
< memos
[changed
].file_pointer_start
; i
++)
535 rb
->read(fp
, temp
, 1);
536 rb
->write(fq
,temp
,1);
540 rb
->fdprintf(fq
, "%02d%02d%04d%01d%01d%s\n",
542 memos
[changed
].month
,
546 memos
[changed
].message
);
548 rb
->lseek(fp
, memos
[changed
].file_pointer_end
, SEEK_SET
);
549 while(rb
->read(fp
, temp
, 1) == 1)
551 rb
->write(fq
,temp
,1);
555 rb
->remove(ROCKBOX_DIR
"/.memo");
556 rb
->rename(ROCKBOX_DIR
"/~temp", ROCKBOX_DIR
"/.memo");
567 static void add_memo(struct shown
*shown
, int type
)
570 if (rb
->kbd_input(memos
[memos_in_memory
].message
,
571 sizeof memos
[memos_in_memory
].message
) == 0)
573 if (rb
->strlen(memos
[memos_in_memory
].message
))
575 memos
[memos_in_memory
].file_pointer_start
= 0;
576 memos
[memos_in_memory
].file_pointer_end
= 0;
577 memos
[memos_in_memory
].day
= shown
->mday
;
578 memos
[memos_in_memory
].month
= shown
->mon
;
579 memos
[memos_in_memory
].wday
= shown
->wday
;
580 memos
[memos_in_memory
].year
= shown
->year
;
581 memos
[memos_in_memory
].type
= type
;
582 if (save_memo(memos_in_memory
,true,shown
))
588 memos
[memos_in_memory
].file_pointer_start
= 0;
589 memos
[memos_in_memory
].file_pointer_end
= 0;
590 memos
[memos_in_memory
].day
= 0;
591 memos
[memos_in_memory
].month
= 0;
592 memos
[memos_in_memory
].year
= 0;
593 memos
[memos_in_memory
].type
= 0;
594 memos
[memos_in_memory
].wday
= 0;
598 rb
->lcd_clear_display();
600 rb
->lcd_setfont(FONT_SYSFIXED
);
602 rb
->splash(HZ
/2,"Event added");
604 rb
->splash(HZ
/2,"Event not added");
607 static int edit_menu_cb(int action
, const struct menu_item_ex
*this_item
)
609 int i
= (intptr_t)this_item
;
610 if (action
== ACTION_REQUEST_MENUITEM
611 && memos_in_shown_memory
<= 0 && (i
==0 || i
==1))
612 return ACTION_EXIT_MENUITEM
;
616 static bool edit_memo(int change
, struct shown
*shown
)
621 MENUITEM_STRINGLIST(edit_menu
, "Edit menu", edit_menu_cb
,
623 "New Weekly", "New Monthly",
624 "New Yearly", "New One off",
629 switch (rb
->do_menu(&edit_menu
, &selected
, NULL
, false))
632 save_memo(pointer_array
[change
],false,shown
);
636 if(rb
->kbd_input(memos
[pointer_array
[change
]].message
,
637 sizeof memos
[pointer_array
[change
]].message
) == 0)
638 save_memo(pointer_array
[change
],true,shown
);
645 case 3: /* monthly */
653 case 5: /* one off */
657 case 6: /* playback control */
658 playback_control(NULL
);
664 case MENU_ATTACHED_USB
:
665 been_in_usb_mode
= true;
672 static char * get_event_text(int selected
, void *data
,
673 char *buffer
, size_t buffer_len
)
675 struct shown
*shown
= (struct shown
*) data
;
676 if (selected
< 0 || memos_in_shown_memory
<= selected
)
680 if (memos
[pointer_array
[selected
]].type
== 2)
681 rb
->snprintf(buffer
, buffer_len
, "%s (%d yrs)",
682 memos
[pointer_array
[selected
]].message
,
683 shown
->year
- memos
[pointer_array
[selected
]].year
);
685 rb
->snprintf(buffer
, buffer_len
, "%s",
686 memos
[pointer_array
[selected
]].message
);
690 static bool view_events(int selected
, struct shown
*shown
)
692 struct gui_synclist gui_memos
;
696 rb
->gui_synclist_init(&gui_memos
, &get_event_text
, shown
, false, 1, NULL
);
697 rb
->gui_synclist_set_title(&gui_memos
, "Events (play : menu)", NOICON
);
698 rb
->gui_synclist_set_nb_items(&gui_memos
, memos_in_shown_memory
);
699 rb
->gui_synclist_select_item(&gui_memos
, selected
);
700 rb
->gui_synclist_draw(&gui_memos
);
704 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
705 rb
->gui_synclist_do_button(&gui_memos
,&button
,LIST_WRAP_UNLESS_HELD
);
710 selected
= rb
->gui_synclist_get_sel_pos(&gui_memos
);
711 return edit_memo(selected
, shown
);
714 case ACTION_STD_CANCEL
:
719 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
720 been_in_usb_mode
= true;
728 static void update_memos_shown(struct shown
*shown
)
731 memos_in_shown_memory
= 0;
732 for (i
= 0; i
< memos_in_memory
; i
++)
733 if (((memos
[i
].type
>= 1) &&
734 (memos
[i
].day
== shown
->mday
)) ||
735 ((memos
[i
].type
< 1) &&
736 (memos
[i
].wday
== shown
->wday
)))
737 pointer_array
[memos_in_shown_memory
++] = i
;
740 static bool any_events(struct shown
*shown
, bool force
)
742 update_memos_shown(shown
);
744 if (memos_in_shown_memory
> 0)
745 return view_events(0, shown
);
747 return edit_memo(0, shown
);
754 static void next_month(struct shown
*shown
, int step
)
761 leap_year
= is_leap_year(shown
->year
);
764 shown
->mday
= shown
->mday
- days_in_month
[leap_year
][shown
->mon
-1];
765 else if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
766 shown
->mday
= days_in_month
[leap_year
][shown
->mon
];
767 shown
->firstday
= shown
->lastday
;
769 draw_calendar(shown
);
772 static void prev_month(struct shown
*shown
, int step
)
779 leap_year
= is_leap_year(shown
->year
);
782 shown
->mday
= shown
->mday
+ days_in_month
[leap_year
][shown
->mon
];
783 else if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
784 shown
->mday
= days_in_month
[leap_year
][shown
->mon
];
785 shown
->firstday
+= 7 - (days_in_month
[leap_year
][shown
->mon
] % 7);
787 draw_calendar(shown
);
790 static void next_day(struct shown
*shown
, int step
)
793 if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
794 next_month(shown
, step
);
796 draw_calendar(shown
);
799 static void prev_day(struct shown
*shown
, int step
)
803 prev_month(shown
, step
);
805 draw_calendar(shown
);
808 enum plugin_status
plugin_start(const void* parameter
)
817 calendar_init(&today
, &shown
);
819 any_events(&shown
, false);
820 draw_calendar(&shown
);
823 button
= rb
->button_get(true);
829 case CALENDAR_NEXT_MONTH
:
830 case CALENDAR_NEXT_MONTH
| BUTTON_REPEAT
:
831 next_month(&shown
, 0);
834 case CALENDAR_PREV_MONTH
:
835 case CALENDAR_PREV_MONTH
| BUTTON_REPEAT
:
836 prev_month(&shown
, 0);
839 case CALENDAR_NEXT_WEEK
:
840 case CALENDAR_NEXT_WEEK
| BUTTON_REPEAT
:
844 case CALENDAR_PREV_WEEK
:
845 case CALENDAR_PREV_WEEK
| BUTTON_REPEAT
:
849 case CALENDAR_PREV_DAY
:
850 case CALENDAR_PREV_DAY
| BUTTON_REPEAT
:
854 case CALENDAR_NEXT_DAY
:
855 case CALENDAR_NEXT_DAY
| BUTTON_REPEAT
:
859 case CALENDAR_SELECT
:
860 any_events(&shown
, true);
861 draw_calendar(&shown
);
865 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
866 been_in_usb_mode
= true;
867 draw_calendar(&shown
);
871 return been_in_usb_mode
?PLUGIN_USB_CONNECTED
:PLUGIN_OK
;