gitscraper: support Python3.
[maemo-rb.git] / apps / menus / main_menu.c
blobb7472a6849acf535018e14bfac8ade6f59825dc2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "string.h"
27 #include "lang.h"
28 #include "action.h"
29 #include "settings.h"
30 #include "power.h"
31 #include "powermgmt.h"
32 #include "menu.h"
33 #include "misc.h"
34 #include "exported_menus.h"
35 #include "tree.h"
36 #include "storage.h"
37 #ifdef HAVE_RECORDING
38 #include "recording.h"
39 #endif
40 #include "yesno.h"
41 #include "keyboard.h"
42 #include "screens.h"
43 #include "plugin.h"
44 #include "talk.h"
45 #include "splash.h"
46 #include "debug_menu.h"
47 #include "version.h"
48 #include "time.h"
49 #include "wps.h"
50 #include "skin_buffer.h"
52 static const struct browse_folder_info config = {ROCKBOX_DIR, SHOW_CFG};
54 /***********************************/
55 /* MANAGE SETTINGS MENU */
57 static int reset_settings(void)
59 static const char *lines[]={ID2P(LANG_RESET_ASK)};
60 static const char *yes_lines[]={
61 ID2P(LANG_SETTINGS),
62 ID2P(LANG_RESET_DONE_CLEAR)
64 static const char *no_lines[]={
65 ID2P(LANG_SETTINGS),
66 ID2P(LANG_CANCEL)
68 static const struct text_message message={lines, 1};
69 static const struct text_message yes_message={yes_lines, 2};
70 static const struct text_message no_message={no_lines, 2};
72 switch(gui_syncyesno_run(&message, &yes_message, &no_message))
74 case YESNO_YES:
75 settings_reset();
76 settings_save();
77 settings_apply(true);
78 settings_apply_skins();
79 break;
80 case YESNO_NO:
81 break;
82 case YESNO_USB:
83 return 1;
85 return 0;
87 static int write_settings_file(void* param)
89 return settings_save_config((intptr_t)param);
92 MENUITEM_FUNCTION(browse_configs, MENU_FUNC_USEPARAM, ID2P(LANG_CUSTOM_CFG),
93 browse_folder, (void*)&config, NULL, Icon_NOICON);
94 MENUITEM_FUNCTION(save_settings_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SETTINGS),
95 write_settings_file, (void*)SETTINGS_SAVE_ALL, NULL, Icon_NOICON);
96 MENUITEM_FUNCTION(save_theme_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_THEME),
97 write_settings_file, (void*)SETTINGS_SAVE_THEME, NULL, Icon_NOICON);
98 MENUITEM_FUNCTION(save_sound_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SOUND),
99 write_settings_file, (void*)SETTINGS_SAVE_SOUND, NULL, Icon_NOICON);
100 MENUITEM_FUNCTION(reset_settings_item, 0, ID2P(LANG_RESET),
101 reset_settings, NULL, NULL, Icon_NOICON);
103 MAKE_MENU(manage_settings, ID2P(LANG_MANAGE_MENU), NULL, Icon_Config,
104 &browse_configs, &reset_settings_item,
105 &save_settings_item, &save_sound_item, &save_theme_item);
106 /* MANAGE SETTINGS MENU */
107 /**********************************/
109 /***********************************/
110 /* INFO MENU */
113 static bool show_credits(void)
115 char credits[MAX_PATH] = { '\0' };
116 snprintf(credits, MAX_PATH, "%s/credits.rock", VIEWERS_DIR);
117 if (plugin_load(credits, NULL) != PLUGIN_OK)
119 /* show the rockbox logo and version untill a button is pressed */
120 show_logo();
121 while (IS_SYSEVENT(get_action(CONTEXT_STD, TIMEOUT_BLOCK)))
124 return false;
127 #ifdef HAVE_LCD_CHARCELLS
128 #define SIZE_FMT "%s%s"
129 #else
130 #define SIZE_FMT "%s %s"
131 #endif
132 struct info_data
135 bool new_data;
136 unsigned long size;
137 unsigned long free;
138 #ifdef HAVE_MULTIVOLUME
139 unsigned long size2;
140 unsigned long free2;
141 #endif
143 enum infoscreenorder
145 INFO_BATTERY = 0,
146 INFO_DISK1, /* capacity or internal capacity/free on hotswap */
147 INFO_DISK2, /* free space or external capacity/free on hotswap */
148 INFO_BUFFER,
149 INFO_VERSION,
150 INFO_COUNT
153 static const char* info_getname(int selected_item, void *data,
154 char *buffer, size_t buffer_len)
156 struct info_data *info = (struct info_data*)data;
157 char s1[32];
158 #if defined(HAVE_MULTIVOLUME)
159 char s2[32];
160 #endif
161 if (info->new_data)
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);
167 else
168 info->size2 = 0;
169 #endif
170 info->new_data = false;
172 switch (selected_item)
174 case INFO_VERSION:
175 snprintf(buffer, buffer_len, "%s: %s",
176 str(LANG_VERSION), rbversion);
177 break;
179 case INFO_BUFFER: /* buffer */
181 long kib = audio_buffer_size() / 1024; /* to KiB */
182 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true);
183 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1);
185 break;
186 case INFO_BATTERY: /* battery */
187 #if CONFIG_CHARGING == CHARGING_SIMPLE
188 /* Only know if plugged */
189 if (charger_inserted())
190 return str(LANG_BATTERY_CHARGE);
191 else
192 #elif CONFIG_CHARGING >= CHARGING_MONITOR
193 #ifdef ARCHOS_RECORDER
194 /* Report the particular algorithm state */
195 if (charge_state == CHARGING)
196 return str(LANG_BATTERY_CHARGE);
197 else if (charge_state == TOPOFF)
198 return str(LANG_BATTERY_TOPOFF_CHARGE);
199 else if (charge_state == TRICKLE)
200 return str(LANG_BATTERY_TRICKLE_CHARGE);
201 else
202 #else /* !ARCHOS_RECORDER */
203 /* Go by what power management reports */
204 if (charging_state())
205 return str(LANG_BATTERY_CHARGE);
206 else
207 #endif /* ARCHOS_RECORDER */
208 #endif /* CONFIG_CHARGING = */
209 if (battery_level() >= 0)
210 snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
211 battery_level(), battery_time() / 60, battery_time() % 60);
212 else
213 return "Battery n/a"; /* translating worth it? */
214 break;
215 case INFO_DISK1: /* disk usage 1 */
216 #ifdef HAVE_MULTIVOLUME
217 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
218 output_dyn_value(s2, sizeof s2, info->size, kbyte_units, true);
219 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
220 s1, s2);
221 #else
222 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
223 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
224 #endif
225 break;
226 case INFO_DISK2: /* disk usage 2 */
227 #ifdef HAVE_MULTIVOLUME
228 if (info->size2)
230 output_dyn_value(s1, sizeof s1, info->free2, kbyte_units, true);
231 output_dyn_value(s2, sizeof s2, info->size2, kbyte_units, true);
232 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_MMC),
233 s1, s2);
235 else
237 snprintf(buffer, buffer_len, "%s %s", str(LANG_DISK_NAME_MMC),
238 str(LANG_NOT_PRESENT));
240 #else
241 output_dyn_value(s1, sizeof s1, info->size, kbyte_units, true);
242 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
243 #endif
244 break;
246 return buffer;
249 static int info_speak_item(int selected_item, void * data)
251 struct info_data *info = (struct info_data*)data;
253 switch (selected_item)
255 case INFO_VERSION: /* version */
256 talk_id(LANG_VERSION, false);
257 talk_spell(rbversion, true);
258 break;
260 case INFO_BUFFER: /* buffer */
262 talk_id(LANG_BUFFER_STAT, false);
263 long kib = audio_buffer_size() / 1024; /* to KiB */
264 output_dyn_value(NULL, 0, kib, kbyte_units, true);
265 break;
267 case INFO_BATTERY: /* battery */
268 #if CONFIG_CHARGING == CHARGING_SIMPLE
269 /* Only know if plugged */
270 if (charger_inserted())
271 talk_id(LANG_BATTERY_CHARGE, true);
272 else
273 #elif CONFIG_CHARGING >= CHARGING_MONITOR
274 #ifdef ARCHOS_RECORDER
275 /* Report the particular algorithm state */
276 if (charge_state == CHARGING)
277 talk_id(LANG_BATTERY_CHARGE, true);
278 else if (charge_state == TOPOFF)
279 talk_id(LANG_BATTERY_TOPOFF_CHARGE, true);
280 else if (charge_state == TRICKLE)
281 talk_id(LANG_BATTERY_TRICKLE_CHARGE, true);
282 else
283 #else /* !ARCHOS_RECORDER */
284 /* Go by what power management reports */
285 if (charging_state())
286 talk_id(LANG_BATTERY_CHARGE, true);
287 else
288 #endif /* ARCHOS_RECORDER */
289 #endif /* CONFIG_CHARGING = */
290 if (battery_level() >= 0)
292 int time_left = battery_time();
293 talk_id(LANG_BATTERY_TIME, false);
294 talk_value(battery_level(), UNIT_PERCENT, true);
295 if (time_left >= 0)
296 talk_value(time_left * 60, UNIT_TIME, true);
298 else talk_id(VOICE_BLANK, false);
299 break;
300 case INFO_DISK1: /* disk 1 */
301 #ifdef HAVE_MULTIVOLUME
302 talk_ids(false, LANG_DISK_NAME_INTERNAL, LANG_DISK_FREE_INFO);
303 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
304 talk_id(LANG_DISK_SIZE_INFO, true);
305 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
306 #else
307 talk_id(LANG_DISK_FREE_INFO, false);
308 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
309 #endif
310 break;
311 case INFO_DISK2: /* disk 2 */
312 #ifdef HAVE_MULTIVOLUME
313 talk_id(LANG_DISK_NAME_MMC, false);
314 if (info->size2)
316 talk_id(LANG_DISK_FREE_INFO, true);
317 output_dyn_value(NULL, 0, info->free2, kbyte_units, true);
318 talk_id(LANG_DISK_SIZE_INFO, true);
319 output_dyn_value(NULL, 0, info->size2, kbyte_units, true);
321 else talk_id(LANG_NOT_PRESENT, true);
322 #else
323 talk_id(LANG_DISK_SIZE_INFO, false);
324 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
325 #endif
326 break;
329 return 0;
332 static int info_action_callback(int action, struct gui_synclist *lists)
334 if (action == ACTION_STD_CANCEL)
335 return action;
336 else if ((action == ACTION_STD_OK)
337 #ifdef HAVE_HOTSWAP
338 || action == SYS_FS_CHANGED
339 #endif
342 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
343 struct info_data *info = (struct info_data *)lists->data;
344 int i;
345 info->new_data = true;
346 splash(0, ID2P(LANG_SCANNING_DISK));
347 for (i = 0; i < NUM_VOLUMES; i++)
349 #ifdef HAVE_HOTSWAP
350 if (fat_ismounted(i))
351 #endif
352 fat_recalc_free(IF_MV(i));
354 #else
355 (void) lists;
356 #endif
357 gui_synclist_speak_item(lists);
358 return ACTION_REDRAW;
360 return action;
362 static bool show_info(void)
364 struct info_data data = {.new_data = true };
365 struct simplelist_info info;
366 simplelist_info_init(&info, str(LANG_ROCKBOX_INFO), INFO_COUNT, (void*)&data);
367 info.hide_selection = !global_settings.talk_menu;
368 if (info.hide_selection)
369 info.scroll_all = true;
370 info.get_name = info_getname;
371 if(global_settings.talk_menu)
372 info.get_talk = info_speak_item;
373 info.action_callback = info_action_callback;
374 return simplelist_show_list(&info);
376 MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
377 (menu_function)show_info, NULL, NULL, Icon_NOICON);
379 #if CONFIG_RTC
380 int time_screen(void* ignored);
381 MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU),
382 time_screen, NULL, NULL, Icon_Menu_setting );
383 #endif
385 MENUITEM_FUNCTION(show_credits_item, 0, ID2P(LANG_CREDITS),
386 (menu_function)show_credits, NULL, NULL, Icon_NOICON);
387 MENUITEM_FUNCTION(show_runtime_item, 0, ID2P(LANG_RUNNING_TIME),
388 (menu_function)view_runtime, NULL, NULL, Icon_NOICON);
389 MENUITEM_FUNCTION(debug_menu_item, 0, ID2P(LANG_DEBUG),
390 (menu_function)debug_menu, NULL, NULL, Icon_NOICON);
392 MAKE_MENU(info_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu,
393 &show_info_item, &show_credits_item,
394 &show_runtime_item, &debug_menu_item);
395 /* INFO MENU */
396 /***********************************/
398 /***********************************/
399 /* MAIN MENU */
402 #ifdef HAVE_LCD_CHARCELLS
403 static int mainmenu_callback(int action,const struct menu_item_ex *this_item)
405 (void)this_item;
406 switch (action)
408 case ACTION_ENTER_MENUITEM:
409 status_set_param(true);
410 break;
411 case ACTION_EXIT_MENUITEM:
412 status_set_param(false);
413 break;
415 return action;
417 #else
418 #define mainmenu_callback NULL
419 #endif
420 MAKE_MENU(main_menu_, ID2P(LANG_SETTINGS), mainmenu_callback,
421 Icon_Submenu_Entered,
422 &sound_settings,
423 &playback_settings,
424 &settings_menu_item, &theme_menu,
425 #ifdef HAVE_RECORDING
426 &recording_settings,
427 #endif
428 #if CONFIG_RTC
429 &timedate_item,
430 #endif
431 &manage_settings,
433 /* MAIN MENU */
434 /***********************************/