Calibrate iPod Classic battery gauge a bit better
[kugel-rb.git] / apps / menus / settings_menu.c
blobb3003bf5c2d924221165e8edc41d75d6c635b4ea
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 "keyboard.h"
32 #include "sound_menu.h"
33 #include "exported_menus.h"
34 #include "tree.h"
35 #include "tagtree.h"
36 #include "usb.h"
37 #include "splash.h"
38 #include "yesno.h"
39 #include "talk.h"
40 #include "powermgmt.h"
41 #if CONFIG_CODEC == SWCODEC
42 #include "playback.h"
43 #endif
44 #if CONFIG_RTC
45 #include "screens.h"
46 #endif
47 #include "quickscreen.h"
48 #ifdef HAVE_DIRCACHE
49 #include "dircache.h"
50 #endif
52 /***********************************/
53 /* TAGCACHE MENU */
54 #ifdef HAVE_TAGCACHE
56 static void tagcache_rebuild_with_splash(void)
58 tagcache_rebuild();
59 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
62 static void tagcache_update_with_splash(void)
64 tagcache_update();
65 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
68 #ifdef HAVE_TC_RAMCACHE
69 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
70 #endif
71 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
72 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
73 (int(*)(void))tagcache_rebuild_with_splash,
74 NULL, NULL, Icon_NOICON);
75 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
76 (int(*)(void))tagcache_update_with_splash,
77 NULL, NULL, Icon_NOICON);
78 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
79 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
80 (int(*)(void))tagtree_export, NULL,
81 NULL, Icon_NOICON);
82 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
83 (int(*)(void))tagtree_import, NULL,
84 NULL, Icon_NOICON);
85 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
86 #ifdef HAVE_TC_RAMCACHE
87 &tagcache_ram,
88 #endif
89 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
90 &tc_export, &tc_import);
91 #endif /* HAVE_TAGCACHE */
92 /* TAGCACHE MENU */
93 /***********************************/
95 /***********************************/
96 /* FILE VIEW MENU */
97 static int fileview_callback(int action,const struct menu_item_ex *this_item);
98 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
99 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
100 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
101 MENUITEM_SETTING(interpret_numbers, &global_settings.interpret_numbers, fileview_callback);
102 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
103 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
104 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
105 #ifdef HAVE_LCD_BITMAP
106 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
107 #endif
108 static int clear_start_directory(void)
110 strcpy(global_settings.start_directory, "/");
111 settings_save();
112 splash(HZ, ID2P(LANG_RESET_DONE_CLEAR));
113 return false;
115 MENUITEM_FUNCTION(clear_start_directory_item, 0, ID2P(LANG_RESET_START_DIR),
116 clear_start_directory, NULL, NULL, Icon_file_view_menu);
117 static int fileview_callback(int action,const struct menu_item_ex *this_item)
119 static int oldval;
120 int *variable = this_item->variable;
121 switch (action)
123 case ACTION_ENTER_MENUITEM: /* on entering an item */
124 oldval = *variable;
125 break;
126 case ACTION_EXIT_MENUITEM: /* on exit */
127 if (*variable != oldval)
128 reload_directory(); /* force reload if this has changed */
129 break;
131 return action;
134 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
135 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
136 &dirfilter, &show_filename_ext, &browse_current,
137 #ifdef HAVE_LCD_BITMAP
138 &show_path_in_browser,
139 #endif
140 &clear_start_directory_item
142 /* FILE VIEW MENU */
143 /***********************************/
146 /***********************************/
147 /* SYSTEM MENU */
149 /* Battery */
150 #if BATTERY_CAPACITY_INC > 0
151 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
152 #endif
153 #if BATTERY_TYPES_COUNT > 1
154 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
155 #endif
156 #ifdef HAVE_USB_CHARGING_ENABLE
157 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
159 (void)this_item;
160 switch (action)
162 case ACTION_EXIT_MENUITEM: /* on exit */
163 usb_charging_enable(global_settings.usb_charging);
164 break;
166 return action;
168 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
169 #endif /* HAVE_USB_CHARGING_ENABLE */
170 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
171 #if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
172 &battery_capacity,
173 #endif
174 #if BATTERY_TYPES_COUNT > 1
175 &battery_type,
176 #endif
177 #ifdef HAVE_USB_CHARGING_ENABLE
178 &usb_charging,
179 #endif
181 /* Disk */
182 #ifdef HAVE_DISK_STORAGE
183 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
184 #endif
185 #ifdef HAVE_DIRCACHE
186 static int dircache_callback(int action,const struct menu_item_ex *this_item)
188 (void)this_item;
189 switch (action)
191 case ACTION_EXIT_MENUITEM: /* on exit */
192 switch (global_settings.dircache)
194 case true:
195 if (!dircache_is_enabled())
196 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
197 break;
198 case false:
199 if (dircache_is_enabled())
200 dircache_disable();
201 break;
203 break;
205 return action;
207 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
208 #endif
209 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
210 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
211 #ifdef HAVE_DISK_STORAGE
212 &disk_spindown,
213 #endif
214 #ifdef HAVE_DIRCACHE
215 &dircache,
216 #endif
218 #endif
220 /* System menu */
221 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
223 /* Limits menu */
224 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
225 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
226 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
227 &max_files_in_dir, &max_files_in_playlist);
230 /* Keyclick menu */
231 #if CONFIG_CODEC == SWCODEC
232 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
233 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
234 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
235 &keyclick, &keyclick_repeats);
236 #endif
239 #if CONFIG_CODEC == MAS3507D
240 void dac_line_in(bool enable);
241 static int linein_callback(int action,const struct menu_item_ex *this_item)
243 (void)this_item;
244 switch (action)
246 case ACTION_EXIT_MENUITEM: /* on exit */
247 #ifndef SIMULATOR
248 dac_line_in(global_settings.line_in);
249 #endif
250 break;
252 return action;
254 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
255 #endif
256 #if CONFIG_CHARGING
257 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
258 #endif
259 #ifdef IPOD_ACCESSORY_PROTOCOL
260 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
261 #endif
262 #ifdef HAVE_ACCESSORY_SUPPLY
263 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
264 #endif
265 #ifdef HAVE_LINEOUT_POWEROFF
266 MENUITEM_SETTING(lineout_onoff, &global_settings.lineout_active, NULL);
267 #endif
268 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
269 #ifdef USB_ENABLE_HID
270 MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL);
271 MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
272 #endif
274 #ifdef HAVE_MORSE_INPUT
275 MENUITEM_SETTING(morse_input, &global_settings.morse_input, NULL);
276 #endif
278 #ifdef HAVE_BUTTON_LIGHT
279 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
280 #endif
282 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
283 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
284 #endif
286 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
287 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
288 #endif
290 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
291 0, Icon_System_menu,
292 &start_screen,
293 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
294 &battery_menu,
295 #endif
296 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
297 &disk_menu,
298 #endif
299 &poweroff,
300 &limits_menu,
301 #ifdef HAVE_MORSE_INPUT
302 &morse_input,
303 #endif
304 #if CONFIG_CODEC == MAS3507D
305 &line_in,
306 #endif
307 #if CONFIG_CHARGING
308 &car_adapter_mode,
309 #endif
310 #ifdef IPOD_ACCESSORY_PROTOCOL
311 &serial_bitrate,
312 #endif
313 #ifdef HAVE_ACCESSORY_SUPPLY
314 &accessory_supply,
315 #endif
316 #ifdef HAVE_LINEOUT_POWEROFF
317 &lineout_onoff,
318 #endif
319 #ifdef HAVE_BUTTON_LIGHT
320 &buttonlight_timeout,
321 #endif
322 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
323 &buttonlight_brightness,
324 #endif
325 #if CONFIG_CODEC == SWCODEC
326 &keyclick_menu,
327 #endif
328 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
329 &touchpad_sensitivity,
330 #endif
331 #ifdef USB_ENABLE_HID
332 &usb_hid,
333 &usb_keypad_mode,
334 #endif
337 /* SYSTEM MENU */
338 /***********************************/
341 /***********************************/
342 /* BOOKMARK MENU */
343 static int bmark_callback(int action,const struct menu_item_ex *this_item)
345 (void)this_item;
346 switch (action)
348 case ACTION_EXIT_MENUITEM: /* on exit */
349 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
350 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
352 if(global_settings.usemrb == BOOKMARK_NO)
353 global_settings.usemrb = BOOKMARK_YES;
356 break;
358 return action;
360 MENUITEM_SETTING(autocreatebookmark,
361 &global_settings.autocreatebookmark, bmark_callback);
362 MENUITEM_SETTING(autoupdatebookmark, &global_settings.autoupdatebookmark, NULL);
363 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
364 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
365 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
366 Icon_Bookmark,
367 &autocreatebookmark, &autoupdatebookmark, &autoloadbookmark, &usemrb);
368 /* BOOKMARK MENU */
369 /***********************************/
371 /***********************************/
372 /* AUTORESUME MENU */
373 #ifdef HAVE_TAGCACHE
374 #if CONFIG_CODEC == SWCODEC
376 static int autoresume_callback(int action, const struct menu_item_ex *this_item)
378 (void)this_item;
380 if (action == ACTION_EXIT_MENUITEM /* on exit */
381 && global_settings.autoresume_enable
382 && !tagcache_is_usable())
384 static const char *lines[] = {ID2P(LANG_TAGCACHE_BUSY),
385 ID2P(LANG_TAGCACHE_FORCE_UPDATE)};
386 static const struct text_message message = {lines, 2};
388 if (gui_syncyesno_run(&message, NULL, NULL) == YESNO_YES)
389 tagcache_rebuild_with_splash();
391 return action;
394 static int autoresume_nexttrack_callback(int action,
395 const struct menu_item_ex *this_item)
397 (void)this_item;
398 static int oldval = 0;
399 switch (action)
401 case ACTION_ENTER_MENUITEM:
402 oldval = global_settings.autoresume_automatic;
403 break;
404 case ACTION_EXIT_MENUITEM:
405 if (global_settings.autoresume_automatic == AUTORESUME_NEXTTRACK_CUSTOM
406 && kbd_input ((char*) &global_settings.autoresume_paths,
407 MAX_PATHNAME+1) < 0)
409 global_settings.autoresume_automatic = oldval;
412 return action;
415 MENUITEM_SETTING(autoresume_enable, &global_settings.autoresume_enable,
416 autoresume_callback);
417 MENUITEM_SETTING(autoresume_automatic, &global_settings.autoresume_automatic,
418 autoresume_nexttrack_callback);
420 MAKE_MENU(autoresume_menu, ID2P(LANG_AUTORESUME),
421 0, Icon_NOICON,
422 &autoresume_enable, &autoresume_automatic);
424 #endif /* CONFIG_CODEC == SWCODEC */
425 #endif /* HAVE_TAGCACHE */
426 /* AUTORESUME MENU */
427 /***********************************/
429 /***********************************/
430 /* VOICE MENU */
431 static int talk_callback(int action,const struct menu_item_ex *this_item);
432 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
433 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
434 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
435 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
436 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
437 static int talk_callback(int action,const struct menu_item_ex *this_item)
439 static int oldval = 0;
440 switch (action)
442 case ACTION_ENTER_MENUITEM:
443 oldval = global_settings.talk_file_clip;
444 break;
445 case ACTION_EXIT_MENUITEM:
446 #ifdef HAVE_CROSSFADE
447 audio_set_crossfade(global_settings.crossfade);
448 #endif
449 if (this_item == &talk_dir_clip_item)
450 break;
451 if (!oldval && global_settings.talk_file_clip)
453 /* force reload if newly talking thumbnails,
454 because the clip presence is cached only if enabled */
455 reload_directory();
457 break;
459 return action;
461 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
462 MENUITEM_SETTING(talk_battery_level_item,
463 &global_settings.talk_battery_level, NULL);
464 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
465 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
466 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
467 &talk_battery_level_item);
468 /* VOICE MENU */
469 /***********************************/
472 /***********************************/
473 /* HOTKEY MENU */
474 #ifdef HAVE_HOTKEY
475 MENUITEM_SETTING(hotkey_wps_item, &global_settings.hotkey_wps, NULL);
476 MENUITEM_SETTING(hotkey_tree_item, &global_settings.hotkey_tree, NULL);
477 MAKE_MENU(hotkey_menu, ID2P(LANG_HOTKEY), 0, Icon_NOICON,
478 &hotkey_wps_item, &hotkey_tree_item);
479 #endif /*have_hotkey */
480 /* HOTKEY MENU */
481 /***********************************/
484 /***********************************/
485 /* SETTINGS MENU */
487 static struct browse_folder_info langs = { LANG_DIR, SHOW_LNG };
489 MENUITEM_FUNCTION(browse_langs, MENU_FUNC_USEPARAM, ID2P(LANG_LANGUAGE),
490 browse_folder, (void*)&langs, NULL, Icon_Language);
492 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
493 Icon_General_settings_menu,
494 &playlist_settings, &file_menu,
495 #ifdef HAVE_TAGCACHE
496 &tagcache_menu,
497 #endif
498 &display_menu, &system_menu,
499 &bookmark_settings_menu,
500 #ifdef HAVE_TAGCACHE
501 #if CONFIG_CODEC == SWCODEC
502 &autoresume_menu,
503 #endif
504 #endif
505 &browse_langs, &voice_settings_menu,
506 #ifdef HAVE_HOTKEY
507 &hotkey_menu,
508 #endif
510 /* SETTINGS MENU */
511 /***********************************/