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"
48 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
54 #include "skin_engine/skin_buffer.h"
56 static const struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
58 /***********************************/
59 /* MANAGE SETTINGS MENU */
61 static int reset_settings(void)
63 static const char *lines
[]={ID2P(LANG_RESET_ASK
)};
64 static const char *yes_lines
[]={
66 ID2P(LANG_RESET_DONE_CLEAR
)
68 static const char *no_lines
[]={
72 static const struct text_message message
={lines
, 1};
73 static const struct text_message yes_message
={yes_lines
, 2};
74 static const struct text_message no_message
={no_lines
, 2};
76 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
82 settings_apply_skins();
91 static int write_settings_file(void* param
)
93 return settings_save_config((intptr_t)param
);
96 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
97 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
98 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
99 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
100 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
101 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
102 MENUITEM_FUNCTION(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
103 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
104 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
105 reset_settings
, NULL
, NULL
, Icon_NOICON
);
107 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
108 &browse_configs
, &reset_settings_item
,
109 &save_settings_item
, &save_sound_item
, &save_theme_item
);
110 /* MANAGE SETTINGS MENU */
111 /**********************************/
113 /***********************************/
116 static bool show_credits(void)
118 if (plugin_load(VIEWERS_DIR
"/credits.rock",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 */
150 INFO_SKIN_USAGE
, /* ram usage of the skins */
155 static const char* info_getname(int selected_item
, void *data
,
156 char *buffer
, size_t buffer_len
)
158 struct info_data
*info
= (struct info_data
*)data
;
163 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
164 #ifdef HAVE_MULTIVOLUME
165 if (fat_ismounted(1))
166 fat_size(1, &info
->size2
, &info
->free2
);
170 info
->new_data
= false;
172 switch (selected_item
)
175 snprintf(buffer
, buffer_len
, "%s: %s",
176 str(LANG_VERSION
), rbversion
);
179 case INFO_BUFFER
: /* buffer */
181 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
182 output_dyn_value(s1
, sizeof(s1
), kib
, kbyte_units
, true);
183 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_BUFFER_STAT
), s1
);
186 case INFO_BATTERY
: /* battery */
187 #if CONFIG_CHARGING == CHARGING_SIMPLE
188 /* Only know if plugged */
189 if (charger_inserted())
190 return str(LANG_BATTERY_CHARGE
);
192 #elif CONFIG_CHARGING >= CHARGING_MONITOR
193 #ifdef ARCHOS_RECORDER
194 /* Report the particular algorithm state */
195 if (charge_state
== CHARGING
)
196 return str(LANG_BATTERY_CHARGE
);
197 else if (charge_state
== TOPOFF
)
198 return str(LANG_BATTERY_TOPOFF_CHARGE
);
199 else if (charge_state
== TRICKLE
)
200 return str(LANG_BATTERY_TRICKLE_CHARGE
);
202 #else /* !ARCHOS_RECORDER */
203 /* Go by what power management reports */
204 if (charging_state())
205 return str(LANG_BATTERY_CHARGE
);
207 #endif /* ARCHOS_RECORDER */
208 #endif /* CONFIG_CHARGING = */
209 if (battery_level() >= 0)
210 snprintf(buffer
, buffer_len
, str(LANG_BATTERY_TIME
),
211 battery_level(), battery_time() / 60, battery_time() % 60);
215 case INFO_DISK1
: /* disk usage 1 */
216 #ifdef HAVE_MULTIVOLUME
217 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
218 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
219 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
222 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
223 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
226 case INFO_DISK2
: /* disk usage 2 */
227 #ifdef HAVE_MULTIVOLUME
230 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
231 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
232 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
237 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
238 str(LANG_NOT_PRESENT
));
241 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
242 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
245 case INFO_SKIN_USAGE
:
246 output_dyn_value(s1
, sizeof s1
, skin_buffer_usage(), byte_units
, true);
247 output_dyn_value(s2
, sizeof s2
, skin_buffer_usage()
248 +skin_buffer_freespace(), byte_units
, true);
249 snprintf(buffer
, buffer_len
, "%s %s / %s", str(LANG_SKIN_RAM_USAGE
), s1
, s2
);
255 static int info_speak_item(int selected_item
, void * data
)
257 struct info_data
*info
= (struct info_data
*)data
;
259 switch (selected_item
)
261 case INFO_VERSION
: /* version */
262 talk_id(LANG_VERSION
, false);
263 talk_spell(rbversion
, true);
266 case INFO_BUFFER
: /* buffer */
268 talk_id(LANG_BUFFER_STAT
, false);
269 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
270 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
273 case INFO_BATTERY
: /* battery */
274 #if CONFIG_CHARGING == CHARGING_SIMPLE
275 /* Only know if plugged */
276 if (charger_inserted())
277 talk_id(LANG_BATTERY_CHARGE
, true);
279 #elif CONFIG_CHARGING >= CHARGING_MONITOR
280 #ifdef ARCHOS_RECORDER
281 /* Report the particular algorithm state */
282 if (charge_state
== CHARGING
)
283 talk_id(LANG_BATTERY_CHARGE
, true);
284 else if (charge_state
== TOPOFF
)
285 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
286 else if (charge_state
== TRICKLE
)
287 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
289 #else /* !ARCHOS_RECORDER */
290 /* Go by what power management reports */
291 if (charging_state())
292 talk_id(LANG_BATTERY_CHARGE
, true);
294 #endif /* ARCHOS_RECORDER */
295 #endif /* CONFIG_CHARGING = */
296 if (battery_level() >= 0)
298 talk_id(LANG_BATTERY_TIME
, false);
299 talk_value(battery_level(), UNIT_PERCENT
, true);
300 talk_value(battery_time() *60, UNIT_TIME
, true);
302 else talk_id(VOICE_BLANK
, false);
304 case INFO_DISK1
: /* disk 1 */
305 #ifdef HAVE_MULTIVOLUME
306 talk_ids(false, LANG_DISK_NAME_INTERNAL
, LANG_DISK_FREE_INFO
);
307 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
308 talk_id(LANG_DISK_SIZE_INFO
, true);
309 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
311 talk_id(LANG_DISK_FREE_INFO
, false);
312 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
315 case INFO_DISK2
: /* disk 2 */
316 #ifdef HAVE_MULTIVOLUME
317 talk_id(LANG_DISK_NAME_MMC
, false);
320 talk_id(LANG_DISK_FREE_INFO
, true);
321 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
322 talk_id(LANG_DISK_SIZE_INFO
, true);
323 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
325 else talk_id(LANG_NOT_PRESENT
, true);
327 talk_id(LANG_DISK_SIZE_INFO
, false);
328 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
331 case INFO_SKIN_USAGE
:
332 talk_id(LANG_SKIN_RAM_USAGE
, false);
333 output_dyn_value(NULL
, 0, skin_buffer_usage(), byte_units
, true);
340 static int info_action_callback(int action
, struct gui_synclist
*lists
)
342 if (action
== ACTION_STD_CANCEL
)
344 else if ((action
== ACTION_STD_OK
)
346 || action
== SYS_FS_CHANGED
350 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
351 struct info_data
*info
= (struct info_data
*)lists
->data
;
353 info
->new_data
= true;
354 splash(0, ID2P(LANG_SCANNING_DISK
));
355 for (i
= 0; i
< NUM_VOLUMES
; i
++)
358 if (fat_ismounted(i
))
360 fat_recalc_free(IF_MV(i
));
365 gui_synclist_speak_item(lists
);
366 return ACTION_REDRAW
;
370 static bool show_info(void)
372 struct info_data data
= {.new_data
= true };
373 struct simplelist_info info
;
374 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
375 info
.hide_selection
= !global_settings
.talk_menu
;
376 if (info
.hide_selection
)
377 info
.scroll_all
= true;
378 info
.get_name
= info_getname
;
379 if(global_settings
.talk_menu
)
380 info
.get_talk
= info_speak_item
;
381 info
.action_callback
= info_action_callback
;
382 return simplelist_show_list(&info
);
384 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
385 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
389 static const char* sleep_timer_formatter(char* buffer
, size_t buffer_size
,
390 int value
, const char* unit
)
397 minutes
= value
- (hours
* 60);
398 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
401 return str(LANG_OFF
);
405 static void sleep_timer_set(int minutes
)
407 set_sleep_timer(minutes
* 60);
410 static int sleep_timer(void)
412 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
413 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
414 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
419 int time_screen(void* ignored
);
420 MENUITEM_FUNCTION(timedate_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_TIME_MENU
),
421 time_screen
, NULL
, NULL
, Icon_Menu_setting
);
423 /* This item is in the time/date screen if there is a RTC */
424 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
425 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
426 setting to the user */
428 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_CREDITS
),
429 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
430 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
431 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
432 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
433 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
435 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_System_menu
,
439 &show_info_item
, &show_credits_item
, &show_runtime_item
,
445 /***********************************/
447 /***********************************/
451 #ifdef HAVE_LCD_CHARCELLS
452 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
457 case ACTION_ENTER_MENUITEM
:
458 status_set_param(true);
460 case ACTION_EXIT_MENUITEM
:
461 status_set_param(false);
467 #define mainmenu_callback NULL
469 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
470 Icon_Submenu_Entered
,
473 &settings_menu_item
, &theme_menu
,
474 #ifdef HAVE_RECORDING
480 /***********************************/