Fix yellow
[Rockbox.git] / apps / menus / settings_menu.c
blob9d816c99b1ff1f8b0dc6364157d48d3856bd84c3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <limits.h>
23 #include <string.h>
24 #include "config.h"
25 #include "lang.h"
26 #include "action.h"
27 #include "settings.h"
28 #include "menu.h"
29 #include "sound_menu.h"
30 #include "exported_menus.h"
31 #include "tree.h"
32 #include "tagtree.h"
33 #include "usb.h"
34 #include "splash.h"
35 #include "talk.h"
36 #include "sprintf.h"
37 #include "powermgmt.h"
38 #if CONFIG_CODEC == SWCODEC
39 #include "playback.h"
40 #endif
41 #ifdef HAVE_RTC_ALARM
42 #include "alarm_menu.h"
43 #endif
44 #if CONFIG_TUNER
45 #include "radio.h"
46 #endif
47 #if CONFIG_RTC
48 #include "screens.h"
49 #endif
51 /***********************************/
52 /* TAGCACHE MENU */
53 #ifdef HAVE_TAGCACHE
55 static void tagcache_rebuild_with_splash(void)
57 tagcache_rebuild();
58 gui_syncsplash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
61 static void tagcache_update_with_splash(void)
63 tagcache_update();
64 gui_syncsplash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
67 #ifdef HAVE_TC_RAMCACHE
68 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
69 #endif
70 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
71 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
72 (int(*)(void))tagcache_rebuild_with_splash,
73 NULL, NULL, Icon_NOICON);
74 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
75 (int(*)(void))tagcache_update_with_splash,
76 NULL, NULL, Icon_NOICON);
77 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
78 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
79 (int(*)(void))tagtree_export, NULL,
80 NULL, Icon_NOICON);
81 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
82 (int(*)(void))tagtree_import, NULL,
83 NULL, Icon_NOICON);
84 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
85 #ifdef HAVE_TC_RAMCACHE
86 &tagcache_ram,
87 #endif
88 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
89 &tc_export, &tc_import);
90 #endif /* HAVE_TAGCACHE */
91 /* TAGCACHE MENU */
92 /***********************************/
94 /***********************************/
95 /* FILE VIEW MENU */
96 static int fileview_callback(int action,const struct menu_item_ex *this_item);
97 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
98 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
99 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
100 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
101 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
102 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
103 #ifdef HAVE_LCD_BITMAP
104 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
105 #endif
106 static int fileview_callback(int action,const struct menu_item_ex *this_item)
108 static int oldval;
109 int *variable = this_item->variable;
110 switch (action)
112 case ACTION_ENTER_MENUITEM: /* on entering an item */
113 oldval = *variable;
114 break;
115 case ACTION_EXIT_MENUITEM: /* on exit */
116 if (*variable != oldval)
117 reload_directory(); /* force reload if this has changed */
118 break;
120 return action;
123 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
124 &sort_case, &sort_dir, &sort_file,
125 &dirfilter, &show_filename_ext, &browse_current,
126 #ifdef HAVE_LCD_BITMAP
127 &show_path_in_browser
128 #endif
130 /* FILE VIEW MENU */
131 /***********************************/
134 /***********************************/
135 /* SYSTEM MENU */
137 /* Battery */
138 #if BATTERY_CAPACITY_INC > 0
139 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
140 #endif
141 #if BATTERY_TYPES_COUNT > 1
142 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
143 #endif
144 #ifdef HAVE_USB_POWER
145 #if CONFIG_CHARGING
146 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
148 (void)this_item;
149 switch (action)
151 case ACTION_EXIT_MENUITEM: /* on exit */
152 usb_charging_enable(global_settings.usb_charging);
153 break;
155 return action;
157 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
158 #endif
159 #endif
160 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
161 #if BATTERY_CAPACITY_INC > 0
162 &battery_capacity,
163 #endif
164 #if BATTERY_TYPES_COUNT > 1
165 &battery_type,
166 #endif
167 #ifdef HAVE_USB_POWER
168 #if CONFIG_CHARGING
169 &usb_charging,
170 #endif
171 #endif
173 /* Disk */
174 #ifndef HAVE_FLASH_STORAGE
175 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
176 #endif
177 #ifdef HAVE_DIRCACHE
178 static int dircache_callback(int action,const struct menu_item_ex *this_item)
180 (void)this_item;
181 switch (action)
183 case ACTION_EXIT_MENUITEM: /* on exit */
184 switch (global_settings.dircache)
186 case true:
187 if (!dircache_is_enabled())
188 gui_syncsplash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
189 break;
190 case false:
191 if (dircache_is_enabled())
192 dircache_disable();
193 break;
195 break;
197 return action;
199 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
200 #endif
201 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
202 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
203 #ifndef HAVE_FLASH_STORAGE
204 &disk_spindown,
205 #endif
206 #ifdef HAVE_DIRCACHE
207 &dircache,
208 #endif
210 #endif
212 /* Time & Date */
213 #if CONFIG_RTC
214 static int timedate_set(void)
216 struct tm tm;
217 int result;
219 /* Make a local copy of the time struct */
220 memcpy(&tm, get_time(), sizeof(struct tm));
222 /* do some range checks */
223 /* This prevents problems with time/date setting after a power loss */
224 if (!valid_time(&tm))
226 /* Macros to convert a 2-digit string to a decimal constant.
227 (YEAR), MONTH and DAY are set by the date command, which outputs
228 DAY as 00..31 and MONTH as 01..12. The leading zero would lead to
229 misinterpretation as an octal constant. */
230 #define S100(x) 1 ## x
231 #define C2DIG2DEC(x) (S100(x)-100)
233 tm.tm_hour = 0;
234 tm.tm_min = 0;
235 tm.tm_sec = 0;
236 tm.tm_mday = C2DIG2DEC(DAY);
237 tm.tm_mon = C2DIG2DEC(MONTH)-1;
238 tm.tm_wday = 1;
239 tm.tm_year = YEAR-1900;
242 result = (int)set_time_screen(str(LANG_SET_TIME), &tm);
244 if(tm.tm_year != -1) {
245 set_time(&tm);
247 return result;
250 MENUITEM_FUNCTION(time_set, 0, ID2P(LANG_SET_TIME),
251 timedate_set, NULL, NULL, Icon_NOICON);
252 MENUITEM_SETTING(timeformat, &global_settings.timeformat, NULL);
253 MAKE_MENU(time_menu, ID2P(LANG_TIME_MENU), 0, Icon_NOICON, &time_set, &timeformat);
254 #endif
256 /* System menu */
257 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
259 #ifdef HAVE_RTC_ALARM
260 MENUITEM_FUNCTION(alarm_screen_call, 0, ID2P(LANG_ALARM_MOD_ALARM_MENU),
261 (menu_function)alarm_screen, NULL, NULL, Icon_NOICON);
262 #if CONFIG_TUNER || defined(HAVE_RECORDING)
264 #if CONFIG_TUNER && !defined(HAVE_RECORDING)
265 /* This need only be shown if we dont have recording, because if we do
266 then always show the setting item, because there will always be at least
267 2 items */
268 static int alarm_callback(int action,const struct menu_item_ex *this_item)
270 (void)this_item;
271 switch (action)
273 case ACTION_REQUEST_MENUITEM:
274 if (radio_hardware_present() == 0)
275 return ACTION_EXIT_MENUITEM;
276 break;
278 return action;
280 #else
281 #define alarm_callback NULL
282 #endif /* CONFIG_TUNER && !HAVE_RECORDING */
283 /* have to do this manually because the setting screen
284 doesnt handle variable item count */
285 static int alarm_setting(void)
287 struct opt_items items[ALARM_START_COUNT];
288 int i = 0;
289 items[i].string = str(LANG_RESUME_PLAYBACK);
290 items[i].voice_id = LANG_RESUME_PLAYBACK;
291 i++;
292 #if CONFIG_TUNER
293 if (radio_hardware_present())
295 items[i].string = str(LANG_FM_RADIO);
296 items[i].voice_id = LANG_FM_RADIO;
297 i++;
299 #endif
300 #ifdef HAVE_RECORDING
301 items[i].string = str(LANG_RECORDING);
302 items[i].voice_id = LANG_RECORDING;
303 i++;
304 #endif
305 return set_option(str(LANG_ALARM_WAKEUP_SCREEN),
306 &global_settings.alarm_wake_up_screen,
307 INT, items, i, NULL);
310 MENUITEM_FUNCTION(alarm_wake_up_screen, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN),
311 alarm_setting, NULL, alarm_callback, Icon_Menu_setting);
312 #endif /* CONFIG_TUNER || defined(HAVE_RECORDING) */
313 #endif /* HAVE_RTC_ALARM */
315 /* Limits menu */
316 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
317 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
318 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
319 &max_files_in_dir, &max_files_in_playlist);
322 /* Keyclick menu */
323 #if CONFIG_CODEC == SWCODEC
324 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
325 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
326 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
327 &keyclick, &keyclick_repeats);
328 #endif
331 #if CONFIG_CODEC == MAS3507D
332 void dac_line_in(bool enable);
333 static int linein_callback(int action,const struct menu_item_ex *this_item)
335 (void)this_item;
336 switch (action)
338 case ACTION_EXIT_MENUITEM: /* on exit */
339 #ifndef SIMULATOR
340 dac_line_in(global_settings.line_in);
341 #endif
342 break;
344 return action;
346 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
347 #endif
348 #if CONFIG_CHARGING
349 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
350 #endif
351 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
353 #ifdef HAVE_BUTTON_LIGHT
354 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
355 #endif
357 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
358 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
359 #endif
362 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
363 0, Icon_System_menu,
364 &start_screen,
365 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
366 &battery_menu,
367 #endif
368 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
369 &disk_menu,
370 #endif
371 #if CONFIG_RTC
372 &time_menu,
373 #endif
374 &poweroff,
375 #ifdef HAVE_RTC_ALARM
376 &alarm_screen_call,
377 #if defined(HAVE_RECORDING) || CONFIG_TUNER
378 &alarm_wake_up_screen,
379 #endif
380 #endif
381 &limits_menu,
382 #if CONFIG_CODEC == MAS3507D
383 &line_in,
384 #endif
385 #if CONFIG_CHARGING
386 &car_adapter_mode,
387 #endif
388 #ifdef HAVE_BUTTON_LIGHT
389 &buttonlight_timeout,
390 #endif
391 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
392 &buttonlight_brightness,
393 #endif
394 #if CONFIG_CODEC == SWCODEC
395 &keyclick_menu,
396 #endif
399 /* SYSTEM MENU */
400 /***********************************/
403 /***********************************/
404 /* BOOKMARK MENU */
405 static int bmark_callback(int action,const struct menu_item_ex *this_item)
407 (void)this_item;
408 switch (action)
410 case ACTION_EXIT_MENUITEM: /* on exit */
411 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
412 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
414 if(global_settings.usemrb == BOOKMARK_NO)
415 global_settings.usemrb = BOOKMARK_YES;
418 break;
420 return action;
422 MENUITEM_SETTING(autocreatebookmark,
423 &global_settings.autocreatebookmark, bmark_callback);
424 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
425 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
426 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
427 Icon_Bookmark,
428 &autocreatebookmark, &autoloadbookmark, &usemrb);
429 /* BOOKMARK MENU */
430 /***********************************/
432 /***********************************/
433 /* VOICE MENU */
434 static int talk_callback(int action,const struct menu_item_ex *this_item);
435 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
436 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
437 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
438 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
439 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
440 static int talk_callback(int action,const struct menu_item_ex *this_item)
442 static int oldval = 0;
443 switch (action)
445 case ACTION_ENTER_MENUITEM:
446 oldval = global_settings.talk_file_clip;
447 break;
448 case ACTION_EXIT_MENUITEM:
449 #if CONFIG_CODEC == SWCODEC
450 audio_set_crossfade(global_settings.crossfade);
451 #endif
452 if (this_item == &talk_dir_clip_item)
453 break;
454 if (!oldval && global_settings.talk_file_clip)
456 /* force reload if newly talking thumbnails,
457 because the clip presence is cached only if enabled */
458 reload_directory();
460 break;
462 return action;
464 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
465 MENUITEM_SETTING(talk_battery_level_item,
466 &global_settings.talk_battery_level, NULL);
467 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
468 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
469 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
470 &talk_battery_level_item);
471 /* VOICE MENU */
472 /***********************************/
474 /***********************************/
476 /***********************************/
477 /* SETTINGS MENU */
478 static int language_browse(void)
480 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
482 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
483 NULL, NULL, Icon_Language);
485 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
486 Icon_General_settings_menu,
487 &playback_menu_item, &playlist_settings, &file_menu,
488 #ifdef HAVE_TAGCACHE
489 &tagcache_menu,
490 #endif
491 &display_menu, &system_menu,
492 &bookmark_settings_menu, &browse_langs, &voice_settings_menu
494 /* SETTINGS MENU */
495 /***********************************/