A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

Settings menu: add main menu customization

Lets you launch the main_menu_config plugin
from Settings, so that it remains accessible,
even after all other menu items have been
hidden.

Includes minor changes to the main menu config
plugin, so that it better fits in with the rest
of the settings menus:

* Keep theme enabled
* Autosave
* Add "On" or "Off" suffix to each item, to prevent
confusion when Icon_Config is blank, as is the case
with certain iconsets
* Update current selection after swapping items
* Prefix spoken selection with row number for enhanced
clarity when swapping items
* Change title to LANG_MAIN_MENU
* ACTION_STD_OK to toggle an item's visibility
* ACTION_STD_CONTEXT to access options for reordering
menu items, or for reverting to the default menu
* Ask for confirmation before reverting

Change-Id: I74240b94243224c76e23ef8f3a0559bd8ba28df0

+97 -63
+7 -7
apps/lang/english.lang
··· 14152 </phrase> 14153 <phrase> 14154 id: LANG_TOGGLE_ITEM 14155 - desc: in main_menu_config 14156 user: core 14157 <source> 14158 - *: "Toggle Item" 14159 </source> 14160 <dest> 14161 - *: "Toggle Item" 14162 </dest> 14163 <voice> 14164 - *: "Toggle Item" 14165 </voice> 14166 </phrase> 14167 <phrase> ··· 14222 </phrase> 14223 <phrase> 14224 id: LANG_MAIN_MENU_ORDER 14225 - desc: main_menu_config plugin title 14226 user: core 14227 <source> 14228 - *: "Rockbox Main Menu Order" 14229 </source> 14230 <dest> 14231 - *: "Rockbox Main Menu Order" 14232 </dest> 14233 <voice> 14234 *: ""
··· 14152 </phrase> 14153 <phrase> 14154 id: LANG_TOGGLE_ITEM 14155 + desc: deprecated 14156 user: core 14157 <source> 14158 + *: "" 14159 </source> 14160 <dest> 14161 + *: "" 14162 </dest> 14163 <voice> 14164 + *: "" 14165 </voice> 14166 </phrase> 14167 <phrase> ··· 14222 </phrase> 14223 <phrase> 14224 id: LANG_MAIN_MENU_ORDER 14225 + desc: deprecated 14226 user: core 14227 <source> 14228 + *: "" 14229 </source> 14230 <dest> 14231 + *: "" 14232 </dest> 14233 <voice> 14234 *: ""
+10
apps/menus/main_menu.c
··· 495 /* INFO MENU */ 496 /***********************************/ 497 498 /***********************************/ 499 /* MAIN MENU */ 500 ··· 509 #if CONFIG_RTC 510 &timedate_item, 511 #endif 512 &manage_settings, 513 ); 514 /* MAIN MENU */
··· 495 /* INFO MENU */ 496 /***********************************/ 497 498 + static int main_menu_config(void) 499 + { 500 + plugin_load(PLUGIN_APPS_DIR "/main_menu_config.rock", NULL); 501 + return 0; 502 + } 503 + 504 + MENUITEM_FUNCTION(main_menu_config_item, 0, ID2P(LANG_MAIN_MENU), 505 + main_menu_config, NULL, Icon_Rockbox); 506 + 507 /***********************************/ 508 /* MAIN MENU */ 509 ··· 518 #if CONFIG_RTC 519 &timedate_item, 520 #endif 521 + &main_menu_config_item, 522 &manage_settings, 523 ); 524 /* MAIN MENU */
+2 -1
apps/plugin.c
··· 860 861 /* for some plugins, the SBS can be left enabled */ 862 const char *sepch = strrchr(plugin, PATH_SEPCH); 863 - bool theme_enabled = sepch && !strcmp("properties.rock", sepch + 1); 864 865 if (current_plugin_handle) 866 {
··· 860 861 /* for some plugins, the SBS can be left enabled */ 862 const char *sepch = strrchr(plugin, PATH_SEPCH); 863 + bool theme_enabled = sepch && (!strcmp("properties.rock", sepch + 1) || 864 + !strcmp("main_menu_config.rock", sepch + 1)); 865 866 if (current_plugin_handle) 867 {
+56 -31
apps/plugins/main_menu_config.c
··· 40 char * buffer, size_t buffer_len) 41 { 42 (void)data; 43 - (void)buffer; 44 - (void)buffer_len; 45 unsigned char *p = menu_items[selected_item].name; 46 int id = P2ID(p); 47 - return (id != -1) ? rb->str(id) : p; 48 } 49 50 static enum themable_icons menu_get_icon(int selected_item, void * data) ··· 157 158 if (id != -1) 159 { 160 - rb->talk_id(id, false); 161 rb->talk_id(menu_items[selected_item].enabled ? LANG_ON : LANG_OFF, true); 162 } 163 ··· 172 rb->global_settings->show_icons = true; 173 struct gui_synclist list; 174 bool done = false; 175 int action, cur_sel; 176 177 menu_table = rb->root_menu_get_options(&menu_item_count); ··· 182 rb->gui_synclist_set_voice_callback(&list, menu_speak_item); 183 rb->gui_synclist_set_icon_callback(&list, menu_get_icon); 184 rb->gui_synclist_set_nb_items(&list, menu_item_count); 185 - rb->gui_synclist_set_title(&list, rb->str(LANG_MAIN_MENU_ORDER), Icon_Rockbox); 186 - rb->gui_synclist_draw(&list); 187 rb->gui_synclist_speak_item(&list); 188 189 while (!done) 190 { 191 cur_sel = rb->gui_synclist_get_sel_pos(&list); 192 - action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); 193 if (rb->gui_synclist_do_button(&list, &action)) 194 continue; 195 196 switch (action) 197 { 198 case ACTION_STD_OK: 199 { 200 - MENUITEM_STRINGLIST(menu, "Main Menu Editor", NULL, 201 - ID2P(LANG_TOGGLE_ITEM), 202 ID2P(LANG_MOVE_ITEM_UP), 203 ID2P(LANG_MOVE_ITEM_DOWN), 204 - "----------", 205 - ID2P(LANG_LOAD_DEFAULT_CONFIGURATION), 206 - ID2P(LANG_SAVE_EXIT)); 207 switch (rb->do_menu(&menu, NULL, NULL, false)) 208 { 209 case 0: 210 - menu_items[cur_sel].enabled = !menu_items[cur_sel].enabled; 211 - break; 212 - case 1: 213 if (cur_sel == 0) 214 break; 215 swap_items(cur_sel, cur_sel - 1); 216 break; 217 - case 2: 218 if (cur_sel + 1 == menu_item_count) 219 break; 220 swap_items(cur_sel, cur_sel + 1); 221 break; 222 - case 4: 223 - rb->root_menu_set_default(&rb->global_settings->root_menu_customized, NULL); 224 - load_from_cfg(); 225 - break; 226 - case 5: 227 - done = true; 228 - save_to_cfg(); 229 - rb->global_settings->root_menu_customized = true; 230 - rb->settings_save(); 231 - break; 232 } 233 - if (!done) 234 - { 235 - rb->gui_synclist_draw(&list); 236 - rb->gui_synclist_speak_item(&list); 237 - } 238 break; 239 } 240 case ACTION_STD_CANCEL: ··· 243 } 244 } 245 246 rb->global_settings->show_icons = show_icons; 247 return PLUGIN_OK; 248 }
··· 40 char * buffer, size_t buffer_len) 41 { 42 (void)data; 43 unsigned char *p = menu_items[selected_item].name; 44 int id = P2ID(p); 45 + 46 + rb->snprintf(buffer, buffer_len, "%s: %s", (id != -1) ? rb->str(id) : p, 47 + menu_items[selected_item].enabled ? 48 + rb->str(LANG_ON) : rb->str(LANG_OFF)); 49 + 50 + return buffer; 51 } 52 53 static enum themable_icons menu_get_icon(int selected_item, void * data) ··· 160 161 if (id != -1) 162 { 163 + rb->talk_number(selected_item + 1, false); 164 + rb->talk_id(id, true); 165 rb->talk_id(menu_items[selected_item].enabled ? LANG_ON : LANG_OFF, true); 166 } 167 ··· 176 rb->global_settings->show_icons = true; 177 struct gui_synclist list; 178 bool done = false; 179 + bool changed = false; 180 int action, cur_sel; 181 182 menu_table = rb->root_menu_get_options(&menu_item_count); ··· 187 rb->gui_synclist_set_voice_callback(&list, menu_speak_item); 188 rb->gui_synclist_set_icon_callback(&list, menu_get_icon); 189 rb->gui_synclist_set_nb_items(&list, menu_item_count); 190 + rb->gui_synclist_set_title(&list, rb->str(LANG_MAIN_MENU), Icon_Rockbox); 191 rb->gui_synclist_speak_item(&list); 192 193 while (!done) 194 { 195 + rb->gui_synclist_draw(&list); 196 cur_sel = rb->gui_synclist_get_sel_pos(&list); 197 + action = rb->get_action(CONTEXT_LIST, HZ/10); 198 if (rb->gui_synclist_do_button(&list, &action)) 199 continue; 200 201 switch (action) 202 { 203 case ACTION_STD_OK: 204 + menu_items[cur_sel].enabled = !menu_items[cur_sel].enabled; 205 + rb->gui_synclist_speak_item(&list); 206 + changed = true; 207 + break; 208 + case ACTION_STD_CONTEXT: 209 { 210 + MENUITEM_STRINGLIST(menu, ID2P(LANG_MAIN_MENU), NULL, 211 ID2P(LANG_MOVE_ITEM_UP), 212 ID2P(LANG_MOVE_ITEM_DOWN), 213 + ID2P(LANG_LOAD_DEFAULT_CONFIGURATION)); 214 switch (rb->do_menu(&menu, NULL, NULL, false)) 215 { 216 case 0: 217 if (cur_sel == 0) 218 + { 219 + rb->splash(HZ, ID2P(LANG_FAILED)); 220 break; 221 + } 222 swap_items(cur_sel, cur_sel - 1); 223 + rb->gui_synclist_select_item(&list, cur_sel - 1); /* speaks */ 224 + changed = true; 225 break; 226 + case 1: 227 if (cur_sel + 1 == menu_item_count) 228 + { 229 + rb->splash(HZ, ID2P(LANG_FAILED)); 230 break; 231 + } 232 swap_items(cur_sel, cur_sel + 1); 233 + rb->gui_synclist_select_item(&list, cur_sel + 1); /* speaks */ 234 + changed = true; 235 break; 236 + case 2:; 237 + static const char *lines[] = 238 + {ID2P(LANG_RESET_ASK), ID2P(LANG_LOAD_DEFAULT_CONFIGURATION)}; 239 + static const struct text_message message={lines, 2}; 240 + 241 + switch(rb->gui_syncyesno_run(&message, NULL, NULL)) 242 + { 243 + case YESNO_YES: 244 + rb->root_menu_set_default(&rb->global_settings->root_menu_customized, NULL); 245 + load_from_cfg(); 246 + break; 247 + default: 248 + rb->splash(HZ, ID2P(LANG_CANCEL)); 249 + break; 250 + } 251 + /* fall-through */ 252 + default: 253 + rb->gui_synclist_speak_item(&list); 254 } 255 + rb->gui_synclist_set_title(&list, rb->str(LANG_MAIN_MENU), Icon_Rockbox); 256 break; 257 } 258 case ACTION_STD_CANCEL: ··· 261 } 262 } 263 264 + if (changed) 265 + { 266 + save_to_cfg(); 267 + rb->global_settings->root_menu_customized = true; 268 + rb->settings_save(); 269 + } 270 rb->global_settings->show_icons = show_icons; 271 + 272 return PLUGIN_OK; 273 }
+5 -8
manual/advanced_topics/main.tex
··· 5 6 \subsection{\label{ref:CustomisingTheMainMenu}Customising The Main Menu} 7 8 - It is possible to customise the main menu, i.e. to reorder or to hide some 9 - of its items (only the main menu can be customised, submenus can not). 10 - To accomplish this, load a \fname{.cfg} file (as described in 11 - \reference{ref:manage_settings}) containing the following line: 12 \config{root~menu~order:items}, where ``items'' is a comma separated list 13 (no spaces around the commas!) of the following 14 words: \config{bookmarks}, \config{files}, \opt{tagcache}{\config{database}, }% ··· 31 32 To reset the menu items to the default, use \config{root~menu~order:-} (i.e. 33 use a hyphen instead of ``items''). 34 - 35 - This configuration entry can only be created and edited with a text editor or 36 - the Main Menu Config Plugin (see \reference{ref:main_menu_config}). 37 - It is not possible to change this setting via the settings menu. 38 39 \subsection{\label{ref:CustomisingThePlayername}Customising The Playername} 40
··· 5 6 \subsection{\label{ref:CustomisingTheMainMenu}Customising The Main Menu} 7 8 + The easiest way to reorder or to hide menu items is via the settings menu 9 + (see \reference{ref:main_menu_config}). 10 + 11 + To accomplish this using a text editor instead, load a \fname{.cfg} file 12 + (as described in \reference{ref:manage_settings}) containing the following line: 13 \config{root~menu~order:items}, where ``items'' is a comma separated list 14 (no spaces around the commas!) of the following 15 words: \config{bookmarks}, \config{files}, \opt{tagcache}{\config{database}, }% ··· 32 33 To reset the menu items to the default, use \config{root~menu~order:-} (i.e. 34 use a hyphen instead of ``items''). 35 36 \subsection{\label{ref:CustomisingThePlayername}Customising The Playername} 37
+16
manual/main_menu/main.tex
··· 141 \reference{ref:Recordingsettings}. 142 } 143 144 \subsection{Manage Settings} 145 The \setting{Manage Settings} option allows the saving and re-loading of user 146 configuration settings, browsing the hard drive for alternate firmwares, and finally
··· 141 \reference{ref:Recordingsettings}. 142 } 143 144 + \subsection{Main Menu} 145 + {\label{ref:main_menu_config}} 146 + Allows you to hide or reorder items from the main menu. 147 + 148 + Press \ActionStdOk{} to toggle an item's visibility. 149 + 150 + Press \ActionStdContext{} to access the following options: 151 + \begin{description} 152 + \item[Move Item Up] Swap selected menu item with the previous one 153 + \item[Move Item down] Swap selected menu item with the next one 154 + \item[Load Default Configuration] Discard all customization 155 + \end{description} 156 + 157 + For an advanced description of the associated configuration entry, 158 + see \reference{ref:CustomisingTheMainMenu}. 159 + 160 \subsection{Manage Settings} 161 The \setting{Manage Settings} option allows the saving and re-loading of user 162 configuration settings, browsing the hard drive for alternate firmwares, and finally
+1 -16
manual/plugins/main_menu_config.tex
··· 1 \subsection{Main Menu Configuration} 2 - {\label{ref:main_menu_config}} 3 - 4 - This plugin helps you customizing the main menu (i.e. reorder or hide menu 5 - items). It changes the appropriate configuration file as described in 6 - \reference{ref:CustomisingTheMainMenu}. 7 - 8 - When you start the plugin, the available main menu items will be displayed. 9 - By pressing \ActionStdOk{} you open a menu with the following options: 10 - \begin{description} 11 - \item[Toggle Item] Hide the selected menu item or make it visible again 12 - \item[Move Item Up] Swap the selected menu item with the previous one 13 - \item[Move Item down] Swap the selected menu item with the next one 14 - \item[Load Default Configuration] Discards all customization 15 - \item[Exit] Save your changes to the configuration file and exit the plugin 16 - \end{description} 17 - You can leave the plugin without saving by pressing \ActionStdCancel{}.
··· 1 \subsection{Main Menu Configuration} 2 + see \reference{ref:main_menu_config}