Reset the number of lines to 0 when initializing the simple list
[kugel-rb.git] / apps / menus / settings_menu.c
blob53c5972ee8045d86b41b94bda429136a98552b5e
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 #if CONFIG_RTC
44 #include "screens.h"
45 #endif
46 #include "quickscreen.h"
47 #ifdef HAVE_DIRCACHE
48 #include "dircache.h"
49 #endif
50 #ifdef HAVE_HOTKEY
51 #include "list.h"
52 #include "settings_list.h"
53 #include "onplay.h"
54 #endif
56 /***********************************/
57 /* TAGCACHE MENU */
58 #ifdef HAVE_TAGCACHE
60 static void tagcache_rebuild_with_splash(void)
62 tagcache_rebuild();
63 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
66 static void tagcache_update_with_splash(void)
68 tagcache_update();
69 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
72 #ifdef HAVE_TC_RAMCACHE
73 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
74 #endif
75 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
76 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
77 (int(*)(void))tagcache_rebuild_with_splash,
78 NULL, NULL, Icon_NOICON);
79 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
80 (int(*)(void))tagcache_update_with_splash,
81 NULL, NULL, Icon_NOICON);
82 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
83 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
84 (int(*)(void))tagtree_export, NULL,
85 NULL, Icon_NOICON);
86 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
87 (int(*)(void))tagtree_import, NULL,
88 NULL, Icon_NOICON);
89 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
90 #ifdef HAVE_TC_RAMCACHE
91 &tagcache_ram,
92 #endif
93 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
94 &tc_export, &tc_import);
95 #endif /* HAVE_TAGCACHE */
96 /* TAGCACHE MENU */
97 /***********************************/
99 /***********************************/
100 /* FILE VIEW MENU */
101 static int fileview_callback(int action,const struct menu_item_ex *this_item);
102 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
103 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
104 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
105 MENUITEM_SETTING(interpret_numbers, &global_settings.interpret_numbers, fileview_callback);
106 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
107 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
108 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
109 #ifdef HAVE_LCD_BITMAP
110 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
111 #endif
112 static int fileview_callback(int action,const struct menu_item_ex *this_item)
114 static int oldval;
115 int *variable = this_item->variable;
116 switch (action)
118 case ACTION_ENTER_MENUITEM: /* on entering an item */
119 oldval = *variable;
120 break;
121 case ACTION_EXIT_MENUITEM: /* on exit */
122 if (*variable != oldval)
123 reload_directory(); /* force reload if this has changed */
124 break;
126 return action;
129 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
130 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
131 &dirfilter, &show_filename_ext, &browse_current,
132 #ifdef HAVE_LCD_BITMAP
133 &show_path_in_browser
134 #endif
136 /* FILE VIEW MENU */
137 /***********************************/
140 /***********************************/
141 /* SYSTEM MENU */
143 /* Battery */
144 #if BATTERY_CAPACITY_INC > 0
145 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
146 #endif
147 #if BATTERY_TYPES_COUNT > 1
148 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
149 #endif
150 #ifdef HAVE_USB_CHARGING_ENABLE
151 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
153 (void)this_item;
154 switch (action)
156 case ACTION_EXIT_MENUITEM: /* on exit */
157 usb_charging_enable(global_settings.usb_charging);
158 break;
160 return action;
162 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
163 #endif /* HAVE_USB_CHARGING_ENABLE */
164 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
165 #if BATTERY_CAPACITY_INC > 0
166 &battery_capacity,
167 #endif
168 #if BATTERY_TYPES_COUNT > 1
169 &battery_type,
170 #endif
171 #ifdef HAVE_USB_CHARGING_ENABLE
172 &usb_charging,
173 #endif
175 /* Disk */
176 #ifdef HAVE_DISK_STORAGE
177 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
178 #endif
179 #ifdef HAVE_DIRCACHE
180 static int dircache_callback(int action,const struct menu_item_ex *this_item)
182 (void)this_item;
183 switch (action)
185 case ACTION_EXIT_MENUITEM: /* on exit */
186 switch (global_settings.dircache)
188 case true:
189 if (!dircache_is_enabled())
190 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
191 break;
192 case false:
193 if (dircache_is_enabled())
194 dircache_disable();
195 break;
197 break;
199 return action;
201 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
202 #endif
203 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
204 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
205 #ifdef HAVE_DISK_STORAGE
206 &disk_spindown,
207 #endif
208 #ifdef HAVE_DIRCACHE
209 &dircache,
210 #endif
212 #endif
214 /* System menu */
215 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
217 /* Limits menu */
218 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
219 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
220 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
221 &max_files_in_dir, &max_files_in_playlist);
224 /* Keyclick menu */
225 #if CONFIG_CODEC == SWCODEC
226 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
227 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
228 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
229 &keyclick, &keyclick_repeats);
230 #endif
233 #if CONFIG_CODEC == MAS3507D
234 void dac_line_in(bool enable);
235 static int linein_callback(int action,const struct menu_item_ex *this_item)
237 (void)this_item;
238 switch (action)
240 case ACTION_EXIT_MENUITEM: /* on exit */
241 #ifndef SIMULATOR
242 dac_line_in(global_settings.line_in);
243 #endif
244 break;
246 return action;
248 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
249 #endif
250 #if CONFIG_CHARGING
251 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
252 #endif
253 #ifdef IPOD_ACCESSORY_PROTOCOL
254 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
255 #endif
256 #ifdef HAVE_ACCESSORY_SUPPLY
257 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
258 #endif
259 #ifdef HAVE_LINEOUT_POWEROFF
260 MENUITEM_SETTING(lineout_onoff, &global_settings.lineout_active, NULL);
261 #endif
262 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
263 #ifdef USB_ENABLE_HID
264 MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL);
265 MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
266 #endif
268 #ifdef HAVE_MORSE_INPUT
269 MENUITEM_SETTING(morse_input, &global_settings.morse_input, NULL);
270 #endif
272 #ifdef HAVE_BUTTON_LIGHT
273 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
274 #endif
276 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
277 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
278 #endif
280 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
281 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
282 #endif
284 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
285 0, Icon_System_menu,
286 &start_screen,
287 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
288 &battery_menu,
289 #endif
290 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
291 &disk_menu,
292 #endif
293 &poweroff,
294 &limits_menu,
295 #ifdef HAVE_MORSE_INPUT
296 &morse_input,
297 #endif
298 #if CONFIG_CODEC == MAS3507D
299 &line_in,
300 #endif
301 #if CONFIG_CHARGING
302 &car_adapter_mode,
303 #endif
304 #ifdef IPOD_ACCESSORY_PROTOCOL
305 &serial_bitrate,
306 #endif
307 #ifdef HAVE_ACCESSORY_SUPPLY
308 &accessory_supply,
309 #endif
310 #ifdef HAVE_LINEOUT_POWEROFF
311 &lineout_onoff,
312 #endif
313 #ifdef HAVE_BUTTON_LIGHT
314 &buttonlight_timeout,
315 #endif
316 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
317 &buttonlight_brightness,
318 #endif
319 #if CONFIG_CODEC == SWCODEC
320 &keyclick_menu,
321 #endif
322 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
323 &touchpad_sensitivity,
324 #endif
325 #ifdef USB_ENABLE_HID
326 &usb_hid,
327 &usb_keypad_mode,
328 #endif
331 /* SYSTEM MENU */
332 /***********************************/
335 /***********************************/
336 /* BOOKMARK MENU */
337 static int bmark_callback(int action,const struct menu_item_ex *this_item)
339 (void)this_item;
340 switch (action)
342 case ACTION_EXIT_MENUITEM: /* on exit */
343 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
344 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
346 if(global_settings.usemrb == BOOKMARK_NO)
347 global_settings.usemrb = BOOKMARK_YES;
350 break;
352 return action;
354 MENUITEM_SETTING(autocreatebookmark,
355 &global_settings.autocreatebookmark, bmark_callback);
356 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
357 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
358 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
359 Icon_Bookmark,
360 &autocreatebookmark, &autoloadbookmark, &usemrb);
361 /* BOOKMARK MENU */
362 /***********************************/
364 /***********************************/
365 /* VOICE MENU */
366 static int talk_callback(int action,const struct menu_item_ex *this_item);
367 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
368 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
369 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
370 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
371 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
372 static int talk_callback(int action,const struct menu_item_ex *this_item)
374 static int oldval = 0;
375 switch (action)
377 case ACTION_ENTER_MENUITEM:
378 oldval = global_settings.talk_file_clip;
379 break;
380 case ACTION_EXIT_MENUITEM:
381 #ifdef HAVE_CROSSFADE
382 audio_set_crossfade(global_settings.crossfade);
383 #endif
384 if (this_item == &talk_dir_clip_item)
385 break;
386 if (!oldval && global_settings.talk_file_clip)
388 /* force reload if newly talking thumbnails,
389 because the clip presence is cached only if enabled */
390 reload_directory();
392 break;
394 return action;
396 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
397 MENUITEM_SETTING(talk_battery_level_item,
398 &global_settings.talk_battery_level, NULL);
399 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
400 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
401 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
402 &talk_battery_level_item);
403 /* VOICE MENU */
404 /***********************************/
407 /***********************************/
408 /* HOTKEY MENU */
409 #ifdef HAVE_HOTKEY
410 static void view_hotkey_info(void)
412 struct simplelist_info info;
413 simplelist_info_init(&info, str(LANG_VIEW_HOTKEY), 0, NULL);
414 info.hide_selection = true;
415 info.scroll_all = true;
416 simplelist_addline(SIMPLELIST_ADD_LINE, str(LANG_HOTKEY_VIEW_WPS),
417 str(get_hotkey_desc_id(global_settings.hotkey_wps)));
418 simplelist_addline(SIMPLELIST_ADD_LINE, str(LANG_HOTKEY_VIEW_FILE_BROWSER),
419 str(get_hotkey_desc_id(global_settings.hotkey_tree)));
420 simplelist_show_list(&info);
423 /* reset hotkey settings to their defaults */
424 static void reset_hotkey_settings(void)
427 const struct settings_list *setting =
428 find_setting(&global_settings.hotkey_wps, NULL);
429 reset_setting(setting, setting->setting);
432 const struct settings_list *setting =
433 find_setting(&global_settings.hotkey_tree, NULL);
434 reset_setting(setting, setting->setting);
436 settings_save();
437 splash(HZ, str(LANG_RESET_DONE_CLEAR));
440 MENUITEM_FUNCTION(hotkey_view, 0, ID2P(LANG_VIEW_HOTKEY),
441 (int(*)(void))view_hotkey_info, NULL,
442 NULL, Icon_NOICON);
443 MENUITEM_FUNCTION(hotkey_reset, 0, ID2P(LANG_RESET),
444 (int(*)(void))reset_hotkey_settings, NULL,
445 NULL, Icon_NOICON);
446 MAKE_MENU(hotkey_menu, ID2P(LANG_HOTKEY), 0, Icon_NOICON,
447 &hotkey_view, &hotkey_reset);
448 #endif /*have_hotkey */
449 /* HOTKEY MENU */
450 /***********************************/
453 /***********************************/
454 /* SETTINGS MENU */
455 static int language_browse(void)
457 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
459 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
460 NULL, NULL, Icon_Language);
462 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
463 Icon_General_settings_menu,
464 &playlist_settings, &file_menu,
465 #ifdef HAVE_TAGCACHE
466 &tagcache_menu,
467 #endif
468 &display_menu, &system_menu,
469 &bookmark_settings_menu, &browse_langs, &voice_settings_menu,
470 #ifdef HAVE_HOTKEY
471 &hotkey_menu,
472 #endif
474 /* SETTINGS MENU */
475 /***********************************/