Fix some drawing problems when displaying the WPS initially with sbs enabled. Move...
[kugel-rb.git] / apps / menus / settings_menu.c
blob5c30e5982f71b8ab7c43f5eca54f6a14706b9396
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
51 /***********************************/
52 /* TAGCACHE MENU */
53 #ifdef HAVE_TAGCACHE
55 static void tagcache_rebuild_with_splash(void)
57 tagcache_rebuild();
58 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
61 static void tagcache_update_with_splash(void)
63 tagcache_update();
64 splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
67 #ifdef HAVE_TC_RAMCACHE
68 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
69 #endif
70 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
71 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
72 (int(*)(void))tagcache_rebuild_with_splash,
73 NULL, NULL, Icon_NOICON);
74 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
75 (int(*)(void))tagcache_update_with_splash,
76 NULL, NULL, Icon_NOICON);
77 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
78 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
79 (int(*)(void))tagtree_export, NULL,
80 NULL, Icon_NOICON);
81 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
82 (int(*)(void))tagtree_import, NULL,
83 NULL, Icon_NOICON);
84 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
85 #ifdef HAVE_TC_RAMCACHE
86 &tagcache_ram,
87 #endif
88 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
89 &tc_export, &tc_import);
90 #endif /* HAVE_TAGCACHE */
91 /* TAGCACHE MENU */
92 /***********************************/
94 /***********************************/
95 /* FILE VIEW MENU */
96 static int fileview_callback(int action,const struct menu_item_ex *this_item);
97 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
98 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
99 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
100 MENUITEM_SETTING(interpret_numbers, &global_settings.interpret_numbers, fileview_callback);
101 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
102 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
103 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
104 #ifdef HAVE_LCD_BITMAP
105 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
106 #endif
107 static int fileview_callback(int action,const struct menu_item_ex *this_item)
109 static int oldval;
110 int *variable = this_item->variable;
111 switch (action)
113 case ACTION_ENTER_MENUITEM: /* on entering an item */
114 oldval = *variable;
115 break;
116 case ACTION_EXIT_MENUITEM: /* on exit */
117 if (*variable != oldval)
118 reload_directory(); /* force reload if this has changed */
119 break;
121 return action;
124 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
125 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
126 &dirfilter, &show_filename_ext, &browse_current,
127 #ifdef HAVE_LCD_BITMAP
128 &show_path_in_browser
129 #endif
131 /* FILE VIEW MENU */
132 /***********************************/
135 /***********************************/
136 /* SYSTEM MENU */
138 /* Battery */
139 #if BATTERY_CAPACITY_INC > 0
140 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
141 #endif
142 #if BATTERY_TYPES_COUNT > 1
143 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
144 #endif
145 #ifdef HAVE_USB_CHARGING_ENABLE
146 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
148 (void)this_item;
149 switch (action)
151 case ACTION_EXIT_MENUITEM: /* on exit */
152 usb_charging_enable(global_settings.usb_charging);
153 break;
155 return action;
157 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
158 #endif /* HAVE_USB_CHARGING_ENABLE */
159 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
160 #if BATTERY_CAPACITY_INC > 0
161 &battery_capacity,
162 #endif
163 #if BATTERY_TYPES_COUNT > 1
164 &battery_type,
165 #endif
166 #ifdef HAVE_USB_CHARGING_ENABLE
167 &usb_charging,
168 #endif
170 /* Disk */
171 #ifdef HAVE_DISK_STORAGE
172 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
173 #endif
174 #ifdef HAVE_DIRCACHE
175 static int dircache_callback(int action,const struct menu_item_ex *this_item)
177 (void)this_item;
178 switch (action)
180 case ACTION_EXIT_MENUITEM: /* on exit */
181 switch (global_settings.dircache)
183 case true:
184 if (!dircache_is_enabled())
185 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
186 break;
187 case false:
188 if (dircache_is_enabled())
189 dircache_disable();
190 break;
192 break;
194 return action;
196 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
197 #endif
198 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
199 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
200 #ifdef HAVE_DISK_STORAGE
201 &disk_spindown,
202 #endif
203 #ifdef HAVE_DIRCACHE
204 &dircache,
205 #endif
207 #endif
209 /* System menu */
210 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
212 /* Limits menu */
213 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
214 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
215 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
216 &max_files_in_dir, &max_files_in_playlist);
219 /* Keyclick menu */
220 #if CONFIG_CODEC == SWCODEC
221 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
222 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
223 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
224 &keyclick, &keyclick_repeats);
225 #endif
228 #if CONFIG_CODEC == MAS3507D
229 void dac_line_in(bool enable);
230 static int linein_callback(int action,const struct menu_item_ex *this_item)
232 (void)this_item;
233 switch (action)
235 case ACTION_EXIT_MENUITEM: /* on exit */
236 #ifndef SIMULATOR
237 dac_line_in(global_settings.line_in);
238 #endif
239 break;
241 return action;
243 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
244 #endif
245 #if CONFIG_CHARGING
246 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
247 #endif
248 #ifdef IPOD_ACCESSORY_PROTOCOL
249 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
250 #endif
251 #ifdef HAVE_ACCESSORY_SUPPLY
252 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
253 #endif
254 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
255 #ifdef USB_ENABLE_HID
256 MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL);
257 MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
258 #endif
260 #ifdef HAVE_MORSE_INPUT
261 MENUITEM_SETTING(morse_input, &global_settings.morse_input, NULL);
262 #endif
264 #ifdef HAVE_BUTTON_LIGHT
265 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
266 #endif
268 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
269 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
270 #endif
272 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
273 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
274 #endif
276 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
277 0, Icon_System_menu,
278 &start_screen,
279 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
280 &battery_menu,
281 #endif
282 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
283 &disk_menu,
284 #endif
285 &poweroff,
286 &limits_menu,
287 #ifdef HAVE_MORSE_INPUT
288 &morse_input,
289 #endif
290 #if CONFIG_CODEC == MAS3507D
291 &line_in,
292 #endif
293 #if CONFIG_CHARGING
294 &car_adapter_mode,
295 #endif
296 #ifdef IPOD_ACCESSORY_PROTOCOL
297 &serial_bitrate,
298 #endif
299 #ifdef HAVE_ACCESSORY_SUPPLY
300 &accessory_supply,
301 #endif
302 #ifdef HAVE_BUTTON_LIGHT
303 &buttonlight_timeout,
304 #endif
305 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
306 &buttonlight_brightness,
307 #endif
308 #if CONFIG_CODEC == SWCODEC
309 &keyclick_menu,
310 #endif
311 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
312 &touchpad_sensitivity,
313 #endif
314 #ifdef USB_ENABLE_HID
315 &usb_hid,
316 &usb_keypad_mode,
317 #endif
320 /* SYSTEM MENU */
321 /***********************************/
324 /***********************************/
325 /* BOOKMARK MENU */
326 static int bmark_callback(int action,const struct menu_item_ex *this_item)
328 (void)this_item;
329 switch (action)
331 case ACTION_EXIT_MENUITEM: /* on exit */
332 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
333 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
335 if(global_settings.usemrb == BOOKMARK_NO)
336 global_settings.usemrb = BOOKMARK_YES;
339 break;
341 return action;
343 MENUITEM_SETTING(autocreatebookmark,
344 &global_settings.autocreatebookmark, bmark_callback);
345 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
346 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
347 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
348 Icon_Bookmark,
349 &autocreatebookmark, &autoloadbookmark, &usemrb);
350 /* BOOKMARK MENU */
351 /***********************************/
353 /***********************************/
354 /* VOICE MENU */
355 static int talk_callback(int action,const struct menu_item_ex *this_item);
356 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
357 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
358 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
359 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
360 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
361 static int talk_callback(int action,const struct menu_item_ex *this_item)
363 static int oldval = 0;
364 switch (action)
366 case ACTION_ENTER_MENUITEM:
367 oldval = global_settings.talk_file_clip;
368 break;
369 case ACTION_EXIT_MENUITEM:
370 #ifdef HAVE_CROSSFADE
371 audio_set_crossfade(global_settings.crossfade);
372 #endif
373 if (this_item == &talk_dir_clip_item)
374 break;
375 if (!oldval && global_settings.talk_file_clip)
377 /* force reload if newly talking thumbnails,
378 because the clip presence is cached only if enabled */
379 reload_directory();
381 break;
383 return action;
385 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
386 MENUITEM_SETTING(talk_battery_level_item,
387 &global_settings.talk_battery_level, NULL);
388 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
389 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
390 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
391 &talk_battery_level_item);
392 /* VOICE MENU */
393 /***********************************/
396 /***********************************/
397 /* SETTINGS MENU */
398 static int language_browse(void)
400 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
402 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
403 NULL, NULL, Icon_Language);
405 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
406 Icon_General_settings_menu,
407 &playlist_settings, &file_menu,
408 #ifdef HAVE_TAGCACHE
409 &tagcache_menu,
410 #endif
411 &display_menu, &system_menu,
412 &bookmark_settings_menu, &browse_langs, &voice_settings_menu
414 /* SETTINGS MENU */
415 /***********************************/