Take out that code from the dynamic playlist viewer that aborts track move-in-progres...
[kugel-rb.git] / apps / playlist_viewer.c
blobdfd2515c95beca4a3ab8e3a0662b6ac2562c1bd7
1 /***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
11 * Copyright (C) 2003 Hardeep Sidhu
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 * Kevin Ferrare 2005/10/16
24 * multi-screen support, rewrote a lot of code
26 #include <string.h>
27 #include <sprintf.h>
28 #include "playlist.h"
29 #include "audio.h"
30 #include "screens.h"
31 #include "settings.h"
32 #include "icons.h"
33 #include "menu.h"
34 #include "plugin.h"
35 #include "keyboard.h"
36 #include "filetypes.h"
37 #include "onplay.h"
38 #include "talk.h"
39 #include "misc.h"
40 #include "action.h"
41 #include "debug.h"
42 #include "backlight.h"
44 #include "lang.h"
46 #include "playlist_viewer.h"
47 #include "playlist_catalog.h"
48 #include "icon.h"
49 #include "list.h"
50 #include "splash.h"
51 #include "playlist_menu.h"
53 /* Maximum number of tracks we can have loaded at one time */
54 #define MAX_PLAYLIST_ENTRIES 200
56 /* The number of items between the selected one and the end/start of
57 * the buffer under which the buffer must reload */
58 #define MIN_BUFFER_MARGIN (screens[0].getnblines()+1)
60 /* Information about a specific track */
61 struct playlist_entry {
62 char *name; /* Formatted track name */
63 int index; /* Playlist index */
64 int display_index; /* Display index */
65 bool queued; /* Is track queued? */
66 bool skipped; /* Is track marked as bad? */
69 enum direction
71 FORWARD,
72 BACKWARD
75 struct playlist_buffer
77 char *name_buffer; /* Buffer used to store track names */
78 int buffer_size; /* Size of name buffer */
80 int first_index; /* Real index of first track loaded inside
81 the buffer */
83 enum direction direction; /* Direction of the buffer (if the buffer
84 was loaded BACKWARD, the last track in
85 the buffer has a real index < to the
86 real index of the the first track)*/
88 struct playlist_entry tracks[MAX_PLAYLIST_ENTRIES];
89 int num_loaded; /* Number of track entries loaded in buffer */
92 /* Global playlist viewer settings */
93 struct playlist_viewer {
94 struct playlist_info* playlist; /* playlist being viewed */
95 int num_tracks; /* Number of tracks in playlist */
96 int current_playing_track; /* Index of current playing track */
97 int selected_track; /* The selected track, relative (first is 0) */
98 int moving_track; /* The track to move, relative (first is 0)
99 or -1 if nothing is currently being moved */
100 int moving_playlist_index; /* Playlist-relative index (as opposed to
101 viewer-relative index) of moving track */
102 struct playlist_buffer buffer;
105 static struct playlist_viewer viewer;
107 /* Used when viewing playlists on disk */
108 static struct playlist_info temp_playlist;
110 static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer,
111 int names_buffer_size);
112 static void playlist_buffer_load_entries(struct playlist_buffer * pb, int index,
113 enum direction direction);
114 static int playlist_entry_load(struct playlist_entry *entry, int index,
115 char* name_buffer, int remaining_size);
117 static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb,
118 int index);
120 static bool playlist_viewer_init(struct playlist_viewer * viewer,
121 const char* filename, bool reload);
123 static void format_name(char* dest, const char* src);
124 static void format_line(const struct playlist_entry* track, char* str,
125 int len);
127 static bool update_playlist(bool force);
128 static int onplay_menu(int index);
129 static bool viewer_menu(void);
130 static int save_playlist_func(void);
132 static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer,
133 int names_buffer_size)
135 pb->name_buffer=names_buffer;
136 pb->buffer_size=names_buffer_size;
137 pb->first_index=0;
138 pb->num_loaded=0;
142 * Loads the entries following 'index' in the playlist buffer
144 static void playlist_buffer_load_entries(struct playlist_buffer *pb, int index,
145 enum direction direction)
147 int num_entries = viewer.num_tracks;
148 char* p = pb->name_buffer;
149 int remaining = pb->buffer_size;
150 int i;
152 pb->first_index = index;
153 if (num_entries > MAX_PLAYLIST_ENTRIES)
154 num_entries = MAX_PLAYLIST_ENTRIES;
156 for(i=0; i<num_entries; i++)
158 int len = playlist_entry_load(&(pb->tracks[i]), index, p, remaining);
159 if (len < 0)
161 /* Out of name buffer space */
162 num_entries = i;
163 break;
166 p += len;
167 remaining -= len;
169 if(direction==FORWARD)
170 index++;
171 else
172 index--;
173 index+=viewer.num_tracks;
174 index%=viewer.num_tracks;
176 pb->direction=direction;
177 pb->num_loaded = i;
180 static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb,
181 enum direction direction)
183 if(direction==FORWARD)
185 int min_start=viewer.selected_track-2*screens[0].getnblines();
186 while(min_start<0)
187 min_start+=viewer.num_tracks;
188 min_start %= viewer.num_tracks;
189 playlist_buffer_load_entries(pb, min_start, FORWARD);
191 else
193 int max_start=viewer.selected_track+2*screens[0].getnblines();
194 max_start%=viewer.num_tracks;
195 playlist_buffer_load_entries(pb, max_start, BACKWARD);
199 static int playlist_entry_load(struct playlist_entry *entry, int index,
200 char* name_buffer, int remaining_size)
202 struct playlist_track_info info;
203 int len;
205 /* Playlist viewer orders songs based on display index. We need to
206 convert to real playlist index to access track */
207 index = (index + playlist_get_first_index(viewer.playlist)) %
208 viewer.num_tracks;
209 if (playlist_get_track_info(viewer.playlist, index, &info) < 0)
210 return -1;
212 len = strlen(info.filename) + 1;
214 if (len <= remaining_size)
216 strcpy(name_buffer, info.filename);
218 entry->name = name_buffer;
219 entry->index = info.index;
220 entry->display_index = info.display_index;
221 entry->queued = info.attr & PLAYLIST_ATTR_QUEUED;
222 entry->skipped = info.attr & PLAYLIST_ATTR_SKIPPED;
223 return len;
225 return -1;
228 static int playlist_buffer_get_index(struct playlist_buffer *pb, int index)
230 int buffer_index;
231 if(pb->direction==FORWARD)
233 if(index>=pb->first_index)
234 buffer_index=index-pb->first_index;
235 else /* rotation : track0 in buffer + requested track */
236 buffer_index=(viewer.num_tracks-pb->first_index)+(index);
238 else
240 if(index<=pb->first_index)
241 buffer_index=pb->first_index-index;
242 else /* rotation : track0 in buffer + dist from the last track
243 to the requested track (num_tracks-requested track) */
244 buffer_index=(pb->first_index)+(viewer.num_tracks-index);
246 return(buffer_index);
249 #define distance(a, b) \
250 a>b? (a) - (b) : (b) - (a)
251 static bool playlist_buffer_needs_reload(struct playlist_buffer* pb,
252 int track_index)
254 if(pb->num_loaded==viewer.num_tracks)
255 return(false);
256 int selected_index=playlist_buffer_get_index(pb, track_index);
257 int first_buffer_index=playlist_buffer_get_index(pb, pb->first_index);
258 int distance_beginning=distance(selected_index, first_buffer_index);
259 if(distance_beginning<MIN_BUFFER_MARGIN)
260 return(true);
262 if(pb->num_loaded - distance_beginning < MIN_BUFFER_MARGIN)
263 return(true);
264 return(false);
267 static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb,
268 int index)
270 int buffer_index=playlist_buffer_get_index(pb, index);
271 return(&(pb->tracks[buffer_index]));
274 /* Initialize the playlist viewer. */
275 static bool playlist_viewer_init(struct playlist_viewer * viewer,
276 const char* filename, bool reload)
278 char* buffer;
279 size_t buffer_size;
280 bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE);
281 bool have_list = filename || is_playing;
282 if (!have_list && (global_status.resume_index != -1))
284 /* Try to restore the list from control file */
285 have_list = (playlist_resume() != -1);
287 if (!have_list && (playlist_amount() > 0))
289 /*If dynamic playlist still exists, view it anyway even
290 if playback has reached the end of the playlist */
291 have_list = true;
293 if (!have_list)
295 /* Nothing to view, exit */
296 splash(HZ, str(LANG_CATALOG_NO_PLAYLISTS));
297 return false;
300 buffer = plugin_get_buffer(&buffer_size);
301 if (!buffer)
302 return false;
304 if (!filename)
305 viewer->playlist = NULL;
306 else
308 /* Viewing playlist on disk */
309 const char *dir, *file;
310 char *temp_ptr;
311 char *index_buffer = NULL;
312 ssize_t index_buffer_size = 0;
314 viewer->playlist = &temp_playlist;
316 /* Separate directory from filename */
317 temp_ptr = strrchr(filename+1,'/');
318 if (temp_ptr)
320 *temp_ptr = 0;
321 dir = filename;
322 file = temp_ptr + 1;
324 else
326 dir = "/";
327 file = filename+1;
330 if (is_playing)
332 /* Something is playing, use half the plugin buffer for playlist
333 indices */
334 index_buffer_size = buffer_size / 2;
335 index_buffer = buffer;
338 playlist_create_ex(viewer->playlist, dir, file, index_buffer,
339 index_buffer_size, buffer+index_buffer_size,
340 buffer_size-index_buffer_size);
342 if (temp_ptr)
343 *temp_ptr = '/';
345 buffer += index_buffer_size;
346 buffer_size -= index_buffer_size;
348 playlist_buffer_init(&viewer->buffer, buffer, buffer_size );
350 viewer->moving_track = -1;
351 viewer->moving_playlist_index = -1;
353 if (!reload)
355 if (viewer->playlist)
356 viewer->selected_track = 0;
357 else
358 viewer->selected_track = playlist_get_display_index() - 1;
361 if (!update_playlist(true))
362 return false;
363 return true;
366 /* Format trackname for display purposes */
367 static void format_name(char* dest, const char* src)
369 switch (global_settings.playlist_viewer_track_display)
371 case 0:
372 default:
374 /* Only display the filename */
375 char* p = strrchr(src, '/');
377 strcpy(dest, p+1);
379 /* Remove the extension */
380 strrsplt(dest, '.');
382 break;
384 case 1:
385 /* Full path */
386 strcpy(dest, src);
387 break;
391 /* Format display line */
392 static void format_line(const struct playlist_entry* track, char* str,
393 int len)
395 char name[MAX_PATH];
396 char *skipped = "";
398 format_name(name, track->name);
400 if (track->skipped)
401 skipped = "(ERR) ";
403 if (global_settings.playlist_viewer_indices)
404 /* Display playlist index */
405 snprintf(str, len, "%d. %s%s", track->display_index, skipped, name);
406 else
407 snprintf(str, len, "%s%s", skipped, name);
411 /* Update playlist in case something has changed or forced */
412 static bool update_playlist(bool force)
414 if (!viewer.playlist)
415 playlist_get_resume_info(&viewer.current_playing_track);
416 else
417 viewer.current_playing_track = -1;
418 int nb_tracks=playlist_amount_ex(viewer.playlist);
419 force=force || nb_tracks != viewer.num_tracks;
420 if (force)
422 /* Reload tracks */
423 viewer.num_tracks = nb_tracks;
424 if (viewer.num_tracks <= 0)
426 global_status.resume_index = -1;
427 global_status.resume_offset = -1;
428 return false;
430 playlist_buffer_load_entries_screen(&viewer.buffer, FORWARD);
431 if (viewer.buffer.num_loaded <= 0)
433 global_status.resume_index = -1;
434 global_status.resume_offset = -1;
435 return false;
438 return true;
441 /* Menu of playlist commands. Invoked via ON+PLAY on main viewer screen.
442 Returns -1 if USB attached, 0 if no playlist change, and 1 if playlist
443 changed. */
444 static int onplay_menu(int index)
446 int result, ret = 0;
447 struct playlist_entry * current_track=
448 playlist_buffer_get_track(&viewer.buffer, index);
449 MENUITEM_STRINGLIST(menu_items, ID2P(LANG_PLAYLIST), NULL,
450 ID2P(LANG_REMOVE), ID2P(LANG_MOVE),
451 ID2P(LANG_CATALOG_ADD_TO), ID2P(LANG_CATALOG_ADD_TO_NEW));
452 bool current = (current_track->index == viewer.current_playing_track);
454 result = do_menu(&menu_items, NULL, NULL, false);
455 if (result == MENU_ATTACHED_USB)
457 ret = -1;
459 else if (result >= 0)
461 /* Abort current move */
462 viewer.moving_track = -1;
463 viewer.moving_playlist_index = -1;
465 switch (result)
467 case 0:
468 /* delete track */
469 playlist_delete(viewer.playlist, current_track->index);
470 if (current)
472 if (playlist_amount_ex(viewer.playlist) <= 0)
473 audio_stop();
474 else
476 /* Start playing new track except if it's the lasttrack
477 track in the playlist and repeat mode is disabled */
478 current_track =
479 playlist_buffer_get_track(&viewer.buffer, index);
480 if (current_track->display_index!=viewer.num_tracks ||
481 global_settings.repeat_mode == REPEAT_ALL)
483 #if CONFIG_CODEC != SWCODEC
484 talk_buffer_steal(); /* will use the mp3 buffer */
485 #endif
486 audio_play(0);
487 viewer.current_playing_track = -1;
491 ret = 1;
492 break;
493 case 1:
494 /* move track */
495 viewer.moving_track = index;
496 viewer.moving_playlist_index = current_track->index;
497 ret = 0;
498 break;
499 case 2: /* add to catalog */
500 case 3: /* add to a new one */
501 catalog_add_to_a_playlist(current_track->name,
502 FILE_ATTR_AUDIO,
503 result==3, NULL);
504 ret = 0;
505 break;
508 return ret;
511 /* Menu of viewer options. Invoked via F1(r) or Menu(p). */
512 MENUITEM_SETTING(show_icons, &global_settings.playlist_viewer_icons, NULL);
513 MENUITEM_SETTING(show_indices, &global_settings.playlist_viewer_indices, NULL);
514 MENUITEM_SETTING(track_display,
515 &global_settings.playlist_viewer_track_display, NULL);
516 MENUITEM_FUNCTION(save_playlist_item, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST),
517 save_playlist_func, 0, NULL, Icon_NOICON);
518 MAKE_MENU(viewer_settings_menu, ID2P(LANG_PLAYLISTVIEWER_SETTINGS),
519 NULL, Icon_Playlist,
520 &show_icons, &show_indices, &track_display, &save_playlist_item);
521 static bool viewer_menu(void)
523 return do_menu(&viewer_settings_menu, NULL, NULL, false) == MENU_ATTACHED_USB;
526 /* Save playlist to disk */
527 static int save_playlist_func(void)
529 save_playlist_screen(viewer.playlist);
530 return 0;
533 /* View current playlist */
534 bool playlist_viewer(void)
536 return playlist_viewer_ex(NULL);
539 static int get_track_num( struct playlist_viewer * local_viewer,
540 int selected_item )
542 if( local_viewer->moving_track >= 0 )
544 if( local_viewer->selected_track == selected_item )
546 return local_viewer->moving_track;
548 else if( local_viewer->selected_track > selected_item
549 && selected_item >= local_viewer->moving_track )
551 return selected_item+1; /* move down */
553 else if( local_viewer->selected_track < selected_item
554 && selected_item <= local_viewer->moving_track )
556 return selected_item-1; /* move up */
559 return selected_item;
562 static const char* playlist_callback_name(int selected_item,
563 void *data,
564 char *buffer,
565 size_t buffer_len)
567 struct playlist_viewer * local_viewer = (struct playlist_viewer *)data;
569 int track_num = get_track_num(local_viewer, selected_item);
570 struct playlist_entry *track =
571 playlist_buffer_get_track(&(local_viewer->buffer), track_num);
573 format_line(track, buffer, buffer_len);
575 return(buffer);
579 static enum themable_icons playlist_callback_icons(int selected_item,
580 void *data)
582 struct playlist_viewer * local_viewer=(struct playlist_viewer *)data;
584 int track_num = get_track_num(local_viewer, selected_item);
585 struct playlist_entry *track=
586 playlist_buffer_get_track(&(local_viewer->buffer), track_num);
588 if (track->index == local_viewer->current_playing_track)
590 /* Current playing track */
591 return Icon_Audio;
593 else if (track->index == local_viewer->moving_playlist_index)
595 /* Track we are moving */
596 return Icon_Moving;
598 else if (track->queued)
600 /* Queued track */
601 return Icon_Queued;
603 else
604 return Icon_NOICON;
607 /* Main viewer function. Filename identifies playlist to be viewed. If NULL,
608 view current playlist. */
609 bool playlist_viewer_ex(const char* filename)
611 bool ret = false; /* return value */
612 bool exit=false; /* exit viewer */
613 int button;
614 struct gui_synclist playlist_lists;
615 if (!playlist_viewer_init(&viewer, filename, false))
616 goto exit;
618 gui_synclist_init(&playlist_lists, playlist_callback_name,
619 &viewer, false, 1, NULL);
620 gui_synclist_set_icon_callback(&playlist_lists,
621 global_settings.playlist_viewer_icons?
622 &playlist_callback_icons:NULL);
623 gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks);
624 gui_synclist_select_item(&playlist_lists, viewer.selected_track);
625 gui_synclist_set_title(&playlist_lists, str(LANG_PLAYLIST), Icon_Playlist);
626 gui_synclist_draw(&playlist_lists);
627 while (!exit)
629 int track;
631 if (global_status.resume_index != -1 && !viewer.playlist)
632 playlist_get_resume_info(&track);
633 else
634 track = -1;
636 if (track != viewer.current_playing_track ||
637 playlist_amount_ex(viewer.playlist) != viewer.num_tracks)
639 /* Playlist has changed (new track started?) */
640 if (!update_playlist(false))
641 goto exit;
642 /*Needed because update_playlist gives wrong value when
643 playing is stopped*/
644 viewer.current_playing_track = track;
645 gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks);
647 gui_synclist_draw(&playlist_lists);
650 /* Timeout so we can determine if play status has changed */
651 button = get_action(CONTEXT_TREE,HZ/2);
652 if( (gui_synclist_do_button(&playlist_lists, &button,LIST_WRAP_UNLESS_HELD)) )
654 viewer.selected_track=gui_synclist_get_sel_pos(&playlist_lists);
655 if(playlist_buffer_needs_reload(&viewer.buffer,
656 viewer.selected_track))
657 playlist_buffer_load_entries_screen(&viewer.buffer,
658 button==ACTION_STD_NEXT?
659 FORWARD
661 BACKWARD
663 gui_synclist_draw(&playlist_lists);
665 switch (button)
667 case ACTION_TREE_WPS:
668 case ACTION_STD_CANCEL:
670 if (viewer.moving_track >= 0)
672 viewer.selected_track = viewer.moving_track;
673 gui_synclist_select_item(&playlist_lists, viewer.moving_track);
674 viewer.moving_track = -1;
675 viewer.moving_playlist_index = -1;
676 gui_synclist_draw(&playlist_lists);
678 else
679 exit = true;
680 break;
682 case ACTION_STD_OK:
684 struct playlist_entry * current_track =
685 playlist_buffer_get_track(&viewer.buffer,
686 viewer.selected_track);
687 if (viewer.moving_track >= 0)
689 /* Move track */
690 int ret_val;
692 ret_val = playlist_move(viewer.playlist,
693 viewer.moving_playlist_index,
694 current_track->index);
695 if (ret_val < 0)
696 splashf(HZ, (unsigned char *)"%s %s", str(LANG_MOVE),
697 str(LANG_FAILED));
698 update_playlist(true);
699 viewer.moving_track = -1;
700 viewer.moving_playlist_index = -1;
702 else if (!viewer.playlist)
704 /* play new track */
705 playlist_start(current_track->index, 0);
706 update_playlist(false);
708 else
710 /* New playlist */
711 if (playlist_set_current(viewer.playlist) < 0)
712 goto exit;
714 playlist_start(current_track->index, 0);
716 /* Our playlist is now the current list */
717 if (!playlist_viewer_init(&viewer, NULL, true))
718 goto exit;
720 gui_synclist_draw(&playlist_lists);
722 break;
724 case ACTION_STD_CONTEXT:
726 /* ON+PLAY menu */
727 int ret_val;
729 ret_val = onplay_menu(viewer.selected_track);
731 if (ret_val < 0)
733 ret = true;
734 goto exit;
736 else if (ret_val > 0)
738 /* Playlist changed */
739 gui_synclist_del_item(&playlist_lists);
740 update_playlist(true);
741 if (viewer.num_tracks <= 0)
742 exit = true;
743 if(viewer.selected_track >= viewer.num_tracks)
744 viewer.selected_track = viewer.num_tracks-1;
746 gui_synclist_draw(&playlist_lists);
747 break;
749 case ACTION_STD_MENU:
750 if (viewer_menu())
752 ret = true;
753 goto exit;
755 gui_synclist_set_icon_callback(
756 &playlist_lists,
757 global_settings.playlist_viewer_icons?
758 &playlist_callback_icons:NULL
760 gui_synclist_draw(&playlist_lists);
761 break;
763 default:
764 if(default_event_handler(button) == SYS_USB_CONNECTED)
766 ret = true;
767 goto exit;
769 break;
773 exit:
774 if (viewer.playlist)
775 playlist_close(viewer.playlist);
776 return ret;
779 static const char* playlist_search_callback_name(int selected_item, void * data,
780 char *buffer, size_t buffer_len)
782 (void)buffer_len; /* this should probably be used */
783 int *found_indicies = (int*)data;
784 static struct playlist_track_info track;
785 playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
786 format_name(buffer, track.filename);
787 return buffer;
790 bool search_playlist(void)
792 char search_str[32] = "";
793 bool ret = false, exit = false;
794 int i, playlist_count;
795 int found_indicies[MAX_PLAYLIST_ENTRIES];
796 int found_indicies_count = 0, last_found_count = -1;
797 int button;
798 struct gui_synclist playlist_lists;
799 struct playlist_track_info track;
801 if (!playlist_viewer_init(&viewer, 0, false))
802 return ret;
803 if (kbd_input(search_str, sizeof(search_str)) < 0)
804 return ret;
805 lcd_clear_display();
806 playlist_count = playlist_amount_ex(viewer.playlist);
808 cpu_boost(true);
810 for (i=0; (i<playlist_count)&&(found_indicies_count<MAX_PLAYLIST_ENTRIES); i++)
812 if (found_indicies_count != last_found_count)
814 splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), found_indicies_count,
815 str(LANG_OFF_ABORT));
816 last_found_count = found_indicies_count;
819 if (action_userabort(TIMEOUT_NOBLOCK))
820 break;
822 playlist_get_track_info(viewer.playlist, i, &track);
824 if (strcasestr(track.filename,search_str))
825 found_indicies[found_indicies_count++] = track.index;
827 yield();
830 cpu_boost(false);
832 if (!found_indicies_count)
834 return ret;
836 backlight_on();
838 gui_synclist_init(&playlist_lists, playlist_search_callback_name,
839 found_indicies, false, 1, NULL);
840 gui_synclist_set_title(&playlist_lists, str(LANG_SEARCH_RESULTS), NOICON);
841 gui_synclist_set_icon_callback(&playlist_lists, NULL);
842 gui_synclist_set_nb_items(&playlist_lists, found_indicies_count);
843 gui_synclist_select_item(&playlist_lists, 0);
844 gui_synclist_draw(&playlist_lists);
845 while (!exit)
847 button = get_action(CONTEXT_LIST, HZ/4);
848 if (gui_synclist_do_button(&playlist_lists, &button, LIST_WRAP_UNLESS_HELD))
849 continue;
850 switch (button)
852 case ACTION_STD_CANCEL:
853 exit = true;
854 break;
856 case ACTION_STD_OK:
857 playlist_start(
858 found_indicies[gui_synclist_get_sel_pos(&playlist_lists)]
859 ,0);
860 exit = 1;
861 break;
863 default:
864 if(default_event_handler(button) == SYS_USB_CONNECTED)
866 ret = true;
867 exit = true;
869 break;
872 return ret;