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 ****************************************************************************/
30 #include "powermgmt.h"
33 #include "exported_menus.h"
36 #include "recording.h"
46 #include "debug_menu.h"
47 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
54 static const struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
56 /***********************************/
57 /* MANAGE SETTINGS MENU */
59 static int reset_settings(void)
61 static const char *lines
[]={ID2P(LANG_RESET_ASK
)};
62 static const char *yes_lines
[]={
64 ID2P(LANG_RESET_DONE_CLEAR
)
66 static const char *no_lines
[]={
70 static const struct text_message message
={lines
, 1};
71 static const struct text_message yes_message
={yes_lines
, 2};
72 static const struct text_message no_message
={no_lines
, 2};
74 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
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 /***********************************/
113 static bool show_credits(void)
115 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
117 /* show the rockbox logo and version untill a button is pressed */
119 get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
124 #ifdef HAVE_LCD_CHARCELLS
125 #define SIZE_FMT "%s%s"
127 #define SIZE_FMT "%s %s"
135 #ifdef HAVE_MULTIVOLUME
143 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
144 INFO_DISK2
, /* free space or external capacity/free on hotswap */
157 static const unsigned char *kbyte_units
[] =
164 static char* info_getname(int selected_item
, void *data
,
165 char *buffer
, size_t buffer_len
)
167 struct info_data
*info
= (struct info_data
*)data
;
172 #ifdef HAVE_MULTIVOLUME
177 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
178 #ifdef HAVE_MULTIVOLUME
179 if (fat_ismounted(1))
180 fat_size(1, &info
->size2
, &info
->free2
);
184 info
->new_data
= false;
186 switch (selected_item
)
189 snprintf(buffer
, buffer_len
, "%s: %s",
190 str(LANG_VERSION
), appsversion
);
197 snprintf(buffer
, buffer_len
, "%02d:%02d:%02d %s",
198 global_settings
.timeformat
== 0 ? tm
->tm_hour
:
199 ((tm
->tm_hour
+ 11) % 12) + 1,
202 global_settings
.timeformat
== 0 ? "" :
203 tm
->tm_hour
>11 ? "P" : "A");
207 strncpy(buffer
, "--:--:--", buffer_len
);
214 snprintf(buffer
, buffer_len
, "%s %d %d",
215 str(LANG_MONTH_JANUARY
+ tm
->tm_mon
),
221 strncpy(buffer
, str(LANG_UNKNOWN
), buffer_len
);
225 case INFO_BUFFER
: /* buffer */
227 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
228 output_dyn_value(s1
, sizeof(s1
), kib
, kbyte_units
, true);
229 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_BUFFER_STAT
), s1
);
232 case INFO_BATTERY
: /* battery */
233 #if CONFIG_CHARGING == CHARGING_SIMPLE
234 if (charger_input_state
== CHARGER
)
235 return (char *)str(LANG_BATTERY_CHARGE
);
237 #elif CONFIG_CHARGING >= CHARGING_MONITOR
238 if (charge_state
== CHARGING
)
239 return (char *)str(LANG_BATTERY_CHARGE
);
241 #if CONFIG_CHARGING == CHARGING_CONTROL
242 if (charge_state
== TOPOFF
)
243 return (char *)str(LANG_BATTERY_TOPOFF_CHARGE
);
246 if (charge_state
== TRICKLE
)
247 return (char *)str(LANG_BATTERY_TRICKLE_CHARGE
);
250 if (battery_level() >= 0)
251 snprintf(buffer
, buffer_len
, (char *)str(LANG_BATTERY_TIME
),
252 battery_level(), battery_time() / 60, battery_time() % 60);
256 case INFO_DISK1
: /* disk usage 1 */
257 #ifdef HAVE_MULTIVOLUME
258 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
259 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
260 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
263 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
264 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
267 case INFO_DISK2
: /* disk usage 2 */
268 #ifdef HAVE_MULTIVOLUME
271 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
272 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
273 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
278 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
279 str(LANG_NOT_PRESENT
));
282 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
283 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
287 case INFO_ALBUMART
: /* album art dimenstions */
288 if (gui_sync_wps_uses_albumart())
290 snprintf(buffer
, buffer_len
, "%s %dx%d", str(LANG_ALBUMART
),
291 gui_wps
[0].data
->albumart_max_width
,
292 gui_wps
[0].data
->albumart_max_height
);
296 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_ALBUMART
),
297 str(LANG_SET_BOOL_NO
));
304 static int info_speak_item(int selected_item
, void * data
)
306 struct info_data
*info
= (struct info_data
*)data
;
312 switch (selected_item
)
314 case INFO_VERSION
: /* version */
315 talk_id(LANG_VERSION
, false);
316 talk_spell(appsversion
, true);
321 talk_id(VOICE_CURRENT_TIME
, false);
328 talk_id(LANG_UNKNOWN
, true);
335 talk_date(get_time(), true);
339 talk_id(LANG_UNKNOWN
, true);
343 case INFO_BUFFER
: /* buffer */
345 talk_id(LANG_BUFFER_STAT
, false);
346 long kib
= (audiobufend
- audiobuf
) / 1024; /* to KiB */
347 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
350 case INFO_BATTERY
: /* battery */
351 #if CONFIG_CHARGING == CHARGING_SIMPLE
352 if (charger_input_state
== CHARGER
)
353 talk_id(LANG_BATTERY_CHARGE
, true);
355 #elif CONFIG_CHARGING >= CHARGING_MONITOR
356 if (charge_state
== CHARGING
)
357 talk_id(LANG_BATTERY_CHARGE
, true);
359 #if CONFIG_CHARGING == CHARGING_CONTROL
360 if (charge_state
== TOPOFF
)
361 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
364 if (charge_state
== TRICKLE
)
365 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
368 if (battery_level() >= 0)
370 talk_id(LANG_BATTERY_TIME
, false);
371 talk_value(battery_level(), UNIT_PERCENT
, true);
372 talk_value(battery_time() *60, UNIT_TIME
, true);
374 else talk_id(VOICE_BLANK
, false);
376 case INFO_DISK1
: /* disk 1 */
377 #ifdef HAVE_MULTIVOLUME
378 talk_id(LANG_DISK_NAME_INTERNAL
, false);
379 talk_id(LANG_DISK_FREE_INFO
, true);
380 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
381 talk_id(LANG_DISK_SIZE_INFO
, true);
382 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
384 talk_id(LANG_DISK_FREE_INFO
, false);
385 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
388 case INFO_DISK2
: /* disk 2 */
389 #ifdef HAVE_MULTIVOLUME
390 talk_id(LANG_DISK_NAME_MMC
, false);
393 talk_id(LANG_DISK_FREE_INFO
, true);
394 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
395 talk_id(LANG_DISK_SIZE_INFO
, true);
396 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
398 else talk_id(LANG_NOT_PRESENT
, true);
400 talk_id(LANG_DISK_SIZE_INFO
, false);
401 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
405 case INFO_ALBUMART
: /* album art dimenstions */
406 if (gui_sync_wps_uses_albumart())
408 talk_id(LANG_ALBUMART
, false);
409 talk_value(gui_wps
[0].data
->albumart_max_width
, UNIT_PIXEL
, true);
410 talk_value(gui_wps
[0].data
->albumart_max_height
, UNIT_PIXEL
, true);
414 talk_id(LANG_ALBUMART
, false);
415 talk_id(LANG_SET_BOOL_NO
, true);
422 static int info_action_callback(int action
, struct gui_synclist
*lists
)
424 if (action
== ACTION_STD_CANCEL
)
426 else if ((action
== ACTION_STD_OK
)
427 #ifdef HAVE_MULTIVOLUME
428 || action
== SYS_HOTSWAP_INSERTED
429 || action
== SYS_HOTSWAP_EXTRACTED
434 struct info_data
*info
= (struct info_data
*)lists
->data
;
435 info
->new_data
= true;
436 splash(0, ID2P(LANG_SCANNING_DISK
));
437 fat_recalc_free(IF_MV(0));
438 #ifdef HAVE_MULTIVOLUME
439 if (fat_ismounted(1))
447 gui_synclist_speak_item(lists
);
448 return ACTION_REDRAW
;
451 else if (action
== ACTION_NONE
)
453 static int last_redraw
= 0;
454 if (gui_synclist_item_is_onscreen(lists
, 0, INFO_TIME
)
455 && TIME_AFTER(current_tick
, last_redraw
+ HZ
*5))
457 last_redraw
= current_tick
;
458 return ACTION_REDRAW
;
464 static bool show_info(void)
466 struct info_data data
= {.new_data
= true };
467 struct simplelist_info info
;
468 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
469 info
.hide_selection
= !global_settings
.talk_menu
;
470 if (info
.hide_selection
)
471 info
.scroll_all
= true;
472 info
.get_name
= info_getname
;
473 if(global_settings
.talk_menu
)
474 info
.get_talk
= info_speak_item
;
475 info
.action_callback
= info_action_callback
;
476 return simplelist_show_list(&info
);
478 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
479 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
483 static void sleep_timer_formatter(char* buffer
, size_t buffer_size
, int value
,
492 minutes
= value
- (hours
* 60);
493 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
495 strncpy(buffer
, str(LANG_OFF
), buffer_size
);
499 static void sleep_timer_set(int minutes
)
501 set_sleep_timer(minutes
* 60);
504 static int sleep_timer(void)
506 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
507 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
508 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
511 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
512 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
513 setting to the user */
514 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_VERSION
),
515 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
516 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
517 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
518 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
519 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
521 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
522 &show_info_item
, &show_credits_item
, &show_runtime_item
,
523 &sleep_timer_call
, &debug_menu_item
);
525 /***********************************/
527 /***********************************/
531 #ifdef HAVE_LCD_CHARCELLS
532 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
537 case ACTION_ENTER_MENUITEM
:
538 status_set_param(true);
540 case ACTION_EXIT_MENUITEM
:
541 status_set_param(false);
547 #define mainmenu_callback NULL
549 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
550 Icon_Submenu_Entered
,
553 &settings_menu_item
, &theme_menu
,
554 #ifdef HAVE_RECORDING
560 /***********************************/