summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/CATEGORIES1
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/main_menu_config.c204
3 files changed, 206 insertions, 0 deletions
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}