1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
31 #include "powermgmt.h"
34 #include "exported_menus.h"
38 #include "recording.h"
47 #include "debug_menu.h"
51 #include "skin_buffer.h"
53 static const struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
55 /***********************************/
56 /* MANAGE SETTINGS MENU */
58 static int reset_settings(void)
60 static const char *lines
[]={ID2P(LANG_RESET_ASK
)};
61 static const char *yes_lines
[]={
63 ID2P(LANG_RESET_DONE_CLEAR
)
65 static const char *no_lines
[]={
69 static const struct text_message message
={lines
, 1};
70 static const struct text_message yes_message
={yes_lines
, 2};
71 static const struct text_message no_message
={no_lines
, 2};
73 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
79 settings_apply_skins();
88 static int write_settings_file(void* param
)
90 return settings_save_config((intptr_t)param
);
93 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
94 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
95 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
96 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
97 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
98 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
99 MENUITEM_FUNCTION(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
100 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
101 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
102 reset_settings
, NULL
, NULL
, Icon_NOICON
);
104 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
105 &browse_configs
, &reset_settings_item
,
106 &save_settings_item
, &save_sound_item
, &save_theme_item
);
107 /* MANAGE SETTINGS MENU */
108 /**********************************/
110 /***********************************/
114 static bool show_credits(void)
116 char credits
[MAX_PATH
] = { '\0' };
117 snprintf(credits
, MAX_PATH
, "%s/credits.rock", VIEWERS_DIR
);
118 if (plugin_load(credits
, NULL
) != PLUGIN_OK
)
120 /* show the rockbox logo and version untill a button is pressed */
122 while (IS_SYSEVENT(get_action(CONTEXT_STD
, TIMEOUT_BLOCK
)))
128 #ifdef HAVE_LCD_CHARCELLS
129 #define SIZE_FMT "%s%s"
131 #define SIZE_FMT "%s %s"
139 #ifdef HAVE_MULTIVOLUME
147 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
148 INFO_DISK2
, /* free space or external capacity/free on hotswap */
151 INFO_SKIN_USAGE
, /* ram usage of the skins */
157 static const char* info_getname(int selected_item
, void *data
,
158 char *buffer
, size_t buffer_len
)
160 struct info_data
*info
= (struct info_data
*)data
;
162 #if defined(HAVE_MULTIVOLUME) || !defined(APPLICATION)
167 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
168 #ifdef HAVE_MULTIVOLUME
169 if (fat_ismounted(1))
170 fat_size(1, &info
->size2
, &info
->free2
);
174 info
->new_data
= false;
176 switch (selected_item
)
179 snprintf(buffer
, buffer_len
, "%s: %s",
180 str(LANG_VERSION
), rbversion
);
183 case INFO_BUFFER
: /* buffer */
185 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
186 output_dyn_value(s1
, sizeof(s1
), kib
, kbyte_units
, true);
187 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_BUFFER_STAT
), s1
);
190 case INFO_BATTERY
: /* battery */
191 #if CONFIG_CHARGING == CHARGING_SIMPLE
192 /* Only know if plugged */
193 if (charger_inserted())
194 return str(LANG_BATTERY_CHARGE
);
196 #elif CONFIG_CHARGING >= CHARGING_MONITOR
197 #ifdef ARCHOS_RECORDER
198 /* Report the particular algorithm state */
199 if (charge_state
== CHARGING
)
200 return str(LANG_BATTERY_CHARGE
);
201 else if (charge_state
== TOPOFF
)
202 return str(LANG_BATTERY_TOPOFF_CHARGE
);
203 else if (charge_state
== TRICKLE
)
204 return str(LANG_BATTERY_TRICKLE_CHARGE
);
206 #else /* !ARCHOS_RECORDER */
207 /* Go by what power management reports */
208 if (charging_state())
209 return str(LANG_BATTERY_CHARGE
);
211 #endif /* ARCHOS_RECORDER */
212 #endif /* CONFIG_CHARGING = */
213 if (battery_level() >= 0)
214 snprintf(buffer
, buffer_len
, str(LANG_BATTERY_TIME
),
215 battery_level(), battery_time() / 60, battery_time() % 60);
219 case INFO_DISK1
: /* disk usage 1 */
220 #ifdef HAVE_MULTIVOLUME
221 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
222 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
223 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
226 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
227 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
230 case INFO_DISK2
: /* disk usage 2 */
231 #ifdef HAVE_MULTIVOLUME
234 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
235 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
236 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
241 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
242 str(LANG_NOT_PRESENT
));
245 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
246 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
250 case INFO_SKIN_USAGE
:
251 output_dyn_value(s1
, sizeof s1
, skin_buffer_usage(), byte_units
, true);
252 output_dyn_value(s2
, sizeof s2
, skin_buffer_usage()
253 +skin_buffer_freespace(), byte_units
, true);
254 snprintf(buffer
, buffer_len
, "%s %s / %s", str(LANG_SKIN_RAM_USAGE
), s1
, s2
);
261 static int info_speak_item(int selected_item
, void * data
)
263 struct info_data
*info
= (struct info_data
*)data
;
265 switch (selected_item
)
267 case INFO_VERSION
: /* version */
268 talk_id(LANG_VERSION
, false);
269 talk_spell(rbversion
, true);
272 case INFO_BUFFER
: /* buffer */
274 talk_id(LANG_BUFFER_STAT
, false);
275 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
276 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
279 case INFO_BATTERY
: /* battery */
280 #if CONFIG_CHARGING == CHARGING_SIMPLE
281 /* Only know if plugged */
282 if (charger_inserted())
283 talk_id(LANG_BATTERY_CHARGE
, true);
285 #elif CONFIG_CHARGING >= CHARGING_MONITOR
286 #ifdef ARCHOS_RECORDER
287 /* Report the particular algorithm state */
288 if (charge_state
== CHARGING
)
289 talk_id(LANG_BATTERY_CHARGE
, true);
290 else if (charge_state
== TOPOFF
)
291 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
292 else if (charge_state
== TRICKLE
)
293 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
295 #else /* !ARCHOS_RECORDER */
296 /* Go by what power management reports */
297 if (charging_state())
298 talk_id(LANG_BATTERY_CHARGE
, true);
300 #endif /* ARCHOS_RECORDER */
301 #endif /* CONFIG_CHARGING = */
302 if (battery_level() >= 0)
304 talk_id(LANG_BATTERY_TIME
, false);
305 talk_value(battery_level(), UNIT_PERCENT
, true);
306 talk_value(battery_time() *60, UNIT_TIME
, true);
308 else talk_id(VOICE_BLANK
, false);
310 case INFO_DISK1
: /* disk 1 */
311 #ifdef HAVE_MULTIVOLUME
312 talk_ids(false, LANG_DISK_NAME_INTERNAL
, LANG_DISK_FREE_INFO
);
313 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
314 talk_id(LANG_DISK_SIZE_INFO
, true);
315 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
317 talk_id(LANG_DISK_FREE_INFO
, false);
318 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
321 case INFO_DISK2
: /* disk 2 */
322 #ifdef HAVE_MULTIVOLUME
323 talk_id(LANG_DISK_NAME_MMC
, false);
326 talk_id(LANG_DISK_FREE_INFO
, true);
327 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
328 talk_id(LANG_DISK_SIZE_INFO
, true);
329 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
331 else talk_id(LANG_NOT_PRESENT
, true);
333 talk_id(LANG_DISK_SIZE_INFO
, false);
334 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
338 case INFO_SKIN_USAGE
:
339 talk_id(LANG_SKIN_RAM_USAGE
, false);
340 output_dyn_value(NULL
, 0, skin_buffer_usage(), byte_units
, true);
348 static int info_action_callback(int action
, struct gui_synclist
*lists
)
350 if (action
== ACTION_STD_CANCEL
)
352 else if ((action
== ACTION_STD_OK
)
354 || action
== SYS_FS_CHANGED
358 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
359 struct info_data
*info
= (struct info_data
*)lists
->data
;
361 info
->new_data
= true;
362 splash(0, ID2P(LANG_SCANNING_DISK
));
363 for (i
= 0; i
< NUM_VOLUMES
; i
++)
366 if (fat_ismounted(i
))
368 fat_recalc_free(IF_MV(i
));
373 gui_synclist_speak_item(lists
);
374 return ACTION_REDRAW
;
378 static bool show_info(void)
380 struct info_data data
= {.new_data
= true };
381 struct simplelist_info info
;
382 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
383 info
.hide_selection
= !global_settings
.talk_menu
;
384 if (info
.hide_selection
)
385 info
.scroll_all
= true;
386 info
.get_name
= info_getname
;
387 if(global_settings
.talk_menu
)
388 info
.get_talk
= info_speak_item
;
389 info
.action_callback
= info_action_callback
;
390 return simplelist_show_list(&info
);
392 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
393 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
397 static const char* sleep_timer_formatter(char* buffer
, size_t buffer_size
,
398 int value
, const char* unit
)
405 minutes
= value
- (hours
* 60);
406 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
409 return str(LANG_OFF
);
413 static void sleep_timer_set(int minutes
)
415 set_sleep_timer(minutes
* 60);
418 static int sleep_timer(void)
420 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
421 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
422 &sleep_timer_set
, 5, 0, 300, sleep_timer_formatter
);
427 int time_screen(void* ignored
);
428 MENUITEM_FUNCTION(timedate_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_TIME_MENU
),
429 time_screen
, NULL
, NULL
, Icon_Menu_setting
);
431 /* This item is in the time/date screen if there is a RTC */
432 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
433 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
434 setting to the user */
436 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_CREDITS
),
437 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
438 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
439 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
440 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
441 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
443 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_System_menu
,
447 &show_info_item
, &show_credits_item
, &show_runtime_item
,
453 /***********************************/
455 /***********************************/
459 #ifdef HAVE_LCD_CHARCELLS
460 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
465 case ACTION_ENTER_MENUITEM
:
466 status_set_param(true);
468 case ACTION_EXIT_MENUITEM
:
469 status_set_param(false);
475 #define mainmenu_callback NULL
477 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
478 Icon_Submenu_Entered
,
481 &settings_menu_item
, &theme_menu
,
482 #ifdef HAVE_RECORDING
488 /***********************************/