Document the sorting setting in the Config file options appendix.
[kugel-rb.git] / apps / menus / settings_menu.c
blob35db9b49e6879c2d959996bc7a62f4cbdfe40640
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 "sprintf.h"
39 #include "powermgmt.h"
40 #if CONFIG_CODEC == SWCODEC
41 #include "playback.h"
42 #endif
43 #ifdef HAVE_RTC_ALARM
44 #include "alarm_menu.h"
45 #endif
46 #if CONFIG_TUNER
47 #include "radio.h"
48 #endif
49 #if CONFIG_RTC
50 #include "screens.h"
51 #endif
52 #include "quickscreen.h"
54 /***********************************/
55 /* TAGCACHE MENU */
56 #ifdef HAVE_TAGCACHE
58 static void tagcache_rebuild_with_splash(void)
60 tagcache_rebuild();
61 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
64 static void tagcache_update_with_splash(void)
66 tagcache_update();
67 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
70 #ifdef HAVE_TC_RAMCACHE
71 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
72 #endif
73 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
74 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
75 (int(*)(void))tagcache_rebuild_with_splash,
76 NULL, NULL, Icon_NOICON);
77 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
78 (int(*)(void))tagcache_update_with_splash,
79 NULL, NULL, Icon_NOICON);
80 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
81 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
82 (int(*)(void))tagtree_export, NULL,
83 NULL, Icon_NOICON);
84 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
85 (int(*)(void))tagtree_import, NULL,
86 NULL, Icon_NOICON);
87 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
88 #ifdef HAVE_TC_RAMCACHE
89 &tagcache_ram,
90 #endif
91 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
92 &tc_export, &tc_import);
93 #endif /* HAVE_TAGCACHE */
94 /* TAGCACHE MENU */
95 /***********************************/
97 /***********************************/
98 /* FILE VIEW MENU */
99 static int fileview_callback(int action,const struct menu_item_ex *this_item);
100 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
101 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
102 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
103 MENUITEM_SETTING(interpret_numbers, &global_settings.interpret_numbers, fileview_callback);
104 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
105 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
106 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
107 #ifdef HAVE_LCD_BITMAP
108 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
109 #endif
110 static int fileview_callback(int action,const struct menu_item_ex *this_item)
112 static int oldval;
113 int *variable = this_item->variable;
114 switch (action)
116 case ACTION_ENTER_MENUITEM: /* on entering an item */
117 oldval = *variable;
118 break;
119 case ACTION_EXIT_MENUITEM: /* on exit */
120 if (*variable != oldval)
121 reload_directory(); /* force reload if this has changed */
122 break;
124 return action;
127 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
128 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
129 &dirfilter, &show_filename_ext, &browse_current,
130 #ifdef HAVE_LCD_BITMAP
131 &show_path_in_browser
132 #endif
134 /* FILE VIEW MENU */
135 /***********************************/
138 /***********************************/
139 /* SYSTEM MENU */
141 /* Battery */
142 #if BATTERY_CAPACITY_INC > 0
143 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
144 #endif
145 #if BATTERY_TYPES_COUNT > 1
146 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
147 #endif
148 #ifdef HAVE_USB_CHARGING_ENABLE
149 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
151 (void)this_item;
152 switch (action)
154 case ACTION_EXIT_MENUITEM: /* on exit */
155 usb_charging_enable(global_settings.usb_charging);
156 break;
158 return action;
160 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
161 #endif /* HAVE_USB_CHARGING_ENABLE */
162 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
163 #if BATTERY_CAPACITY_INC > 0
164 &battery_capacity,
165 #endif
166 #if BATTERY_TYPES_COUNT > 1
167 &battery_type,
168 #endif
169 #ifdef HAVE_USB_CHARGING_ENABLE
170 &usb_charging,
171 #endif
173 /* Disk */
174 #ifdef HAVE_DISK_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 splash(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_DISK_STORAGE)
202 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
203 #ifdef HAVE_DISK_STORAGE
204 &disk_spindown,
205 #endif
206 #ifdef HAVE_DIRCACHE
207 &dircache,
208 #endif
210 #endif
212 /* System menu */
213 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
215 /* Limits menu */
216 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
217 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
218 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
219 &max_files_in_dir, &max_files_in_playlist);
222 /* Keyclick menu */
223 #if CONFIG_CODEC == SWCODEC
224 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
225 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
226 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
227 &keyclick, &keyclick_repeats);
228 #endif
231 #if CONFIG_CODEC == MAS3507D
232 void dac_line_in(bool enable);
233 static int linein_callback(int action,const struct menu_item_ex *this_item)
235 (void)this_item;
236 switch (action)
238 case ACTION_EXIT_MENUITEM: /* on exit */
239 #ifndef SIMULATOR
240 dac_line_in(global_settings.line_in);
241 #endif
242 break;
244 return action;
246 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
247 #endif
248 #if CONFIG_CHARGING
249 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
250 #endif
251 #ifdef IPOD_ACCESSORY_PROTOCOL
252 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
253 #endif
254 #ifdef HAVE_ACCESSORY_SUPPLY
255 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
256 #endif
257 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
259 #ifdef HAVE_BUTTON_LIGHT
260 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
261 #endif
263 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
264 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
265 #endif
267 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
268 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
269 #endif
272 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
273 0, Icon_System_menu,
274 &start_screen,
275 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
276 &battery_menu,
277 #endif
278 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
279 &disk_menu,
280 #endif
281 &poweroff,
282 &limits_menu,
283 #if CONFIG_CODEC == MAS3507D
284 &line_in,
285 #endif
286 #if CONFIG_CHARGING
287 &car_adapter_mode,
288 #endif
289 #ifdef IPOD_ACCESSORY_PROTOCOL
290 &serial_bitrate,
291 #endif
292 #ifdef HAVE_ACCESSORY_SUPPLY
293 &accessory_supply,
294 #endif
295 #ifdef HAVE_BUTTON_LIGHT
296 &buttonlight_timeout,
297 #endif
298 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
299 &buttonlight_brightness,
300 #endif
301 #if CONFIG_CODEC == SWCODEC
302 &keyclick_menu,
303 #endif
304 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
305 &touchpad_sensitivity,
306 #endif
309 /* SYSTEM MENU */
310 /***********************************/
313 /***********************************/
314 /* BOOKMARK MENU */
315 static int bmark_callback(int action,const struct menu_item_ex *this_item)
317 (void)this_item;
318 switch (action)
320 case ACTION_EXIT_MENUITEM: /* on exit */
321 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
322 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
324 if(global_settings.usemrb == BOOKMARK_NO)
325 global_settings.usemrb = BOOKMARK_YES;
328 break;
330 return action;
332 MENUITEM_SETTING(autocreatebookmark,
333 &global_settings.autocreatebookmark, bmark_callback);
334 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
335 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
336 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
337 Icon_Bookmark,
338 &autocreatebookmark, &autoloadbookmark, &usemrb);
339 /* BOOKMARK MENU */
340 /***********************************/
342 /***********************************/
343 /* VOICE MENU */
344 static int talk_callback(int action,const struct menu_item_ex *this_item);
345 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
346 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
347 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
348 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
349 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
350 static int talk_callback(int action,const struct menu_item_ex *this_item)
352 static int oldval = 0;
353 switch (action)
355 case ACTION_ENTER_MENUITEM:
356 oldval = global_settings.talk_file_clip;
357 break;
358 case ACTION_EXIT_MENUITEM:
359 #if CONFIG_CODEC == SWCODEC
360 audio_set_crossfade(global_settings.crossfade);
361 #endif
362 if (this_item == &talk_dir_clip_item)
363 break;
364 if (!oldval && global_settings.talk_file_clip)
366 /* force reload if newly talking thumbnails,
367 because the clip presence is cached only if enabled */
368 reload_directory();
370 break;
372 return action;
374 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
375 MENUITEM_SETTING(talk_battery_level_item,
376 &global_settings.talk_battery_level, NULL);
377 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
378 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
379 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
380 &talk_battery_level_item);
381 /* VOICE MENU */
382 /***********************************/
385 /***********************************/
386 /* SETTINGS MENU */
387 static int language_browse(void)
389 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
391 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
392 NULL, NULL, Icon_Language);
394 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
395 Icon_General_settings_menu,
396 &playlist_settings, &file_menu,
397 #ifdef HAVE_TAGCACHE
398 &tagcache_menu,
399 #endif
400 &display_menu, &system_menu,
401 &bookmark_settings_menu, &browse_langs, &voice_settings_menu
403 /* SETTINGS MENU */
404 /***********************************/