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"
37 #include "recording.h"
46 #include "debug_menu.h"
47 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
53 #include "skin_engine/skin_buffer.h"
55 static const struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
57 /***********************************/
58 /* MANAGE SETTINGS MENU */
60 static int reset_settings(void)
62 static const char *lines
[]={ID2P(LANG_RESET_ASK
)};
63 static const char *yes_lines
[]={
65 ID2P(LANG_RESET_DONE_CLEAR
)
67 static const char *no_lines
[]={
71 static const struct text_message message
={lines
, 1};
72 static const struct text_message yes_message
={yes_lines
, 2};
73 static const struct text_message no_message
={no_lines
, 2};
75 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
81 settings_apply_skins();
90 static int write_settings_file(void* param
)
92 return settings_save_config((intptr_t)param
);
95 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
96 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
97 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
98 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
99 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
100 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
101 MENUITEM_FUNCTION(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
102 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
103 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
104 reset_settings
, NULL
, NULL
, Icon_NOICON
);
106 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
107 &browse_configs
, &reset_settings_item
,
108 &save_settings_item
, &save_sound_item
, &save_theme_item
);
109 /* MANAGE SETTINGS MENU */
110 /**********************************/
112 /***********************************/
115 static bool show_credits(void)
117 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
119 /* show the rockbox logo and version untill a button is pressed */
121 while (IS_SYSEVENT(get_action(CONTEXT_STD
, TIMEOUT_BLOCK
)))
127 #ifdef HAVE_LCD_CHARCELLS
128 #define SIZE_FMT "%s%s"
130 #define SIZE_FMT "%s %s"
138 #ifdef HAVE_MULTIVOLUME
146 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
147 INFO_DISK2
, /* free space or external capacity/free on hotswap */
149 INFO_SKIN_USAGE
, /* ram usage of the skins */
154 static const char* info_getname(int selected_item
, void *data
,
155 char *buffer
, size_t buffer_len
)
157 struct info_data
*info
= (struct info_data
*)data
;
162 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
163 #ifdef HAVE_MULTIVOLUME
164 if (fat_ismounted(1))
165 fat_size(1, &info
->size2
, &info
->free2
);
169 info
->new_data
= false;
171 switch (selected_item
)
174 snprintf(buffer
, buffer_len
, "%s: %s",
175 str(LANG_VERSION
), rbversion
);
178 case INFO_BUFFER
: /* buffer */
180 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
181 output_dyn_value(s1
, sizeof(s1
), kib
, kbyte_units
, true);
182 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_BUFFER_STAT
), s1
);
185 case INFO_BATTERY
: /* battery */
186 #if CONFIG_CHARGING == CHARGING_SIMPLE
187 /* Only know if plugged */
188 if (charger_inserted())
189 return str(LANG_BATTERY_CHARGE
);
191 #elif CONFIG_CHARGING >= CHARGING_MONITOR
192 #ifdef ARCHOS_RECORDER
193 /* Report the particular algorithm state */
194 if (charge_state
== CHARGING
)
195 return str(LANG_BATTERY_CHARGE
);
196 else if (charge_state
== TOPOFF
)
197 return str(LANG_BATTERY_TOPOFF_CHARGE
);
198 else if (charge_state
== TRICKLE
)
199 return str(LANG_BATTERY_TRICKLE_CHARGE
);
201 #else /* !ARCHOS_RECORDER */
202 /* Go by what power management reports */
203 if (charging_state())
204 return str(LANG_BATTERY_CHARGE
);
206 #endif /* ARCHOS_RECORDER */
207 #endif /* CONFIG_CHARGING = */
208 if (battery_level() >= 0)
209 snprintf(buffer
, buffer_len
, str(LANG_BATTERY_TIME
),
210 battery_level(), battery_time() / 60, battery_time() % 60);
214 case INFO_DISK1
: /* disk usage 1 */
215 #ifdef HAVE_MULTIVOLUME
216 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
217 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
218 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
221 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
222 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
225 case INFO_DISK2
: /* disk usage 2 */
226 #ifdef HAVE_MULTIVOLUME
229 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
230 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
231 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
236 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
237 str(LANG_NOT_PRESENT
));
240 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
241 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
244 case INFO_SKIN_USAGE
:
245 output_dyn_value(s1
, sizeof s1
, skin_buffer_usage(), byte_units
, true);
246 output_dyn_value(s2
, sizeof s2
, skin_buffer_usage()
247 +skin_buffer_freespace(), byte_units
, true);
248 snprintf(buffer
, buffer_len
, "%s %s / %s", str(LANG_SKIN_RAM_USAGE
), s1
, s2
);
254 static int info_speak_item(int selected_item
, void * data
)
256 struct info_data
*info
= (struct info_data
*)data
;
258 switch (selected_item
)
260 case INFO_VERSION
: /* version */
261 talk_id(LANG_VERSION
, false);
262 talk_spell(rbversion
, true);
265 case INFO_BUFFER
: /* buffer */
267 talk_id(LANG_BUFFER_STAT
, false);
268 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
269 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
272 case INFO_BATTERY
: /* battery */
273 #if CONFIG_CHARGING == CHARGING_SIMPLE
274 /* Only know if plugged */
275 if (charger_inserted())
276 talk_id(LANG_BATTERY_CHARGE
, true);
278 #elif CONFIG_CHARGING >= CHARGING_MONITOR
279 #ifdef ARCHOS_RECORDER
280 /* Report the particular algorithm state */
281 if (charge_state
== CHARGING
)
282 talk_id(LANG_BATTERY_CHARGE
, true);
283 else if (charge_state
== TOPOFF
)
284 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
285 else if (charge_state
== TRICKLE
)
286 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
288 #else /* !ARCHOS_RECORDER */
289 /* Go by what power management reports */
290 if (charging_state())
291 talk_id(LANG_BATTERY_CHARGE
, true);
293 #endif /* ARCHOS_RECORDER */
294 #endif /* CONFIG_CHARGING = */
295 if (battery_level() >= 0)
297 talk_id(LANG_BATTERY_TIME
, false);
298 talk_value(battery_level(), UNIT_PERCENT
, true);
299 talk_value(battery_time() *60, UNIT_TIME
, true);
301 else talk_id(VOICE_BLANK
, false);
303 case INFO_DISK1
: /* disk 1 */
304 #ifdef HAVE_MULTIVOLUME
305 talk_ids(false, LANG_DISK_NAME_INTERNAL
, LANG_DISK_FREE_INFO
);
306 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
307 talk_id(LANG_DISK_SIZE_INFO
, true);
308 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
310 talk_id(LANG_DISK_FREE_INFO
, false);
311 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
314 case INFO_DISK2
: /* disk 2 */
315 #ifdef HAVE_MULTIVOLUME
316 talk_id(LANG_DISK_NAME_MMC
, false);
319 talk_id(LANG_DISK_FREE_INFO
, true);
320 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
321 talk_id(LANG_DISK_SIZE_INFO
, true);
322 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
324 else talk_id(LANG_NOT_PRESENT
, true);
326 talk_id(LANG_DISK_SIZE_INFO
, false);
327 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
330 case INFO_SKIN_USAGE
:
331 talk_id(LANG_SKIN_RAM_USAGE
, false);
332 output_dyn_value(NULL
, 0, skin_buffer_usage(), byte_units
, true);
339 static int info_action_callback(int action
, struct gui_synclist
*lists
)
341 if (action
== ACTION_STD_CANCEL
)
343 else if ((action
== ACTION_STD_OK
)
344 #ifdef HAVE_MULTIVOLUME
345 || action
== SYS_HOTSWAP_INSERTED
346 || action
== SYS_HOTSWAP_EXTRACTED
351 struct info_data
*info
= (struct info_data
*)lists
->data
;
352 info
->new_data
= true;
353 splash(0, ID2P(LANG_SCANNING_DISK
));
354 fat_recalc_free(IF_MV(0));
355 #ifdef HAVE_MULTIVOLUME
356 if (fat_ismounted(1))
364 gui_synclist_speak_item(lists
);
365 return ACTION_REDRAW
;
369 static bool show_info(void)
371 struct info_data data
= {.new_data
= true };
372 struct simplelist_info info
;
373 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
374 info
.hide_selection
= !global_settings
.talk_menu
;
375 if (info
.hide_selection
)
376 info
.scroll_all
= true;
377 info
.get_name
= info_getname
;
378 if(global_settings
.talk_menu
)
379 info
.get_talk
= info_speak_item
;
380 info
.action_callback
= info_action_callback
;
381 return simplelist_show_list(&info
);
383 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
384 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
388 static const char* sleep_timer_formatter(char* buffer
, size_t buffer_size
,
389 int value
, const char* unit
)
396 minutes
= value
- (hours
* 60);
397 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
400 return str(LANG_OFF
);
404 static void sleep_timer_set(int minutes
)
406 set_sleep_timer(minutes
* 60);
409 static int sleep_timer(void)
411 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
412 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
413 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
418 int time_screen(void* ignored
);
419 MENUITEM_FUNCTION(timedate_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_TIME_MENU
),
420 time_screen
, NULL
, NULL
, Icon_Menu_setting
);
422 /* This item is in the time/date screen if there is a RTC */
423 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
424 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
425 setting to the user */
427 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_CREDITS
),
428 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
429 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
430 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
431 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
432 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
434 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_System_menu
,
438 &show_info_item
, &show_credits_item
, &show_runtime_item
,
444 /***********************************/
446 /***********************************/
450 #ifdef HAVE_LCD_CHARCELLS
451 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
456 case ACTION_ENTER_MENUITEM
:
457 status_set_param(true);
459 case ACTION_EXIT_MENUITEM
:
460 status_set_param(false);
466 #define mainmenu_callback NULL
468 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
469 Icon_Submenu_Entered
,
472 &settings_menu_item
, &theme_menu
,
473 #ifdef HAVE_RECORDING
479 /***********************************/