Themes need to specify backdrop, colours, icon sets and selector type bar if they...
[kugel-rb.git] / apps / menus / settings_menu.c
blob08fd071a36a747aae064cbfa0912c9ee482d2f3c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <limits.h>
23 #include <string.h>
24 #include "config.h"
25 #include "lang.h"
26 #include "action.h"
27 #include "settings.h"
28 #include "menu.h"
29 #include "sound_menu.h"
30 #include "exported_menus.h"
31 #include "tree.h"
32 #include "tagtree.h"
33 #include "usb.h"
34 #include "splash.h"
35 #include "talk.h"
36 #include "sprintf.h"
37 #include "powermgmt.h"
38 #ifdef HAVE_RTC_ALARM
39 #include "alarm_menu.h"
40 #endif
41 #if CONFIG_TUNER
42 #include "radio.h"
43 #endif
45 /***********************************/
46 /* TAGCACHE MENU */
47 #ifdef HAVE_TAGCACHE
49 static void tagcache_rebuild_with_splash(void)
51 tagcache_rebuild();
52 gui_syncsplash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
55 static void tagcache_update_with_splash(void)
57 tagcache_update();
58 gui_syncsplash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH));
61 #ifdef HAVE_TC_RAMCACHE
62 MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
63 #endif
64 MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
65 MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
66 (int(*)(void))tagcache_rebuild_with_splash,
67 NULL, NULL, Icon_NOICON);
68 MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE),
69 (int(*)(void))tagcache_update_with_splash,
70 NULL, NULL, Icon_NOICON);
71 MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
72 MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT),
73 (int(*)(void))tagtree_export, NULL,
74 NULL, Icon_NOICON);
75 MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT),
76 (int(*)(void))tagtree_import, NULL,
77 NULL, Icon_NOICON);
78 MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON,
79 #ifdef HAVE_TC_RAMCACHE
80 &tagcache_ram,
81 #endif
82 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
83 &tc_export, &tc_import);
84 #endif /* HAVE_TAGCACHE */
85 /* TAGCACHE MENU */
86 /***********************************/
88 /***********************************/
89 /* FILE VIEW MENU */
90 static int fileview_callback(int action,const struct menu_item_ex *this_item);
91 MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
92 MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
93 MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
94 MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
95 MENUITEM_SETTING(show_filename_ext, &global_settings.show_filename_ext, NULL);
96 MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
97 #ifdef HAVE_LCD_BITMAP
98 MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
99 #endif
100 static int fileview_callback(int action,const struct menu_item_ex *this_item)
102 static int oldval;
103 int *variable = this_item->variable;
104 switch (action)
106 case ACTION_ENTER_MENUITEM: /* on entering an item */
107 oldval = *variable;
108 break;
109 case ACTION_EXIT_MENUITEM: /* on exit */
110 if (*variable != oldval)
111 reload_directory(); /* force reload if this has changed */
112 break;
114 return action;
117 MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu,
118 &sort_case, &sort_dir, &sort_file,
119 &dirfilter, &show_filename_ext, &browse_current,
120 #ifdef HAVE_LCD_BITMAP
121 &show_path_in_browser
122 #endif
124 /* FILE VIEW MENU */
125 /***********************************/
128 /***********************************/
129 /* SYSTEM MENU */
131 /* Battery */
132 #if BATTERY_CAPACITY_INC > 0
133 MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
134 #endif
135 #if BATTERY_TYPES_COUNT > 1
136 MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
137 #endif
138 #ifdef HAVE_USB_POWER
139 #if CONFIG_CHARGING
140 static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
142 (void)this_item;
143 switch (action)
145 case ACTION_EXIT_MENUITEM: /* on exit */
146 usb_charging_enable(global_settings.usb_charging);
147 break;
149 return action;
151 MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
152 #endif
153 #endif
154 MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
155 #if BATTERY_CAPACITY_INC > 0
156 &battery_capacity,
157 #endif
158 #if BATTERY_TYPES_COUNT > 1
159 &battery_type,
160 #endif
161 #ifdef HAVE_USB_POWER
162 #if CONFIG_CHARGING
163 &usb_charging,
164 #endif
165 #endif
167 /* Disk */
168 #ifndef HAVE_FLASH_STORAGE
169 MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
170 #endif
171 #ifdef HAVE_DIRCACHE
172 static int dircache_callback(int action,const struct menu_item_ex *this_item)
174 (void)this_item;
175 switch (action)
177 case ACTION_EXIT_MENUITEM: /* on exit */
178 switch (global_settings.dircache)
180 case true:
181 if (!dircache_is_enabled())
182 gui_syncsplash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
183 break;
184 case false:
185 if (dircache_is_enabled())
186 dircache_disable();
187 break;
189 break;
191 return action;
193 MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
194 #endif
195 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
196 MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON,
197 #ifndef HAVE_FLASH_STORAGE
198 &disk_spindown,
199 #endif
200 #ifdef HAVE_DIRCACHE
201 &dircache,
202 #endif
204 #endif
206 /* Time & Date */
207 #if CONFIG_RTC
208 static int timedate_set(void)
210 struct tm tm;
211 int result;
213 /* Make a local copy of the time struct */
214 memcpy(&tm, get_time(), sizeof(struct tm));
216 /* do some range checks */
217 /* This prevents problems with time/date setting after a power loss */
218 if (!valid_time(&tm))
220 /* Macros to convert a 2-digit string to a decimal constant.
221 (YEAR), MONTH and DAY are set by the date command, which outputs
222 DAY as 00..31 and MONTH as 01..12. The leading zero would lead to
223 misinterpretation as an octal constant. */
224 #define S100(x) 1 ## x
225 #define C2DIG2DEC(x) (S100(x)-100)
227 tm.tm_hour = 0;
228 tm.tm_min = 0;
229 tm.tm_sec = 0;
230 tm.tm_mday = C2DIG2DEC(DAY);
231 tm.tm_mon = C2DIG2DEC(MONTH)-1;
232 tm.tm_wday = 1;
233 tm.tm_year = YEAR-1900;
236 result = (int)set_time_screen(str(LANG_SET_TIME), &tm);
238 if(tm.tm_year != -1) {
239 set_time(&tm);
241 return result;
244 MENUITEM_FUNCTION(time_set, 0, ID2P(LANG_SET_TIME),
245 timedate_set, NULL, NULL, Icon_NOICON);
246 MENUITEM_SETTING(timeformat, &global_settings.timeformat, NULL);
247 MAKE_MENU(time_menu, ID2P(LANG_TIME_MENU), 0, Icon_NOICON, &time_set, &timeformat);
248 #endif
250 /* System menu */
251 MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
253 #ifdef HAVE_RTC_ALARM
254 MENUITEM_FUNCTION(alarm_screen_call, 0, ID2P(LANG_ALARM_MOD_ALARM_MENU),
255 (menu_function)alarm_screen, NULL, NULL, Icon_NOICON);
256 #if CONFIG_TUNER || defined(HAVE_RECORDING)
258 #if CONFIG_TUNER && !defined(HAVE_RECORDING)
259 /* This need only be shown if we dont have recording, because if we do
260 then always show the setting item, because there will always be at least
261 2 items */
262 static int alarm_callback(int action,const struct menu_item_ex *this_item)
264 (void)this_item;
265 switch (action)
267 case ACTION_REQUEST_MENUITEM:
268 if (radio_hardware_present() == 0)
269 return ACTION_EXIT_MENUITEM;
270 break;
272 return action;
274 #else
275 #define alarm_callback NULL
276 #endif /* CONFIG_TUNER && !HAVE_RECORDING */
277 /* have to do this manually because the setting screen
278 doesnt handle variable item count */
279 static int alarm_setting(void)
281 struct opt_items items[ALARM_START_COUNT];
282 int i = 0;
283 items[i].string = str(LANG_RESUME_PLAYBACK);
284 items[i].voice_id = LANG_RESUME_PLAYBACK;
285 i++;
286 #if CONFIG_TUNER
287 if (radio_hardware_present())
289 items[i].string = str(LANG_FM_RADIO);
290 items[i].voice_id = LANG_FM_RADIO;
291 i++;
293 #endif
294 #ifdef HAVE_RECORDING
295 items[i].string = str(LANG_RECORDING);
296 items[i].voice_id = LANG_RECORDING;
297 i++;
298 #endif
299 return set_option(str(LANG_ALARM_WAKEUP_SCREEN),
300 &global_settings.alarm_wake_up_screen,
301 INT, items, i, NULL);
304 MENUITEM_FUNCTION(alarm_wake_up_screen, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN),
305 alarm_setting, NULL, alarm_callback, Icon_Menu_setting);
306 #endif /* CONFIG_TUNER || defined(HAVE_RECORDING) */
307 #endif /* HAVE_RTC_ALARM */
309 /* Limits menu */
310 MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
311 MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
312 MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0, Icon_NOICON,
313 &max_files_in_dir, &max_files_in_playlist);
316 /* Keyclick menu */
317 #if CONFIG_CODEC == SWCODEC
318 MENUITEM_SETTING(keyclick, &global_settings.keyclick, NULL);
319 MENUITEM_SETTING(keyclick_repeats, &global_settings.keyclick_repeats, NULL);
320 MAKE_MENU(keyclick_menu, ID2P(LANG_KEYCLICK), 0, Icon_NOICON,
321 &keyclick, &keyclick_repeats);
322 #endif
325 #if CONFIG_CODEC == MAS3507D
326 void dac_line_in(bool enable);
327 static int linein_callback(int action,const struct menu_item_ex *this_item)
329 (void)this_item;
330 switch (action)
332 case ACTION_EXIT_MENUITEM: /* on exit */
333 #ifndef SIMULATOR
334 dac_line_in(global_settings.line_in);
335 #endif
336 break;
338 return action;
340 MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
341 #endif
342 #if CONFIG_CHARGING
343 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
344 #endif
345 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
347 #ifdef HAVE_BUTTON_LIGHT
348 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
349 #endif
351 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
352 MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness, NULL);
353 #endif
356 MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
357 0, Icon_System_menu,
358 &start_screen,
359 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
360 &battery_menu,
361 #endif
362 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
363 &disk_menu,
364 #endif
365 #if CONFIG_RTC
366 &time_menu,
367 #endif
368 &poweroff,
369 #ifdef HAVE_RTC_ALARM
370 &alarm_screen_call,
371 #if defined(HAVE_RECORDING) || CONFIG_TUNER
372 &alarm_wake_up_screen,
373 #endif
374 #endif
375 &limits_menu,
376 #if CONFIG_CODEC == MAS3507D
377 &line_in,
378 #endif
379 #if CONFIG_CHARGING
380 &car_adapter_mode,
381 #endif
382 #ifdef HAVE_BUTTON_LIGHT
383 &buttonlight_timeout,
384 #endif
385 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
386 &buttonlight_brightness,
387 #endif
388 #if CONFIG_CODEC == SWCODEC
389 &keyclick_menu,
390 #endif
393 /* SYSTEM MENU */
394 /***********************************/
397 /***********************************/
398 /* BOOKMARK MENU */
399 static int bmark_callback(int action,const struct menu_item_ex *this_item)
401 (void)this_item;
402 switch (action)
404 case ACTION_EXIT_MENUITEM: /* on exit */
405 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
406 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
408 if(global_settings.usemrb == BOOKMARK_NO)
409 global_settings.usemrb = BOOKMARK_YES;
412 break;
414 return action;
416 MENUITEM_SETTING(autocreatebookmark,
417 &global_settings.autocreatebookmark, bmark_callback);
418 MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
419 MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
420 MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
421 Icon_Bookmark,
422 &autocreatebookmark, &autoloadbookmark, &usemrb);
423 /* BOOKMARK MENU */
424 /***********************************/
426 /***********************************/
427 /* VOICE MENU */
428 static int talk_callback(int action,const struct menu_item_ex *this_item);
429 MENUITEM_SETTING(talk_menu_item, &global_settings.talk_menu, NULL);
430 MENUITEM_SETTING(talk_dir_item, &global_settings.talk_dir, NULL);
431 MENUITEM_SETTING(talk_dir_clip_item, &global_settings.talk_dir_clip, talk_callback);
432 MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, NULL);
433 MENUITEM_SETTING(talk_file_clip_item, &global_settings.talk_file_clip, talk_callback);
434 static int talk_callback(int action,const struct menu_item_ex *this_item)
436 static int oldval = 0;
437 switch (action)
439 case ACTION_ENTER_MENUITEM:
440 oldval = global_settings.talk_file_clip;
441 break;
442 case ACTION_EXIT_MENUITEM:
443 #if CONFIG_CODEC == SWCODEC
444 audio_set_crossfade(global_settings.crossfade);
445 #endif
446 if (this_item == &talk_dir_clip_item)
447 break;
448 if (!oldval && global_settings.talk_file_clip)
450 /* force reload if newly talking thumbnails,
451 because the clip presence is cached only if enabled */
452 reload_directory();
454 break;
456 return action;
458 MENUITEM_SETTING(talk_filetype_item, &global_settings.talk_filetype, NULL);
459 MENUITEM_SETTING(talk_battery_level_item,
460 &global_settings.talk_battery_level, NULL);
461 MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
462 &talk_menu_item, &talk_dir_item, &talk_dir_clip_item,
463 &talk_file_item, &talk_file_clip_item, &talk_filetype_item,
464 &talk_battery_level_item);
465 /* VOICE MENU */
466 /***********************************/
468 /***********************************/
470 /***********************************/
471 /* SETTINGS MENU */
472 static int language_browse(void)
474 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
476 MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse,
477 NULL, NULL, Icon_Language);
479 MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
480 Icon_General_settings_menu,
481 &playback_menu_item, &playlist_settings, &file_menu,
482 #ifdef HAVE_TAGCACHE
483 &tagcache_menu,
484 #endif
485 &display_menu, &system_menu,
486 &bookmark_settings_menu, &browse_langs, &voice_settings_menu
488 /* SETTINGS MENU */
489 /***********************************/