summaryrefslogtreecommitdiff
path: root/apps/plugins/main_menu_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/main_menu_config.c')
-rw-r--r--apps/plugins/main_menu_config.c66
1 files changed, 54 insertions, 12 deletions
diff --git a/apps/plugins/main_menu_config.c b/apps/plugins/main_menu_config.c
index 1015da7a40..f66165e63d 100644
--- a/apps/plugins/main_menu_config.c
+++ b/apps/plugins/main_menu_config.c
@@ -28,6 +28,7 @@ static int menu_item_count;
28#define MAX_ITEMS 16 28#define MAX_ITEMS 16
29struct items 29struct items
30{ 30{
31 unsigned char *name;
31 char string[MAX_ITEM_NAME]; 32 char string[MAX_ITEM_NAME];
32 bool enabled; 33 bool enabled;
33}; 34};
@@ -41,8 +42,9 @@ static const char * menu_get_name(int selected_item, void * data,
41 (void)data; 42 (void)data;
42 (void)buffer; 43 (void)buffer;
43 (void)buffer_len; 44 (void)buffer_len;
44 45 unsigned char *p = menu_items[selected_item].name;
45 return menu_items[selected_item].string; 46 int id = P2ID(p);
47 return (id != -1) ? rb->str(id) : p;
46} 48}
47 49
48static enum themable_icons menu_get_icon(int selected_item, void * data) 50static enum themable_icons menu_get_icon(int selected_item, void * data)
@@ -52,6 +54,16 @@ static enum themable_icons menu_get_icon(int selected_item, void * data)
52 return menu_items[selected_item].enabled ? Icon_Config : Icon_NOICON; 54 return menu_items[selected_item].enabled ? Icon_Config : Icon_NOICON;
53} 55}
54 56
57static unsigned char *item_name(int n)
58{
59 const struct menu_item_ex *item = menu_table[n].item;
60 return (item->flags & MENU_HAS_DESC) ?
61 item->callback_and_desc->desc :
62 (rb->strcmp("wps", menu_table[n].string) ?
63 (unsigned char *)menu_table[n].string :
64 ID2P(LANG_RESUME_PLAYBACK));
65}
66
55void load_from_cfg(void) 67void load_from_cfg(void)
56{ 68{
57 char config_str[128]; 69 char config_str[128];
@@ -60,20 +72,21 @@ void load_from_cfg(void)
60 int i = 0; 72 int i = 0;
61 bool found = false; 73 bool found = false;
62 74
75 config_str[0] = '\0';
63 rb->root_menu_write_to_cfg(NULL, config_str, sizeof(config_str)); 76 rb->root_menu_write_to_cfg(NULL, config_str, sizeof(config_str));
64 77
65 token = rb->strtok_r(config_str, ", ", &save); 78 token = rb->strtok_r(config_str, ", ", &save);
66 79
67 while (token) 80 while (token)
68 { 81 {
69 i = 0; 82 for (i = 0, found = false; i < menu_item_count; i++)
70 found = false;
71 for (i = 0, found = false; i < menu_item_count && !found; i++)
72 { 83 {
73 found = rb->strcmp(token, menu_table[i].string) == 0; 84 found = rb->strcmp(token, menu_table[i].string) == 0;
85 if (found) break;
74 } 86 }
75 if (found) 87 if (found)
76 { 88 {
89 menu_items[done].name = item_name(i);
77 rb->strcpy(menu_items[done].string, token); 90 rb->strcpy(menu_items[done].string, token);
78 menu_items[done].enabled = true; 91 menu_items[done].enabled = true;
79 done++; 92 done++;
@@ -93,6 +106,7 @@ void load_from_cfg(void)
93 106
94 if (!found) 107 if (!found)
95 { 108 {
109 menu_items[done].name = item_name(i);
96 rb->strcpy(menu_items[done].string, menu_table[i].string); 110 rb->strcpy(menu_items[done].string, menu_table[i].string);
97 menu_items[done].enabled = false; 111 menu_items[done].enabled = false;
98 done++; 112 done++;
@@ -120,18 +134,36 @@ static void save_to_cfg(void)
120 134
121static void swap_items(int a, int b) 135static void swap_items(int a, int b)
122{ 136{
137 unsigned char *name;
123 char temp[MAX_ITEM_NAME]; 138 char temp[MAX_ITEM_NAME];
124 bool enabled; 139 bool enabled;
125 140
141 name = menu_items[a].name;
126 rb->strcpy(temp, menu_items[a].string); 142 rb->strcpy(temp, menu_items[a].string);
127 enabled = menu_items[a].enabled; 143 enabled = menu_items[a].enabled;
144 menu_items[a].name = menu_items[b].name;
128 rb->strcpy(menu_items[a].string, 145 rb->strcpy(menu_items[a].string,
129 menu_items[b].string); 146 menu_items[b].string);
130 menu_items[a].enabled = menu_items[b].enabled; 147 menu_items[a].enabled = menu_items[b].enabled;
148 menu_items[b].name = name;
131 rb->strcpy(menu_items[b].string, temp); 149 rb->strcpy(menu_items[b].string, temp);
132 menu_items[b].enabled = enabled; 150 menu_items[b].enabled = enabled;
133} 151}
134 152
153static int menu_speak_item(int selected_item, void *data)
154{
155 (void) data;
156 int id = P2ID(menu_items[selected_item].name);
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
164 return 0;
165}
166
135/* this is the plugin entry point */ 167/* this is the plugin entry point */
136enum plugin_status plugin_start(const void* parameter) 168enum plugin_status plugin_start(const void* parameter)
137{ 169{
@@ -144,13 +176,16 @@ enum plugin_status plugin_start(const void* parameter)
144 load_from_cfg(); 176 load_from_cfg();
145 177
146 rb->gui_synclist_init(&list, menu_get_name, NULL, false, 1, NULL); 178 rb->gui_synclist_init(&list, menu_get_name, NULL, false, 1, NULL);
179 if (rb->global_settings->talk_menu)
180 rb->gui_synclist_set_voice_callback(&list, menu_speak_item);
147 rb->gui_synclist_set_icon_callback(&list, menu_get_icon); 181 rb->gui_synclist_set_icon_callback(&list, menu_get_icon);
148 rb->gui_synclist_set_nb_items(&list, menu_item_count); 182 rb->gui_synclist_set_nb_items(&list, menu_item_count);
149 rb->gui_synclist_set_title(&list, "Rockbox Main Menu Order", Icon_Rockbox); 183 rb->gui_synclist_set_title(&list, rb->str(LANG_MAIN_MENU_ORDER), Icon_Rockbox);
184 rb->gui_synclist_draw(&list);
185 rb->gui_synclist_speak_item(&list);
150 186
151 while (!done) 187 while (!done)
152 { 188 {
153 rb->gui_synclist_draw(&list);
154 cur_sel = rb->gui_synclist_get_sel_pos(&list); 189 cur_sel = rb->gui_synclist_get_sel_pos(&list);
155 action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); 190 action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
156 if (rb->gui_synclist_do_button(&list,&action,LIST_WRAP_UNLESS_HELD)) 191 if (rb->gui_synclist_do_button(&list,&action,LIST_WRAP_UNLESS_HELD))
@@ -161,10 +196,12 @@ enum plugin_status plugin_start(const void* parameter)
161 case ACTION_STD_OK: 196 case ACTION_STD_OK:
162 { 197 {
163 MENUITEM_STRINGLIST(menu, "Main Menu Editor", NULL, 198 MENUITEM_STRINGLIST(menu, "Main Menu Editor", NULL,
164 "Toggle Item", 199 ID2P(LANG_TOGGLE_ITEM),
165 "Move Item Up", "Move Item down", 200 ID2P(LANG_MOVE_ITEM_UP),
166 "----------", 201 ID2P(LANG_MOVE_ITEM_DOWN),
167 "Load Default Configuration", "Exit"); 202 "----------",
203 ID2P(LANG_LOAD_DEFAULT_CONFIGURATION),
204 ID2P(LANG_SAVE_EXIT));
168 switch (rb->do_menu(&menu, NULL, NULL, false)) 205 switch (rb->do_menu(&menu, NULL, NULL, false))
169 { 206 {
170 case 0: 207 case 0:
@@ -191,6 +228,11 @@ enum plugin_status plugin_start(const void* parameter)
191 rb->settings_save(); 228 rb->settings_save();
192 break; 229 break;
193 } 230 }
231 if (!done)
232 {
233 rb->gui_synclist_draw(&list);
234 rb->gui_synclist_speak_item(&list);
235 }
194 break; 236 break;
195 } 237 }
196 case ACTION_STD_CANCEL: 238 case ACTION_STD_CANCEL: