Move language resources to a separate file. Only build and include langs when buildin...
[Rockbox.git] / apps / menus / settings_menu.c
blob05cfd23e3268fda47c32e4c5006c7df566e95112
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 #ifdef HAVE_ACCESSORY_SUPPLY
352 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
353 #endif
354 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
356 #ifdef HAVE_BUTTON_LIGHT
357 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
358 #endif
360 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
361 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
362 #endif
364 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
365 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
366 #endif
369 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
370 0, Icon_System_menu,
371 &start_screen,
372 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
373 &battery_menu,
374 #endif
375 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
376 &disk_menu,
377 #endif
378 #if CONFIG_RTC
379 &time_menu,
380 #endif
381 &poweroff,
382 #ifdef HAVE_RTC_ALARM
383 &alarm_screen_call,
384 #if defined(HAVE_RECORDING) || CONFIG_TUNER
385 &alarm_wake_up_screen,
386 #endif
387 #endif
388 &limits_menu,
389 #if CONFIG_CODEC == MAS3507D
390 &line_in,
391 #endif
392 #if CONFIG_CHARGING
393 &car_adapter_mode,
394 #endif
395 #ifdef HAVE_ACCESSORY_SUPPLY
396 &accessory_supply,
397 #endif
398 #ifdef HAVE_BUTTON_LIGHT
399 &buttonlight_timeout,
400 #endif
401 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
402 &buttonlight_brightness,
403 #endif
404 #if CONFIG_CODEC == SWCODEC
405 &keyclick_menu,
406 #endif
407 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
408 &touchpad_sensitivity,
409 #endif
412 /* SYSTEM MENU */
413 /***********************************/
416 /***********************************/
417 /* BOOKMARK MENU */
418 static int bmark_callback(int action,const struct menu_item_ex *this_item)
420 (void)this_item;
421 switch (action)
423 case ACTION_EXIT_MENUITEM: /* on exit */
424 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
425 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
427 if(global_settings.usemrb == BOOKMARK_NO)
428 global_settings.usemrb = BOOKMARK_YES;
431 break;
433 return action;
435 MENUITEM_SETTING(autocreatebookmark,
436 &global_settings.autocreatebookmark, bmark_callback);
437 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
438 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
439 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
440 Icon_Bookmark,
441 &autocreatebookmark, &autoloadbookmark, &usemrb);
442 /* BOOKMARK MENU */
443 /***********************************/
445 /***********************************/
446 /* VOICE MENU */
447 static int talk_callback(int action,const struct menu_item_ex *this_item);
448 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
449 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
450 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
451 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
452 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
453 static int talk_callback(int action,const struct menu_item_ex *this_item)
455 static int oldval = 0;
456 switch (action)
458 case ACTION_ENTER_MENUITEM:
459 oldval = global_settings.talk_file_clip;
460 break;
461 case ACTION_EXIT_MENUITEM:
462 #if CONFIG_CODEC == SWCODEC
463 audio_set_crossfade(global_settings.crossfade);
464 #endif
465 if (this_item == &talk_dir_clip_item)
466 break;
467 if (!oldval && global_settings.talk_file_clip)
469 /* force reload if newly talking thumbnails,
470 because the clip presence is cached only if enabled */
471 reload_directory();
473 break;
475 return action;
477 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
478 MENUITEM_SETTING(talk_battery_level_item,
479 &global_settings.talk_battery_level, NULL);
480 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
481 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
482 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
483 &talk_battery_level_item);
484 /* VOICE MENU */
485 /***********************************/
487 /***********************************/
489 /***********************************/
490 /* SETTINGS MENU */
491 static int language_browse(void)
493 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
495 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
496 NULL, NULL, Icon_Language);
498 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
499 Icon_General_settings_menu,
500 &playback_settings, &playlist_settings, &file_menu,
501 #ifdef HAVE_TAGCACHE
502 &tagcache_menu,
503 #endif
504 &display_menu, &system_menu,
505 &bookmark_settings_menu, &browse_langs, &voice_settings_menu
507 /* SETTINGS MENU */
508 /***********************************/