-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathme.patch
More file actions
216 lines (210 loc) · 6.96 KB
/
me.patch
File metadata and controls
216 lines (210 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
Index: apps/menu.c
===================================================================
--- apps/menu.c (revision 12552)
+++ apps/menu.c (working copy)
@@ -390,7 +390,7 @@
static void init_menu_lists(const struct menu_item_ex *menu,
struct gui_synclist *lists, int selected, bool callback)
{
- int i, count = (menu->flags&MENU_COUNT_MASK)>>MENU_COUNT_SHIFT;
+ int i, count = MENU_NUM_OF_ITEMS(menu);
menu_callback_type menu_callback = NULL;
ICON icon = NOICON;
current_subitems_count = 0;
@@ -771,3 +771,64 @@
{
return do_menu(NULL, 0);
}
+
+/* How many items can be reordered */
+#define MAX_ITEMS_TO_REORDER 20
+
+static int find_item(char *find_what, char *where[], int cnt) {
+ int i;
+ for (i = 0; i < cnt; i++) {
+ if (strcmp(find_what, where[i]) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+bool menu_reorder_items(const struct menu_item_ex **items, char *item_names[],
+ char *ordered_names[], int item_cnt) {
+ const struct menu_item_ex *ordered_items[MAX_ITEMS_TO_REORDER];
+ bool item_occurred[MAX_ITEMS_TO_REORDER];
+ int item_pos; /* item position in the original list */
+ int i;
+
+ DEBUGF("Items to order (orig, permuted)\n");
+ for (i = 0; i < item_cnt; i++) {
+ DEBUGF("(%s, %s)\n", item_names[i], ordered_names[i]);
+ }
+
+ if (item_cnt > MAX_ITEMS_TO_REORDER) {
+ DEBUGF("Too many items to reorder: %d\n", item_cnt);
+ return false;
+ }
+ for (i = 0; i < item_cnt; i++) {
+ item_occurred[i] = false;
+ }
+ for (i = 0; i < item_cnt; i++) {
+ item_pos = find_item(ordered_names[i], item_names, item_cnt);
+ DEBUGF("Pos(%s) = %d\n", ordered_names[i], item_pos);
+ if (item_pos < 0) {
+ DEBUGF("Unknown item '%s'\n", ordered_names[i]);
+ return false;
+ }
+ if (item_occurred[item_pos]) {
+ DEBUGF("Double item '%s'\n", ordered_names[i]);
+ return false;
+ }
+ ordered_items[i] = items[item_pos];
+ item_occurred[item_pos] = true;
+ }
+ /* One more check (shouldn't be necessary but just for the case) */
+ for (i = 0; i < item_cnt; i++) {
+ if (!item_occurred[i]) {
+ DEBUGF("Item '%s' does not occur\n", item_names[i]);
+ return false;
+ }
+ }
+ /* If we've got here then everything went ok, i.e. it was a permutation */
+ for (i = 0; i < item_cnt; i++) {
+ items[i] = ordered_items[i];
+ }
+ DEBUGF("Successfully permuted %d items\n", item_cnt);
+ return true;
+}
Index: apps/menu.h
===================================================================
--- apps/menu.h (revision 12552)
+++ apps/menu.h (working copy)
@@ -56,7 +56,6 @@
void menu_set_cursor(int menu, int position);
void menu_talk_selected(int m);
-
enum menu_item_type {
MT_MENU = 0,
MT_SETTING,
@@ -123,6 +122,8 @@
bool do_setting_from_menu(const struct menu_item_ex *temp);
#define MENU_ITEM_COUNT(c) (c<<MENU_COUNT_SHIFT)
+#define MENU_NUM_OF_ITEMS(menu_ptr) ((menu_ptr->flags&MENU_COUNT_MASK)>>MENU_COUNT_SHIFT)
+
/* In all the following macros the argument names are as follows:
- name: The name for the variable (so it can be used in a MAKE_MENU()
- str: the string to display for this menu item. use ID2P() for LANG_* id's
@@ -241,5 +242,23 @@
{ (void*)name##_},{.callback_and_desc = & name##__}};
#endif /* HAVE_LCD_BITMAP */
+
+/* Reorders the given items.
+ *
+ * items menu items to reorder
+ * item_names names for referring of the items in the same order as the items
+ * ordered_names how the items should be reordered. These must be the names
+ * from item_names but (possibly) in the other order, i.e. a permutation
+ * of item_names.
+ * item_cnt number of the items and of the names
+ *
+ * The array items is reordered in-place. If something goes wrong
+ * (e.g. ordered_names contains a string not present in item_names)
+ * nothing is changed.
+ *
+ * Returns true iff everything went ok (and hence the items have been reordered).
+ */
+bool menu_reorder_items(const struct menu_item_ex **items, char *item_names[],
+ char *ordered_names[], int item_cnt);
#endif /* End __MENU_H__ */
Index: apps/root_menu.c
===================================================================
--- apps/root_menu.c (revision 12552)
+++ apps/root_menu.c (working copy)
@@ -299,13 +299,88 @@
return action;
}
+static bool adjust_menu(const struct menu_item_ex *menu, char *item_names[],
+ char *reorder_file_name) {
+ #define MAX_ENTRY_LENGTH 15
+ #define MAX_ENTRIES 15
+
+ char entries_storage[MAX_ENTRIES*MAX_ENTRY_LENGTH];
+ char *entries[MAX_ENTRIES], *p;
+ int fd, rc;
+ int entry_cnt, i;
+ bool retval;
+
+ /* Read the entries from the file */
+ fd = open(reorder_file_name, O_RDONLY);
+ if (fd < 0) {
+ return false;
+ }
+ entry_cnt = 0;
+ while (entry_cnt < MAX_ENTRIES) {
+ p = entries_storage+entry_cnt*MAX_ENTRY_LENGTH;
+ rc = read_line(fd, p, MAX_ENTRY_LENGTH);
+ if (rc <= 0) {
+ break;
+ }
+ if ((*p == '#') || (*p == '\0')) {
+ /* Skip comments and empty lines */
+ continue;
+ }
+ entries[entry_cnt++] = p;
+ }
+ close(fd);
+ DEBUGF("Read %d items\n", entry_cnt);
+ for (i = 0; i < entry_cnt; i++) {
+ DEBUGF("%d: '%s'\n", (i+1), entries_storage+i*MAX_ENTRY_LENGTH);
+ }
+ if (entry_cnt != MENU_NUM_OF_ITEMS(menu)) {
+ DEBUGF("Bad number of items in the file: %d (should be %d)\n",
+ entry_cnt, MENU_NUM_OF_ITEMS(menu));
+ return false;
+ }
+ retval = menu_reorder_items(menu->submenus, item_names, &(entries[0]), entry_cnt);
+ return retval;
+}
+
void root_menu(void)
{
+ /* Set to true when the entries in the root menu are reordered.
+ * This is made only once.
+ */
+ static bool tried_to_adjust_root_menu = false;
+ /* The strings in the following array must be in the same order
+ * as the entries in the MAKE_MENU for the root_menu_ (see above)
+ */
+ static char *root_menu_names[] = {
+ "bookmarks",
+ "files",
+ "database",
+ "now playing",
+ "settings",
+#ifdef HAVE_RECORDING
+ "recording",
+#endif
+#if CONFIG_TUNER
+ "fm radio",
+#endif
+ "playlists",
+ "plugins",
+ "system",
+#ifdef HAVE_LCD_CHARCELLS
+ "shutdown"
+#endif
+ };
+
int previous_browser = GO_TO_FILEBROWSER;
int previous_music = GO_TO_WPS;
int ret_val = GO_TO_ROOT;
int this_screen = GO_TO_ROOT;
int selected = 0;
+
+ if (!tried_to_adjust_root_menu) {
+ adjust_menu(&root_menu_, root_menu_names, "/.rockbox/main_menu.mnu");
+ tried_to_adjust_root_menu = true;
+ }
if (global_settings.start_in_screen == 0)
ret_val = (int)global_status.last_screen;