diff options
Diffstat (limited to 'apps/shortcuts.c')
-rw-r--r-- | apps/shortcuts.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/apps/shortcuts.c b/apps/shortcuts.c index d7868461a7..50b8decfc6 100644 --- a/apps/shortcuts.c +++ b/apps/shortcuts.c | |||
@@ -6,7 +6,6 @@ | |||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | 6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | 7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
8 | * \/ \/ \/ \/ \/ | 8 | * \/ \/ \/ \/ \/ |
9 | * $Id$ | ||
10 | * | 9 | * |
11 | * Copyright (C) 2011 Jonathan Gordon | 10 | * Copyright (C) 2011 Jonathan Gordon |
12 | * | 11 | * |
@@ -44,6 +43,7 @@ | |||
44 | #include "onplay.h" | 43 | #include "onplay.h" |
45 | #include "screens.h" | 44 | #include "screens.h" |
46 | #include "talk.h" | 45 | #include "talk.h" |
46 | #include "yesno.h" | ||
47 | 47 | ||
48 | 48 | ||
49 | #define MAX_SHORTCUT_NAME 32 | 49 | #define MAX_SHORTCUT_NAME 32 |
@@ -135,6 +135,21 @@ static struct shortcut* get_shortcut(int index) | |||
135 | return &h->shortcuts[handle_index]; | 135 | return &h->shortcuts[handle_index]; |
136 | } | 136 | } |
137 | 137 | ||
138 | static void remove_shortcut(int index) | ||
139 | { | ||
140 | int this = index, next = index + 1; | ||
141 | struct shortcut *prev = get_shortcut(this); | ||
142 | |||
143 | while (next <= shortcut_count) | ||
144 | { | ||
145 | struct shortcut *sc = get_shortcut(next); | ||
146 | memcpy(prev, sc, sizeof(struct shortcut)); | ||
147 | next++; | ||
148 | prev = sc; | ||
149 | } | ||
150 | shortcut_count--; | ||
151 | } | ||
152 | |||
138 | static bool verify_shortcut(struct shortcut* sc) | 153 | static bool verify_shortcut(struct shortcut* sc) |
139 | { | 154 | { |
140 | switch (sc->type) | 155 | switch (sc->type) |
@@ -168,15 +183,18 @@ static void init_shortcut(struct shortcut* sc) | |||
168 | } | 183 | } |
169 | 184 | ||
170 | static int first_idx_to_writeback = -1; | 185 | static int first_idx_to_writeback = -1; |
186 | static bool overwrite_shortcuts = false; | ||
171 | static void shortcuts_ata_idle_callback(void* data) | 187 | static void shortcuts_ata_idle_callback(void* data) |
172 | { | 188 | { |
173 | (void)data; | 189 | (void)data; |
174 | int fd; | 190 | int fd; |
175 | char buf[MAX_PATH]; | 191 | char buf[MAX_PATH]; |
176 | int current_idx = first_idx_to_writeback; | 192 | int current_idx = first_idx_to_writeback; |
193 | int append = overwrite_shortcuts ? O_TRUNC : O_APPEND; | ||
194 | |||
177 | if (first_idx_to_writeback < 0) | 195 | if (first_idx_to_writeback < 0) |
178 | return; | 196 | return; |
179 | fd = open(SHORTCUTS_FILENAME, O_APPEND|O_RDWR|O_CREAT, 0644); | 197 | fd = open(SHORTCUTS_FILENAME, append|O_RDWR|O_CREAT, 0644); |
180 | if (fd < 0) | 198 | if (fd < 0) |
181 | return; | 199 | return; |
182 | while (current_idx < shortcut_count) | 200 | while (current_idx < shortcut_count) |
@@ -218,8 +236,10 @@ void shortcuts_add(enum shortcut_type type, const char* value) | |||
218 | sc->u.setting = (void*)value; | 236 | sc->u.setting = (void*)value; |
219 | else | 237 | else |
220 | strlcpy(sc->u.path, value, MAX_PATH); | 238 | strlcpy(sc->u.path, value, MAX_PATH); |
239 | |||
221 | if (first_idx_to_writeback < 0) | 240 | if (first_idx_to_writeback < 0) |
222 | first_idx_to_writeback = shortcut_count - 1; | 241 | first_idx_to_writeback = shortcut_count - 1; |
242 | overwrite_shortcuts = false; | ||
223 | register_storage_idle_func(shortcuts_ata_idle_callback); | 243 | register_storage_idle_func(shortcuts_ata_idle_callback); |
224 | } | 244 | } |
225 | 245 | ||
@@ -354,6 +374,24 @@ static int shortcut_menu_get_action(int action, struct gui_synclist *lists) | |||
354 | (void)lists; | 374 | (void)lists; |
355 | if (action == ACTION_STD_OK) | 375 | if (action == ACTION_STD_OK) |
356 | return ACTION_STD_CANCEL; | 376 | return ACTION_STD_CANCEL; |
377 | else if (action == ACTION_STD_CONTEXT) | ||
378 | { | ||
379 | int selection = gui_synclist_get_sel_pos(lists); | ||
380 | |||
381 | if (!yesno_pop(ID2P(LANG_REALLY_DELETE))) | ||
382 | return ACTION_REDRAW; | ||
383 | |||
384 | remove_shortcut(selection); | ||
385 | gui_synclist_set_nb_items(lists, shortcut_count); | ||
386 | if (selection >= shortcut_count) | ||
387 | gui_synclist_select_item(lists, shortcut_count - 1); | ||
388 | first_idx_to_writeback = 0; | ||
389 | overwrite_shortcuts = true; | ||
390 | shortcuts_ata_idle_callback(NULL); | ||
391 | if (shortcut_count == 0) | ||
392 | return ACTION_STD_CANCEL; | ||
393 | return ACTION_REDRAW; | ||
394 | } | ||
357 | return action; | 395 | return action; |
358 | } | 396 | } |
359 | 397 | ||