1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
28 #include "powermgmt.h"
31 #include "exported_menus.h"
34 #include "recording.h"
44 #include "debug_menu.h"
45 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
51 static const struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
53 /***********************************/
54 /* MANAGE SETTINGS MENU */
56 static int reset_settings(void)
58 const unsigned char *lines
[]={ID2P(LANG_RESET_ASK
)};
59 const unsigned char *yes_lines
[]={
61 ID2P(LANG_RESET_DONE_CLEAR
)
63 const unsigned char *no_lines
[]={yes_lines
[0], ID2P(LANG_CANCEL
)};
64 struct text_message message
={(char **)lines
, 1};
65 struct text_message yes_message
={(char **)yes_lines
, 2};
66 struct text_message no_message
={(char **)no_lines
, 2};
68 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
82 static int write_settings_file(void* param
)
84 return settings_save_config((intptr_t)param
);
87 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
88 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
89 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
90 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
91 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
92 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
93 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
94 reset_settings
, NULL
, NULL
, Icon_NOICON
);
96 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
97 &browse_configs
, &reset_settings_item
,
98 &save_settings_item
, &save_theme_item
);
99 /* MANAGE SETTINGS MENU */
100 /**********************************/
102 /***********************************/
105 static bool show_credits(void)
107 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
109 /* show the rockbox logo and version untill a button is pressed */
111 get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
116 #ifdef HAVE_LCD_CHARCELLS
117 #define SIZE_FMT "%s%s"
119 #define SIZE_FMT "%s %s"
126 #ifdef HAVE_MULTIVOLUME
140 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
141 INFO_DISK2
, /* free space or external capacity/free on hotswap */
145 static char* info_getname(int selected_item
, void *data
, char *buffer
)
147 struct info_data
*info
= (struct info_data
*)data
;
151 const unsigned char *kbyte_units
[] =
158 #ifdef 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
, MAX_PATH
, "%s: %s",
176 str(LANG_VERSION
), appsversion
);
181 snprintf(buffer
, MAX_PATH
, "%02d:%02d:%02d %s",
182 global_settings
.timeformat
== 0 ? tm
->tm_hour
: tm
->tm_hour
-12,
185 global_settings
.timeformat
== 0 ? "" : tm
->tm_hour
>11 ? "P" : "A");
189 snprintf(buffer
, MAX_PATH
, "%s %d %d",
190 str(LANG_MONTH_JANUARY
+ tm
->tm_mon
),
195 case INFO_BUFFER
: /* buffer */
197 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
198 int integer
= buflen
/ 1000;
199 int decimal
= buflen
% 1000;
200 snprintf(buffer
, MAX_PATH
, (char *)str(LANG_BUFFER_STAT
),
204 case INFO_BATTERY
: /* battery */
205 #if CONFIG_CHARGING == CHARGING_CONTROL
206 if (charge_state
== CHARGING
)
207 snprintf(buffer
, MAX_PATH
, (char *)str(LANG_BATTERY_CHARGE
));
208 else if (charge_state
== TOPOFF
)
209 snprintf(buffer
, MAX_PATH
, (char *)str(LANG_BATTERY_TOPOFF_CHARGE
));
210 else if (charge_state
== TRICKLE
)
211 snprintf(buffer
, MAX_PATH
, (char *)str(LANG_BATTERY_TRICKLE_CHARGE
));
214 if (battery_level() >= 0)
215 snprintf(buffer
, MAX_PATH
, (char *)str(LANG_BATTERY_TIME
), battery_level(),
216 battery_time() / 60, battery_time() % 60);
218 strcpy(buffer
, "(n/a)");
220 case INFO_DISK1
: /* disk usage 1 */
221 #ifdef HAVE_MULTIVOLUME
222 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
223 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
224 snprintf(buffer
, MAX_PATH
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
227 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
228 snprintf(buffer
, MAX_PATH
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
231 case INFO_DISK2
: /* disk usage 2 */
232 #ifdef HAVE_MULTIVOLUME
235 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
236 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
237 snprintf(buffer
, MAX_PATH
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
243 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
244 snprintf(buffer
, MAX_PATH
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
250 static int info_speak_item(int selected_item
, void * data
)
252 struct info_data
*info
= (struct info_data
*)data
;
253 const unsigned char *kbyte_units
[] = {
258 switch (selected_item
)
260 case INFO_VERSION
: /* version */
261 talk_id(LANG_VERSION
, false);
262 talk_spell(appsversion
, true);
266 talk_id(LANG_CURRENT_TIME
, false);
267 talk_time(get_time(), true);
270 talk_date(get_time(), true);
273 case INFO_BUFFER
: /* buffer */
275 talk_id(LANG_BUFFER_STAT
, false);
276 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
277 output_dyn_value(NULL
, 0, buflen
, kbyte_units
, true);
280 case INFO_BATTERY
: /* battery */
281 if (battery_level() >= 0)
283 talk_id(LANG_BATTERY_TIME
, false);
284 talk_value(battery_level(), UNIT_PERCENT
, true);
285 if(battery_time () / 60 > 0)
286 talk_value(battery_time () / 60, UNIT_INT
, true);
287 if(battery_time () % 60 > 0)
288 talk_value(battery_time () % 60, UNIT_INT
, true);
289 #if CONFIG_CHARGING >= CHARGING_MONITOR
290 if (charge_state
== CHARGING
)
291 talk_id(LANG_BATTERY_CHARGE
, true);
292 #if CONFIG_CHARGING == CHARGING_CONTROL
293 else if (charge_state
== TOPOFF
)
294 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
296 else if (charge_state
== TRICKLE
)
297 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
301 case INFO_DISK1
: /* disk 1 */
302 #ifdef HAVE_MULTIVOLUME
303 talk_id(LANG_DISK_FREE_INFO
, false);
304 talk_id(LANG_DISK_NAME_INTERNAL
, true);
305 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
307 talk_id(LANG_DISK_SIZE_INFO
, false);
308 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
311 case INFO_DISK2
: /* disk 2 */
312 #ifdef HAVE_MULTIVOLUME
315 talk_id(LANG_DISK_FREE_INFO
, false);
316 talk_id(LANG_DISK_NAME_MMC
, false);
317 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
320 talk_id(LANG_DISK_FREE_INFO
, false);
321 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
328 static int info_action_callback(int action
, struct gui_synclist
*lists
)
330 if (action
== ACTION_STD_CANCEL
)
332 if ((action
== ACTION_STD_OK
)
333 #ifdef HAVE_MULTIVOLUME
334 || action
== SYS_HOTSWAP_INSERTED
335 || action
== SYS_HOTSWAP_EXTRACTED
340 struct info_data
*info
= (struct info_data
*)lists
->gui_list
[SCREEN_MAIN
].data
;
341 info
->new_data
= true;
342 gui_syncsplash(0, ID2P(LANG_SCANNING_DISK
));
343 fat_recalc_free(IF_MV(0));
344 #ifdef HAVE_MULTIVOLUME
345 if (fat_ismounted(1))
351 return ACTION_REDRAW
;
355 static bool show_info(void)
357 struct info_data data
= {.new_data
= true };
358 struct simplelist_info info
;
359 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
360 info
.hide_selection
= !global_settings
.talk_menu
;
361 info
.get_name
= info_getname
;
362 if(global_settings
.talk_menu
)
363 info
.get_talk
= info_speak_item
;
364 info
.action_callback
= info_action_callback
;
365 return simplelist_show_list(&info
);
367 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
368 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
372 static void sleep_timer_formatter(char* buffer
, size_t buffer_size
, int value
,
381 minutes
= value
- (hours
* 60);
382 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
384 snprintf(buffer
, buffer_size
, "%s", str(LANG_OFF
));
388 static void sleep_timer_set(int minutes
)
390 set_sleep_timer(minutes
* 60);
393 static int sleep_timer(void)
395 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
396 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
397 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
400 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
401 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
402 setting to the user */
403 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_VERSION
),
404 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
405 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
406 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
407 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
408 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
410 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
411 &show_info_item
, &show_credits_item
, &show_runtime_item
,
412 &sleep_timer_call
, &debug_menu_item
);
414 /***********************************/
416 /***********************************/
420 #ifdef HAVE_LCD_CHARCELLS
421 int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
426 case ACTION_ENTER_MENUITEM
:
427 status_set_param(true);
429 case ACTION_EXIT_MENUITEM
:
430 status_set_param(false);
436 #define mainmenu_callback NULL
438 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
439 Icon_Submenu_Entered
,
441 &settings_menu_item
, &theme_menu
,
442 #ifdef HAVE_RECORDING
448 /***********************************/