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
);
129 extern bool simulate_usb(void);
132 #ifdef HAVE_LCD_CHARCELLS
133 #define SIZE_FMT "%s%s"
135 #define SIZE_FMT "%s %s"
138 static bool show_info(void)
141 unsigned long size
, free
;
142 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
146 bool new_info
= true;
147 #ifdef HAVE_MULTIVOLUME
149 unsigned long size2
, free2
;
151 #ifdef HAVE_LCD_CHARCELLS
155 const unsigned char *kbyte_units
[] = {
160 #if defined(HAVE_LCD_BITMAP)
162 screens
[i
].setmargins(0, 0);
170 fat_size( IF_MV2(0,) &size
, &free
);
171 #ifdef HAVE_MULTIVOLUME
172 if (fat_ismounted(1))
173 fat_size( 1, &size2
, &free2
);
178 if (talk_menus_enabled())
180 /* say whatever is reasonable, no real connection to the screen */
181 bool enqueue
= false; /* enqueue all but the first */
182 if (battery_level() >= 0)
184 talk_id(LANG_BATTERY_TIME
, enqueue
);
186 talk_value(battery_level(), UNIT_PERCENT
, true);
187 #if CONFIG_CHARGING >= CHARGING_MONITOR
188 if (charge_state
== CHARGING
)
189 talk_id(LANG_BATTERY_CHARGE
, true);
190 #if CONFIG_CHARGING == CHARGING_CONTROL
191 else if (charge_state
== TOPOFF
)
192 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
194 else if (charge_state
== TRICKLE
)
195 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
199 talk_id(LANG_DISK_FREE_INFO
, enqueue
);
200 #ifdef HAVE_MULTIVOLUME
201 talk_id(LANG_DISK_NAME_INTERNAL
, true);
202 output_dyn_value(NULL
, 0, free
, kbyte_units
, true);
205 talk_id(LANG_DISK_NAME_MMC
, true);
206 output_dyn_value(NULL
, 0, free2
, kbyte_units
, true);
209 output_dyn_value(NULL
, 0, free
, kbyte_units
, true);
214 struct tm
* tm
= get_time();
215 talk_id(VOICE_CURRENT_TIME
, true);
216 talk_value(tm
->tm_hour
, UNIT_HOUR
, true);
217 talk_value(tm
->tm_min
, UNIT_MIN
, true);
218 talk_value(tm
->tm_sec
, UNIT_SEC
, true);
219 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, true);
220 talk_number(tm
->tm_mday
, true);
221 talk_number(1900 + tm
->tm_year
, true);
230 screens
[i
].clear_display();
231 #ifdef HAVE_LCD_BITMAP
232 screens
[i
].puts(0, y
, str(LANG_ROCKBOX_INFO
));
235 #ifdef HAVE_LCD_BITMAP
238 #ifdef HAVE_LCD_CHARCELLS
242 snprintf(s
, sizeof(s
), "%s: %s", str(LANG_VERSION
), appsversion
);
244 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
245 #ifdef HAVE_LCD_BITMAP
250 #ifdef HAVE_LCD_CHARCELLS
254 int integer
= buflen
/ 1000;
255 int decimal
= buflen
% 1000;
257 snprintf(s
, sizeof(s
), (char *)str(LANG_BUFFER_STAT
),
261 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
263 #if CONFIG_CHARGING == CHARGING_CONTROL
264 if (charge_state
== CHARGING
)
265 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_CHARGE
));
266 else if (charge_state
== TOPOFF
)
267 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_TOPOFF_CHARGE
));
268 else if (charge_state
== TRICKLE
)
269 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_TRICKLE_CHARGE
));
272 if (battery_level() >= 0)
273 snprintf(s
, sizeof(s
), (char *)str(LANG_BATTERY_TIME
), battery_level(),
274 battery_time() / 60, battery_time() % 60);
276 strncpy(s
, "(n/a)", sizeof(s
));
278 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
282 #ifdef HAVE_LCD_CHARCELLS
286 #ifdef HAVE_MULTIVOLUME
287 output_dyn_value(s1
, sizeof s1
, free
, kbyte_units
, true);
288 output_dyn_value(s2
, sizeof s2
, size
, kbyte_units
, true);
289 snprintf(s
, sizeof s
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
292 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
296 output_dyn_value(s1
, sizeof s1
, free2
, kbyte_units
, true);
297 output_dyn_value(s2
, sizeof s2
, size2
, kbyte_units
, true);
298 snprintf(s
, sizeof s
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
301 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
305 output_dyn_value(s1
, sizeof s1
, size
, kbyte_units
, true);
306 snprintf(s
, sizeof s
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
308 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
310 output_dyn_value(s1
, sizeof s1
, free
, kbyte_units
, true);
311 snprintf(s
, sizeof s
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
313 screens
[i
].puts_scroll(0, y
, (unsigned char *)s
);
321 /* Wait for a key to be pushed */
322 key
= get_action(CONTEXT_MAINMENU
,HZ
*5);
325 case ACTION_STD_CANCEL
:
329 #ifdef HAVE_LCD_CHARCELLS
330 case ACTION_STD_NEXT
:
333 case ACTION_STD_PREV
:
342 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
343 fat_recalc_free(IF_MV(0));
344 #ifdef HAVE_MULTIVOLUME
345 if (fat_ismounted(1))
353 if (default_event_handler(key
) == SYS_USB_CONNECTED
)
360 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
361 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
365 static void sleep_timer_formatter(char* buffer
, int buffer_size
, int value
,
374 minutes
= value
- (hours
* 60);
375 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
377 snprintf(buffer
, buffer_size
, "%s", str(LANG_OFF
));
381 static void sleep_timer_set(int minutes
)
383 set_sleep_timer(minutes
* 60);
386 static int sleep_timer(void)
388 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
389 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
390 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
393 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
394 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
395 setting to the user */
396 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_VERSION
),
397 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
398 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
399 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
400 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
401 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
403 MENUITEM_FUNCTION(simulate_usb_item
, 0, ID2P(LANG_USB
),
404 (menu_function
)simulate_usb
, NULL
, NULL
, Icon_NOICON
);
407 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
408 &show_info_item
, &show_credits_item
, &show_runtime_item
,
409 &sleep_timer_call
, &debug_menu_item
415 /***********************************/
417 /***********************************/
420 MENUITEM_FUNCTION(browse_themes
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_THEME
),
421 browse_folder
, (void*)&theme
, NULL
, Icon_Folder
);
423 #ifdef HAVE_LCD_CHARCELLS
424 int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
429 case ACTION_ENTER_MENUITEM
:
430 status_set_param(true);
432 case ACTION_EXIT_MENUITEM
:
433 status_set_param(false);
439 #define mainmenu_callback NULL
441 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
442 Icon_Submenu_Entered
,
444 &settings_menu_item
, &manage_settings
, &browse_themes
,
445 #ifdef HAVE_RECORDING
450 /***********************************/