Hopefully fix read.
[kugel-rb.git] / apps / menus / settings_menu.c
blob85e4f9649fed956671ef2be2269c8384adc16d02
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(dirfilter, &global_settings.dirfilter, NULL);
104 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
105 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
106 #ifdef HAVE_LCD_BITMAP
107 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
108 #endif
109 static int fileview_callback(int action,const struct menu_item_ex *this_item)
111 static int oldval;
112 int *variable = this_item->variable;
113 switch (action)
115 case ACTION_ENTER_MENUITEM: /* on entering an item */
116 oldval = *variable;
117 break;
118 case ACTION_EXIT_MENUITEM: /* on exit */
119 if (*variable != oldval)
120 reload_directory(); /* force reload if this has changed */
121 break;
123 return action;
126 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
127 &sort_case, &sort_dir, &sort_file,
128 &dirfilter, &show_filename_ext, &browse_current,
129 #ifdef HAVE_LCD_BITMAP
130 &show_path_in_browser
131 #endif
133 /* FILE VIEW MENU */
134 /***********************************/
137 /***********************************/
138 /* SYSTEM MENU */
140 /* Battery */
141 #if BATTERY_CAPACITY_INC > 0
142 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
143 #endif
144 #if BATTERY_TYPES_COUNT > 1
145 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
146 #endif
147 #ifdef HAVE_USB_CHARGING_ENABLE
148 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
150 (void)this_item;
151 switch (action)
153 case ACTION_EXIT_MENUITEM: /* on exit */
154 usb_charging_enable(global_settings.usb_charging);
155 break;
157 return action;
159 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
160 #endif /* HAVE_USB_CHARGING_ENABLE */
161 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
162 #if BATTERY_CAPACITY_INC > 0
163 &battery_capacity,
164 #endif
165 #if BATTERY_TYPES_COUNT > 1
166 &battery_type,
167 #endif
168 #ifdef HAVE_USB_CHARGING_ENABLE
169 &usb_charging,
170 #endif
172 /* Disk */
173 #ifdef HAVE_DISK_STORAGE
174 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
175 #endif
176 #ifdef HAVE_DIRCACHE
177 static int dircache_callback(int action,const struct menu_item_ex *this_item)
179 (void)this_item;
180 switch (action)
182 case ACTION_EXIT_MENUITEM: /* on exit */
183 switch (global_settings.dircache)
185 case true:
186 if (!dircache_is_enabled())
187 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
188 break;
189 case false:
190 if (dircache_is_enabled())
191 dircache_disable();
192 break;
194 break;
196 return action;
198 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
199 #endif
200 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
201 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
202 #ifdef HAVE_DISK_STORAGE
203 &disk_spindown,
204 #endif
205 #ifdef HAVE_DIRCACHE
206 &dircache,
207 #endif
209 #endif
211 /* System menu */
212 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
214 /* Limits menu */
215 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
216 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
217 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
218 &max_files_in_dir, &max_files_in_playlist);
221 /* Keyclick menu */
222 #if CONFIG_CODEC == SWCODEC
223 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
224 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
225 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
226 &keyclick, &keyclick_repeats);
227 #endif
230 #if CONFIG_CODEC == MAS3507D
231 void dac_line_in(bool enable);
232 static int linein_callback(int action,const struct menu_item_ex *this_item)
234 (void)this_item;
235 switch (action)
237 case ACTION_EXIT_MENUITEM: /* on exit */
238 #ifndef SIMULATOR
239 dac_line_in(global_settings.line_in);
240 #endif
241 break;
243 return action;
245 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
246 #endif
247 #if CONFIG_CHARGING
248 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
249 #endif
250 #ifdef IPOD_ACCESSORY_PROTOCOL
251 MENUITEM_SETTING(serial_bitrate, &global_settings.serial_bitrate, NULL);
252 #endif
253 #ifdef HAVE_ACCESSORY_SUPPLY
254 MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
255 #endif
256 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
258 #ifdef HAVE_BUTTON_LIGHT
259 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
260 #endif
262 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
263 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
264 #endif
266 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
267 MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
268 #endif
271 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
272 0, Icon_System_menu,
273 &start_screen,
274 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
275 &battery_menu,
276 #endif
277 #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE)
278 &disk_menu,
279 #endif
280 &poweroff,
281 &limits_menu,
282 #if CONFIG_CODEC == MAS3507D
283 &line_in,
284 #endif
285 #if CONFIG_CHARGING
286 &car_adapter_mode,
287 #endif
288 #ifdef IPOD_ACCESSORY_PROTOCOL
289 &serial_bitrate,
290 #endif
291 #ifdef HAVE_ACCESSORY_SUPPLY
292 &accessory_supply,
293 #endif
294 #ifdef HAVE_BUTTON_LIGHT
295 &buttonlight_timeout,
296 #endif
297 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
298 &buttonlight_brightness,
299 #endif
300 #if CONFIG_CODEC == SWCODEC
301 &keyclick_menu,
302 #endif
303 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
304 &touchpad_sensitivity,
305 #endif
308 /* SYSTEM MENU */
309 /***********************************/
312 /***********************************/
313 /* BOOKMARK MENU */
314 static int bmark_callback(int action,const struct menu_item_ex *this_item)
316 (void)this_item;
317 switch (action)
319 case ACTION_EXIT_MENUITEM: /* on exit */
320 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
321 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
323 if(global_settings.usemrb == BOOKMARK_NO)
324 global_settings.usemrb = BOOKMARK_YES;
327 break;
329 return action;
331 MENUITEM_SETTING(autocreatebookmark,
332 &global_settings.autocreatebookmark, bmark_callback);
333 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
334 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
335 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
336 Icon_Bookmark,
337 &autocreatebookmark, &autoloadbookmark, &usemrb);
338 /* BOOKMARK MENU */
339 /***********************************/
341 /***********************************/
342 /* VOICE MENU */
343 static int talk_callback(int action,const struct menu_item_ex *this_item);
344 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
345 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
346 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
347 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
348 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
349 static int talk_callback(int action,const struct menu_item_ex *this_item)
351 static int oldval = 0;
352 switch (action)
354 case ACTION_ENTER_MENUITEM:
355 oldval = global_settings.talk_file_clip;
356 break;
357 case ACTION_EXIT_MENUITEM:
358 #if CONFIG_CODEC == SWCODEC
359 audio_set_crossfade(global_settings.crossfade);
360 #endif
361 if (this_item == &talk_dir_clip_item)
362 break;
363 if (!oldval && global_settings.talk_file_clip)
365 /* force reload if newly talking thumbnails,
366 because the clip presence is cached only if enabled */
367 reload_directory();
369 break;
371 return action;
373 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
374 MENUITEM_SETTING(talk_battery_level_item,
375 &global_settings.talk_battery_level, NULL);
376 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
377 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
378 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
379 &talk_battery_level_item);
380 /* VOICE MENU */
381 /***********************************/
384 /***********************************/
385 /* SETTINGS MENU */
386 static int language_browse(void)
388 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
390 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
391 NULL, NULL, Icon_Language);
393 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
394 Icon_General_settings_menu,
395 &playlist_settings, &file_menu,
396 #ifdef HAVE_TAGCACHE
397 &tagcache_menu,
398 #endif
399 &display_menu, &system_menu,
400 &bookmark_settings_menu, &browse_langs, &voice_settings_menu
402 /* SETTINGS MENU */
403 /***********************************/