Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / menus / settings_menu.c
blob1007d2aeb081c5c2c0282b6f63212b3a2d0946b5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include <string.h>
26 #include "config.h"
27 #include "lang.h"
28 #include "action.h"
29 #include "settings.h"
30 #include "menu.h"
31 #include "sound_menu.h"
32 #include "exported_menus.h"
33 #include "tree.h"
34 #include "tagtree.h"
35 #include "usb.h"
36 #include "splash.h"
37 #include "talk.h"
38 #include "powermgmt.h"
39 #if CONFIG_CODEC == SWCODEC
40 #include "playback.h"
41 #endif
42 #if CONFIG_RTC
43 #include "screens.h"
44 #endif
45 #include "quickscreen.h"
46 #ifdef HAVE_DIRCACHE
47 #include "dircache.h"
48 #endif
49 #ifdef HAVE_HOTKEY
50 #include "list.h"
51 #include "settings_list.h"
52 #include "onplay.h"
53 #endif
55 /***********************************/
56 /* TAGCACHE MENU */
57 #ifdef HAVE_TAGCACHE
59 static void tagcache_rebuild_with_splash(void)
61 tagcache_rebuild();
62 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
65 static void tagcache_update_with_splash(void)
67 tagcache_update();
68 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
71 #ifdef HAVE_TC_RAMCACHE
72 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
73 #endif
74 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
75 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
76 (int(*)(void))tagcache_rebuild_with_splash,
77 NULL, NULL, Icon_NOICON);
78 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
79 (int(*)(void))tagcache_update_with_splash,
80 NULL, NULL, Icon_NOICON);
81 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
82 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
83 (int(*)(void))tagtree_export, NULL,
84 NULL, Icon_NOICON);
85 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
86 (int(*)(void))tagtree_import, NULL,
87 NULL, Icon_NOICON);
88 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
89 #ifdef HAVE_TC_RAMCACHE
90 &tagcache_ram,
91 #endif
92 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
93 &tc_export, &tc_import);
94 #endif /* HAVE_TAGCACHE */
95 /* TAGCACHE MENU */
96 /***********************************/
98 /***********************************/
99 /* FILE VIEW MENU */
100 static int fileview_callback(int action,const struct menu_item_ex *this_item);
101 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
102 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
103 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
104 MENUITEM_SETTING(interpret_numbers, &global_settings.interpret_numbers, fileview_callback);
105 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
106 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
107 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
108 #ifdef HAVE_LCD_BITMAP
109 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
110 #endif
111 static int fileview_callback(int action,const struct menu_item_ex *this_item)
113 static int oldval;
114 int *variable = this_item->variable;
115 switch (action)
117 case ACTION_ENTER_MENUITEM: /* on entering an item */
118 oldval = *variable;
119 break;
120 case ACTION_EXIT_MENUITEM: /* on exit */
121 if (*variable != oldval)
122 reload_directory(); /* force reload if this has changed */
123 break;
125 return action;
128 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
129 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
130 &dirfilter, &show_filename_ext, &browse_current,
131 #ifdef HAVE_LCD_BITMAP
132 &show_path_in_browser
133 #endif
135 /* FILE VIEW MENU */
136 /***********************************/
139 /***********************************/
140 /* SYSTEM MENU */
142 /* Battery */
143 #if BATTERY_CAPACITY_INC > 0
144 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
145 #endif
146 #if BATTERY_TYPES_COUNT > 1
147 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
148 #endif
149 #ifdef HAVE_USB_CHARGING_ENABLE
150 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
152 (void)this_item;
153 switch (action)
155 case ACTION_EXIT_MENUITEM: /* on exit */
156 usb_charging_enable(global_settings.usb_charging);
157 break;
159 return action;
161 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
162 #endif /* HAVE_USB_CHARGING_ENABLE */
163 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
164 #if BATTERY_CAPACITY_INC > 0
165 &battery_capacity,
166 #endif
167 #if BATTERY_TYPES_COUNT > 1
168 &battery_type,
169 #endif
170 #ifdef HAVE_USB_CHARGING_ENABLE
171 &usb_charging,
172 #endif
174 /* Disk */
175 #ifdef HAVE_DISK_STORAGE
176 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
177 #endif
178 #ifdef HAVE_DIRCACHE
179 static int dircache_callback(int action,const struct menu_item_ex *this_item)
181 (void)this_item;
182 switch (action)
184 case ACTION_EXIT_MENUITEM: /* on exit */
185 switch (global_settings.dircache)
187 case true:
188 if (!dircache_is_enabled())
189 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
190 break;
191 case false:
192 if (dircache_is_enabled())
193 dircache_disable();
194 break;
196 break;
198 return action;
200 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
201 #endif
202 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
203 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
204 #ifdef HAVE_DISK_STORAGE
205 &disk_spindown,
206 #endif
207 #ifdef HAVE_DIRCACHE
208 &dircache,
209 #endif
211 #endif
213 /* System menu */
214 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
216 /* Limits menu */
217 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
218 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
219 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
220 &max_files_in_dir, &max_files_in_playlist);
223 /* Keyclick menu */
224 #if CONFIG_CODEC == SWCODEC
225 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
226 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
227 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
228 &keyclick, &keyclick_repeats);
229 #endif
232 #if CONFIG_CODEC == MAS3507D
233 void dac_line_in(bool enable);
234 static int linein_callback(int action,const struct menu_item_ex *this_item)
236 (void)this_item;
237 switch (action)
239 case ACTION_EXIT_MENUITEM: /* on exit */
240 #ifndef SIMULATOR
241 dac_line_in(global_settings.line_in);
242 #endif
243 break;
245 return action;
247 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
248 #endif
249 #if CONFIG_CHARGING
250 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
251 #endif
252 #ifdef IPOD_ACCESSORY_PROTOCOL
253 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
254 #endif
255 #ifdef HAVE_ACCESSORY_SUPPLY
256 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
257 #endif
258 #ifdef HAVE_LINEOUT_POWEROFF
259 MENUITEM_SETTING(lineout_onoff, &global_settings.lineout_active, NULL);
260 #endif
261 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
262 #ifdef USB_ENABLE_HID
263 MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL);
264 MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
265 #endif
267 #ifdef HAVE_MORSE_INPUT
268 MENUITEM_SETTING(morse_input, &global_settings.morse_input, NULL);
269 #endif
271 #ifdef HAVE_BUTTON_LIGHT
272 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
273 #endif
275 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
276 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
277 #endif
279 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
280 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
281 #endif
283 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
284 0, Icon_System_menu,
285 &start_screen,
286 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
287 &battery_menu,
288 #endif
289 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
290 &disk_menu,
291 #endif
292 &poweroff,
293 &limits_menu,
294 #ifdef HAVE_MORSE_INPUT
295 &morse_input,
296 #endif
297 #if CONFIG_CODEC == MAS3507D
298 &line_in,
299 #endif
300 #if CONFIG_CHARGING
301 &car_adapter_mode,
302 #endif
303 #ifdef IPOD_ACCESSORY_PROTOCOL
304 &serial_bitrate,
305 #endif
306 #ifdef HAVE_ACCESSORY_SUPPLY
307 &accessory_supply,
308 #endif
309 #ifdef HAVE_LINEOUT_POWEROFF
310 &lineout_onoff,
311 #endif
312 #ifdef HAVE_BUTTON_LIGHT
313 &buttonlight_timeout,
314 #endif
315 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
316 &buttonlight_brightness,
317 #endif
318 #if CONFIG_CODEC == SWCODEC
319 &keyclick_menu,
320 #endif
321 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
322 &touchpad_sensitivity,
323 #endif
324 #ifdef USB_ENABLE_HID
325 &usb_hid,
326 &usb_keypad_mode,
327 #endif
330 /* SYSTEM MENU */
331 /***********************************/
334 /***********************************/
335 /* BOOKMARK MENU */
336 static int bmark_callback(int action,const struct menu_item_ex *this_item)
338 (void)this_item;
339 switch (action)
341 case ACTION_EXIT_MENUITEM: /* on exit */
342 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
343 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
345 if(global_settings.usemrb == BOOKMARK_NO)
346 global_settings.usemrb = BOOKMARK_YES;
349 break;
351 return action;
353 MENUITEM_SETTING(autocreatebookmark,
354 &global_settings.autocreatebookmark, bmark_callback);
355 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
356 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
357 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
358 Icon_Bookmark,
359 &autocreatebookmark, &autoloadbookmark, &usemrb);
360 /* BOOKMARK MENU */
361 /***********************************/
363 /***********************************/
364 /* VOICE MENU */
365 static int talk_callback(int action,const struct menu_item_ex *this_item);
366 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
367 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
368 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
369 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
370 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
371 static int talk_callback(int action,const struct menu_item_ex *this_item)
373 static int oldval = 0;
374 switch (action)
376 case ACTION_ENTER_MENUITEM:
377 oldval = global_settings.talk_file_clip;
378 break;
379 case ACTION_EXIT_MENUITEM:
380 #ifdef HAVE_CROSSFADE
381 audio_set_crossfade(global_settings.crossfade);
382 #endif
383 if (this_item == &talk_dir_clip_item)
384 break;
385 if (!oldval && global_settings.talk_file_clip)
387 /* force reload if newly talking thumbnails,
388 because the clip presence is cached only if enabled */
389 reload_directory();
391 break;
393 return action;
395 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
396 MENUITEM_SETTING(talk_battery_level_item,
397 &global_settings.talk_battery_level, NULL);
398 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
399 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
400 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
401 &talk_battery_level_item);
402 /* VOICE MENU */
403 /***********************************/
406 /***********************************/
407 /* HOTKEY MENU */
408 #ifdef HAVE_HOTKEY
409 static void view_hotkey_info(void)
411 struct simplelist_info info;
412 simplelist_info_init(&info, str(LANG_VIEW_HOTKEY), 0, NULL);
413 info.hide_selection = true;
414 info.scroll_all = true;
415 simplelist_addline(SIMPLELIST_ADD_LINE, str(LANG_HOTKEY_VIEW_WPS),
416 get_hotkey_desc(global_settings.hotkey_wps));
417 simplelist_addline(SIMPLELIST_ADD_LINE, str(LANG_HOTKEY_VIEW_FILE_BROWSER),
418 get_hotkey_desc(global_settings.hotkey_tree));
419 simplelist_show_list(&info);
422 /* reset hotkey settings to their defaults */
423 static void reset_hotkey_settings(void)
426 const struct settings_list *setting =
427 find_setting(&global_settings.hotkey_wps, NULL);
428 reset_setting(setting, setting->setting);
431 const struct settings_list *setting =
432 find_setting(&global_settings.hotkey_tree, NULL);
433 reset_setting(setting, setting->setting);
435 settings_save();
436 splash(HZ, str(LANG_RESET_DONE_CLEAR));
439 MENUITEM_FUNCTION(hotkey_view, 0, ID2P(LANG_VIEW_HOTKEY),
440 (int(*)(void))view_hotkey_info, NULL,
441 NULL, Icon_NOICON);
442 MENUITEM_FUNCTION(hotkey_reset, 0, ID2P(LANG_RESET),
443 (int(*)(void))reset_hotkey_settings, NULL,
444 NULL, Icon_NOICON);
445 MAKE_MENU(hotkey_menu, ID2P(LANG_HOTKEY), 0, Icon_NOICON,
446 &hotkey_view, &hotkey_reset);
447 #endif /*have_hotkey */
448 /* HOTKEY MENU */
449 /***********************************/
452 /***********************************/
453 /* SETTINGS MENU */
454 static int language_browse(void)
456 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
458 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
459 NULL, NULL, Icon_Language);
461 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
462 Icon_General_settings_menu,
463 &playlist_settings, &file_menu,
464 #ifdef HAVE_TAGCACHE
465 &tagcache_menu,
466 #endif
467 &display_menu, &system_menu,
468 &bookmark_settings_menu, &browse_langs, &voice_settings_menu,
469 #ifdef HAVE_HOTKEY
470 &hotkey_menu,
471 #endif
473 /* SETTINGS MENU */
474 /***********************************/