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"
28 #include "lib/configfile.h"
32 #if CONFIG_KEYPAD == RECORDER_PAD
33 #define CALENDAR_QUIT BUTTON_OFF
34 #define CALENDAR_SELECT BUTTON_PLAY
35 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
36 #define CALENDAR_PREV_WEEK BUTTON_UP
37 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
38 #define CALENDAR_PREV_DAY BUTTON_LEFT
39 #define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN)
40 #define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP)
42 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
43 #define CALENDAR_QUIT BUTTON_OFF
44 #define CALENDAR_SELECT BUTTON_SELECT
45 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
46 #define CALENDAR_PREV_WEEK BUTTON_UP
47 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
48 #define CALENDAR_PREV_DAY BUTTON_LEFT
49 #define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN)
50 #define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP)
52 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
53 (CONFIG_KEYPAD == IRIVER_H300_PAD)
54 #define CALENDAR_QUIT BUTTON_OFF
55 #define CALENDAR_SELECT BUTTON_SELECT
56 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
57 #define CALENDAR_PREV_WEEK BUTTON_UP
58 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
59 #define CALENDAR_PREV_DAY BUTTON_LEFT
60 #define CALENDAR_NEXT_MONTH BUTTON_MODE
61 #define CALENDAR_PREV_MONTH BUTTON_REC
63 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
64 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
65 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
66 #define CALENDAR_QUIT (BUTTON_SELECT|BUTTON_MENU)
67 #define CALENDAR_SELECT (BUTTON_SELECT|BUTTON_REL)
68 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD
69 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK
70 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
71 #define CALENDAR_PREV_DAY BUTTON_LEFT
72 #define CALENDAR_NEXT_MONTH BUTTON_PLAY
73 #define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_REL)
75 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
76 #define CALENDAR_QUIT BUTTON_POWER
77 #define CALENDAR_SELECT BUTTON_SELECT
78 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
79 #define CALENDAR_PREV_WEEK BUTTON_UP
80 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
81 #define CALENDAR_PREV_DAY BUTTON_LEFT
82 #define CALENDAR_NEXT_MONTH BUTTON_PLAY
83 #define CALENDAR_PREV_MONTH BUTTON_REC
85 #elif CONFIG_KEYPAD == GIGABEAT_PAD
86 #define CALENDAR_QUIT BUTTON_POWER
87 #define CALENDAR_SELECT BUTTON_SELECT
88 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
89 #define CALENDAR_PREV_WEEK BUTTON_UP
90 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
91 #define CALENDAR_PREV_DAY BUTTON_LEFT
92 #define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN
93 #define CALENDAR_PREV_MONTH BUTTON_VOL_UP
95 #elif CONFIG_KEYPAD == SANSA_E200_PAD
96 #define CALENDAR_QUIT BUTTON_POWER
97 #define CALENDAR_SELECT BUTTON_SELECT
98 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD
99 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK
100 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
101 #define CALENDAR_PREV_DAY BUTTON_LEFT
102 #define CALENDAR_NEXT_MONTH BUTTON_DOWN
103 #define CALENDAR_PREV_MONTH BUTTON_UP
105 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
106 #define CALENDAR_QUIT (BUTTON_HOME|BUTTON_REPEAT)
107 #define CALENDAR_SELECT BUTTON_SELECT
108 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD
109 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK
110 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
111 #define CALENDAR_PREV_DAY BUTTON_LEFT
112 #define CALENDAR_NEXT_MONTH BUTTON_DOWN
113 #define CALENDAR_PREV_MONTH BUTTON_UP
115 #elif CONFIG_KEYPAD == SANSA_C200_PAD || \
116 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
117 CONFIG_KEYPAD == SANSA_M200_PAD
118 #define CALENDAR_QUIT BUTTON_POWER
119 #define CALENDAR_SELECT BUTTON_SELECT
120 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
121 #define CALENDAR_PREV_WEEK BUTTON_UP
122 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
123 #define CALENDAR_PREV_DAY BUTTON_LEFT
124 #define CALENDAR_NEXT_MONTH BUTTON_VOL_UP
125 #define CALENDAR_PREV_MONTH BUTTON_VOL_DOWN
127 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
128 #define CALENDAR_QUIT BUTTON_POWER
129 #define CALENDAR_SELECT BUTTON_PLAY
130 #define CALENDAR_NEXT_WEEK BUTTON_SCROLL_DOWN
131 #define CALENDAR_PREV_WEEK BUTTON_SCROLL_UP
132 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
133 #define CALENDAR_PREV_DAY BUTTON_LEFT
134 #define CALENDAR_NEXT_MONTH BUTTON_FF
135 #define CALENDAR_PREV_MONTH BUTTON_REW
137 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
138 #define CALENDAR_QUIT BUTTON_BACK
139 #define CALENDAR_SELECT BUTTON_SELECT
140 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
141 #define CALENDAR_PREV_WEEK BUTTON_UP
142 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
143 #define CALENDAR_PREV_DAY BUTTON_LEFT
144 #define CALENDAR_NEXT_MONTH BUTTON_NEXT
145 #define CALENDAR_PREV_MONTH BUTTON_PREV
147 #elif CONFIG_KEYPAD == MROBE100_PAD
148 #define CALENDAR_QUIT BUTTON_POWER
149 #define CALENDAR_SELECT BUTTON_SELECT
150 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
151 #define CALENDAR_PREV_WEEK BUTTON_UP
152 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
153 #define CALENDAR_PREV_DAY BUTTON_LEFT
154 #define CALENDAR_NEXT_MONTH (BUTTON_MENU|BUTTON_DOWN)
155 #define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_UP)
157 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
158 #define CALENDAR_QUIT BUTTON_RC_REC
159 #define CALENDAR_SELECT BUTTON_RC_PLAY
160 #define CALENDAR_NEXT_WEEK BUTTON_RC_VOL_DOWN
161 #define CALENDAR_PREV_WEEK BUTTON_RC_VOL_UP
162 #define CALENDAR_NEXT_DAY BUTTON_RC_FF
163 #define CALENDAR_PREV_DAY BUTTON_RC_REW
164 #define CALENDAR_NEXT_MONTH BUTTON_RC_MODE
165 #define CALENDAR_PREV_MONTH BUTTON_RC_MENU
167 #elif (CONFIG_KEYPAD == COWOND2_PAD)
168 #define CALENDAR_QUIT BUTTON_POWER
169 #define CALENDAR_SELECT BUTTON_CENTER
170 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
171 #define CALENDAR_PREV_WEEK BUTTON_UP
172 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
173 #define CALENDAR_PREV_DAY BUTTON_LEFT
174 #define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT
175 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT
177 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
178 #define CALENDAR_QUIT BUTTON_POWER
179 #define CALENDAR_SELECT BUTTON_SELECT
180 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
181 #define CALENDAR_PREV_WEEK BUTTON_UP
182 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
183 #define CALENDAR_PREV_DAY BUTTON_LEFT
184 #define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN
185 #define CALENDAR_PREV_MONTH BUTTON_VOL_UP
187 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
188 #define CALENDAR_QUIT BUTTON_POWER
189 #define CALENDAR_SELECT BUTTON_MENU
190 #define CALENDAR_NEXT_WEEK BUTTON_VOL_DOWN
191 #define CALENDAR_PREV_WEEK BUTTON_VOL_UP
192 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
193 #define CALENDAR_PREV_DAY BUTTON_LEFT
194 #define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT
195 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT
197 #elif (CONFIG_KEYPAD == ONDAVX777_PAD)
198 #define CALENDAR_QUIT BUTTON_POWER
200 #elif CONFIG_KEYPAD == MROBE500_PAD
201 #define CALENDAR_QUIT BUTTON_POWER
203 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
204 #define CALENDAR_QUIT BUTTON_REC
205 #define CALENDAR_SELECT BUTTON_PLAY
206 #define CALENDAR_NEXT_WEEK BUTTON_DOWN
207 #define CALENDAR_PREV_WEEK BUTTON_UP
208 #define CALENDAR_NEXT_DAY BUTTON_RIGHT
209 #define CALENDAR_PREV_DAY BUTTON_LEFT
210 #define CALENDAR_NEXT_MONTH BUTTON_FFWD
211 #define CALENDAR_PREV_MONTH BUTTON_REW
214 #error "No keypad setting."
217 #ifdef HAVE_TOUCHSCREEN
218 #ifndef CALENDAR_QUIT
219 #define CALENDAR_QUIT BUTTON_MIDLEFT
221 #ifndef CALENDAR_SELECT
222 #define CALENDAR_SELECT BUTTON_CENTER
224 #ifndef CALENDAR_NEXT_DAY
225 #define CALENDAR_NEXT_DAY BUTTON_TOPLEFT
227 #ifndef CALENDAR_PREV_DAY
228 #define CALENDAR_PREV_DAY BUTTON_BOTTOMLEFT
230 #ifndef CALENDAR_NEXT_WEEK
231 #define CALENDAR_NEXT_WEEK BUTTON_TOPMIDDLE
233 #ifndef CALENDAR_PREV_WEEK
234 #define CALENDAR_PREV_WEEK BUTTON_BOTTOMMIDDLE
236 #ifndef CALENDAR_NEXT_MONTH
237 #define CALENDAR_NEXT_MONTH BUTTON_TOPRIGHT
239 #ifndef CALENDAR_PREV_MONTH
240 #define CALENDAR_PREV_MONTH BUTTON_BOTTOMRIGHT
244 #define MEMO_FILE PLUGIN_APPS_DIR "/.memo"
245 #define TEMP_FILE PLUGIN_APPS_DIR "/~temp"
247 #define X_OFFSET ((LCD_WIDTH%7)/2)
253 #define CELL_WIDTH (LCD_WIDTH / 7)
254 #define CELL_HEIGHT (LCD_HEIGHT / 7)
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
},
262 static bool leap_year
;
263 /* days_in_month[][0] is for December */
264 static const int days_in_month
[2][13] = {
265 {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
266 {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
269 static const char *dayname_long
[7] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
270 static const char *dayname_short
[7] = {"M","T","W","T","F","S","S"};
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 ;
299 static void calendar_init(struct shown
*shown
)
305 rb
->lcd_getstringsize("A", &w
, &h
);
306 if ( ((w
* 14) > LCD_WIDTH
) || ((h
* 7) > LCD_HEIGHT
) )
308 use_system_font
= true;
312 shown
->mday
= tm
->tm_mday
;
313 shown
->mon
= tm
->tm_mon
+ 1;
314 shown
->year
= 2000 + (tm
->tm_year
%100);
315 shown
->wday
= tm
->tm_wday
- 1;
317 shown
->firstday
= calc_weekday(shown
);
318 leap_year
= is_leap_year(shown
->year
);
321 static void draw_headers(void)
326 const char **dayname
= dayname_long
;
328 for (i
= 0; i
< 7; i
++)
330 rb
->lcd_getstringsize(dayname
[i
], &w
, &h
);
333 dayname
= dayname_short
;
339 rb
->lcd_getstringsize("A", &w
, &h
);
340 for (i
= 0; i
< 7; i
++)
342 if (wday
>= 7) wday
= 0;
343 rb
->lcd_putsxy(x
, 0, dayname
[wday
++]);
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
;
357 const char *monthname
[] = {
358 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
359 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
363 rb
->lcd_setfont(FONT_SYSFIXED
);
365 rb
->lcd_getstringsize("A", &w
, &h
);
366 rb
->lcd_clear_display();
368 wday
= shown
->firstday
;
369 pos
= wday
+ 7 - first_wday
;
370 if (pos
>= 7) pos
-= 7;
372 days_per_month
= days_in_month
[leap_year
][shown
->mon
];
373 x
= X_OFFSET
+ (pos
* CELL_WIDTH
);
375 for (j
= 1; j
<= days_per_month
; j
++)
377 if ( (day_has_memo
[j
]) || (wday_has_memo
[wday
]) )
378 rb
->snprintf(buffer
, 4, "%02d.", j
);
380 rb
->snprintf(buffer
, 4, "%02d", j
);
381 if (shown
->mday
== j
)
383 rb
->lcd_set_drawmode(DRMODE_SOLID
);
384 rb
->lcd_fillrect(x
, y
- 1, CELL_WIDTH
- 1, CELL_HEIGHT
);
385 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
390 rb
->lcd_set_drawmode(DRMODE_SOLID
);
392 rb
->lcd_putsxy(x
, y
, buffer
);
405 shown
->lastday
= wday
;
406 rb
->lcd_set_drawmode(DRMODE_SOLID
);
407 rb
->lcd_vline(LCD_WIDTH
-w
*8-10, LCD_HEIGHT
-h
-3, LCD_HEIGHT
-1);
408 rb
->lcd_hline(LCD_WIDTH
-w
*8-10, LCD_WIDTH
-1, LCD_HEIGHT
-h
-3);
409 rb
->snprintf(buffer
, sizeof(buffer
), "%s %04d",
410 monthname
[shown
->mon
-1], shown
->year
);
411 rb
->lcd_putsxy(LCD_WIDTH
-w
*8-8, LCD_HEIGHT
-h
-1, buffer
);
415 #define MAX_CHAR_MEMO_LEN 64
416 #define MAX_MEMOS_IN_A_MONTH 128
418 char message
[MAX_CHAR_MEMO_LEN
];
421 int file_pointer_start
;
422 int file_pointer_end
;
426 } memos
[MAX_MEMOS_IN_A_MONTH
];
427 static int pointer_array
[MAX_MEMOS_IN_A_MONTH
];
428 static int memos_in_memory
= 0;
429 static int memos_in_shown_memory
= 0;
431 static void load_memo(struct shown
*shown
)
441 for (k
= 1; k
< 32; k
++)
442 day_has_memo
[k
] = false;
443 for (k
= 0; k
< 7; k
++)
444 wday_has_memo
[k
] = false;
446 fp
= rb
->open(MEMO_FILE
, O_RDONLY
);
449 rb
->lseek(fp
, 0, SEEK_SET
);
453 struct memo
*memo
= &memos
[memos_in_memory
];
454 rb
->memset(memo
, 0, sizeof(*memo
));
455 memo
->file_pointer_start
= rb
->lseek(fp
, 0, SEEK_CUR
);
456 if (rb
->read(fp
, temp_memo2
, 2) == 2)
457 memo
->day
= rb
->atoi(temp_memo2
);
458 if (rb
->read(fp
, temp_memo2
, 2) == 2)
459 memo
->month
= rb
->atoi(temp_memo2
);
460 if (rb
->read(fp
, temp_memo4
, 4) == 4)
461 memo
->year
= rb
->atoi(temp_memo4
);
462 if (rb
->read(fp
, temp_memo1
, 1) == 1)
463 memo
->wday
= rb
->atoi(temp_memo1
);
464 if (rb
->read(fp
, temp_memo1
, 1) == 1)
465 memo
->type
= rb
->atoi(temp_memo1
);
466 load_to_memory
= ((memo
->type
< 2) ||
467 ((memo
->type
== 2) &&
468 (memo
->month
== shown
->mon
)) ||
470 (memo
->month
== shown
->mon
) &&
471 (memo
->year
== shown
->year
)));
475 if (rb
->read(fp
, temp_memo1
, 1) != 1)
479 memo
->file_pointer_start
= 0;
480 memo
->file_pointer_end
= 0;
484 memo
->message
[0] = 0;
490 if (temp_memo1
[0] == '\n')
493 day_has_memo
[memo
->day
] = true;
495 wday_has_memo
[memo
->wday
] = true;
496 memo
->file_pointer_end
= rb
->lseek(fp
, 0, SEEK_CUR
);
499 else if ( (temp_memo1
[0] != '\r') &&
500 (temp_memo1
[0] != '\t') &&
501 k
< MAX_CHAR_MEMO_LEN
-1 )
502 memo
->message
[k
++] = temp_memo1
[0];
504 if (temp_memo1
[0] == '\n')
512 static bool save_memo(int changed
, bool new_mod
, struct shown
*shown
)
515 /* use O_RDWR|O_CREAT so that file is created if it doesn't exist. */
516 fp
= rb
->open(MEMO_FILE
, O_RDWR
|O_CREAT
);
517 fq
= rb
->creat(TEMP_FILE
);
518 if ( (fq
> -1) && (fp
> -1) )
521 char temp
[MAX_CHAR_MEMO_LEN
];
522 struct memo
*memo
= &memos
[changed
];
523 rb
->lseek(fp
, 0, SEEK_SET
);
524 for (i
= 0; i
< memo
->file_pointer_start
; i
++)
526 rb
->read(fp
, temp
, 1);
527 rb
->write(fq
, temp
, 1);
531 rb
->fdprintf(fq
, "%02d%02d%04d%01d%01d%s\n",
532 memo
->day
, memo
->month
, memo
->year
, memo
->wday
,
533 memo
->type
, memo
->message
);
535 rb
->lseek(fp
, memo
->file_pointer_end
, SEEK_SET
);
536 while(rb
->read(fp
, temp
, 1) == 1)
538 rb
->write(fq
, temp
, 1);
542 rb
->remove(MEMO_FILE
);
543 rb
->rename(TEMP_FILE
, MEMO_FILE
);
554 static void add_memo(struct shown
*shown
, int type
)
557 struct memo
*memo
= &memos
[memos_in_memory
];
558 if (rb
->kbd_input(memo
->message
, MAX_CHAR_MEMO_LEN
) == 0)
560 if (memo
->message
[0])
562 memo
->file_pointer_start
= 0;
563 memo
->file_pointer_end
= 0;
564 memo
->day
= shown
->mday
;
565 memo
->month
= shown
->mon
;
566 memo
->wday
= shown
->wday
;
567 memo
->year
= shown
->year
;
569 if (save_memo(memos_in_memory
, true, shown
))
575 memo
->file_pointer_start
= 0;
576 memo
->file_pointer_end
= 0;
585 rb
->lcd_clear_display();
587 rb
->splash(HZ
/2, "Event added");
589 rb
->splash(HZ
/2, "Event not added");
592 static int edit_menu_cb(int action
, const struct menu_item_ex
*this_item
)
594 int i
= (intptr_t)this_item
;
595 if (action
== ACTION_REQUEST_MENUITEM
596 && memos_in_shown_memory
<= 0 && (i
==0 || i
==1))
597 return ACTION_EXIT_MENUITEM
;
601 static bool edit_memo(int change
, struct shown
*shown
)
606 static const struct opt_items modes
[7] = {
616 MENUITEM_STRINGLIST(edit_menu
, "Edit menu", edit_menu_cb
,
618 "New Weekly", "New Monthly",
619 "New Yearly", "New One off",
625 switch (rb
->do_menu(&edit_menu
, &selected
, NULL
, false))
628 save_memo(change
, false, shown
);
632 if(rb
->kbd_input(memos
[change
].message
,
633 MAX_CHAR_MEMO_LEN
) == 0)
634 save_memo(change
, true, shown
);
641 case 3: /* monthly */
649 case 5: /* one off */
653 case 6: /* weekday */
654 rb
->set_option("First Day of Week", &first_wday
,
655 INT
, modes
, 7, NULL
);
658 case 7: /* playback control */
659 playback_control(NULL
);
665 case MENU_ATTACHED_USB
:
666 been_in_usb_mode
= true;
673 static const char* get_event_text(int selected
, void *data
,
674 char *buffer
, size_t buffer_len
)
676 struct shown
*shown
= (struct shown
*) data
;
678 if (selected
< 0 || memos_in_shown_memory
<= selected
)
682 memo
= &memos
[pointer_array
[selected
]];
684 rb
->snprintf(buffer
, buffer_len
, "%s (%d yrs)",
685 memo
->message
, shown
->year
- memo
->year
);
687 rb
->snprintf(buffer
, buffer_len
, "%s", memo
->message
);
691 static bool view_events(int selected
, struct shown
*shown
)
693 struct gui_synclist gui_memos
;
697 rb
->gui_synclist_init(&gui_memos
, &get_event_text
, shown
, false, 1, NULL
);
698 rb
->gui_synclist_set_title(&gui_memos
, "Events (play : menu)", NOICON
);
699 rb
->gui_synclist_set_nb_items(&gui_memos
, memos_in_shown_memory
);
700 rb
->gui_synclist_select_item(&gui_memos
, selected
);
701 rb
->gui_synclist_draw(&gui_memos
);
705 button
= rb
->get_action(CONTEXT_LIST
, TIMEOUT_BLOCK
);
706 rb
->gui_synclist_do_button(&gui_memos
, &button
, LIST_WRAP_UNLESS_HELD
);
711 selected
= rb
->gui_synclist_get_sel_pos(&gui_memos
);
712 return edit_memo(pointer_array
[selected
], shown
);
715 case ACTION_STD_CANCEL
:
720 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
721 been_in_usb_mode
= true;
729 static void update_memos_shown(struct shown
*shown
)
733 memos_in_shown_memory
= 0;
734 for (i
= 0; i
< memos_in_memory
; i
++)
737 if (((memo
->type
>= 1) && (memo
->day
== shown
->mday
)) ||
738 ((memo
->type
< 1) && (memo
->wday
== shown
->wday
)))
739 pointer_array
[memos_in_shown_memory
++] = i
;
743 static bool any_events(struct shown
*shown
, bool force
)
745 update_memos_shown(shown
);
747 if (memos_in_shown_memory
> 0)
748 return view_events(0, shown
);
750 return edit_memo(0, shown
);
757 static void next_month(struct shown
*shown
, int step
)
764 leap_year
= is_leap_year(shown
->year
);
767 shown
->mday
= shown
->mday
- days_in_month
[leap_year
][shown
->mon
-1];
768 else if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
769 shown
->mday
= days_in_month
[leap_year
][shown
->mon
];
770 shown
->firstday
= shown
->lastday
;
772 draw_calendar(shown
);
775 static void prev_month(struct shown
*shown
, int step
)
782 leap_year
= is_leap_year(shown
->year
);
785 shown
->mday
= shown
->mday
+ days_in_month
[leap_year
][shown
->mon
];
786 else if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
787 shown
->mday
= days_in_month
[leap_year
][shown
->mon
];
788 shown
->firstday
+= 7 - (days_in_month
[leap_year
][shown
->mon
] % 7);
789 if (shown
->firstday
>= 7)
790 shown
->firstday
-= 7;
792 draw_calendar(shown
);
795 static void next_day(struct shown
*shown
, int step
)
798 if (shown
->mday
> days_in_month
[leap_year
][shown
->mon
])
799 next_month(shown
, step
);
801 draw_calendar(shown
);
804 static void prev_day(struct shown
*shown
, int step
)
808 prev_month(shown
, step
);
810 draw_calendar(shown
);
813 enum plugin_status
plugin_start(const void* parameter
)
821 configfile_load(CFG_FILE
, config
, 1, 0);
822 old_first_wday
= first_wday
;
824 calendar_init(&shown
);
826 any_events(&shown
, false);
827 draw_calendar(&shown
);
831 button
= rb
->button_get(true);
838 case CALENDAR_NEXT_MONTH
:
839 case CALENDAR_NEXT_MONTH
| BUTTON_REPEAT
:
840 next_month(&shown
, 0);
843 case CALENDAR_PREV_MONTH
:
844 case CALENDAR_PREV_MONTH
| BUTTON_REPEAT
:
845 prev_month(&shown
, 0);
848 case CALENDAR_NEXT_WEEK
:
849 case CALENDAR_NEXT_WEEK
| BUTTON_REPEAT
:
853 case CALENDAR_PREV_WEEK
:
854 case CALENDAR_PREV_WEEK
| BUTTON_REPEAT
:
858 case CALENDAR_PREV_DAY
:
859 case CALENDAR_PREV_DAY
| BUTTON_REPEAT
:
863 case CALENDAR_NEXT_DAY
:
864 case CALENDAR_NEXT_DAY
| BUTTON_REPEAT
:
868 case CALENDAR_SELECT
:
869 any_events(&shown
, true);
870 draw_calendar(&shown
);
874 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
875 been_in_usb_mode
= true;
876 draw_calendar(&shown
);
881 if (old_first_wday
!= first_wday
)
882 configfile_save(CFG_FILE
, config
, 1, 0);
883 return been_in_usb_mode
?PLUGIN_USB_CONNECTED
:PLUGIN_OK
;