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)
52 struct browse_folder_info
{
56 static struct browse_folder_info theme
= {THEME_DIR
, SHOW_CFG
};
57 static struct browse_folder_info config
= {ROCKBOX_DIR
, SHOW_CFG
};
58 int browse_folder(void *param
)
60 const struct browse_folder_info
*info
=
61 (const struct browse_folder_info
*)param
;
62 return rockbox_browse(info
->dir
, info
->show_options
);
65 /***********************************/
66 /* MANAGE SETTINGS MENU */
68 static int reset_settings(void)
70 unsigned char *lines
[]={ID2P(LANG_RESET_ASK
)};
71 unsigned char *yes_lines
[]={
73 ID2P(LANG_RESET_DONE_CLEAR
)
75 unsigned char *no_lines
[]={yes_lines
[0], ID2P(LANG_CANCEL
)};
76 struct text_message message
={(char **)lines
, 1};
77 struct text_message yes_message
={(char **)yes_lines
, 2};
78 struct text_message no_message
={(char **)no_lines
, 2};
80 switch(gui_syncyesno_run(&message
, &yes_message
, &no_message
))
94 static int write_settings_file(void* param
)
96 return settings_save_config((intptr_t)param
);
99 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
100 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
101 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
102 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
103 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
104 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
105 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
106 reset_settings
, NULL
, NULL
, Icon_NOICON
);
108 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
109 &browse_configs
, &reset_settings_item
,
110 &save_settings_item
, &save_theme_item
);
111 /* MANAGE SETTINGS MENU */
112 /**********************************/
114 /***********************************/
117 static bool show_credits(void)
119 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
121 /* show the rockbox logo and version untill a button is pressed */
123 get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
128 #ifdef HAVE_LCD_CHARCELLS
129 #define SIZE_FMT "%s%s"
131 #define SIZE_FMT "%s %s"
134 static bool show_info(void)
137 unsigned long size
, free
;
138 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
142 bool new_info
= true;
143 #ifdef HAVE_MULTIVOLUME
145 unsigned long size2
, free2
;
147 #ifdef HAVE_LCD_CHARCELLS
151 const unsigned char *kbyte_units
[] = {
156 #if defined(HAVE_LCD_BITMAP)
158 screens
[i
].setmargins(0, 0);
166 fat_size( IF_MV2(0,) &size
, &free
);
167 #ifdef HAVE_MULTIVOLUME
168 if (fat_ismounted(1))
169 fat_size( 1, &size2
, &free2
);
174 if (talk_menus_enabled())
176 /* say whatever is reasonable, no real connection to the screen */
177 bool enqueue
= false; /* enqueue all but the first */
178 if (battery_level() >= 0)
180 talk_id(LANG_BATTERY_TIME
, enqueue
);
182 talk_value(battery_level(), UNIT_PERCENT
, true);
183 #if CONFIG_CHARGING >= CHARGING_MONITOR
184 if (charge_state
== CHARGING
)
185 talk_id(LANG_BATTERY_CHARGE
, true);
186 #if CONFIG_CHARGING == CHARGING_CONTROL
187 else if (charge_state
== TOPOFF
)
188 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
190 else if (charge_state
== TRICKLE
)
191 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
195 talk_id(LANG_DISK_FREE_INFO
, enqueue
);
196 #ifdef HAVE_MULTIVOLUME
197 talk_id(LANG_DISK_NAME_INTERNAL
, true);
198 output_dyn_value(NULL
, 0, free
, kbyte_units
, true);
201 talk_id(LANG_DISK_NAME_MMC
, true);
202 output_dyn_value(NULL
, 0, free2
, kbyte_units
, true);
205 output_dyn_value(NULL
, 0, free
, kbyte_units
, true);
210 struct tm
* tm
= get_time();
211 talk_id(VOICE_CURRENT_TIME
, true);
212 if (global_settings
.timeformat
== 1)
214 long am_pm_id
= VOICE_AM
;
215 int hour
= tm
->tm_hour
;
225 talk_number(hour
, true);
227 /* Voice the minutes */
230 /* Say o'clock if the minute is 0. */
231 talk_id(VOICE_OCLOCK
, true);
235 /* Pronounce the leading 0 */
238 talk_id(VOICE_OH
, true);
240 talk_number(tm
->tm_min
, true);
242 talk_id(am_pm_id
, true);
246 /* Voice the time in 24 hour format */
247 talk_number(tm
->tm_hour
, true);
250 talk_id(VOICE_HUNDRED
, true);
251 talk_id(VOICE_HOUR
, true);
255 /* Pronounce the leading 0 */
258 talk_id(VOICE_OH
, true);
260 talk_number(tm
->tm_min
, true);
264 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, true);
265 talk_number(tm
->tm_mday
, true);
266 talk_number(1900 + tm
->tm_year
, true);
275 screens
[i
].clear_display();
276 #ifdef HAVE_LCD_BITMAP
277 screens
[i
].puts(0, y
, str(LANG_ROCKBOX_INFO
));
280 #ifdef HAVE_LCD_BITMAP
283 #ifdef HAVE_LCD_CHARCELLS
287 snprintf(s
, sizeof(s
), "%s: %s", str(LANG_VERSION
), appsversion
);
289 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
290 #ifdef HAVE_LCD_BITMAP
295 #ifdef HAVE_LCD_CHARCELLS
299 int integer
= buflen
/ 1000;
300 int decimal
= buflen
% 1000;
302 snprintf(s
, sizeof(s
), (char *)str(LANG_BUFFER_STAT
),
306 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
308 #if CONFIG_CHARGING == CHARGING_CONTROL
309 if (charge_state
== CHARGING
)
310 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_CHARGE
));
311 else if (charge_state
== TOPOFF
)
312 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_TOPOFF_CHARGE
));
313 else if (charge_state
== TRICKLE
)
314 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_TRICKLE_CHARGE
));
317 if (battery_level() >= 0)
318 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_TIME
), battery_level(),
319 battery_time() / 60, battery_time() % 60);
321 strncpy(s
, "(n/a)", sizeof(s
));
323 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
327 #ifdef HAVE_LCD_CHARCELLS
331 #ifdef HAVE_MULTIVOLUME
332 output_dyn_value(s1
, sizeof s1
, free
, kbyte_units
, true);
333 output_dyn_value(s2
, sizeof s2
, size
, kbyte_units
, true);
334 snprintf(s
, sizeof s
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
337 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
341 output_dyn_value(s1
, sizeof s1
, free2
, kbyte_units
, true);
342 output_dyn_value(s2
, sizeof s2
, size2
, kbyte_units
, true);
343 snprintf(s
, sizeof s
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
346 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
350 output_dyn_value(s1
, sizeof s1
, size
, kbyte_units
, true);
351 snprintf(s
, sizeof s
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
353 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
355 output_dyn_value(s1
, sizeof s1
, free
, kbyte_units
, true);
356 snprintf(s
, sizeof s
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
358 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
366 /* Wait for a key to be pushed */
367 key
= get_action(CONTEXT_MAINMENU
,HZ
*5);
370 case ACTION_STD_CANCEL
:
374 #ifdef HAVE_LCD_CHARCELLS
375 case ACTION_STD_NEXT
:
378 case ACTION_STD_PREV
:
387 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
388 fat_recalc_free(IF_MV(0));
389 #ifdef HAVE_MULTIVOLUME
390 if (fat_ismounted(1))
398 if (default_event_handler(key
) == SYS_USB_CONNECTED
)
405 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
406 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
410 static void sleep_timer_formatter(char* buffer
, size_t buffer_size
, int value
,
419 minutes
= value
- (hours
* 60);
420 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
422 snprintf(buffer
, buffer_size
, "%s", str(LANG_OFF
));
426 static void sleep_timer_set(int minutes
)
428 set_sleep_timer(minutes
* 60);
431 static int sleep_timer(void)
433 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
434 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
435 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
438 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
439 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
440 setting to the user */
441 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_VERSION
),
442 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
443 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
444 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
445 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
446 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
448 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
449 &show_info_item
, &show_credits_item
, &show_runtime_item
,
450 &sleep_timer_call
, &debug_menu_item
);
452 /***********************************/
454 /***********************************/
457 MENUITEM_FUNCTION(browse_themes
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_THEME
),
458 browse_folder
, (void*)&theme
, NULL
, Icon_Folder
);
460 #ifdef HAVE_LCD_CHARCELLS
461 int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
466 case ACTION_ENTER_MENUITEM
:
467 status_set_param(true);
469 case ACTION_EXIT_MENUITEM
:
470 status_set_param(false);
476 #define mainmenu_callback NULL
478 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
479 Icon_Submenu_Entered
,
481 &settings_menu_item
, &manage_settings
, &browse_themes
,
482 #ifdef HAVE_RECORDING
487 /***********************************/