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 == ONDAVX777_PAD)
197 #define CALENDAR_QUIT BUTTON_POWER
199 #elif CONFIG_KEYPAD == MROBE500_PAD
200 #define CALENDAR_QUIT BUTTON_POWER
202 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
203 #define CALENDAR_QUIT BUTTON_REC
204 #define CALENDAR_SELECT BUTTON_PLAY
205 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
206 #define CALENDAR_PREV_WEEK BUTTON_UP
207 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
208 #define CALENDAR_PREV_DAY BUTTON_LEFT
209 #define CALENDAR_NEXT_MONTH BUTTON_FFWD
210 #define CALENDAR_PREV_MONTH BUTTON_REW
213 #error "No keypad setting."
216 #ifdef HAVE_TOUCHSCREEN
217 #ifndef CALENDAR_QUIT
218 #define CALENDAR_QUIT BUTTON_MIDLEFT
220 #ifndef CALENDAR_SELECT
221 #define CALENDAR_SELECT BUTTON_CENTER
223 #ifndef CALENDAR_NEXT_DAY
224 #define CALENDAR_NEXT_DAY BUTTON_TOPLEFT
226 #ifndef CALENDAR_PREV_DAY
227 #define CALENDAR_PREV_DAY BUTTON_BOTTOMLEFT
229 #ifndef CALENDAR_NEXT_WEEK
230 #define CALENDAR_NEXT_WEEK BUTTON_TOPMIDDLE
232 #ifndef CALENDAR_PREV_WEEK
233 #define CALENDAR_PREV_WEEK BUTTON_BOTTOMMIDDLE
235 #ifndef CALENDAR_NEXT_MONTH
236 #define CALENDAR_NEXT_MONTH BUTTON_TOPRIGHT
238 #ifndef CALENDAR_PREV_MONTH
239 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMRIGHT
243 #define MEMO_FILE PLUGIN_APPS_DIR "/.memo"
244 #define TEMP_FILE PLUGIN_APPS_DIR "/~temp"
246 #define X_OFFSET ((LCD_WIDTH%7)/2)
252 #define CELL_WIDTH (LCD_WIDTH / 7)
253 #define CELL_HEIGHT (LCD_HEIGHT / 7)
255 static bool leap_year
;
256 /* days_in_month[][0] is for December */
257 static const int days_in_month
[2][13] = {
258 {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
259 {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
262 static const char *dayname_long
[7] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
263 static const char *dayname_short
[7] = {"M","T","W","T","F","S","S"};
266 int mday
; /* day of the month */
268 int year
; /* year since 1900 */
269 int wday
; /* day of the week */
273 int mday
; /* day of the month */
275 int year
; /* year since 1900 */
276 int wday
; /* day of the week */
277 int firstday
; /* first (w)day of month */
278 int lastday
; /* last (w)day of month */
281 static bool use_system_font
= false;
283 static bool been_in_usb_mode
= false;
285 /* leap year -- account for gregorian reformation in 1752 */
286 static int is_leap_year(int yr
)
288 return ((yr
) <= 1752 ? !((yr
) % 4) : \
289 (!((yr
) % 4) && ((yr
) % 100)) || !((yr
) % 400)) ? 1:0 ;
292 /* searches the weekday of the first day in month,
293 * relative to the given values */
294 static int calc_weekday( struct shown
*shown
)
296 return ( shown
->wday
+ 36 - shown
->mday
) % 7 ;
300 static void calendar_init(struct today
*today
, struct shown
*shown
)
308 rb
->lcd_getstringsize("A",&w
,&h
);
309 if ( ((w
* 14) > LCD_WIDTH
) || ((h
* 7) > LCD_HEIGHT
) )
311 rb
->lcd_setfont(FONT_SYSFIXED
);
312 use_system_font
= true;
314 rb
->lcd_clear_display();
317 today
->mon
= tm
->tm_mon
+1;
318 today
->year
= 2000+tm
->tm_year
%100;
319 today
->wday
= tm
->tm_wday
-1;
320 today
->mday
= tm
->tm_mday
;
321 shown
->mday
= today
->mday
;
322 shown
->mon
= today
->mon
;
323 shown
->year
= today
->year
;
324 shown
->wday
= today
->wday
;
326 shown
->firstday
= calc_weekday(shown
);
327 leap_year
= is_leap_year(shown
->year
);
330 static void draw_headers(void)
334 const char **dayname
= (const char**)&dayname_long
;
336 for (i
= 0; i
< 7; i
++)
338 rb
->lcd_getstringsize(dayname
[i
],&w
,&h
);
341 dayname
= (const char**)&dayname_short
;
346 rb
->lcd_getstringsize("A",&w
,&h
);
347 for (i
= 0; i
< 7; i
++)
349 rb
->lcd_putsxy(x
, 0 , dayname
[i
]);
352 rb
->lcd_hline(0, LCD_WIDTH
-1 ,h
);
355 static bool day_has_memo
[32];
356 static bool wday_has_memo
[7];
357 static void draw_calendar(struct shown
*shown
)
360 int x
,y
,pos
,days_per_month
,j
;
362 const char *monthname
[] = {
363 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
364 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
367 rb
->lcd_setfont(FONT_SYSFIXED
);
368 rb
->lcd_getstringsize("A",&w
,&h
);
369 rb
->lcd_clear_display();
371 if (shown
->firstday
> 6)
372 shown
->firstday
-= 7;
373 pos
= shown
->firstday
;
374 days_per_month
= days_in_month
[leap_year
][shown
->mon
];
375 x
= X_OFFSET
+ (pos
* CELL_WIDTH
);
377 for (j
= 1; j
<= days_per_month
; j
++)
379 if ( (day_has_memo
[j
]) || (wday_has_memo
[pos
]) )
380 rb
->snprintf(buffer
,4,"%02d.", j
);
382 rb
->snprintf(buffer
,4,"%02d", j
);
383 if (shown
->mday
== j
)
385 rb
->lcd_set_drawmode(DRMODE_SOLID
);
386 rb
->lcd_fillrect(x
, y
- 1, CELL_WIDTH
- 1, CELL_HEIGHT
);
387 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
392 rb
->lcd_set_drawmode(DRMODE_SOLID
);
394 rb
->lcd_putsxy(x
, y
, buffer
);
404 rb
->lcd_set_drawmode(DRMODE_SOLID
);
405 rb
->lcd_vline(LCD_WIDTH
-w
*8-10,LCD_HEIGHT
-h
-3,LCD_HEIGHT
-1);
406 rb
->lcd_hline(LCD_WIDTH
-w
*8-10,LCD_WIDTH
-1,LCD_HEIGHT
-h
-3);
407 rb
->snprintf(buffer
,9,"%s %04d",monthname
[shown
->mon
-1],shown
->year
);
408 rb
->lcd_putsxy(LCD_WIDTH
-w
*8-8,LCD_HEIGHT
-h
-1,buffer
);
409 shown
->lastday
= pos
;
413 #define MAX_CHAR_MEMO_LEN 64
414 #define MAX_MEMOS_IN_A_MONTH 128
416 char message
[MAX_CHAR_MEMO_LEN
];
419 int file_pointer_start
;
420 int file_pointer_end
;
424 } memos
[MAX_MEMOS_IN_A_MONTH
];
425 static int pointer_array
[MAX_MEMOS_IN_A_MONTH
];
426 static int memos_in_memory
= 0;
427 static int memos_in_shown_memory
= 0;
429 static void load_memo(struct shown
*shown
)
439 for (k
= 1; k
< 32; k
++)
440 day_has_memo
[k
] = false;
441 for (k
= 0; k
< 7; k
++)
442 wday_has_memo
[k
] = false;
444 fp
= rb
->open(MEMO_FILE
, O_RDONLY
);
447 rb
->lseek(fp
, 0, SEEK_SET
);
451 rb
->memset(&memos
[memos_in_memory
].message
, 0, MAX_CHAR_MEMO_LEN
);
452 memos
[memos_in_memory
].file_pointer_start
=
453 rb
->lseek(fp
, 0, SEEK_CUR
);
454 if (rb
->read(fp
, temp_memo2
, 2) == 2)
455 memos
[memos_in_memory
].day
= rb
->atoi(&temp_memo2
[0]);
457 memos
[memos_in_memory
].day
= 0;
458 if (rb
->read(fp
, temp_memo2
, 2) == 2)
459 memos
[memos_in_memory
].month
= rb
->atoi(&temp_memo2
[0]);
461 memos
[memos_in_memory
].month
= 0;
462 if (rb
->read(fp
, temp_memo4
, 4) == 4)
463 memos
[memos_in_memory
].year
= rb
->atoi(&temp_memo4
[0]);
465 memos
[memos_in_memory
].year
= 0;
466 /* as the year returned is sometimes yearmonth, ie if yr should =
467 2003, and month = 06, then it returns 200306 */
468 if (memos
[memos_in_memory
].year
> (shown
->year
* 10))
469 memos
[memos_in_memory
].year
= (memos
[memos_in_memory
].year
-
470 memos
[memos_in_memory
].month
) /
472 if (rb
->read(fp
, temp_memo1
, 1) == 1)
473 memos
[memos_in_memory
].wday
= rb
->atoi(&temp_memo1
[0]);
475 memos
[memos_in_memory
].wday
= 0;
476 if (rb
->read(fp
, temp_memo1
, 1) == 1)
477 memos
[memos_in_memory
].type
= rb
->atoi(&temp_memo1
[0]);
479 memos
[memos_in_memory
].type
= 0;
480 load_to_memory
= ((memos
[memos_in_memory
].type
< 2) ||
481 ((memos
[memos_in_memory
].type
== 2) &&
482 (memos
[memos_in_memory
].month
== shown
->mon
)) ||
483 ((memos
[memos_in_memory
].type
> 2) &&
484 (memos
[memos_in_memory
].month
== shown
->mon
) &&
485 (memos
[memos_in_memory
].year
== shown
->year
)));
489 if (rb
->read(fp
, temp_memo1
, 1) != 1)
491 memos
[memos_in_memory
].day
= 0;
492 memos
[memos_in_memory
].month
= 0;
493 memos
[memos_in_memory
].file_pointer_start
= 0;
494 memos
[memos_in_memory
].file_pointer_end
= 0;
495 memos
[memos_in_memory
].year
= 0;
496 memos
[memos_in_memory
].type
= 0;
497 memos
[memos_in_memory
].wday
= 0;
498 memos
[memos_in_memory
].message
[0] = 0;
504 if (temp_memo1
[0] == '\n')
506 if (memos
[memos_in_memory
].type
> 0)
507 day_has_memo
[memos
[memos_in_memory
].day
] =
510 wday_has_memo
[memos
[memos_in_memory
].wday
] =
512 memos
[memos_in_memory
++].file_pointer_end
=
513 rb
->lseek(fp
, 0, SEEK_CUR
);
515 else if ( (temp_memo1
[0] != '\r') &&
516 (temp_memo1
[0] != '\t') &&
517 k
< MAX_CHAR_MEMO_LEN
-1 )
518 memos
[memos_in_memory
].message
[k
++] = temp_memo1
[0];
520 if (temp_memo1
[0] == '\n')
528 static bool save_memo(int changed
, bool new_mod
, struct shown
*shown
)
531 /* use O_RDWR|O_CREAT so that file is created if it doesn't exist. */
532 fp
= rb
->open(MEMO_FILE
, O_RDWR
|O_CREAT
);
533 fq
= rb
->creat(TEMP_FILE
);
534 if ( (fq
> -1) && (fp
> -1) )
537 char temp
[MAX_CHAR_MEMO_LEN
];
538 rb
->lseek(fp
, 0, SEEK_SET
);
539 for (i
= 0; i
< memos
[changed
].file_pointer_start
; i
++)
541 rb
->read(fp
, temp
, 1);
542 rb
->write(fq
,temp
,1);
546 rb
->fdprintf(fq
, "%02d%02d%04d%01d%01d%s\n",
548 memos
[changed
].month
,
552 memos
[changed
].message
);
554 rb
->lseek(fp
, memos
[changed
].file_pointer_end
, SEEK_SET
);
555 while(rb
->read(fp
, temp
, 1) == 1)
557 rb
->write(fq
,temp
,1);
561 rb
->remove(MEMO_FILE
);
562 rb
->rename(TEMP_FILE
, MEMO_FILE
);
573 static void add_memo(struct shown
*shown
, int type
)
576 if (rb
->kbd_input(memos
[memos_in_memory
].message
,
577 sizeof memos
[memos_in_memory
].message
) == 0)
579 if (rb
->strlen(memos
[memos_in_memory
].message
))
581 memos
[memos_in_memory
].file_pointer_start
= 0;
582 memos
[memos_in_memory
].file_pointer_end
= 0;
583 memos
[memos_in_memory
].day
= shown
->mday
;
584 memos
[memos_in_memory
].month
= shown
->mon
;
585 memos
[memos_in_memory
].wday
= shown
->wday
;
586 memos
[memos_in_memory
].year
= shown
->year
;
587 memos
[memos_in_memory
].type
= type
;
588 if (save_memo(memos_in_memory
,true,shown
))
594 memos
[memos_in_memory
].file_pointer_start
= 0;
595 memos
[memos_in_memory
].file_pointer_end
= 0;
596 memos
[memos_in_memory
].day
= 0;
597 memos
[memos_in_memory
].month
= 0;
598 memos
[memos_in_memory
].year
= 0;
599 memos
[memos_in_memory
].type
= 0;
600 memos
[memos_in_memory
].wday
= 0;
604 rb
->lcd_clear_display();
606 rb
->lcd_setfont(FONT_SYSFIXED
);
608 rb
->splash(HZ
/2,"Event added");
610 rb
->splash(HZ
/2,"Event not added");
613 static int edit_menu_cb(int action
, const struct menu_item_ex
*this_item
)
615 int i
= (intptr_t)this_item
;
616 if (action
== ACTION_REQUEST_MENUITEM
617 && memos_in_shown_memory
<= 0 && (i
==0 || i
==1))
618 return ACTION_EXIT_MENUITEM
;
622 static bool edit_memo(int change
, struct shown
*shown
)
627 MENUITEM_STRINGLIST(edit_menu
, "Edit menu", edit_menu_cb
,
629 "New Weekly", "New Monthly",
630 "New Yearly", "New One off",
635 switch (rb
->do_menu(&edit_menu
, &selected
, NULL
, false))
638 save_memo(pointer_array
[change
],false,shown
);
642 if(rb
->kbd_input(memos
[pointer_array
[change
]].message
,
643 sizeof memos
[pointer_array
[change
]].message
) == 0)
644 save_memo(pointer_array
[change
],true,shown
);
651 case 3: /* monthly */
659 case 5: /* one off */
663 case 6: /* playback control */
664 playback_control(NULL
);
670 case MENU_ATTACHED_USB
:
671 been_in_usb_mode
= true;
678 static const char* get_event_text(int selected
, void *data
,
679 char *buffer
, size_t buffer_len
)
681 struct shown
*shown
= (struct shown
*) data
;
682 if (selected
< 0 || memos_in_shown_memory
<= selected
)
686 if (memos
[pointer_array
[selected
]].type
== 2)
687 rb
->snprintf(buffer
, buffer_len
, "%s (%d yrs)",
688 memos
[pointer_array
[selected
]].message
,
689 shown
->year
- memos
[pointer_array
[selected
]].year
);
691 rb
->snprintf(buffer
, buffer_len
, "%s",
692 memos
[pointer_array
[selected
]].message
);
696 static bool view_events(int selected
, struct shown
*shown
)
698 struct gui_synclist gui_memos
;
702 rb
->gui_synclist_init(&gui_memos
, &get_event_text
, shown
, false, 1, NULL
);
703 rb
->gui_synclist_set_title(&gui_memos
, "Events (play : menu)", NOICON
);
704 rb
->gui_synclist_set_nb_items(&gui_memos
, memos_in_shown_memory
);
705 rb
->gui_synclist_select_item(&gui_memos
, selected
);
706 rb
->gui_synclist_draw(&gui_memos
);
710 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
711 rb
->gui_synclist_do_button(&gui_memos
,&button
,LIST_WRAP_UNLESS_HELD
);
716 selected
= rb
->gui_synclist_get_sel_pos(&gui_memos
);
717 return edit_memo(selected
, shown
);
720 case ACTION_STD_CANCEL
:
725 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
726 been_in_usb_mode
= true;
734 static void update_memos_shown(struct shown
*shown
)
737 memos_in_shown_memory
= 0;
738 for (i
= 0; i
< memos_in_memory
; i
++)
739 if (((memos
[i
].type
>= 1) &&
740 (memos
[i
].day
== shown
->mday
)) ||
741 ((memos
[i
].type
< 1) &&
742 (memos
[i
].wday
== shown
->wday
)))
743 pointer_array
[memos_in_shown_memory
++] = i
;
746 static bool any_events(struct shown
*shown
, bool force
)
748 update_memos_shown(shown
);
750 if (memos_in_shown_memory
> 0)
751 return view_events(0, shown
);
753 return edit_memo(0, shown
);
760 static void next_month(struct shown
*shown
, int step
)
767 leap_year
= is_leap_year(shown
->year
);
770 shown
->mday
= shown
->mday
- days_in_month
[leap_year
][shown
->mon
-1];
771 else if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
772 shown
->mday
= days_in_month
[leap_year
][shown
->mon
];
773 shown
->firstday
= shown
->lastday
;
775 draw_calendar(shown
);
778 static void prev_month(struct shown
*shown
, int step
)
785 leap_year
= is_leap_year(shown
->year
);
788 shown
->mday
= shown
->mday
+ days_in_month
[leap_year
][shown
->mon
];
789 else if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
790 shown
->mday
= days_in_month
[leap_year
][shown
->mon
];
791 shown
->firstday
+= 7 - (days_in_month
[leap_year
][shown
->mon
] % 7);
793 draw_calendar(shown
);
796 static void next_day(struct shown
*shown
, int step
)
799 if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
800 next_month(shown
, step
);
802 draw_calendar(shown
);
805 static void prev_day(struct shown
*shown
, int step
)
809 prev_month(shown
, step
);
811 draw_calendar(shown
);
814 enum plugin_status
plugin_start(const void* parameter
)
823 calendar_init(&today
, &shown
);
825 any_events(&shown
, false);
826 draw_calendar(&shown
);
829 button
= rb
->button_get(true);
836 case CALENDAR_NEXT_MONTH
:
837 case CALENDAR_NEXT_MONTH
| BUTTON_REPEAT
:
838 next_month(&shown
, 0);
841 case CALENDAR_PREV_MONTH
:
842 case CALENDAR_PREV_MONTH
| BUTTON_REPEAT
:
843 prev_month(&shown
, 0);
846 case CALENDAR_NEXT_WEEK
:
847 case CALENDAR_NEXT_WEEK
| BUTTON_REPEAT
:
851 case CALENDAR_PREV_WEEK
:
852 case CALENDAR_PREV_WEEK
| BUTTON_REPEAT
:
856 case CALENDAR_PREV_DAY
:
857 case CALENDAR_PREV_DAY
| BUTTON_REPEAT
:
861 case CALENDAR_NEXT_DAY
:
862 case CALENDAR_NEXT_DAY
| BUTTON_REPEAT
:
866 case CALENDAR_SELECT
:
867 any_events(&shown
, true);
868 draw_calendar(&shown
);
872 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
873 been_in_usb_mode
= true;
874 draw_calendar(&shown
);
878 return been_in_usb_mode
?PLUGIN_USB_CONNECTED
:PLUGIN_OK
;