Commit part of FS#11748 by Michael Hohmuth. Adds support for automatically resuming...
[kugel-rb.git] / apps / menus / settings_menu.c
blobe609a4032e023b2a098e0e6ab2b2a4320f7774c5
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
50 /***********************************/
51 /* TAGCACHE MENU */
52 #ifdef HAVE_TAGCACHE
54 static void tagcache_rebuild_with_splash(void)
56 tagcache_rebuild();
57 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
60 static void tagcache_update_with_splash(void)
62 tagcache_update();
63 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
66 #ifdef HAVE_TC_RAMCACHE
67 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
68 #endif
69 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
70 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
71 (int(*)(void))tagcache_rebuild_with_splash,
72 NULL, NULL, Icon_NOICON);
73 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
74 (int(*)(void))tagcache_update_with_splash,
75 NULL, NULL, Icon_NOICON);
76 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
77 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
78 (int(*)(void))tagtree_export, NULL,
79 NULL, Icon_NOICON);
80 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
81 (int(*)(void))tagtree_import, NULL,
82 NULL, Icon_NOICON);
83 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
84 #ifdef HAVE_TC_RAMCACHE
85 &tagcache_ram,
86 #endif
87 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
88 &tc_export, &tc_import);
89 #endif /* HAVE_TAGCACHE */
90 /* TAGCACHE MENU */
91 /***********************************/
93 /***********************************/
94 /* FILE VIEW MENU */
95 static int fileview_callback(int action,const struct menu_item_ex *this_item);
96 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
97 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
98 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
99 MENUITEM_SETTING(interpret_numbers, &global_settings.interpret_numbers, 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 clear_start_directory(void)
108 strcpy(global_settings.start_directory, "/");
109 settings_save();
110 splash(HZ, ID2P(LANG_RESET_DONE_CLEAR));
111 return false;
113 MENUITEM_FUNCTION(clear_start_directory_item, 0, ID2P(LANG_RESET_START_DIR),
114 clear_start_directory, NULL, NULL, Icon_file_view_menu);
115 static int fileview_callback(int action,const struct menu_item_ex *this_item)
117 static int oldval;
118 int *variable = this_item->variable;
119 switch (action)
121 case ACTION_ENTER_MENUITEM: /* on entering an item */
122 oldval = *variable;
123 break;
124 case ACTION_EXIT_MENUITEM: /* on exit */
125 if (*variable != oldval)
126 reload_directory(); /* force reload if this has changed */
127 break;
129 return action;
132 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
133 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
134 &dirfilter, &show_filename_ext, &browse_current,
135 #ifdef HAVE_LCD_BITMAP
136 &show_path_in_browser,
137 #endif
138 &clear_start_directory_item
140 /* FILE VIEW MENU */
141 /***********************************/
144 /***********************************/
145 /* SYSTEM MENU */
147 /* Battery */
148 #if BATTERY_CAPACITY_INC > 0
149 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
150 #endif
151 #if BATTERY_TYPES_COUNT > 1
152 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
153 #endif
154 #ifdef HAVE_USB_CHARGING_ENABLE
155 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
157 (void)this_item;
158 switch (action)
160 case ACTION_EXIT_MENUITEM: /* on exit */
161 usb_charging_enable(global_settings.usb_charging);
162 break;
164 return action;
166 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
167 #endif /* HAVE_USB_CHARGING_ENABLE */
168 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
169 #if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
170 &battery_capacity,
171 #endif
172 #if BATTERY_TYPES_COUNT > 1
173 &battery_type,
174 #endif
175 #ifdef HAVE_USB_CHARGING_ENABLE
176 &usb_charging,
177 #endif
179 /* Disk */
180 #ifdef HAVE_DISK_STORAGE
181 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
182 #endif
183 #ifdef HAVE_DIRCACHE
184 static int dircache_callback(int action,const struct menu_item_ex *this_item)
186 (void)this_item;
187 switch (action)
189 case ACTION_EXIT_MENUITEM: /* on exit */
190 switch (global_settings.dircache)
192 case true:
193 if (!dircache_is_enabled())
194 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
195 break;
196 case false:
197 if (dircache_is_enabled())
198 dircache_disable();
199 break;
201 break;
203 return action;
205 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
206 #endif
207 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
208 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
209 #ifdef HAVE_DISK_STORAGE
210 &disk_spindown,
211 #endif
212 #ifdef HAVE_DIRCACHE
213 &dircache,
214 #endif
216 #endif
218 /* System menu */
219 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
221 /* Limits menu */
222 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
223 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
224 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
225 &max_files_in_dir, &max_files_in_playlist);
228 /* Keyclick menu */
229 #if CONFIG_CODEC == SWCODEC
230 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
231 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
232 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
233 &keyclick, &keyclick_repeats);
234 #endif
237 #if CONFIG_CODEC == MAS3507D
238 void dac_line_in(bool enable);
239 static int linein_callback(int action,const struct menu_item_ex *this_item)
241 (void)this_item;
242 switch (action)
244 case ACTION_EXIT_MENUITEM: /* on exit */
245 #ifndef SIMULATOR
246 dac_line_in(global_settings.line_in);
247 #endif
248 break;
250 return action;
252 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
253 #endif
254 #if CONFIG_CHARGING
255 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
256 #endif
257 #ifdef IPOD_ACCESSORY_PROTOCOL
258 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
259 #endif
260 #ifdef HAVE_ACCESSORY_SUPPLY
261 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
262 #endif
263 #ifdef HAVE_LINEOUT_POWEROFF
264 MENUITEM_SETTING(lineout_onoff, &global_settings.lineout_active, NULL);
265 #endif
266 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
267 #ifdef USB_ENABLE_HID
268 MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL);
269 MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
270 #endif
272 #ifdef HAVE_MORSE_INPUT
273 MENUITEM_SETTING(morse_input, &global_settings.morse_input, NULL);
274 #endif
276 #ifdef HAVE_BUTTON_LIGHT
277 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
278 #endif
280 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
281 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
282 #endif
284 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
285 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
286 #endif
288 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
289 0, Icon_System_menu,
290 &start_screen,
291 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
292 &battery_menu,
293 #endif
294 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
295 &disk_menu,
296 #endif
297 &poweroff,
298 &limits_menu,
299 #ifdef HAVE_MORSE_INPUT
300 &morse_input,
301 #endif
302 #if CONFIG_CODEC == MAS3507D
303 &line_in,
304 #endif
305 #if CONFIG_CHARGING
306 &car_adapter_mode,
307 #endif
308 #ifdef IPOD_ACCESSORY_PROTOCOL
309 &serial_bitrate,
310 #endif
311 #ifdef HAVE_ACCESSORY_SUPPLY
312 &accessory_supply,
313 #endif
314 #ifdef HAVE_LINEOUT_POWEROFF
315 &lineout_onoff,
316 #endif
317 #ifdef HAVE_BUTTON_LIGHT
318 &buttonlight_timeout,
319 #endif
320 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
321 &buttonlight_brightness,
322 #endif
323 #if CONFIG_CODEC == SWCODEC
324 &keyclick_menu,
325 #endif
326 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
327 &touchpad_sensitivity,
328 #endif
329 #ifdef USB_ENABLE_HID
330 &usb_hid,
331 &usb_keypad_mode,
332 #endif
335 /* SYSTEM MENU */
336 /***********************************/
339 /***********************************/
340 /* BOOKMARK MENU */
341 static int bmark_callback(int action,const struct menu_item_ex *this_item)
343 (void)this_item;
344 switch (action)
346 case ACTION_EXIT_MENUITEM: /* on exit */
347 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
348 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
350 if(global_settings.usemrb == BOOKMARK_NO)
351 global_settings.usemrb = BOOKMARK_YES;
354 break;
356 return action;
358 MENUITEM_SETTING(autocreatebookmark,
359 &global_settings.autocreatebookmark, bmark_callback);
360 MENUITEM_SETTING(autoupdatebookmark, &global_settings.autoupdatebookmark, NULL);
361 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
362 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
363 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
364 Icon_Bookmark,
365 &autocreatebookmark, &autoupdatebookmark, &autoloadbookmark, &usemrb);
366 /* BOOKMARK MENU */
367 /***********************************/
369 /***********************************/
370 /* VOICE MENU */
371 static int talk_callback(int action,const struct menu_item_ex *this_item);
372 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
373 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
374 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
375 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
376 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
377 static int talk_callback(int action,const struct menu_item_ex *this_item)
379 static int oldval = 0;
380 switch (action)
382 case ACTION_ENTER_MENUITEM:
383 oldval = global_settings.talk_file_clip;
384 break;
385 case ACTION_EXIT_MENUITEM:
386 #ifdef HAVE_CROSSFADE
387 audio_set_crossfade(global_settings.crossfade);
388 #endif
389 if (this_item == &talk_dir_clip_item)
390 break;
391 if (!oldval && global_settings.talk_file_clip)
393 /* force reload if newly talking thumbnails,
394 because the clip presence is cached only if enabled */
395 reload_directory();
397 break;
399 return action;
401 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
402 MENUITEM_SETTING(talk_battery_level_item,
403 &global_settings.talk_battery_level, NULL);
404 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
405 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
406 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
407 &talk_battery_level_item);
408 /* VOICE MENU */
409 /***********************************/
412 /***********************************/
413 /* HOTKEY MENU */
414 #ifdef HAVE_HOTKEY
415 MENUITEM_SETTING(hotkey_wps_item, &global_settings.hotkey_wps, NULL);
416 MENUITEM_SETTING(hotkey_tree_item, &global_settings.hotkey_tree, NULL);
417 MAKE_MENU(hotkey_menu, ID2P(LANG_HOTKEY), 0, Icon_NOICON,
418 &hotkey_wps_item, &hotkey_tree_item);
419 #endif /*have_hotkey */
420 /* HOTKEY MENU */
421 /***********************************/
424 /***********************************/
425 /* SETTINGS MENU */
427 #ifdef HAVE_TAGCACHE
428 MENUITEM_SETTING(autoresume_enable, &global_settings.autoresume_enable, NULL);
429 #endif
431 static struct browse_folder_info langs = { LANG_DIR, SHOW_LNG };
433 MENUITEM_FUNCTION(browse_langs, MENU_FUNC_USEPARAM, ID2P(LANG_LANGUAGE),
434 browse_folder, (void*)&langs, NULL, Icon_Language);
436 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
437 Icon_General_settings_menu,
438 &playlist_settings, &file_menu,
439 #ifdef HAVE_TAGCACHE
440 &tagcache_menu,
441 #endif
442 &display_menu, &system_menu,
443 &bookmark_settings_menu,
444 #ifdef HAVE_TAGCACHE
445 &autoresume_enable,
446 #endif
447 &browse_langs, &voice_settings_menu,
448 #ifdef HAVE_HOTKEY
449 &hotkey_menu,
450 #endif
452 /* SETTINGS MENU */
453 /***********************************/