diff options
-rw-r--r-- | apps/root_menu.c | 116 | ||||
-rw-r--r-- | apps/root_menu.h | 9 | ||||
-rw-r--r-- | apps/settings.h | 2 | ||||
-rw-r--r-- | apps/settings_list.c | 5 | ||||
-rw-r--r-- | manual/advanced_topics/main.tex | 23 |
5 files changed, 142 insertions, 13 deletions
diff --git a/apps/root_menu.c b/apps/root_menu.c index 747ba76c24..16665c1824 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c @@ -477,26 +477,118 @@ static int do_shutdown(void) MENUITEM_FUNCTION(do_shutdown_item, 0, ID2P(LANG_SHUTDOWN), do_shutdown, NULL, NULL, Icon_NOICON); #endif -MAKE_MENU(root_menu_, ID2P(LANG_ROCKBOX_TITLE), - item_callback, Icon_Rockbox, - &bookmarks, &file_browser, + +struct menu_item_ex root_menu_; +static struct menu_callback_with_desc root_menu_desc = { + item_callback, ID2P(LANG_ROCKBOX_TITLE), Icon_Rockbox }; +struct menu_table { + char *string; + const struct menu_item_ex *item; +}; +static struct menu_table menu_table[] = { + /* Order here represents the default ordering */ + { "bookmarks", &bookmarks }, + { "files", &file_browser }, #ifdef HAVE_TAGCACHE - &db_browser, + { "database", &db_browser }, #endif - &wps_item, &menu_, + { "wps", &wps_item }, + { "settings", &menu_ }, #ifdef HAVE_RECORDING - &rec, + { "recording", &rec }, #endif #if CONFIG_TUNER - &fm, + { "radio", &fm }, #endif - &playlists, &rocks_browser, &system_menu_ - + { "playlists", &playlists }, + { "plugins", &rocks_browser }, + { "system_menu", &system_menu_ }, #if CONFIG_KEYPAD == PLAYER_PAD - ,&do_shutdown_item + { "shutdown", &do_shutdown_item }, #endif - ,&shortcut_menu - ); + { "shortcuts", &shortcut_menu }, +}; +#define MAX_MENU_ITEMS (sizeof(menu_table) / sizeof(struct menu_table)) +static struct menu_item_ex *root_menu__[MAX_MENU_ITEMS]; + +void root_menu_load_from_cfg(void* setting, char *value) +{ + char *next = value, *start; + unsigned int menu_item_count = 0, i; + bool main_menu_added = false; + + root_menu_.flags = MENU_HAS_DESC | MT_MENU; + root_menu_.submenus = (const struct menu_item_ex **)&root_menu__; + root_menu_.callback_and_desc = &root_menu_desc; + + while (next && menu_item_count < MAX_MENU_ITEMS) + { + start = next; + next = strchr(next, ','); + if (next) + { + *next = '\0'; + next++; + } + for (i=0; i<MAX_MENU_ITEMS; i++) + { + if (*start && !strcmp(start, menu_table[i].string)) + { + root_menu__[menu_item_count++] = (struct menu_item_ex *)menu_table[i].item; + if (menu_table[i].item == &menu_) + main_menu_added = true; + break; + } + } + } + if (!main_menu_added) + root_menu__[menu_item_count++] = (struct menu_item_ex *)&menu_; + root_menu_.flags |= MENU_ITEM_COUNT(menu_item_count); + *(int*)setting = 1; +} + +char* root_menu_write_to_cfg(void* setting, char*buf, int buf_len) +{ + (void)setting; + unsigned i, written, j; + for (i = 0; i < MENU_GET_COUNT(root_menu_.flags); i++) + { + for (j=0; j<MAX_MENU_ITEMS; j++) + { + if (menu_table[j].item == root_menu__[i]) + { + written = snprintf(buf, buf_len, "%s,", menu_table[j].string); + buf_len -= written; + buf += written; + break; + } + } + } + return buf; +} + +void root_menu_set_default(void* setting, void* defaultval) +{ + unsigned i; + (void)defaultval; + + root_menu_.flags = MENU_HAS_DESC | MT_MENU; + root_menu_.submenus = (const struct menu_item_ex **)&root_menu__; + root_menu_.callback_and_desc = &root_menu_desc; + + for (i=0; i<MAX_MENU_ITEMS; i++) + { + root_menu__[i] = (struct menu_item_ex *)menu_table[i].item; + } + root_menu_.flags |= MENU_ITEM_COUNT(MAX_MENU_ITEMS); + *(int*)setting = 0; +} + +bool root_menu_is_changed(void* setting, void* defaultval) +{ + (void)defaultval; + return *(int*)setting != 0; +} static int item_callback(int action, const struct menu_item_ex *this_item) { diff --git a/apps/root_menu.h b/apps/root_menu.h index 8d11d9b338..32385d9530 100644 --- a/apps/root_menu.h +++ b/apps/root_menu.h @@ -61,8 +61,15 @@ enum { GO_TO_SHORTCUTMENU }; -extern const struct menu_item_ex root_menu_; +extern struct menu_item_ex root_menu_; extern void previous_music_is_wps(void); +void root_menu_load_from_cfg(void* setting, char *value); +char* root_menu_write_to_cfg(void* setting, char*buf, int buf_len); +void root_menu_set_default(void* setting, void* defaultval); +bool root_menu_is_changed(void* setting, void* defaultval); + + + #endif /* __ROOT_MENU_H__ */ diff --git a/apps/settings.h b/apps/settings.h index 7a6fa55e79..ca0abaa202 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -844,6 +844,8 @@ struct user_settings #endif char start_directory[MAX_PATHNAME+1]; + /* status setting for the root menu customisability. 0 = default, 1 = loaded from cfg */ + int root_menu; }; /** global variables **/ diff --git a/apps/settings_list.c b/apps/settings_list.c index 44295ac5aa..c4d4d27f45 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1921,6 +1921,11 @@ const struct settings_list settings[] = { "resume rewind", UNIT_SEC, 0, 60, 5, NULL, NULL, NULL), #endif + CUSTOM_SETTING(0, root_menu, + LANG_ROCKBOX_TITLE, /* lang string here is never actually used */ + NULL, "root_menu_order", + root_menu_load_from_cfg, root_menu_write_to_cfg, + root_menu_is_changed, root_menu_set_default), }; const int nb_settings = sizeof(settings)/sizeof(*settings); diff --git a/manual/advanced_topics/main.tex b/manual/advanced_topics/main.tex index 93d1935785..196053759b 100644 --- a/manual/advanced_topics/main.tex +++ b/manual/advanced_topics/main.tex @@ -2,6 +2,29 @@ \chapter{Advanced Topics} \section{\label{ref:CustomisingUI}Customising the User Interface} + +\subsection{\label{ref:CustomisingTheMainMenu}Customising The Main Menu} + +It is possible to customise the main menu, i.e. to reorder or to hide some +of its items. To accomplish this, the file \fname{/.rockbox/config.cfg} must +be edited (presumably on the computer while the \dap{} is connected to it +via USB). There, the line starting with \config{root\_menu\_order:} must +be edited (or created if it is not present yet). + +The line should look like \config{root\_menu\_order:items}, where ``items'' +is a comma separated list (no spaces around the commas!) of the following +words: \config{bookmarks}, \config{files}, \opt{database}{\config{database}, }% +\config{wps}, \config{settings}, \opt{recording}{\config{recording}, }% +\opt{radio}{\config{radio}, }\config{playlists}, \config{plugins}, +\config{system\_menu}, \opt{PLAYER_PAD}{\config{shutdown}, }\config{shortcuts}. +Each of the words, if it occurs in the list, activates the appropriate item +in the main menu. The order of the items is given by the order of the words +in the list. The items whose words do not occur in the list will be hidden, +with one exception: the menu item ``Settings'' will be shown even if its word +is not in the list (it is added as the last item then). + +Only the main menu can be customised this way, submenus can not. + \opt{lcd_bitmap}{ \subsection{\label{ref:GettingExtras}Getting Extras} |