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(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
94 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
95 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
96 reset_settings
, NULL
, NULL
, Icon_NOICON
);
98 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
99 &browse_configs
, &reset_settings_item
,
100 &save_settings_item
, &save_sound_item
, &save_theme_item
);
101 /* MANAGE SETTINGS MENU */
102 /**********************************/
104 /***********************************/
107 static bool show_credits(void)
109 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
111 /* show the rockbox logo and version untill a button is pressed */
113 get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
118 #ifdef HAVE_LCD_CHARCELLS
119 #define SIZE_FMT "%s%s"
121 #define SIZE_FMT "%s %s"
129 #ifdef HAVE_MULTIVOLUME
137 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
138 INFO_DISK2
, /* free space or external capacity/free on hotswap */
148 static const unsigned char *kbyte_units
[] =
155 static 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 #ifdef HAVE_MULTIVOLUME
168 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
169 #ifdef HAVE_MULTIVOLUME
170 if (fat_ismounted(1))
171 fat_size(1, &info
->size2
, &info
->free2
);
175 info
->new_data
= false;
177 switch (selected_item
)
180 snprintf(buffer
, buffer_len
, "%s: %s",
181 str(LANG_VERSION
), appsversion
);
186 snprintf(buffer
, buffer_len
, "%02d:%02d:%02d %s",
187 global_settings
.timeformat
== 0 ? tm
->tm_hour
:
188 ((tm
->tm_hour
+ 11) % 12) + 1,
191 global_settings
.timeformat
== 0 ? "" :
192 tm
->tm_hour
>11 ? "P" : "A");
196 snprintf(buffer
, buffer_len
, "%s %d %d",
197 str(LANG_MONTH_JANUARY
+ tm
->tm_mon
),
202 case INFO_BUFFER
: /* buffer */
204 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
205 int integer
= buflen
/ 1000;
206 int decimal
= buflen
% 1000;
207 snprintf(buffer
, buffer_len
, (char *)str(LANG_BUFFER_STAT
),
211 case INFO_BATTERY
: /* battery */
212 #if CONFIG_CHARGING == CHARGING_SIMPLE
213 if (charger_input_state
== CHARGER
)
214 return (char *)str(LANG_BATTERY_CHARGE
);
216 #elif CONFIG_CHARGING >= CHARGING_MONITOR
217 if (charge_state
== CHARGING
)
218 return (char *)str(LANG_BATTERY_CHARGE
);
220 #if CONFIG_CHARGING == CHARGING_CONTROL
221 if (charge_state
== TOPOFF
)
222 return (char *)str(LANG_BATTERY_TOPOFF_CHARGE
);
225 if (charge_state
== TRICKLE
)
226 return (char *)str(LANG_BATTERY_TRICKLE_CHARGE
);
229 if (battery_level() >= 0)
230 snprintf(buffer
, buffer_len
, (char *)str(LANG_BATTERY_TIME
),
231 battery_level(), battery_time() / 60, battery_time() % 60);
235 case INFO_DISK1
: /* disk usage 1 */
236 #ifdef HAVE_MULTIVOLUME
237 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
238 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
239 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
242 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
243 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
246 case INFO_DISK2
: /* disk usage 2 */
247 #ifdef HAVE_MULTIVOLUME
250 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
251 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
252 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
257 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
258 str(LANG_NOT_PRESENT
));
261 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
262 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
269 static int info_speak_item(int selected_item
, void * data
)
271 struct info_data
*info
= (struct info_data
*)data
;
273 switch (selected_item
)
275 case INFO_VERSION
: /* version */
276 talk_id(LANG_VERSION
, false);
277 talk_spell(appsversion
, true);
281 talk_id(VOICE_CURRENT_TIME
, false);
282 talk_time(get_time(), true);
285 talk_date(get_time(), true);
288 case INFO_BUFFER
: /* buffer */
290 talk_id(LANG_BUFFER_STAT
, false);
291 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
292 output_dyn_value(NULL
, 0, buflen
, kbyte_units
, true);
295 case INFO_BATTERY
: /* battery */
296 #if CONFIG_CHARGING == CHARGING_SIMPLE
297 if (charger_input_state
== CHARGER
)
298 talk_id(LANG_BATTERY_CHARGE
, true);
300 #elif CONFIG_CHARGING >= CHARGING_MONITOR
301 if (charge_state
== CHARGING
)
302 talk_id(LANG_BATTERY_CHARGE
, true);
304 #if CONFIG_CHARGING == CHARGING_CONTROL
305 if (charge_state
== TOPOFF
)
306 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
309 if (charge_state
== TRICKLE
)
310 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
313 if (battery_level() >= 0)
315 talk_id(LANG_BATTERY_TIME
, false);
316 talk_value(battery_level(), UNIT_PERCENT
, true);
317 talk_value(battery_time() *60, UNIT_TIME
, true);
319 else talk_id(VOICE_BLANK
, false);
321 case INFO_DISK1
: /* disk 1 */
322 #ifdef HAVE_MULTIVOLUME
323 talk_id(LANG_DISK_NAME_INTERNAL
, false);
324 talk_id(LANG_DISK_FREE_INFO
, true);
325 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
326 talk_id(LANG_DISK_SIZE_INFO
, true);
327 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
329 talk_id(LANG_DISK_FREE_INFO
, false);
330 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
333 case INFO_DISK2
: /* disk 2 */
334 #ifdef HAVE_MULTIVOLUME
335 talk_id(LANG_DISK_NAME_MMC
, false);
338 talk_id(LANG_DISK_FREE_INFO
, true);
339 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
340 talk_id(LANG_DISK_SIZE_INFO
, true);
341 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
343 else talk_id(LANG_NOT_PRESENT
, true);
345 talk_id(LANG_DISK_SIZE_INFO
, false);
346 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
353 static int info_action_callback(int action
, struct gui_synclist
*lists
)
355 if (action
== ACTION_STD_CANCEL
)
357 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 gui_syncsplash(0, ID2P(LANG_SCANNING_DISK
));
368 fat_recalc_free(IF_MV(0));
369 #ifdef HAVE_MULTIVOLUME
370 if (fat_ismounted(1))
378 return ACTION_REDRAW
;
382 static bool show_info(void)
384 struct info_data data
= {.new_data
= true };
385 struct simplelist_info info
;
386 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
387 info
.hide_selection
= !global_settings
.talk_menu
;
388 info
.get_name
= info_getname
;
389 if(global_settings
.talk_menu
)
390 info
.get_talk
= info_speak_item
;
391 info
.action_callback
= info_action_callback
;
392 return simplelist_show_list(&info
);
394 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
395 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
399 static void sleep_timer_formatter(char* buffer
, size_t buffer_size
, int value
,
408 minutes
= value
- (hours
* 60);
409 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
411 snprintf(buffer
, buffer_size
, "%s", str(LANG_OFF
));
415 static void sleep_timer_set(int minutes
)
417 set_sleep_timer(minutes
* 60);
420 static int sleep_timer(void)
422 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
423 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
424 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
427 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
428 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
429 setting to the user */
430 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_VERSION
),
431 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
432 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
433 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
434 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
435 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
437 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
438 &show_info_item
, &show_credits_item
, &show_runtime_item
,
439 &sleep_timer_call
, &debug_menu_item
);
441 /***********************************/
443 /***********************************/
447 #ifdef HAVE_LCD_CHARCELLS
448 int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
453 case ACTION_ENTER_MENUITEM
:
454 status_set_param(true);
456 case ACTION_EXIT_MENUITEM
:
457 status_set_param(false);
463 #define mainmenu_callback NULL
465 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
466 Icon_Submenu_Entered
,
468 &settings_menu_item
, &theme_menu
,
469 #ifdef HAVE_RECORDING
475 /***********************************/