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
))
89 static int write_settings_file(void* param
)
91 return settings_save_config((intptr_t)param
);
94 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
95 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
96 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
97 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
98 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
99 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
100 MENUITEM_FUNCTION(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
101 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
102 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
103 reset_settings
, NULL
, NULL
, Icon_NOICON
);
105 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
106 &browse_configs
, &reset_settings_item
,
107 &save_settings_item
, &save_sound_item
, &save_theme_item
);
108 /* MANAGE SETTINGS MENU */
109 /**********************************/
111 /***********************************/
114 static bool show_credits(void)
116 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
118 /* show the rockbox logo and version untill a button is pressed */
120 while (IS_SYSEVENT(get_action(CONTEXT_STD
, TIMEOUT_BLOCK
)))
126 #ifdef HAVE_LCD_CHARCELLS
127 #define SIZE_FMT "%s%s"
129 #define SIZE_FMT "%s %s"
137 #ifdef HAVE_MULTIVOLUME
145 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
146 INFO_DISK2
, /* free space or external capacity/free on hotswap */
148 INFO_SKIN_USAGE
, /* ram usage of the skins */
153 static const unsigned char *kbyte_units
[] =
160 static const unsigned char *byte_units
[] =
167 static const char* info_getname(int selected_item
, void *data
,
168 char *buffer
, size_t buffer_len
)
170 struct info_data
*info
= (struct info_data
*)data
;
175 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
176 #ifdef HAVE_MULTIVOLUME
177 if (fat_ismounted(1))
178 fat_size(1, &info
->size2
, &info
->free2
);
182 info
->new_data
= false;
184 switch (selected_item
)
187 snprintf(buffer
, buffer_len
, "%s: %s",
188 str(LANG_VERSION
), appsversion
);
191 case INFO_BUFFER
: /* buffer */
193 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
194 output_dyn_value(s1
, sizeof(s1
), kib
, kbyte_units
, true);
195 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_BUFFER_STAT
), s1
);
198 case INFO_BATTERY
: /* battery */
199 #if CONFIG_CHARGING == CHARGING_SIMPLE
200 /* Only know if plugged */
201 if (charger_inserted())
202 return str(LANG_BATTERY_CHARGE
);
204 #elif CONFIG_CHARGING >= CHARGING_MONITOR
205 #ifdef ARCHOS_RECORDER
206 /* Report the particular algorithm state */
207 if (charge_state
== CHARGING
)
208 return str(LANG_BATTERY_CHARGE
);
209 else if (charge_state
== TOPOFF
)
210 return str(LANG_BATTERY_TOPOFF_CHARGE
);
211 else if (charge_state
== TRICKLE
)
212 return str(LANG_BATTERY_TRICKLE_CHARGE
);
214 #else /* !ARCHOS_RECORDER */
215 /* Go by what power management reports */
216 if (charging_state())
217 return str(LANG_BATTERY_CHARGE
);
219 #endif /* ARCHOS_RECORDER */
220 #endif /* CONFIG_CHARGING = */
221 if (battery_level() >= 0)
222 snprintf(buffer
, buffer_len
, str(LANG_BATTERY_TIME
),
223 battery_level(), battery_time() / 60, battery_time() % 60);
227 case INFO_DISK1
: /* disk usage 1 */
228 #ifdef HAVE_MULTIVOLUME
229 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
230 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
231 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
234 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
235 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
238 case INFO_DISK2
: /* disk usage 2 */
239 #ifdef HAVE_MULTIVOLUME
242 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
243 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
244 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
249 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
250 str(LANG_NOT_PRESENT
));
253 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
254 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
257 case INFO_SKIN_USAGE
:
258 output_dyn_value(s1
, sizeof s1
, skin_buffer_usage(), byte_units
, true);
259 output_dyn_value(s2
, sizeof s2
, skin_buffer_usage()
260 +skin_buffer_freespace(), byte_units
, true);
261 snprintf(buffer
, buffer_len
, "%s %s / %s", str(LANG_SKIN_RAM_USAGE
), s1
, s2
);
267 static int info_speak_item(int selected_item
, void * data
)
269 struct info_data
*info
= (struct info_data
*)data
;
271 switch (selected_item
)
273 case INFO_VERSION
: /* version */
274 talk_id(LANG_VERSION
, false);
275 talk_spell(appsversion
, true);
278 case INFO_BUFFER
: /* buffer */
280 talk_id(LANG_BUFFER_STAT
, false);
281 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
282 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
285 case INFO_BATTERY
: /* battery */
286 #if CONFIG_CHARGING == CHARGING_SIMPLE
287 /* Only know if plugged */
288 if (charger_inserted())
289 talk_id(LANG_BATTERY_CHARGE
, true);
291 #elif CONFIG_CHARGING >= CHARGING_MONITOR
292 #ifdef ARCHOS_RECORDER
293 /* Report the particular algorithm state */
294 if (charge_state
== CHARGING
)
295 talk_id(LANG_BATTERY_CHARGE
, true);
296 else if (charge_state
== TOPOFF
)
297 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
298 else if (charge_state
== TRICKLE
)
299 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
301 #else /* !ARCHOS_RECORDER */
302 /* Go by what power management reports */
303 if (charging_state())
304 talk_id(LANG_BATTERY_CHARGE
, true);
306 #endif /* ARCHOS_RECORDER */
307 #endif /* CONFIG_CHARGING = */
308 if (battery_level() >= 0)
310 talk_id(LANG_BATTERY_TIME
, false);
311 talk_value(battery_level(), UNIT_PERCENT
, true);
312 talk_value(battery_time() *60, UNIT_TIME
, true);
314 else talk_id(VOICE_BLANK
, false);
316 case INFO_DISK1
: /* disk 1 */
317 #ifdef HAVE_MULTIVOLUME
318 talk_id(LANG_DISK_NAME_INTERNAL
, false);
319 talk_id(LANG_DISK_FREE_INFO
, true);
320 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
321 talk_id(LANG_DISK_SIZE_INFO
, true);
322 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
324 talk_id(LANG_DISK_FREE_INFO
, false);
325 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
328 case INFO_DISK2
: /* disk 2 */
329 #ifdef HAVE_MULTIVOLUME
330 talk_id(LANG_DISK_NAME_MMC
, false);
333 talk_id(LANG_DISK_FREE_INFO
, true);
334 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
335 talk_id(LANG_DISK_SIZE_INFO
, true);
336 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
338 else talk_id(LANG_NOT_PRESENT
, true);
340 talk_id(LANG_DISK_SIZE_INFO
, false);
341 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
344 case INFO_SKIN_USAGE
:
345 talk_id(LANG_SKIN_RAM_USAGE
, false);
346 output_dyn_value(NULL
, 0, skin_buffer_usage(), byte_units
, true);
353 static int info_action_callback(int action
, struct gui_synclist
*lists
)
355 if (action
== ACTION_STD_CANCEL
)
357 else if ((action
== ACTION_STD_OK
)
358 #ifdef HAVE_MULTIVOLUME
359 || action
== SYS_HOTSWAP_INSERTED
360 || action
== SYS_HOTSWAP_EXTRACTED
365 struct info_data
*info
= (struct info_data
*)lists
->data
;
366 info
->new_data
= true;
367 splash(0, ID2P(LANG_SCANNING_DISK
));
368 fat_recalc_free(IF_MV(0));
369 #ifdef HAVE_MULTIVOLUME
370 if (fat_ismounted(1))
378 gui_synclist_speak_item(lists
);
379 return ACTION_REDRAW
;
383 static bool show_info(void)
385 struct info_data data
= {.new_data
= true };
386 struct simplelist_info info
;
387 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
388 info
.hide_selection
= !global_settings
.talk_menu
;
389 if (info
.hide_selection
)
390 info
.scroll_all
= true;
391 info
.get_name
= info_getname
;
392 if(global_settings
.talk_menu
)
393 info
.get_talk
= info_speak_item
;
394 info
.action_callback
= info_action_callback
;
395 return simplelist_show_list(&info
);
397 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
398 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
402 static const char* sleep_timer_formatter(char* buffer
, size_t buffer_size
,
403 int value
, const char* unit
)
410 minutes
= value
- (hours
* 60);
411 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
414 return str(LANG_OFF
);
418 static void sleep_timer_set(int minutes
)
420 set_sleep_timer(minutes
* 60);
423 static int sleep_timer(void)
425 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
426 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
427 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
432 int time_screen(void* ignored
);
433 MENUITEM_FUNCTION(timedate_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_TIME_MENU
), time_screen
,
434 NULL
, NULL
, Icon_Menu_setting
);
436 /* This item is in the time/date screen if there is a RTC */
437 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
438 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
439 setting to the user */
441 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_CREDITS
),
442 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
443 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
444 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
445 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
446 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
448 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
452 &show_info_item
, &show_credits_item
, &show_runtime_item
,
458 /***********************************/
460 /***********************************/
464 #ifdef HAVE_LCD_CHARCELLS
465 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
470 case ACTION_ENTER_MENUITEM
:
471 status_set_param(true);
473 case ACTION_EXIT_MENUITEM
:
474 status_set_param(false);
480 #define mainmenu_callback NULL
482 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
483 Icon_Submenu_Entered
,
486 &settings_menu_item
, &theme_menu
,
487 #ifdef HAVE_RECORDING
493 /***********************************/