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"
46 #include "debug_menu.h"
50 #include "skin_buffer.h"
52 static const struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
54 /***********************************/
55 /* MANAGE SETTINGS MENU */
57 static int reset_settings(void)
59 static const char *lines
[]={ID2P(LANG_RESET_ASK
)};
60 static const char *yes_lines
[]={
62 ID2P(LANG_RESET_DONE_CLEAR
)
64 static const char *no_lines
[]={
68 static const struct text_message message
={lines
, 1};
69 static const struct text_message yes_message
={yes_lines
, 2};
70 static const struct text_message no_message
={no_lines
, 2};
72 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
78 settings_apply_skins();
87 static int write_settings_file(void* param
)
89 return settings_save_config((intptr_t)param
);
92 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
93 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
94 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
95 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
96 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
97 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
98 MENUITEM_FUNCTION(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
99 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
100 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
101 reset_settings
, NULL
, NULL
, Icon_NOICON
);
103 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
104 &browse_configs
, &reset_settings_item
,
105 &save_settings_item
, &save_sound_item
, &save_theme_item
);
106 /* MANAGE SETTINGS MENU */
107 /**********************************/
109 /***********************************/
113 static bool show_credits(void)
115 char credits
[MAX_PATH
] = { '\0' };
116 snprintf(credits
, MAX_PATH
, "%s/credits.rock", VIEWERS_DIR
);
117 if (plugin_load(credits
, 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 */
153 static const char* info_getname(int selected_item
, void *data
,
154 char *buffer
, size_t buffer_len
)
156 struct info_data
*info
= (struct info_data
*)data
;
158 #if defined(HAVE_MULTIVOLUME)
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
= audio_buffer_size() / 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);
213 return "Battery n/a"; /* translating worth it? */
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
);
249 static int info_speak_item(int selected_item
, void * data
)
251 struct info_data
*info
= (struct info_data
*)data
;
253 switch (selected_item
)
255 case INFO_VERSION
: /* version */
256 talk_id(LANG_VERSION
, false);
257 talk_spell(rbversion
, true);
260 case INFO_BUFFER
: /* buffer */
262 talk_id(LANG_BUFFER_STAT
, false);
263 long kib
= audio_buffer_size() / 1024; /* to KiB */
264 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
267 case INFO_BATTERY
: /* battery */
268 #if CONFIG_CHARGING == CHARGING_SIMPLE
269 /* Only know if plugged */
270 if (charger_inserted())
271 talk_id(LANG_BATTERY_CHARGE
, true);
273 #elif CONFIG_CHARGING >= CHARGING_MONITOR
274 #ifdef ARCHOS_RECORDER
275 /* Report the particular algorithm state */
276 if (charge_state
== CHARGING
)
277 talk_id(LANG_BATTERY_CHARGE
, true);
278 else if (charge_state
== TOPOFF
)
279 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
280 else if (charge_state
== TRICKLE
)
281 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
283 #else /* !ARCHOS_RECORDER */
284 /* Go by what power management reports */
285 if (charging_state())
286 talk_id(LANG_BATTERY_CHARGE
, true);
288 #endif /* ARCHOS_RECORDER */
289 #endif /* CONFIG_CHARGING = */
290 if (battery_level() >= 0)
292 int time_left
= battery_time();
293 talk_id(LANG_BATTERY_TIME
, false);
294 talk_value(battery_level(), UNIT_PERCENT
, true);
296 talk_value(time_left
* 60, UNIT_TIME
, true);
298 else talk_id(VOICE_BLANK
, false);
300 case INFO_DISK1
: /* disk 1 */
301 #ifdef HAVE_MULTIVOLUME
302 talk_ids(false, LANG_DISK_NAME_INTERNAL
, LANG_DISK_FREE_INFO
);
303 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
304 talk_id(LANG_DISK_SIZE_INFO
, true);
305 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
307 talk_id(LANG_DISK_FREE_INFO
, false);
308 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
311 case INFO_DISK2
: /* disk 2 */
312 #ifdef HAVE_MULTIVOLUME
313 talk_id(LANG_DISK_NAME_MMC
, false);
316 talk_id(LANG_DISK_FREE_INFO
, true);
317 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
318 talk_id(LANG_DISK_SIZE_INFO
, true);
319 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
321 else talk_id(LANG_NOT_PRESENT
, true);
323 talk_id(LANG_DISK_SIZE_INFO
, false);
324 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
332 static int info_action_callback(int action
, struct gui_synclist
*lists
)
334 if (action
== ACTION_STD_CANCEL
)
336 else if ((action
== ACTION_STD_OK
)
338 || action
== SYS_FS_CHANGED
342 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
343 struct info_data
*info
= (struct info_data
*)lists
->data
;
345 info
->new_data
= true;
346 splash(0, ID2P(LANG_SCANNING_DISK
));
347 for (i
= 0; i
< NUM_VOLUMES
; i
++)
350 if (fat_ismounted(i
))
352 fat_recalc_free(IF_MV(i
));
357 gui_synclist_speak_item(lists
);
358 return ACTION_REDRAW
;
362 static bool show_info(void)
364 struct info_data data
= {.new_data
= true };
365 struct simplelist_info info
;
366 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
367 info
.hide_selection
= !global_settings
.talk_menu
;
368 if (info
.hide_selection
)
369 info
.scroll_all
= true;
370 info
.get_name
= info_getname
;
371 if(global_settings
.talk_menu
)
372 info
.get_talk
= info_speak_item
;
373 info
.action_callback
= info_action_callback
;
374 return simplelist_show_list(&info
);
376 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
377 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
380 int time_screen(void* ignored
);
381 MENUITEM_FUNCTION(timedate_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_TIME_MENU
),
382 time_screen
, NULL
, NULL
, Icon_Menu_setting
);
385 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_CREDITS
),
386 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
387 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
388 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
389 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
390 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
392 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_System_menu
,
393 &show_info_item
, &show_credits_item
,
394 &show_runtime_item
, &debug_menu_item
);
396 /***********************************/
398 /***********************************/
402 #ifdef HAVE_LCD_CHARCELLS
403 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
408 case ACTION_ENTER_MENUITEM
:
409 status_set_param(true);
411 case ACTION_EXIT_MENUITEM
:
412 status_set_param(false);
418 #define mainmenu_callback NULL
420 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
421 Icon_Submenu_Entered
,
424 &settings_menu_item
, &theme_menu
,
425 #ifdef HAVE_RECORDING
434 /***********************************/