summaryrefslogtreecommitdiff
path: root/apps/menus/settings_menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/menus/settings_menu.c')
-rw-r--r--apps/menus/settings_menu.c354
1 files changed, 350 insertions, 4 deletions
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c
index ed83940d8f..df39dc20ad 100644
--- a/apps/menus/settings_menu.c
+++ b/apps/menus/settings_menu.c
@@ -1,4 +1,3 @@
1
2/*************************************************************************** 1/***************************************************************************
3 * __________ __ ___. 2 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
@@ -21,13 +20,360 @@
21#include <stdbool.h> 20#include <stdbool.h>
22#include <stddef.h> 21#include <stddef.h>
23#include <limits.h> 22#include <limits.h>
23#include <string.h>
24#include "config.h" 24#include "config.h"
25#include "lang.h" 25#include "lang.h"
26#include "action.h" 26#include "action.h"
27#include "settings.h" 27#include "settings.h"
28#include "menu.h" 28#include "menu.h"
29#include "sound_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_ALARM_MOD
39#include "alarm_menu.h"
40#endif
41
42/***********************************/
43/* TAGCACHE MENU */
44#ifdef HAVE_TAGCACHE
45#ifdef HAVE_TC_RAMCACHE
46MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL);
47#endif
48MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL);
49MENUITEM_FUNCTION(tc_init, ID2P(LANG_TAGCACHE_FORCE_UPDATE),
50 (int(*)(void))tagcache_rebuild, NULL);
51MENUITEM_FUNCTION(tc_update, ID2P(LANG_TAGCACHE_UPDATE),
52 (int(*)(void))tagcache_update, NULL);
53MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL);
54MENUITEM_FUNCTION(tc_export, ID2P(LANG_TAGCACHE_EXPORT),
55 (int(*)(void))tagtree_export, NULL);
56MENUITEM_FUNCTION(tc_import, ID2P(LANG_TAGCACHE_IMPORT),
57 (int(*)(void))tagtree_import, NULL);
58MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0,
59#ifdef HAVE_TC_RAMCACHE
60 &tagcache_ram,
61#endif
62 &tagcache_autoupdate, &tc_init, &tc_update, &runtimedb,
63 &tc_export, &tc_import);
64#endif /* HAVE_TAGCACHE */
65/* TAGCACHE MENU */
66/***********************************/
67
68/***********************************/
69/* FILE VIEW MENU */
70static int fileview_callback(int action,const struct menu_item_ex *this_item);
71MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL);
72MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback);
73MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback);
74MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL);
75MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL);
76MENUITEM_SETTING(show_icons, &global_settings.show_icons, NULL);
77MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL);
78static int fileview_callback(int action,const struct menu_item_ex *this_item)
79{
80 static int oldval;
81 int *variable = this_item->variable;
82 switch (action)
83 {
84 case ACTION_ENTER_MENUITEM: /* on entering an item */
85 oldval = *variable;
86 break;
87 case ACTION_EXIT_MENUITEM: /* on exit */
88 if (*variable != oldval)
89 reload_directory(); /* force reload if this has changed */
90 break;
91 }
92 return action;
93}
94
95MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, &sort_case, &sort_dir, &sort_file,
96 &dirfilter, &browse_current, &show_icons, &show_path_in_browser,
97#ifdef HAVE_TAGCACHE
98 &tagcache_menu
99#endif
100 );
101/* FILE VIEW MENU */
102/***********************************/
103
104
105/***********************************/
106/* SYSTEM MENU */
107
108/* Battery */
109#ifndef SIMULATOR
110MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL);
111MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
112#ifdef HAVE_USB_POWER
113#ifdef CONFIG_CHARGING
114static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
115{
116 (void)this_item;
117 switch (action)
118 {
119 case ACTION_EXIT_MENUITEM: /* on exit */
120 usb_charging_enable(global_settings.usb_charging);
121 break;
122 }
123 return action;
124}
125MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
126#endif
127#endif
128MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0,
129 &battery_capacity,
130#if BATTERY_TYPES_COUNT > 1
131 &battery_type,
132#endif
133#ifdef HAVE_USB_POWER
134#ifdef CONFIG_CHARGING
135 &usb_charging,
136#endif
137#endif
138 );
139#endif /* SIMULATOR */
140/* Disk */
141#ifndef HAVE_MMC
142MENUITEM_SETTING(disk_spindown, &global_settings.disk_spindown, NULL);
143#ifdef HAVE_DIRCACHE
144static int dircache_callback(int action,const struct menu_item_ex *this_item)
145{
146 (void)this_item;
147 switch (action)
148 {
149 case ACTION_EXIT_MENUITEM: /* on exit */
150 switch (global_settings.dircache)
151 {
152 case true:
153 if (!dircache_is_enabled())
154 gui_syncsplash(HZ*2, true, str(LANG_PLEASE_REBOOT));
155 break;
156 case false:
157 if (dircache_is_enabled())
158 dircache_disable();
159 break;
160 }
161 break;
162 }
163 return action;
164}
165MENUITEM_SETTING(dircache, &global_settings.dircache, dircache_callback);
166#endif
167MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0,
168 &disk_spindown,
169#ifdef HAVE_DIRCACHE
170 &dircache,
171#endif
172 );
173#endif
174
175/* Time & Date */
176#ifdef CONFIG_RTC
177static int timedate_set(void)
178{
179 struct tm tm;
180 int result;
181
182 /* Make a local copy of the time struct */
183 memcpy(&tm, get_time(), sizeof(struct tm));
184
185 /* do some range checks */
186 /* This prevents problems with time/date setting after a power loss */
187 if (!valid_time(&tm))
188 {
189 /* hour */
190 tm.tm_hour = 0;
191 tm.tm_min = 0;
192 tm.tm_sec = 0;
193 tm.tm_mday = 1;
194 tm.tm_mon = 0;
195 tm.tm_wday = 1;
196 tm.tm_year = 100;
197 }
198
199 result = (int)set_time_screen(str(LANG_TIME), &tm);
200
201 if(tm.tm_year != -1) {
202 set_time(&tm);
203 }
204 return result;
205}
206
207MENUITEM_FUNCTION(time_set, ID2P(LANG_TIME), timedate_set, NULL);
208MENUITEM_SETTING(timeformat, &global_settings.timeformat, NULL);
209MAKE_MENU(time_menu, ID2P(LANG_TIME_MENU), 0, &time_set, &timeformat);
210#endif
211
212/* System menu */
213MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
214
215/* sleep Menu */
216static void sleep_timer_formatter(char* buffer, int buffer_size, int value,
217 const char* unit)
218{
219 int minutes, hours;
220
221 (void) unit;
222
223 if (value) {
224 hours = value / 60;
225 minutes = value - (hours * 60);
226 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
227 } else {
228 snprintf(buffer, buffer_size, "%s", str(LANG_OFF));
229 }
230}
231
232static void sleep_timer_set(int minutes)
233{
234 set_sleep_timer(minutes * 60);
235}
236
237static int sleep_timer(void)
238{
239 int minutes = (get_sleep_timer() + 59) / 60; /* round up */
240 return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
241 &sleep_timer_set, 5, 0, 300, sleep_timer_formatter);
242}
243
244MENUITEM_FUNCTION(sleep_timer_call, ID2P(LANG_SLEEP_TIMER), sleep_timer, NULL);
245#ifdef HAVE_ALARM_MOD
246MENUITEM_FUNCTION(alarm_screen_call, ID2P(LANG_ALARM_MOD_ALARM_MENU),
247 (menu_function)alarm_screen, NULL);
248#endif
249
250/* Limits menu */
251MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL);
252MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL);
253MAKE_MENU(limits_menu, ID2P(LANG_LIMITS_MENU), 0,
254 &max_files_in_dir, &max_files_in_playlist);
255
256#if CONFIG_CODEC == MAS3507D
257void dac_line_in(bool enable);
258static int linein_callback(int action,const struct menu_item_ex *this_item)
259{
260 (void)this_item;
261 switch (action)
262 {
263 case ACTION_EXIT_MENUITEM: /* on exit */
264#ifndef SIMULATOR
265 dac_line_in(global_settings.line_in);
266#endif
267 break;
268 }
269 return action;
270}
271MENUITEM_SETTING(line_in, &global_settings.line_in, linein_callback);
272#endif
273#ifdef CONFIG_CHARGING
274MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
275#endif
276
277MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), 0,
278#ifndef SIMULATOR
279 &battery_menu,
280#endif
281#ifndef HAVE_MMC
282 &disk_menu,
283#endif
284#ifdef CONFIG_RTC
285 &time_menu,
286#endif
287 &poweroff,
288 &sleep_timer_call,
289#ifdef HAVE_ALARM_MOD
290 &alarm_screen_call,
291#endif
292 &limits_menu,
293#if CONFIG_CODEC == MAS3507D
294 &line_in,
295#endif
296#ifdef CONFIG_CHARGING
297 &car_adapter_mode,
298#endif
299 );
300
301/* SYSTEM MENU */
302/***********************************/
303
304
305/***********************************/
306/* BOOKMARK MENU */
307static int bmark_callback(int action,const struct menu_item_ex *this_item)
308{
309 (void)this_item;
310 switch (action)
311 {
312 case ACTION_EXIT_MENUITEM: /* on exit */
313 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
314 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
315 {
316 if(global_settings.usemrb == BOOKMARK_NO)
317 global_settings.usemrb = BOOKMARK_YES;
318
319 }
320 break;
321 }
322 return action;
323}
324MENUITEM_SETTING(autocreatebookmark,
325 &global_settings.autocreatebookmark, bmark_callback);
326MENUITEM_SETTING(autoloadbookmark, &global_settings.autoloadbookmark, NULL);
327MENUITEM_SETTING(usemrb, &global_settings.usemrb, NULL);
328MAKE_MENU(bookmark_settings_menu, ID2P(LANG_BOOKMARK_SETTINGS), 0,
329 &autocreatebookmark, &autoloadbookmark, &usemrb);
330/* BOOKMARK MENU */
331/***********************************/
332
333/***********************************/
334/* VOICE MENU */
335static int talk_callback(int action,const struct menu_item_ex *this_item);
336MENUITEM_SETTING(talk_menu, &global_settings.talk_menu, NULL);
337MENUITEM_SETTING(talk_dir, &global_settings.talk_dir, talk_callback);
338MENUITEM_SETTING(talk_file_item, &global_settings.talk_file, talk_callback);
339static int talk_callback(int action,const struct menu_item_ex *this_item)
340{
341 static int oldval = 0;
342 switch (action)
343 {
344 case ACTION_ENTER_MENUITEM:
345 oldval = global_settings.talk_file;
346 break;
347 case ACTION_EXIT_MENUITEM:
348#if CONFIG_CODEC == SWCODEC
349 audio_set_crossfade(global_settings.crossfade);
350#endif
351 if (this_item == &talk_dir)
352 break;
353 if (oldval != 3 && global_settings.talk_file == 3)
354 { /* force reload if newly talking thumbnails,
355 because the clip presence is cached only if enabled */
356 reload_directory();
357 }
358 break;
359 }
360 return action;
361}
362MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0,
363 &talk_menu, &talk_dir, &talk_file_item);
364/* VOICE MENU */
365/***********************************/
366
367/***********************************/
368/* SETTINGS MENU */
369static int language_browse(void)
370{
371 return (int)rockbox_browse(LANG_DIR, SHOW_LNG);
372}
373MENUITEM_FUNCTION(browse_langs, ID2P(LANG_LANGUAGE), language_browse, NULL);
30 374
31#include "settings_menu.h" 375MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0,
32MENUITEM_FUNCTION(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 376 &playback_menu_item, &file_menu, &display_menu, &system_menu,
33 (menu_function)settings_menu, NULL); 377 &bookmark_settings_menu, &browse_langs, &voice_settings_menu );
378/* SETTINGS MENU */
379/***********************************/