blob: 0d5935480444725d87987be5fe472456907f2091 [file] [log] [blame]
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +00001/***************************************************************************
2 *
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2003 Hardeep Sidhu
12 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000013 * 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.
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000017 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
Kevin Ferrare8517ed82005-11-16 02:12:25 +000022/*
23 * Kevin Ferrare 2005/10/16
24 * multi-screen support, rewrote a lot of code
25 */
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000026#include <string.h>
27#include <sprintf.h>
28#include "playlist.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000029#include "audio.h"
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000030#include "screens.h"
31#include "status.h"
32#include "settings.h"
33#include "icons.h"
34#include "menu.h"
35#include "plugin.h"
Hardeep Sidhu107ebc52004-01-26 17:05:21 +000036#include "keyboard.h"
Jonathan Gordon36a2e302007-04-18 13:03:01 +000037#include "filetypes.h"
Hardeep Sidhu107ebc52004-01-26 17:05:21 +000038#include "onplay.h"
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000039#include "talk.h"
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +000040#include "misc.h"
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +000041#include "action.h"
Linus Nielsen Feltzing2f56ee92006-01-17 14:15:47 +000042#include "debug.h"
Tomas Salfischberger4ec9dbd2006-03-05 00:16:34 +000043#include "backlight.h"
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000044
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000045#include "lang.h"
46
Hardeep Sidhu107ebc52004-01-26 17:05:21 +000047#include "playlist_viewer.h"
Jonathan Gordonce584282007-02-12 05:02:42 +000048#include "playlist_catalog.h"
Kevin Ferrare8517ed82005-11-16 02:12:25 +000049#include "icon.h"
50#include "list.h"
51#include "statusbar.h"
52#include "splash.h"
Hardeep Sidhu0cca6ca2006-02-09 09:09:32 +000053#include "playlist_menu.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000054#include "action.h"
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000055
56/* Maximum number of tracks we can have loaded at one time */
Kevin Ferrare6a53c332005-11-16 02:55:26 +000057#define MAX_PLAYLIST_ENTRIES 200
Kevin Ferrare8517ed82005-11-16 02:12:25 +000058
59/* The number of items between the selected one and the end/start of
60 * the buffer under which the buffer must reload */
Hardeep Sidhu06605a92006-05-17 07:57:54 +000061#define MIN_BUFFER_MARGIN (screens[0].nb_lines+1)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000062
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000063/* Information about a specific track */
64struct playlist_entry {
65 char *name; /* Formatted track name */
66 int index; /* Playlist index */
67 int display_index; /* Display index */
68 bool queued; /* Is track queued? */
Miika Pekkarinenc52f7f12005-10-21 06:40:45 +000069 bool skipped; /* Is track marked as bad? */
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +000070};
71
Kevin Ferrare8517ed82005-11-16 02:12:25 +000072enum direction
73{
74 FORWARD,
75 BACKWARD
76};
77
78struct playlist_buffer
79{
80 char *name_buffer; /* Buffer used to store track names */
81 int buffer_size; /* Size of name buffer */
82
83 int first_index; /* Real index of first track loaded inside
84 the buffer */
85
86 enum direction direction; /* Direction of the buffer (if the buffer
87 was loaded BACKWARD, the last track in
88 the buffer has a real index < to the
89 real index of the the first track)*/
90
91 struct playlist_entry tracks[MAX_PLAYLIST_ENTRIES];
92 int num_loaded; /* Number of track entries loaded in buffer */
93};
94
95/* Global playlist viewer settings */
96struct playlist_viewer {
97 struct playlist_info* playlist; /* playlist being viewed */
98 int num_tracks; /* Number of tracks in playlist */
99 int current_playing_track; /* Index of current playing track */
100 int selected_track; /* The selected track, relative (first is 0)*/
101 int move_track; /* Playlist index of track to move or -1 */
102 struct playlist_buffer buffer;
103};
104
105static struct playlist_viewer viewer;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000106
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000107/* Used when viewing playlists on disk */
Hardeep Sidhu30743942005-11-19 18:19:46 +0000108static struct playlist_info temp_playlist;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000109
Jens Arnold2597a132006-12-25 14:01:47 +0000110static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer,
111 int names_buffer_size);
112static void playlist_buffer_load_entries(struct playlist_buffer * pb, int index,
113 enum direction direction);
114static int playlist_entry_load(struct playlist_entry *entry, int index,
115 char* name_buffer, int remaining_size);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000116
Jens Arnold2597a132006-12-25 14:01:47 +0000117static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb,
118 int index);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000119
120static bool playlist_viewer_init(struct playlist_viewer * viewer,
Steve Bavinad95df22008-05-12 17:52:50 +0000121 const char* filename, bool reload);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000122
Jens Arnold8fb33612004-08-18 01:09:31 +0000123static void format_name(char* dest, const char* src);
Hardeep Sidhu30743942005-11-19 18:19:46 +0000124static void format_line(const struct playlist_entry* track, char* str,
125 int len);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000126
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000127static bool update_playlist(bool force);
128static int onplay_menu(int index);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000129static bool viewer_menu(void);
Jonathan Gordona2740d92007-04-25 11:20:19 +0000130static int save_playlist_func(void);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000131
Jens Arnold2597a132006-12-25 14:01:47 +0000132static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer,
133 int names_buffer_size)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000134{
135 pb->name_buffer=names_buffer;
136 pb->buffer_size=names_buffer_size;
137 pb->first_index=0;
138 pb->num_loaded=0;
139}
Hardeep Sidhu30743942005-11-19 18:19:46 +0000140
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000141/*
142 * Loads the entries following 'index' in the playlist buffer
143 */
Jens Arnold2597a132006-12-25 14:01:47 +0000144static void playlist_buffer_load_entries(struct playlist_buffer *pb, int index,
145 enum direction direction)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000146{
147 int num_entries = viewer.num_tracks;
148 char* p = pb->name_buffer;
149 int remaining = pb->buffer_size;
150 int i;
151
152 pb->first_index = index;
153 if (num_entries > MAX_PLAYLIST_ENTRIES)
154 num_entries = MAX_PLAYLIST_ENTRIES;
155
156 for(i=0; i<num_entries; i++)
157 {
158 int len = playlist_entry_load(&(pb->tracks[i]), index, p, remaining);
159 if (len < 0)
160 {
161 /* Out of name buffer space */
162 num_entries = i;
163 break;
164 }
165
166 p += len;
167 remaining -= len;
168
169 if(direction==FORWARD)
170 index++;
171 else
172 index--;
173 index+=viewer.num_tracks;
174 index%=viewer.num_tracks;
175 }
176 pb->direction=direction;
177 pb->num_loaded = i;
178}
179
Jens Arnold2597a132006-12-25 14:01:47 +0000180static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb,
181 enum direction direction)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000182{
183 if(direction==FORWARD)
184 {
185 int min_start=viewer.selected_track-2*screens[0].nb_lines;
Linus Nielsen Feltzing2f56ee92006-01-17 14:15:47 +0000186 while(min_start<0)
187 min_start+=viewer.num_tracks;
188 min_start %= viewer.num_tracks;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000189 playlist_buffer_load_entries(pb, min_start, FORWARD);
190 }
191 else
192 {
193 int max_start=viewer.selected_track+2*screens[0].nb_lines;
194 max_start%=viewer.num_tracks;
195 playlist_buffer_load_entries(pb, max_start, BACKWARD);
196 }
197}
198
Jens Arnold2597a132006-12-25 14:01:47 +0000199static int playlist_entry_load(struct playlist_entry *entry, int index,
200 char* name_buffer, int remaining_size)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000201{
202 struct playlist_track_info info;
203 int len;
204
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;
211
212 len = strlen(info.filename) + 1;
213
214 if (len <= remaining_size)
215 {
216 strcpy(name_buffer, info.filename);
217
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;
224 }
225 return -1;
226}
227
Nils Wallménius791e0922008-04-09 21:47:43 +0000228static int playlist_buffer_get_index(struct playlist_buffer *pb, int index)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000229{
230 int buffer_index;
231 if(pb->direction==FORWARD)
232 {
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);
237 }
238 else
239 {
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);
245 }
246 return(buffer_index);
247}
248
249#define distance(a, b) \
250 a>b? (a) - (b) : (b) - (a)
Nils Wallménius791e0922008-04-09 21:47:43 +0000251static bool playlist_buffer_needs_reload(struct playlist_buffer* pb,
252 int track_index)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000253{
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);
261
262 if(pb->num_loaded - distance_beginning < MIN_BUFFER_MARGIN)
263 return(true);
264 return(false);
265}
266
Jens Arnold2597a132006-12-25 14:01:47 +0000267static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb,
268 int index)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000269{
270 int buffer_index=playlist_buffer_get_index(pb, index);
271 return(&(pb->tracks[buffer_index]));
272}
273
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000274/* Initialize the playlist viewer. */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000275static bool playlist_viewer_init(struct playlist_viewer * viewer,
Steve Bavinad95df22008-05-12 17:52:50 +0000276 const char* filename, bool reload)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000277{
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000278 char* buffer;
Michael Sevakiseb85f142007-04-21 19:20:20 +0000279 size_t buffer_size;
Jonathan Gordon3d44a202007-04-26 08:21:29 +0000280 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))
283 {
284 /* Try to restore the list from control file */
285 have_list = (playlist_resume() != -1);
286 }
Peter D'Hoyeb8ded7d2007-08-25 16:05:58 +0000287 if (!have_list && (playlist_amount() > 0))
288 {
289 /*If dynamic playlist still exists, view it anyway even
290 if playback has reached the end of the playlist */
291 have_list = true;
292 }
Jonathan Gordon3d44a202007-04-26 08:21:29 +0000293 if (!have_list)
294 {
295 /* Nothing to view, exit */
296 gui_syncsplash(HZ, str(LANG_CATALOG_NO_PLAYLISTS));
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000297 return false;
Jonathan Gordon3d44a202007-04-26 08:21:29 +0000298 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000299
Michael Sevakiseb85f142007-04-21 19:20:20 +0000300 buffer = plugin_get_buffer(&buffer_size);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000301 if (!buffer)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000302 return false;
303
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000304 if (!filename)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000305 viewer->playlist = NULL;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000306 else
307 {
308 /* Viewing playlist on disk */
Steve Bavinad95df22008-05-12 17:52:50 +0000309 const char *dir, *file;
310 char *temp_ptr;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000311 char *index_buffer = NULL;
Michael Sevakis26d242a2007-04-21 18:38:25 +0000312 ssize_t index_buffer_size = 0;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000313
314 viewer->playlist = &temp_playlist;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000315
316 /* Separate directory from filename */
317 temp_ptr = strrchr(filename+1,'/');
318 if (temp_ptr)
319 {
320 *temp_ptr = 0;
321 dir = filename;
322 file = temp_ptr + 1;
323 }
324 else
325 {
326 dir = "/";
327 file = filename+1;
328 }
329
330 if (is_playing)
331 {
332 /* Something is playing, use half the plugin buffer for playlist
333 indices */
334 index_buffer_size = buffer_size / 2;
335 index_buffer = buffer;
336 }
337
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000338 playlist_create_ex(viewer->playlist, dir, file, index_buffer,
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000339 index_buffer_size, buffer+index_buffer_size,
340 buffer_size-index_buffer_size);
341
342 if (temp_ptr)
343 *temp_ptr = '/';
344
345 buffer += index_buffer_size;
346 buffer_size -= index_buffer_size;
347 }
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000348 playlist_buffer_init(&viewer->buffer, buffer, buffer_size );
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000349
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000350 viewer->move_track = -1;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000351
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000352 if (!reload)
Hardeep Sidhu30743942005-11-19 18:19:46 +0000353 {
Linus Nielsen Feltzing0b8149f2006-01-17 12:30:03 +0000354 if (viewer->playlist)
Hardeep Sidhu30743942005-11-19 18:19:46 +0000355 viewer->selected_track = 0;
Linus Nielsen Feltzing0b8149f2006-01-17 12:30:03 +0000356 else
357 viewer->selected_track = playlist_get_display_index() - 1;
Hardeep Sidhu30743942005-11-19 18:19:46 +0000358 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000359
360 if (!update_playlist(true))
361 return false;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000362 return true;
363}
364
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000365/* Format trackname for display purposes */
Jens Arnold8fb33612004-08-18 01:09:31 +0000366static void format_name(char* dest, const char* src)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000367{
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000368 switch (global_settings.playlist_viewer_track_display)
369 {
370 case 0:
371 default:
372 {
Antoine Cellerier59dc18d2006-08-10 21:08:44 +0000373 /* Only display the filename */
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000374 char* p = strrchr(src, '/');
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000375
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000376 strcpy(dest, p+1);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000377
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000378 /* Remove the extension */
Nils Wallménius4acae4d2007-11-18 14:12:01 +0000379 strrsplt(dest, '.');
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000380
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000381 break;
382 }
383 case 1:
384 /* Full path */
385 strcpy(dest, src);
386 break;
387 }
388}
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000389
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000390/* Format display line */
Hardeep Sidhu30743942005-11-19 18:19:46 +0000391static void format_line(const struct playlist_entry* track, char* str,
392 int len)
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000393{
394 char name[MAX_PATH];
Miika Pekkarinenc52f7f12005-10-21 06:40:45 +0000395 char *skipped = "";
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000396
397 format_name(name, track->name);
398
Miika Pekkarinenc52f7f12005-10-21 06:40:45 +0000399 if (track->skipped)
400 skipped = "(ERR) ";
Zakk Roberts34ad56d2006-04-03 04:13:26 +0000401
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000402 if (global_settings.playlist_viewer_indices)
403 /* Display playlist index */
Miika Pekkarinenc52f7f12005-10-21 06:40:45 +0000404 snprintf(str, len, "%d. %s%s", track->display_index, skipped, name);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000405 else
Miika Pekkarinenc52f7f12005-10-21 06:40:45 +0000406 snprintf(str, len, "%s%s", skipped, name);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000407
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000408}
409
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000410/* Update playlist in case something has changed or forced */
411static bool update_playlist(bool force)
412{
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000413 if (!viewer.playlist)
414 playlist_get_resume_info(&viewer.current_playing_track);
415 else
416 viewer.current_playing_track = -1;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000417 int nb_tracks=playlist_amount_ex(viewer.playlist);
418 force=force || nb_tracks != viewer.num_tracks;
419 if (force)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000420 {
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000421 /* Reload tracks */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000422 viewer.num_tracks = nb_tracks;
Hardeep Sidhuc7f304e2006-04-20 07:30:28 +0000423 if (viewer.num_tracks <= 0)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000424 return false;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000425 playlist_buffer_load_entries_screen(&viewer.buffer, FORWARD);
426 if (viewer.buffer.num_loaded <= 0)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000427 return false;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000428 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000429 return true;
430}
431
432/* Menu of playlist commands. Invoked via ON+PLAY on main viewer screen.
433 Returns -1 if USB attached, 0 if no playlist change, and 1 if playlist
434 changed. */
435static int onplay_menu(int index)
436{
Jonathan Gordona2740d92007-04-25 11:20:19 +0000437 int result, ret = 0;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000438 struct playlist_entry * current_track=
439 playlist_buffer_get_track(&viewer.buffer, index);
Nils Wallméniusb3113672007-08-05 19:19:39 +0000440 MENUITEM_STRINGLIST(menu_items, ID2P(LANG_PLAYLIST), NULL,
Jonathan Gordona2740d92007-04-25 11:20:19 +0000441 ID2P(LANG_REMOVE), ID2P(LANG_MOVE),
442 ID2P(LANG_CATALOG_ADD_TO), ID2P(LANG_CATALOG_ADD_TO_NEW));
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000443 bool current = (current_track->index == viewer.current_playing_track);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000444
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000445 result = do_menu(&menu_items, NULL, NULL, false);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000446 if (result == MENU_ATTACHED_USB)
Jonathan Gordonce584282007-02-12 05:02:42 +0000447 {
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000448 ret = -1;
Jonathan Gordonce584282007-02-12 05:02:42 +0000449 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000450 else if (result >= 0)
451 {
452 /* Abort current move */
453 viewer.move_track = -1;
454
455 switch (result)
456 {
457 case 0:
458 /* delete track */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000459 playlist_delete(viewer.playlist, current_track->index);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000460 if (current)
461 {
Hardeep Sidhuc7f304e2006-04-20 07:30:28 +0000462 if (playlist_amount_ex(viewer.playlist) <= 0)
463 audio_stop();
464 else
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000465 {
Hardeep Sidhuc7f304e2006-04-20 07:30:28 +0000466 /* Start playing new track except if it's the lasttrack
467 track in the playlist and repeat mode is disabled */
468 current_track =
469 playlist_buffer_get_track(&viewer.buffer, index);
470 if (current_track->display_index!=viewer.num_tracks ||
471 global_settings.repeat_mode == REPEAT_ALL)
472 {
Michael Sevakisacc29d92006-11-18 02:18:29 +0000473#if CONFIG_CODEC != SWCODEC
Hardeep Sidhuc7f304e2006-04-20 07:30:28 +0000474 talk_buffer_steal(); /* will use the mp3 buffer */
Michael Sevakisacc29d92006-11-18 02:18:29 +0000475#endif
Hardeep Sidhuc7f304e2006-04-20 07:30:28 +0000476 audio_play(0);
477 viewer.current_playing_track = -1;
478 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000479 }
480 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000481 ret = 1;
482 break;
483 case 1:
484 /* move track */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000485 viewer.move_track = current_track->index;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000486 ret = 0;
487 break;
Jonathan Gordonce584282007-02-12 05:02:42 +0000488 case 2: /* add to catalog */
489 case 3: /* add to a new one */
490 catalog_add_to_a_playlist(current_track->name,
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000491 FILE_ATTR_AUDIO,
Jonathan Gordon517aca82008-05-04 13:01:16 +0000492 result==3, NULL);
Jonathan Gordonce584282007-02-12 05:02:42 +0000493 ret = 0;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000494 break;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000495 }
496 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000497 return ret;
498}
499
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000500/* Menu of viewer options. Invoked via F1(r) or Menu(p). */
Jonathan Gordona2740d92007-04-25 11:20:19 +0000501MENUITEM_SETTING(show_icons, &global_settings.playlist_viewer_icons, NULL);
502MENUITEM_SETTING(show_indices, &global_settings.playlist_viewer_indices, NULL);
503MENUITEM_SETTING(track_display,
504 &global_settings.playlist_viewer_track_display, NULL);
505MENUITEM_FUNCTION(save_playlist_item, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST),
506 save_playlist_func, 0, NULL, Icon_NOICON);
507MAKE_MENU(viewer_settings_menu, ID2P(LANG_PLAYLISTVIEWER_SETTINGS),
508 NULL, Icon_Playlist,
509 &show_icons, &show_indices, &track_display, &save_playlist_item);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000510static bool viewer_menu(void)
511{
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000512 return do_menu(&viewer_settings_menu, NULL, NULL, false) == MENU_ATTACHED_USB;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000513}
514
515/* Save playlist to disk */
Jonathan Gordona2740d92007-04-25 11:20:19 +0000516static int save_playlist_func(void)
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000517{
Hardeep Sidhu0cca6ca2006-02-09 09:09:32 +0000518 save_playlist_screen(viewer.playlist);
Jonathan Gordona2740d92007-04-25 11:20:19 +0000519 return 0;
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000520}
521
522/* View current playlist */
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000523bool playlist_viewer(void)
524{
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000525 return playlist_viewer_ex(NULL);
526}
527
Antoine Cellerier24907002007-10-15 20:34:02 +0000528static int get_track_num( struct playlist_viewer * local_viewer,
529 int selected_item )
530{
531 if( local_viewer->move_track >= 0 )
532 {
533 if( local_viewer->selected_track == selected_item )
534 {
535 return local_viewer->move_track;
536 }
537 else if( local_viewer->selected_track > selected_item
538 && selected_item >= local_viewer->move_track )
539 {
540 return selected_item+1;
541 }
542 else if( local_viewer->selected_track < selected_item
543 && selected_item <= local_viewer->move_track )
544 {
545 return selected_item-1;
546 }
547 }
548 return selected_item;
549}
550
Nils Wallménius68489612008-04-09 15:25:17 +0000551static char *playlist_callback_name(int selected_item,
552 void *data,
553 char *buffer,
554 size_t buffer_len)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000555{
556 struct playlist_viewer * local_viewer = (struct playlist_viewer *)data;
Nils Wallménius791e0922008-04-09 21:47:43 +0000557
558 int track_num = get_track_num(local_viewer, selected_item);
559 struct playlist_entry *track =
560 playlist_buffer_get_track(&(local_viewer->buffer), track_num);
561
Nils Wallménius68489612008-04-09 15:25:17 +0000562 format_line(track, buffer, buffer_len);
Nils Wallménius791e0922008-04-09 21:47:43 +0000563
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000564 return(buffer);
565}
566
567
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000568static int playlist_callback_icons(int selected_item, void *data)
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000569{
570 struct playlist_viewer * local_viewer=(struct playlist_viewer *)data;
Nils Wallménius791e0922008-04-09 21:47:43 +0000571
572 int track_num = get_track_num(local_viewer, selected_item);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000573 struct playlist_entry *track=
Nils Wallménius791e0922008-04-09 21:47:43 +0000574 playlist_buffer_get_track(&(local_viewer->buffer), track_num);
575
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000576 if (track->index == local_viewer->current_playing_track)
577 {
578 /* Current playing track */
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000579 return Icon_Audio;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000580 }
581 else if (track->index == local_viewer->move_track)
582 {
583 /* Track we are moving */
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000584 return Icon_Moving;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000585 }
586 else if (track->queued)
587 {
588 /* Queued track */
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000589 return Icon_Queued;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000590 }
591 else
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000592 return Icon_NOICON;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000593}
594
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000595/* Main viewer function. Filename identifies playlist to be viewed. If NULL,
596 view current playlist. */
Steve Bavinad95df22008-05-12 17:52:50 +0000597bool playlist_viewer_ex(const char* filename)
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000598{
599 bool ret = false; /* return value */
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000600 bool exit=false; /* exit viewer */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000601 int button;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000602 struct gui_synclist playlist_lists;
603 if (!playlist_viewer_init(&viewer, filename, false))
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000604 goto exit;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000605
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000606 gui_synclist_init(&playlist_lists, playlist_callback_name,
607 &viewer, false, 1, NULL);
Kevin Ferrare15046f92005-11-16 17:23:49 +0000608 gui_synclist_set_icon_callback(&playlist_lists,
Hardeep Sidhu30743942005-11-19 18:19:46 +0000609 global_settings.playlist_viewer_icons?
610 &playlist_callback_icons:NULL);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000611 gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks);
612 gui_synclist_select_item(&playlist_lists, viewer.selected_track);
Nils Wallméniusb3113672007-08-05 19:19:39 +0000613 gui_synclist_set_title(&playlist_lists, str(LANG_PLAYLIST), Icon_Playlist);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000614 gui_synclist_draw(&playlist_lists);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000615 while (!exit)
616 {
Björn Stenberga108ec22004-01-14 00:13:04 +0000617 int track;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000618
Peter D'Hoyedf328132007-08-21 23:50:26 +0000619 if (global_status.resume_index != -1 && !viewer.playlist)
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000620 playlist_get_resume_info(&track);
621 else
622 track = -1;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000623
624 if (track != viewer.current_playing_track ||
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000625 playlist_amount_ex(viewer.playlist) != viewer.num_tracks)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000626 {
627 /* Playlist has changed (new track started?) */
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000628 if (!update_playlist(false))
Hardeep Sidhu1b446322004-04-15 06:12:02 +0000629 goto exit;
Peter D'Hoyedf328132007-08-21 23:50:26 +0000630 /*Needed because update_playlist gives wrong value when
631 playing is stopped*/
632 viewer.current_playing_track = track;
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000633 gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000634 /* Abort move on playlist change */
635 viewer.move_track = -1;
Hardeep Sidhu9a681dd2006-06-12 23:25:12 +0000636 gui_synclist_draw(&playlist_lists);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000637 }
638
Hardeep Sidhu1b446322004-04-15 06:12:02 +0000639 /* Timeout so we can determine if play status has changed */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000640 button = get_action(CONTEXT_TREE,HZ/2);
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000641 if( (gui_synclist_do_button(&playlist_lists, &button,LIST_WRAP_UNLESS_HELD)) )
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000642 {
643 viewer.selected_track=gui_synclist_get_sel_pos(&playlist_lists);
Hardeep Sidhu30743942005-11-19 18:19:46 +0000644 if(playlist_buffer_needs_reload(&viewer.buffer,
645 viewer.selected_track))
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000646 playlist_buffer_load_entries_screen(&viewer.buffer,
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000647 button==ACTION_STD_NEXT?
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000648 FORWARD
649 :
650 BACKWARD
651 );
Antoine Cellerier24907002007-10-15 20:34:02 +0000652 gui_synclist_draw(&playlist_lists);
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000653 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000654 switch (button)
655 {
Peter D'Hoye734278b2007-04-12 21:28:58 +0000656 case ACTION_TREE_WPS:
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000657 case ACTION_STD_CANCEL:
Antoine Celleriera6d4e532007-12-15 17:14:04 +0000658 {
659 if (viewer.move_track >= 0)
660 {
661 viewer.selected_track = viewer.move_track;
662 gui_synclist_select_item(&playlist_lists, viewer.move_track);
663 viewer.move_track = -1;
664 gui_synclist_draw(&playlist_lists);
665 }
666 else
667 exit = true;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000668 break;
Antoine Celleriera6d4e532007-12-15 17:14:04 +0000669 }
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000670 case ACTION_STD_OK:
671 {
Hardeep Sidhu30743942005-11-19 18:19:46 +0000672 struct playlist_entry * current_track =
673 playlist_buffer_get_track(&viewer.buffer,
674 viewer.selected_track);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000675 if (viewer.move_track >= 0)
676 {
677 /* Move track */
Jonathan Gordon52ba1c62007-04-26 10:28:32 +0000678 int ret_val;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000679
Jonathan Gordon52ba1c62007-04-26 10:28:32 +0000680 ret_val = playlist_move(viewer.playlist, viewer.move_track,
Hardeep Sidhu30743942005-11-19 18:19:46 +0000681 current_track->index);
Jonathan Gordon52ba1c62007-04-26 10:28:32 +0000682 if (ret_val < 0)
Nils Wallméniusb3113672007-08-05 19:19:39 +0000683 gui_syncsplash(HZ, (unsigned char *)"%s %s",
684 str(LANG_MOVE), str(LANG_FAILED));
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000685 update_playlist(true);
686 viewer.move_track = -1;
687 }
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000688 else if (!viewer.playlist)
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000689 {
Hardeep Sidhu05741512005-06-23 17:31:44 +0000690 /* play new track */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000691 playlist_start(current_track->index, 0);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000692 update_playlist(false);
693 }
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000694 else
695 {
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000696 /* New playlist */
697 if (playlist_set_current(viewer.playlist) < 0)
698 goto exit;
699
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000700 playlist_start(current_track->index, 0);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000701
702 /* Our playlist is now the current list */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000703 if (!playlist_viewer_init(&viewer, NULL, true))
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000704 goto exit;
705 }
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000706 gui_synclist_draw(&playlist_lists);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000707
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000708 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000709 }
710 case ACTION_STD_CONTEXT:
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000711 {
712 /* ON+PLAY menu */
Jonathan Gordon52ba1c62007-04-26 10:28:32 +0000713 int ret_val;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000714
Jonathan Gordon52ba1c62007-04-26 10:28:32 +0000715 ret_val = onplay_menu(viewer.selected_track);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000716
Jonathan Gordon52ba1c62007-04-26 10:28:32 +0000717 if (ret_val < 0)
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000718 {
719 ret = true;
720 goto exit;
721 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000722 else if (ret > 0)
723 {
724 /* Playlist changed */
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000725 gui_synclist_del_item(&playlist_lists);
726 update_playlist(true);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000727 if (viewer.num_tracks <= 0)
728 exit = true;
Peter D'Hoyeb16137e2007-04-11 22:39:12 +0000729 if(viewer.selected_track >= viewer.num_tracks)
730 viewer.selected_track = viewer.num_tracks-1;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000731 }
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000732 gui_synclist_draw(&playlist_lists);
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000733 break;
734 }
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000735 case ACTION_STD_MENU:
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000736 if (viewer_menu())
737 {
738 ret = true;
739 goto exit;
740 }
Kevin Ferrare15046f92005-11-16 17:23:49 +0000741 gui_synclist_set_icon_callback(
742 &playlist_lists,
743 global_settings.playlist_viewer_icons?
744 &playlist_callback_icons:NULL
745 );
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000746 gui_synclist_draw(&playlist_lists);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000747 break;
748
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000749 case ACTION_NONE:
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000750 gui_syncstatusbar_draw(&statusbars, false);
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000751 break;
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000752
753 default:
754 if(default_event_handler(button) == SYS_USB_CONNECTED)
755 {
756 ret = true;
757 goto exit;
758 }
759 break;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000760 }
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000761 }
762
Hardeep Sidhu107ebc52004-01-26 17:05:21 +0000763exit:
764 if (viewer.playlist)
765 playlist_close(viewer.playlist);
766 return ret;
Hardeep Sidhu00acdfa2003-12-10 00:11:25 +0000767}
Jens Arnold2597a132006-12-25 14:01:47 +0000768
Nils Wallménius68489612008-04-09 15:25:17 +0000769static char *playlist_search_callback_name(int selected_item, void * data,
770 char *buffer, size_t buffer_len)
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000771{
Nils Wallménius68489612008-04-09 15:25:17 +0000772 (void)buffer_len; /* this should probably be used */
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000773 int *found_indicies = (int*)data;
Zakk Roberts34ad56d2006-04-03 04:13:26 +0000774 static struct playlist_track_info track;
Nils Wallménius68489612008-04-09 15:25:17 +0000775 playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
776 format_name(buffer, track.filename);
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000777 return(buffer);
778}
779
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000780bool search_playlist(void)
781{
782 char search_str[32] = "";
783 bool ret = false, exit = false;
784 int i, playlist_count;
785 int found_indicies[MAX_PLAYLIST_ENTRIES],found_indicies_count = 0;
786 int button;
787 struct gui_synclist playlist_lists;
788 struct playlist_track_info track;
Zakk Roberts34ad56d2006-04-03 04:13:26 +0000789
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000790 if (!playlist_viewer_init(&viewer, 0, false))
791 return ret;
792 if (kbd_input(search_str,sizeof(search_str)) == -1)
Zakk Roberts34ad56d2006-04-03 04:13:26 +0000793 return ret;
794 lcd_clear_display();
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000795 playlist_count = playlist_amount_ex(viewer.playlist);
796 for (i=0;(i<playlist_count)&&(found_indicies_count<MAX_PLAYLIST_ENTRIES);i++)
797 {
Jens Arnold4d6374c2007-03-16 21:56:08 +0000798 gui_syncsplash(0, str(LANG_PLAYLIST_SEARCH_MSG),found_indicies_count,
Nils Wallméniusb3113672007-08-05 19:19:39 +0000799 str(LANG_OFF_ABORT));
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000800 if (action_userabort(TIMEOUT_NOBLOCK))
Jonathan Gordon88882a82007-08-04 09:36:47 +0000801 {
802 if (!found_indicies_count)
803 return ret;
804 break;
805 }
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000806 playlist_get_track_info(viewer.playlist,i,&track);
807 if (strcasestr(track.filename,search_str))
808 {
809 found_indicies[found_indicies_count++] = track.index;
810 }
811 }
812 if (!found_indicies_count)
813 {
814 return ret;
815 }
816 backlight_on();
817 gui_synclist_init(&playlist_lists, playlist_search_callback_name,
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000818 found_indicies, false, 1, NULL);
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000819 gui_synclist_set_icon_callback(&playlist_lists, NULL);
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000820 gui_synclist_set_nb_items(&playlist_lists, found_indicies_count);
821 gui_synclist_select_item(&playlist_lists, 0);
822 gui_synclist_draw(&playlist_lists);
823 while (!exit)
824 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000825 button = get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000826 if (gui_synclist_do_button(&playlist_lists, &button, LIST_WRAP_UNLESS_HELD))
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000827 continue;
828 switch (button)
829 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000830 case ACTION_STD_CANCEL:
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000831 exit = true;
832 break;
833
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000834 case ACTION_STD_OK:
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000835 playlist_start(
836 found_indicies[gui_synclist_get_sel_pos(&playlist_lists)]
837 ,0);
838 exit = 1;
839 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000840 case ACTION_NONE:
Tomas Salfischbergerc2e86cd2006-03-04 23:53:09 +0000841 break;
842 default:
843 if(default_event_handler(button) == SYS_USB_CONNECTED)
844 {
845 ret = true;
846 exit = true;
847 }
848 break;
849 }
850 }
851 return ret;
852}
853