summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2014-02-13 22:01:13 +1100
committerJonathan Gordon <rockbox@jdgordon.info>2014-02-13 22:11:23 +1100
commit6dbfd44b6e6a4e01066ff3a99748e586d7cd458a (patch)
tree0570c0dbe96277cb8e31a6797b3b8628aea1e5b0
parent1210de217ebdbd35734f57d82a6e935ef60e6555 (diff)
downloadrockbox-6dbfd44b6e6a4e01066ff3a99748e586d7cd458a.tar.gz
rockbox-6dbfd44b6e6a4e01066ff3a99748e586d7cd458a.zip
main_menu_config: New plugin to configur the main menu order
Plugins/Applications/main_menu_config allows you to edit the main menu order without having to manually edit config.cfg. Press the standard OK button to access the internal menu which allows you to move items up/down in the order and toggle their visibility. Exit via this menu to have the order saved. (Suggestions welcome to improve this UI) Change-Id: I59715ef1ca265aeb6f9666ef27026bc1093f2579
-rw-r--r--apps/plugin.c5
-rw-r--r--apps/plugin.h6
-rw-r--r--apps/plugins/CATEGORIES1
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/main_menu_config.c204
-rw-r--r--apps/root_menu.c12
-rw-r--r--apps/root_menu.h10
7 files changed, 233 insertions, 6 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index af06a4c484..f9179f3f08 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -792,6 +792,11 @@ static const struct plugin_api rockbox_api = {
792#endif 792#endif
793 793
794 rbversion, 794 rbversion,
795 root_menu_get_options,
796 root_menu_set_default,
797 root_menu_write_to_cfg,
798 root_menu_load_from_cfg,
799 settings_save,
795 800
796 /* new stuff at the end, sort into place next time 801 /* new stuff at the end, sort into place next time
797 the API gets incompatible */ 802 the API gets incompatible */
diff --git a/apps/plugin.h b/apps/plugin.h
index 1d1e9ee26e..0e0580501d 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -68,6 +68,7 @@ void* plugin_get_buffer(size_t *buffer_size);
68#include "mpeg.h" 68#include "mpeg.h"
69#include "audio.h" 69#include "audio.h"
70#include "mp3_playback.h" 70#include "mp3_playback.h"
71#include "root_menu.h"
71#include "talk.h" 72#include "talk.h"
72#ifdef RB_PROFILE 73#ifdef RB_PROFILE
73#include "profile.h" 74#include "profile.h"
@@ -964,6 +965,11 @@ struct plugin_api {
964#endif 965#endif
965 966
966 const char *rbversion; 967 const char *rbversion;
968 struct menu_table *(*root_menu_get_options)(int *nb_options);
969 void (*root_menu_set_default)(void* setting, void* defaultval);
970 char* (*root_menu_write_to_cfg)(void* setting, char*buf, int buf_len);
971 void (*root_menu_load_from_cfg)(void* setting, char *value);
972 int (*settings_save)(void);
967 973
968 /* new stuff at the end, sort into place next time 974 /* new stuff at the end, sort into place next time
969 the API gets incompatible */ 975 the API gets incompatible */
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES
index 54a316e84b..8a849aafc2 100644
--- a/apps/plugins/CATEGORIES
+++ b/apps/plugins/CATEGORIES
@@ -48,6 +48,7 @@ logo,demos
48lrcplayer,apps 48lrcplayer,apps
49lua,viewers 49lua,viewers
50fractals,demos 50fractals,demos
51main_menu_config,apps
51matrix,demos 52matrix,demos
52maze,games 53maze,games
53mazezam,games 54mazezam,games
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index c512a9e02f..59bd4023cc 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -11,6 +11,7 @@ keybox.c
11logo.c 11logo.c
12lrcplayer.c 12lrcplayer.c
13mosaique.c 13mosaique.c
14main_menu_config.c
14properties.c 15properties.c
15random_folder_advance_config.c 16random_folder_advance_config.c
16rockblox.c 17rockblox.c
diff --git a/apps/plugins/main_menu_config.c b/apps/plugins/main_menu_config.c
new file mode 100644
index 0000000000..da9fde8384
--- /dev/null
+++ b/apps/plugins/main_menu_config.c
@@ -0,0 +1,204 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2014 Jonathan Gordon
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21/* mandatory include for all plugins */
22#include "plugin.h"
23
24static struct menu_table *menu_table;
25static int menu_item_count;
26
27#define MAX_ITEM_NAME 64
28#define MAX_ITEMS 16
29struct items
30{
31 char string[MAX_ITEM_NAME];
32 bool enabled;
33};
34
35static struct items menu_items[MAX_ITEMS];
36
37
38static const char * menu_get_name(int selected_item, void * data,
39 char * buffer, size_t buffer_len)
40{
41 (void)data;
42 (void)buffer;
43 (void)buffer_len;
44
45 return menu_items[selected_item].string;
46}
47
48static enum themable_icons menu_get_icon(int selected_item, void * data)
49{
50 (void)data;
51
52 return menu_items[selected_item].enabled ? Icon_Config : Icon_NOICON;
53}
54
55void load_from_cfg(void)
56{
57 char config_str[128];
58 char *token, *save;
59 int done = 0;
60 int i = 0;
61 bool found = false;
62
63 rb->root_menu_write_to_cfg(NULL, config_str, sizeof(config_str));
64
65 token = strtok_r(config_str, ", ", &save);
66
67 while (token)
68 {
69 i = 0;
70 found = false;
71 for (i = 0, found = false; i < menu_item_count && !found; i++)
72 {
73 found = rb->strcmp(token, menu_table[i].string) == 0;
74 }
75 if (found)
76 {
77 rb->strcpy(menu_items[done].string, token);
78 menu_items[done].enabled = true;
79 done++;
80 }
81 token = strtok_r(NULL, ", ", &save);
82 }
83
84 if (done < menu_item_count)
85 {
86 for (i = 0; i < menu_item_count; i++)
87 {
88 found = false;
89 for (int j = 0; !found && j < done; j++)
90 {
91 found = rb->strcmp(menu_table[i].string, menu_items[j].string) == 0;
92 }
93
94 if (!found)
95 {
96 rb->strcpy(menu_items[done].string, menu_table[i].string);
97 menu_items[done].enabled = false;
98 done++;
99 }
100 }
101 }
102}
103
104static void save_to_cfg(void)
105{
106 char out[128];
107 int i, j = 0;
108
109 out[0] = '\0';
110 for (i = 0; i < menu_item_count; i++)
111 {
112 if (menu_items[i].enabled)
113 {
114 j += rb->snprintf(&out[j],sizeof(out) - j, "%s, ", menu_items[i].string);
115 }
116 }
117
118 rb->root_menu_load_from_cfg(&rb->global_settings->root_menu_customized, out);
119}
120
121static void swap_items(int a, int b)
122{
123 char temp[MAX_ITEM_NAME];
124 bool enabled;
125
126 rb->strcpy(temp, menu_items[a].string);
127 enabled = menu_items[a].enabled;
128 rb->strcpy(menu_items[a].string,
129 menu_items[b].string);
130 menu_items[a].enabled = menu_items[b].enabled;
131 rb->strcpy(menu_items[b].string, temp);
132 menu_items[b].enabled = enabled;
133}
134
135/* this is the plugin entry point */
136enum plugin_status plugin_start(const void* parameter)
137{
138 (void)parameter;
139 struct gui_synclist list;
140 bool done = false;
141 int action, cur_sel;
142
143 menu_table = rb->root_menu_get_options(&menu_item_count);
144 load_from_cfg();
145
146 rb->gui_synclist_init(&list, menu_get_name, NULL, false, 1, NULL);
147 rb->gui_synclist_set_icon_callback(&list, menu_get_icon);
148 rb->gui_synclist_set_nb_items(&list, menu_item_count);
149 rb->gui_synclist_set_title(&list, "Rockbox Main Menu Order", Icon_Rockbox);
150
151 while (!done)
152 {
153 rb->gui_synclist_draw(&list);
154 cur_sel = rb->gui_synclist_get_sel_pos(&list);
155 action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
156 if (rb->gui_synclist_do_button(&list,&action,LIST_WRAP_UNLESS_HELD))
157 continue;
158
159 switch (action)
160 {
161 case ACTION_STD_OK:
162 {
163 MENUITEM_STRINGLIST(menu, "Main Menu Editor", NULL,
164 "Toggle Item",
165 "Move Item Up", "Move Item down",
166 "----------",
167 "Load Default Configuration", "Exit");
168 switch (rb->do_menu(&menu, NULL, NULL, false))
169 {
170 case 0:
171 menu_items[cur_sel].enabled = !menu_items[cur_sel].enabled;
172 break;
173 case 1:
174 if (cur_sel == 0)
175 break;
176 swap_items(cur_sel, cur_sel - 1);
177 break;
178 case 2:
179 if (cur_sel + 1 == menu_item_count)
180 break;
181 swap_items(cur_sel, cur_sel + 1);
182 break;
183 case 4:
184 rb->root_menu_set_default(&rb->global_settings->root_menu_customized, NULL);
185 load_from_cfg();
186 break;
187 case 5:
188 done = true;
189 save_to_cfg();
190 rb->global_settings->root_menu_customized = true;
191 rb->settings_save();
192 break;
193 }
194 break;
195 }
196 case ACTION_STD_CANCEL:
197 done = true;
198 break;
199 }
200 }
201
202
203 return PLUGIN_OK;
204}
diff --git a/apps/root_menu.c b/apps/root_menu.c
index 71844dd41a..f83a97b9ed 100644
--- a/apps/root_menu.c
+++ b/apps/root_menu.c
@@ -484,10 +484,7 @@ MENUITEM_FUNCTION(do_shutdown_item, 0, ID2P(LANG_SHUTDOWN),
484struct menu_item_ex root_menu_; 484struct menu_item_ex root_menu_;
485static struct menu_callback_with_desc root_menu_desc = { 485static struct menu_callback_with_desc root_menu_desc = {
486 item_callback, ID2P(LANG_ROCKBOX_TITLE), Icon_Rockbox }; 486 item_callback, ID2P(LANG_ROCKBOX_TITLE), Icon_Rockbox };
487struct menu_table { 487
488 char *string;
489 const struct menu_item_ex *item;
490};
491static struct menu_table menu_table[] = { 488static struct menu_table menu_table[] = {
492 /* Order here represents the default ordering */ 489 /* Order here represents the default ordering */
493 { "bookmarks", &bookmarks }, 490 { "bookmarks", &bookmarks },
@@ -514,6 +511,13 @@ static struct menu_table menu_table[] = {
514#define MAX_MENU_ITEMS (sizeof(menu_table) / sizeof(struct menu_table)) 511#define MAX_MENU_ITEMS (sizeof(menu_table) / sizeof(struct menu_table))
515static struct menu_item_ex *root_menu__[MAX_MENU_ITEMS]; 512static struct menu_item_ex *root_menu__[MAX_MENU_ITEMS];
516 513
514struct menu_table *root_menu_get_options(int *nb_options)
515{
516 *nb_options = MAX_MENU_ITEMS;
517
518 return menu_table;
519}
520
517void root_menu_load_from_cfg(void* setting, char *value) 521void root_menu_load_from_cfg(void* setting, char *value)
518{ 522{
519 char *next = value, *start, *end; 523 char *next = value, *start, *end;
diff --git a/apps/root_menu.h b/apps/root_menu.h
index 32385d9530..6004a43f34 100644
--- a/apps/root_menu.h
+++ b/apps/root_menu.h
@@ -25,6 +25,12 @@
25#include "gcc_extensions.h" 25#include "gcc_extensions.h"
26 26
27void root_menu(void) NORETURN_ATTR; 27void root_menu(void) NORETURN_ATTR;
28struct menu_table {
29 char *string;
30 const struct menu_item_ex *item;
31};
32
33struct menu_table *root_menu_get_options(int *nb_options);
28 34
29enum { 35enum {
30 /* from old menu api, but still required*/ 36 /* from old menu api, but still required*/
@@ -60,7 +66,7 @@ enum {
60 GO_TO_SYSTEM_SCREEN, 66 GO_TO_SYSTEM_SCREEN,
61 GO_TO_SHORTCUTMENU 67 GO_TO_SHORTCUTMENU
62}; 68};
63 69#ifndef PLUGIN
64extern struct menu_item_ex root_menu_; 70extern struct menu_item_ex root_menu_;
65 71
66extern void previous_music_is_wps(void); 72extern void previous_music_is_wps(void);
@@ -69,7 +75,7 @@ void root_menu_load_from_cfg(void* setting, char *value);
69char* root_menu_write_to_cfg(void* setting, char*buf, int buf_len); 75char* root_menu_write_to_cfg(void* setting, char*buf, int buf_len);
70void root_menu_set_default(void* setting, void* defaultval); 76void root_menu_set_default(void* setting, void* defaultval);
71bool root_menu_is_changed(void* setting, void* defaultval); 77bool root_menu_is_changed(void* setting, void* defaultval);
72 78#endif
73 79
74 80
75#endif /* __ROOT_MENU_H__ */ 81#endif /* __ROOT_MENU_H__ */