Mercurial > audlegacy
annotate src/audacious/playlist.c @ 2690:62579e205746 trunk
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
author | yaz |
---|---|
date | Fri, 27 Apr 2007 10:22:03 -0700 |
parents | d2ffabee3ced |
children | 906caaf4737d |
rev | line source |
---|---|
2313 | 1 /* Audacious |
2 * Copyright (C) 2005-2007 Audacious team. | |
3 * | |
4 * BMP (C) GPL 2003 $top_src_dir/AUTHORS | |
5 * | |
6 * based on: | |
7 * | |
8 * XMMS - Cross-platform multimedia player | |
9 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
10 * Thomas Nilsson and 4Front Technologies | |
11 * Copyright (C) 1999-2003 Haavard Kvaalen | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; under version 2 of the License. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
24 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02110-1301, USA. | |
25 */ | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 # include "config.h" | |
29 #endif | |
30 | |
31 #include "playlist.h" | |
32 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
33 #include <mowgli.h> |
2313 | 34 #include <glib.h> |
35 #include <glib/gprintf.h> | |
36 #include <stdlib.h> | |
37 #include <string.h> | |
38 #include <time.h> | |
39 | |
40 #include <unistd.h> | |
41 #include <sys/types.h> | |
42 #include <sys/stat.h> | |
43 #include <sys/errno.h> | |
44 | |
45 #if defined(USE_REGEX_ONIGURUMA) | |
46 #include <onigposix.h> | |
47 #elif defined(USE_REGEX_PCRE) | |
48 #include <pcreposix.h> | |
49 #else | |
50 #include <regex.h> | |
51 #endif | |
52 | |
53 #include "input.h" | |
54 #include "main.h" | |
55 #include "ui_main.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2408
diff
changeset
|
56 #include "util.h" |
2313 | 57 #include "libaudacious/configdb.h" |
58 #include "vfs.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2408
diff
changeset
|
59 #include "urldecode.h" |
2313 | 60 #include "ui_equalizer.h" |
61 #include "playback.h" | |
62 #include "playlist.h" | |
63 #include "playlist_container.h" | |
2499
15a1f5ee4d1c
[svn] - playlist_manager -> ui_playlist_manager, since it's a UI component.
nenolod
parents:
2493
diff
changeset
|
64 #include "ui_playlist_manager.h" |
2313 | 65 #include "ui_playlist.h" |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
66 #include "strings.h" |
2313 | 67 #include "ui_fileinfo.h" |
68 | |
69 #include "debug.h" | |
70 | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
71 #include "hook.h" |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
72 |
2313 | 73 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
74 typedef void (*PlaylistSaveFunc) (FILE * file); | |
75 | |
76 /* If we manually change the song, p_p_b_j will show us where to go back to */ | |
77 PlaylistEntry *playlist_position_before_jump = NULL; | |
78 | |
79 static GList *playlists = NULL; | |
80 static GList *playlists_iter; | |
81 | |
82 /* If this is set to TRUE, we do not probe upon playlist add. | |
83 * | |
84 * Under Audacious 0.1.x, this was not a big deal because we used | |
85 * file extension introspection instead of looking for file format magic | |
86 * strings. | |
87 * | |
88 * Because we use file magic strings, we have to fstat a file being added | |
89 * to a playlist up to 1 * <number of input plugins installed> times. | |
90 * | |
91 * This can get really slow now that we're looking for files to add to a | |
92 * playlist. (Up to 5 minutes for 5000 songs, etcetera.) | |
93 * | |
94 * So, we obviously don't want to probe while opening a large playlist | |
95 * up. Hince the boolean below. | |
96 * | |
97 * January 7, 2006, William Pitcock <nenolod@nenolod.net> | |
98 */ | |
99 | |
100 G_LOCK_DEFINE(playlist_get_info_going); | |
101 | |
2328 | 102 //static gchar *playlist_current_name = NULL; |
2313 | 103 |
104 static gboolean playlist_get_info_scan_active = FALSE; | |
105 static gboolean playlist_get_info_going = FALSE; | |
106 static GThread *playlist_get_info_thread; | |
107 | |
108 static gint path_compare(const gchar * a, const gchar * b); | |
109 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); | |
110 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
111 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
112 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
113 static time_t playlist_get_mtime(const gchar *filename); | |
114 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); | |
115 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); | |
116 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); | |
117 | |
118 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
119 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
120 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
121 | |
122 static PlaylistCompareFunc playlist_compare_func_table[] = { | |
123 playlist_compare_path, | |
124 playlist_compare_filename, | |
125 playlist_compare_title, | |
126 playlist_compare_artist, | |
127 playlist_compare_date, | |
128 playlist_compare_track, | |
129 playlist_compare_playlist | |
130 }; | |
131 | |
132 static guint playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos); | |
133 | |
134 static void playlist_generate_shuffle_list(Playlist *); | |
135 static void playlist_generate_shuffle_list_nolock(Playlist *); | |
136 | |
137 static void playlist_recalc_total_time_nolock(Playlist *); | |
138 static void playlist_recalc_total_time(Playlist *); | |
139 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | |
140 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
141 static mowgli_heap_t *playlist_entry_heap = NULL; |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
142 |
2313 | 143 /* *********************** playlist entry code ********************** */ |
144 | |
145 PlaylistEntry * | |
146 playlist_entry_new(const gchar * filename, | |
147 const gchar * title, | |
148 const gint length, | |
149 InputPlugin * dec) | |
150 { | |
151 PlaylistEntry *entry; | |
152 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
153 entry = mowgli_heap_alloc(playlist_entry_heap); |
2313 | 154 entry->filename = g_strdup(filename); |
155 entry->title = str_to_utf8(title); | |
156 entry->length = length; | |
157 entry->selected = FALSE; | |
158 entry->decoder = dec; | |
159 | |
160 /* only do this if we have a decoder, otherwise it just takes too long */ | |
161 if (entry->decoder) | |
162 playlist_entry_get_info(entry); | |
163 | |
164 return entry; | |
165 } | |
166 | |
167 void | |
168 playlist_entry_free(PlaylistEntry * entry) | |
169 { | |
170 if (!entry) | |
171 return; | |
172 | |
173 if (entry->tuple != NULL) { | |
174 bmp_title_input_free(entry->tuple); | |
175 entry->tuple = NULL; | |
176 } | |
177 | |
178 if (entry->filename != NULL) | |
179 g_free(entry->filename); | |
180 | |
181 if (entry->title != NULL) | |
182 g_free(entry->title); | |
183 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
184 mowgli_heap_free(playlist_entry_heap, entry); |
2313 | 185 } |
186 | |
187 static gboolean | |
188 playlist_entry_get_info(PlaylistEntry * entry) | |
189 { | |
190 TitleInput *tuple; | |
191 time_t modtime; | |
192 | |
193 g_return_val_if_fail(entry != NULL, FALSE); | |
194 | |
195 if (entry->tuple == NULL || entry->tuple->mtime > 0 || entry->tuple->mtime == -1) | |
2636 | 196 modtime = playlist_get_mtime(entry->filename); |
2313 | 197 else |
2636 | 198 modtime = 0; /* URI -nenolod */ |
2313 | 199 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
200 if (str_has_prefix_nocase(entry->filename, "http:") && |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
201 g_thread_self() != playlist_get_info_thread) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
202 { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
203 g_print("attempting to retrieve remote info not in background thread!\n"); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
204 return FALSE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
205 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
206 |
2313 | 207 if (entry->decoder == NULL) |
208 entry->decoder = input_check_file(entry->filename, FALSE); | |
209 | |
210 /* renew tuple if file mtime is newer than tuple mtime. */ | |
211 if(entry->tuple){ | |
212 if(entry->tuple->mtime == modtime) | |
213 return TRUE; | |
214 else { | |
215 bmp_title_input_free(entry->tuple); | |
216 entry->tuple = NULL; | |
217 } | |
218 } | |
219 | |
220 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) | |
221 tuple = input_get_song_tuple(entry->filename); | |
222 else | |
223 tuple = entry->decoder->get_song_tuple(entry->filename); | |
224 | |
225 if (tuple == NULL) | |
226 return FALSE; | |
227 | |
228 /* attach mtime */ | |
229 tuple->mtime = modtime; | |
230 | |
231 /* entry is still around */ | |
232 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); | |
233 entry->length = tuple->length; | |
234 entry->tuple = tuple; | |
235 | |
236 return TRUE; | |
237 } | |
238 | |
239 /* *********************** playlist selector code ************************* */ | |
240 | |
241 void | |
242 playlist_init(void) | |
243 { | |
244 Playlist *initial_pl; | |
245 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
246 /* create a heap with 1024 playlist entry nodes preallocated. --nenolod */ |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
247 playlist_entry_heap = mowgli_heap_create(sizeof(PlaylistEntry), 1024, |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
248 BH_NOW); |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
249 |
2313 | 250 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ |
251 | |
252 initial_pl = playlist_new(); | |
253 | |
254 playlist_add_playlist(initial_pl); | |
255 } | |
256 | |
257 void | |
258 playlist_add_playlist(Playlist *playlist) | |
259 { | |
260 playlists = g_list_append(playlists, playlist); | |
261 | |
262 if (playlists_iter == NULL) | |
263 playlists_iter = playlists; | |
264 | |
265 playlist_manager_update(); | |
266 } | |
267 | |
268 void | |
269 playlist_remove_playlist(Playlist *playlist) | |
270 { | |
271 /* trying to free the last playlist simply clears and resets it */ | |
272 if (g_list_length(playlists) < 2) { | |
273 playlist_clear(playlist); | |
274 playlist_set_current_name(playlist, NULL); | |
275 return; | |
276 } | |
277 | |
278 if (playlist == playlist_get_active()) | |
279 playlist_select_next(); | |
280 | |
281 /* upon removal, a playlist should be cleared and freed */ | |
282 playlists = g_list_remove(playlists, playlist); | |
283 playlist_clear(playlist); | |
284 playlist_free(playlist); | |
285 | |
286 if (playlists_iter == NULL) | |
287 playlists_iter = playlists; | |
288 | |
289 playlist_manager_update(); | |
290 } | |
291 | |
292 GList * | |
293 playlist_get_playlists(void) | |
294 { | |
295 return playlists; | |
296 } | |
297 | |
298 void | |
299 playlist_select_next(void) | |
300 { | |
301 if (playlists_iter == NULL) | |
302 playlists_iter = playlists; | |
303 | |
304 playlists_iter = g_list_next(playlists_iter); | |
305 | |
306 if (playlists_iter == NULL) | |
307 playlists_iter = playlists; | |
308 | |
309 playlistwin_update_list(playlist_get_active()); | |
310 } | |
311 | |
312 void | |
313 playlist_select_prev(void) | |
314 { | |
315 if (playlists_iter == NULL) | |
316 playlists_iter = playlists; | |
317 | |
318 playlists_iter = g_list_previous(playlists_iter); | |
319 | |
320 if (playlists_iter == NULL) | |
321 playlists_iter = playlists; | |
322 | |
323 playlistwin_update_list(playlist_get_active()); | |
324 } | |
325 | |
326 void | |
327 playlist_select_playlist(Playlist *playlist) | |
328 { | |
329 if (playlists_iter == NULL) | |
330 playlists_iter = playlists; | |
331 | |
332 playlists_iter = g_list_find(playlists, playlist); | |
333 | |
334 if (playlists_iter == NULL) | |
335 playlists_iter = playlists; | |
336 | |
337 playlistwin_update_list(playlist); | |
338 } | |
339 | |
340 /* *********************** playlist code ********************** */ | |
341 | |
342 const gchar * | |
343 playlist_get_current_name(Playlist *playlist) | |
344 { | |
345 return playlist->title; | |
346 } | |
347 | |
348 gboolean | |
349 playlist_set_current_name(Playlist *playlist, const gchar * filename) | |
350 { | |
351 if (playlist->title) | |
352 g_free(playlist->title); | |
353 | |
354 if (!filename) { | |
355 playlist->title = NULL; | |
356 return FALSE; | |
357 } | |
358 | |
2504
fcf730269639
[svn] - convert filename string to utf8 for playlist->title (closes bug #789)
giacomo
parents:
2499
diff
changeset
|
359 playlist->title = filename_to_utf8(filename); |
2313 | 360 return TRUE; |
361 } | |
362 | |
363 static GList * | |
364 find_playlist_position_list(Playlist *playlist) | |
365 { | |
366 REQUIRE_LOCK(playlist->mutex); | |
367 | |
368 if (!playlist->position) { | |
369 if (cfg.shuffle) | |
370 return playlist->shuffle; | |
371 else | |
372 return playlist->entries; | |
373 } | |
374 | |
375 if (cfg.shuffle) | |
376 return g_list_find(playlist->shuffle, playlist->position); | |
377 else | |
378 return g_list_find(playlist->entries, playlist->position); | |
379 } | |
380 | |
381 static void | |
382 play_queued(Playlist *playlist) | |
383 { | |
384 GList *tmp = playlist->queue; | |
385 | |
386 REQUIRE_LOCK( playlist->mutex ); | |
387 | |
388 playlist->position = playlist->queue->data; | |
389 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | |
390 g_list_free_1(tmp); | |
391 } | |
392 | |
393 void | |
394 playlist_clear(Playlist *playlist) | |
395 { | |
396 if (!playlist) | |
397 return; | |
398 | |
399 PLAYLIST_LOCK( playlist->mutex ); | |
400 | |
401 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); | |
402 g_list_free(playlist->entries); | |
403 playlist->position = NULL; | |
404 playlist->entries = NULL; | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
405 playlist->tail = NULL; |
2637
420ce282920d
[svn] - clear playlist attribute when playlist_clear() is called.
yaz
parents:
2636
diff
changeset
|
406 playlist->attribute = PLAYLIST_PLAIN; |
2313 | 407 |
408 PLAYLIST_UNLOCK( playlist->mutex ); | |
409 | |
410 playlist_generate_shuffle_list(playlist); | |
411 playlistwin_update_list(playlist); | |
412 playlist_recalc_total_time(playlist); | |
413 playlist_manager_update(); | |
414 } | |
415 | |
416 static void | |
417 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
418 gboolean * restart_playing) | |
419 { | |
420 PlaylistEntry *entry; | |
421 GList *playing_song = NULL; | |
422 | |
423 REQUIRE_LOCK(playlist->mutex); | |
424 | |
425 /* We call g_list_find manually here because we don't want an item | |
426 * in the shuffle_list */ | |
427 | |
428 if (playlist->position) | |
429 playing_song = g_list_find(playlist->entries, playlist->position); | |
430 | |
431 entry = PLAYLIST_ENTRY(node->data); | |
432 | |
433 if (playing_song == node) { | |
434 *set_info_text = TRUE; | |
435 | |
436 if (playback_get_playing()) { | |
437 PLAYLIST_UNLOCK(playlist->mutex); | |
438 ip_data.stop = TRUE; | |
439 playback_stop(); | |
440 ip_data.stop = FALSE; | |
441 PLAYLIST_LOCK(playlist->mutex); | |
442 *restart_playing = TRUE; | |
443 } | |
444 | |
445 playing_song = find_playlist_position_list(playlist); | |
446 | |
447 if (g_list_next(playing_song)) | |
448 playlist->position = g_list_next(playing_song)->data; | |
449 else if (g_list_previous(playing_song)) | |
450 playlist->position = g_list_previous(playing_song)->data; | |
451 else | |
452 playlist->position = NULL; | |
453 | |
454 /* Make sure the entry did not disappear under us */ | |
455 if (g_list_index(playlist->entries, entry) == -1) | |
456 return; | |
457 | |
458 } | |
459 else if (g_list_position(playlist->entries, playing_song) > | |
460 g_list_position(playlist->entries, node)) { | |
461 *set_info_text = TRUE; | |
462 } | |
463 | |
464 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
465 playlist->queue = g_list_remove(playlist->queue, entry); | |
466 playlist->entries = g_list_remove_link(playlist->entries, node); | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
467 playlist->tail = g_list_last(playlist->entries); |
2313 | 468 playlist_entry_free(entry); |
469 g_list_free_1(node); | |
470 | |
471 playlist_recalc_total_time_nolock(playlist); | |
472 } | |
473 | |
474 void | |
475 playlist_delete_index(Playlist *playlist, guint pos) | |
476 { | |
477 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
478 GList *node; | |
479 | |
480 if (!playlist) | |
481 return; | |
482 | |
483 PLAYLIST_LOCK(playlist->mutex); | |
484 | |
485 node = g_list_nth(playlist->entries, pos); | |
486 | |
487 if (!node) { | |
488 PLAYLIST_UNLOCK(playlist->mutex); | |
489 return; | |
490 } | |
491 | |
492 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
493 | |
494 PLAYLIST_UNLOCK(playlist->mutex); | |
495 | |
496 playlist_recalc_total_time(playlist); | |
497 | |
498 playlistwin_update_list(playlist); | |
499 if (restart_playing) { | |
500 if (playlist->position) { | |
501 playback_initiate(); | |
502 } | |
503 else { | |
504 mainwin_clear_song_info(); | |
505 } | |
506 } | |
507 else if (set_info_text) { | |
508 mainwin_set_info_text(); | |
509 } | |
510 | |
511 playlist_manager_update(); | |
512 } | |
513 | |
514 void | |
515 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
516 { | |
517 GList *node, *fnode; | |
518 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
519 | |
520 PLAYLIST_LOCK(playlist->mutex); | |
521 | |
522 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
523 node = playlist->entries; | |
524 | |
525 while (node) { | |
526 GList *next = g_list_next(node); | |
527 PlaylistEntry *entry = node->data; | |
528 | |
529 if (!strcmp(entry->filename, fnode->data)) | |
530 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
531 | |
532 node = next; | |
533 } | |
534 } | |
535 | |
536 playlist_recalc_total_time(playlist); | |
537 PLAYLIST_UNLOCK(playlist->mutex); | |
538 | |
539 playlistwin_update_list(playlist); | |
540 | |
541 if (restart_playing) { | |
542 if (playlist->position) { | |
543 playback_initiate(); | |
544 } | |
545 else { | |
546 mainwin_clear_song_info(); | |
547 } | |
548 } | |
549 else if (set_info_text) { | |
550 mainwin_set_info_text(); | |
551 } | |
552 | |
553 playlist_manager_update(); | |
554 } | |
555 | |
556 void | |
557 playlist_delete(Playlist * playlist, gboolean crop) | |
558 { | |
559 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
560 GList *node, *next_node; | |
561 PlaylistEntry *entry; | |
562 | |
563 g_return_if_fail(playlist != NULL); | |
564 | |
565 PLAYLIST_LOCK(playlist->mutex); | |
566 | |
567 node = playlist->entries; | |
568 | |
569 while (node) { | |
570 entry = PLAYLIST_ENTRY(node->data); | |
571 | |
572 next_node = g_list_next(node); | |
573 | |
574 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
575 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
576 } | |
577 | |
578 node = next_node; | |
579 } | |
580 | |
581 PLAYLIST_UNLOCK(playlist->mutex); | |
582 | |
583 playlist_recalc_total_time(playlist); | |
584 | |
585 if (set_info_text) { | |
586 mainwin_set_info_text(); | |
587 } | |
588 | |
589 if (restart_playing) { | |
590 if (playlist->position) { | |
591 playback_initiate(); | |
592 } | |
593 else { | |
594 mainwin_clear_song_info(); | |
595 } | |
596 } | |
597 | |
598 playlistwin_update_list(playlist); | |
599 playlist_manager_update(); | |
600 } | |
601 | |
602 static void | |
603 __playlist_ins_with_info(Playlist * playlist, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
604 const gchar * filename, |
2313 | 605 gint pos, |
606 const gchar * title, | |
607 gint len, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
608 InputPlugin * dec) |
2313 | 609 { |
610 g_return_if_fail(filename != NULL); | |
611 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
612 PLAYLIST_LOCK( playlist->mutex ); |
2313 | 613 playlist->entries = g_list_insert(playlist->entries, |
614 playlist_entry_new(filename, title, len, dec), | |
615 pos); | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
616 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 617 |
618 g_mutex_lock(mutex_scan); | |
619 playlist_get_info_scan_active = TRUE; | |
620 g_mutex_unlock(mutex_scan); | |
621 g_cond_signal(cond_scan); | |
622 } | |
623 | |
624 static void | |
625 __playlist_ins_with_info_tuple(Playlist * playlist, | |
626 const gchar * filename, | |
627 gint pos, | |
628 TitleInput *tuple, | |
629 InputPlugin * dec) | |
630 { | |
631 PlaylistEntry *entry; | |
632 | |
633 g_return_if_fail(playlist != NULL); | |
634 g_return_if_fail(filename != NULL); | |
635 | |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
636 entry = playlist_entry_new(filename, tuple->track_name, tuple->length, dec); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
637 if(!playlist->tail) |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
638 playlist->tail = g_list_last(playlist->entries); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
639 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
640 PLAYLIST_LOCK( playlist->mutex ); |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
641 if(pos == -1) { // the common case |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
642 GList *element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
643 element = g_list_alloc(); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
644 element->data = entry; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
645 element->prev = playlist->tail; // NULL is allowed here. |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
646 element->next = NULL; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
647 |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
648 if(!playlist->entries) { // this is the first element |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
649 playlist->entries = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
650 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
651 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
652 else { // the rests |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
653 g_return_if_fail(playlist->tail != NULL); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
654 playlist->tail->next = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
655 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
656 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
657 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
658 else { |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
659 playlist->entries = g_list_insert(playlist->entries, entry, pos); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
660 } |
2313 | 661 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
662 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 663 if (tuple != NULL) { |
664 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); | |
665 entry->length = tuple->length; | |
666 entry->tuple = tuple; | |
667 } | |
668 | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
669 if(tuple->mtime == -1) { // kick the scanner thread only if mtime = -1 (uninitialized). |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
670 g_mutex_lock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
671 playlist_get_info_scan_active = TRUE; |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
672 g_mutex_unlock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
673 g_cond_signal(cond_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
674 } |
2313 | 675 } |
676 | |
677 static void | |
678 __playlist_ins(Playlist * playlist, const gchar * filename, gint pos, InputPlugin *dec) | |
679 { | |
680 __playlist_ins_with_info(playlist, filename, pos, NULL, -1, dec); | |
681 playlist_recalc_total_time(playlist); | |
682 playlist_manager_update(); | |
683 } | |
684 | |
685 gboolean | |
686 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
687 { | |
688 gchar buf[64], *p; | |
689 gint r; | |
690 VFSFile *file; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
691 InputPlugin *dec = NULL; |
2313 | 692 |
693 g_return_val_if_fail(playlist != NULL, FALSE); | |
694 g_return_val_if_fail(filename != NULL, FALSE); | |
695 | |
696 if (is_playlist_name(filename)) { | |
697 playlist->loading_playlist = TRUE; | |
698 playlist_load_ins(playlist, filename, pos); | |
699 playlist->loading_playlist = FALSE; | |
700 return TRUE; | |
701 } | |
702 | |
703 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | |
704 dec = NULL; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
705 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
706 !str_has_prefix_nocase(filename, "https://")) |
2313 | 707 dec = input_check_file(filename, TRUE); |
708 | |
2690
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
709 #if 0 |
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
710 printf("loading_playlist = %d filename = %s is_playlist_name = %d\n", |
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
711 playlist->loading_playlist, filename, playlist->loading_playlist); |
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
712 #endif |
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
713 /* XXX this line causes cuesheet plugin infinite addition to the playlist. --yaz */ |
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
714 // if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || (playlist->loading_playlist == FALSE && dec != NULL) || (playlist->loading_playlist == FALSE && !is_playlist_name(filename))) |
62579e205746
[svn] - temporal workaround for a bug which introduced in r4360. without this patch, cuesheet plugin endlessly adds entries in a cue sheet to the current playlist.
yaz
parents:
2683
diff
changeset
|
715 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || (playlist->loading_playlist == FALSE && dec != NULL)) |
2313 | 716 { |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
717 __playlist_ins(playlist, filename, pos, dec); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
718 playlist_generate_shuffle_list(playlist); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
719 playlistwin_update_list(playlist); |
2313 | 720 return TRUE; |
721 } | |
722 | |
723 /* Some files (typically produced by some cgi-scripts) don't have | |
724 * the correct extension. Try to recognize these files by looking | |
725 * at their content. We only check for http entries since it does | |
726 * not make sense to have file entries in a playlist fetched from | |
727 * the net. */ | |
728 | |
729 /* Some strange people put fifo's with the .mp3 extension, so we | |
730 * need to make sure it's a real file (otherwise fread() may block | |
731 * and stall the entire program) */ | |
732 | |
733 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
734 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
735 return FALSE; | |
736 | |
737 if (!(file = vfs_fopen(filename, "rb"))) | |
738 return FALSE; | |
739 | |
740 r = vfs_fread(buf, 1, sizeof(buf), file); | |
741 vfs_fclose(file); | |
742 | |
743 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
744 | |
745 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
746 playlist_load_ins(playlist, filename, pos); | |
747 return TRUE; | |
748 } | |
749 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
750 if (r > 6 && str_has_prefix_nocase(p, "https:")) { |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
751 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
752 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
753 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
754 |
2313 | 755 return FALSE; |
756 } | |
757 | |
758 /* FIXME: The next few functions are specific to Unix | |
759 * filesystems. Either abstract it away, or don't even bother checking | |
760 * at such low level */ | |
761 | |
762 typedef struct { | |
763 dev_t dev; | |
764 ino_t ino; | |
765 } DeviceInode; | |
766 | |
767 static DeviceInode * | |
768 devino_new(dev_t device, | |
769 ino_t inode) | |
770 { | |
771 DeviceInode *devino = g_new0(DeviceInode, 1); | |
772 | |
773 if (devino) | |
774 { | |
775 devino->dev = device; | |
776 devino->ino = inode; | |
777 } | |
778 | |
779 return devino; | |
780 } | |
781 | |
782 static guint | |
783 devino_hash(gconstpointer key) | |
784 { | |
785 const DeviceInode *d = key; | |
786 return d->ino; | |
787 } | |
788 | |
789 static gint | |
790 devino_compare(gconstpointer a, | |
791 gconstpointer b) | |
792 { | |
793 const DeviceInode *da = a, *db = b; | |
794 return (da->dev == db->dev && da->ino == db->ino); | |
795 } | |
796 | |
797 static gboolean | |
798 devino_destroy(gpointer key, | |
799 gpointer value, | |
800 gpointer data) | |
801 { | |
802 g_free(key); | |
803 return TRUE; | |
804 } | |
805 | |
806 static gboolean | |
807 file_is_hidden(const gchar * filename) | |
808 { | |
809 g_return_val_if_fail(filename != NULL, FALSE); | |
2570 | 810 return (g_basename(filename)[0] == '.'); |
2313 | 811 } |
812 | |
813 static GList * | |
814 playlist_dir_find_files(const gchar * path, | |
815 gboolean background, | |
816 GHashTable * htab) | |
817 { | |
818 GDir *dir; | |
819 GList *list = NULL, *ilist; | |
820 const gchar *dir_entry; | |
821 | |
822 struct stat statbuf; | |
823 DeviceInode *devino; | |
824 | |
825 if (!g_file_test(path, G_FILE_TEST_IS_DIR)) | |
826 return NULL; | |
827 | |
828 stat(path, &statbuf); | |
829 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
830 | |
831 if (g_hash_table_lookup(htab, devino)) { | |
832 g_free(devino); | |
833 return NULL; | |
834 } | |
835 | |
836 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
837 | |
838 if ((ilist = input_scan_dir(path))) { | |
839 GList *node; | |
840 for (node = ilist; node; node = g_list_next(node)) { | |
841 gchar *name = g_build_filename(path, node->data, NULL); | |
842 list = g_list_prepend(list, name); | |
843 g_free(node->data); | |
844 } | |
845 g_list_free(ilist); | |
846 return list; | |
847 } | |
848 | |
849 if (!(dir = g_dir_open(path, 0, NULL))) | |
850 return NULL; | |
851 | |
852 while ((dir_entry = g_dir_read_name(dir))) { | |
853 gchar *filename; | |
854 | |
855 if (file_is_hidden(dir_entry)) | |
856 continue; | |
857 | |
858 filename = g_build_filename(path, dir_entry, NULL); | |
859 | |
860 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
861 GList *sub; | |
862 sub = playlist_dir_find_files(filename, background, htab); | |
863 g_free(filename); | |
864 list = g_list_concat(list, sub); | |
865 } | |
866 else if (cfg.playlist_detect == TRUE) | |
867 list = g_list_prepend(list, filename); | |
868 else if (input_check_file(filename, TRUE)) | |
869 list = g_list_prepend(list, filename); | |
870 else | |
871 g_free(filename); | |
872 | |
873 while (background && gtk_events_pending()) | |
874 gtk_main_iteration(); | |
875 } | |
876 g_dir_close(dir); | |
877 | |
878 return list; | |
879 } | |
880 | |
881 gboolean | |
882 playlist_add(Playlist * playlist, const gchar * filename) | |
883 { | |
884 return playlist_ins(playlist, filename, -1); | |
885 } | |
886 | |
887 guint | |
888 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
889 { | |
890 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
891 } | |
892 | |
893 guint | |
894 playlist_add_url(Playlist * playlist, const gchar * url) | |
895 { | |
896 return playlist_ins_url(playlist, url, -1); | |
897 } | |
898 | |
2579 | 899 static gchar * |
900 _playlist_urldecode_basic_path(const gchar * encoded_path) | |
901 { | |
902 const gchar *cur, *ext; | |
903 gchar *path, *tmp; | |
904 gint realchar; | |
905 | |
906 if (!encoded_path) | |
907 return NULL; | |
908 | |
909 if (!str_has_prefix_nocase(encoded_path, "file:")) | |
910 return NULL; | |
911 | |
912 cur = encoded_path + 5; | |
913 | |
914 if (str_has_prefix_nocase(cur, "//localhost")) | |
915 cur += 11; | |
916 | |
917 if (*cur == '/') | |
918 while (cur[1] == '/') | |
919 cur++; | |
920 | |
921 tmp = g_malloc0(strlen(cur) + 1); | |
922 | |
923 while ((ext = strchr(cur, '%')) != NULL) { | |
924 strncat(tmp, cur, ext - cur); | |
925 ext++; | |
926 cur = ext + 2; | |
927 if (!sscanf(ext, "%2x", &realchar)) { | |
928 /* Assume it is a literal '%'. Several file | |
929 * managers send unencoded file: urls on drag | |
930 * and drop. */ | |
931 realchar = '%'; | |
932 cur -= 2; | |
933 } | |
934 tmp[strlen(tmp)] = realchar; | |
935 } | |
936 | |
937 path = g_strconcat(tmp, cur, NULL); | |
938 g_free(tmp); | |
939 return path; | |
940 } | |
941 | |
2313 | 942 guint |
943 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
944 gint pos, | |
945 gboolean background) | |
946 { | |
947 guint entries = 0; | |
948 GList *list, *node; | |
949 GHashTable *htab; | |
2579 | 950 gchar *path2 = _playlist_urldecode_basic_path(path); |
2313 | 951 |
2580
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
952 if (path2 == NULL) |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
953 path2 = g_strdup(path); |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
954 |
2313 | 955 htab = g_hash_table_new(devino_hash, devino_compare); |
956 | |
2579 | 957 list = playlist_dir_find_files(path2, background, htab); |
2313 | 958 list = g_list_sort(list, (GCompareFunc) path_compare); |
959 | |
960 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
961 | |
962 for (node = list; node; node = g_list_next(node)) { | |
963 __playlist_ins(playlist, node->data, pos, NULL); | |
964 g_free(node->data); | |
965 entries++; | |
966 if (pos >= 0) | |
967 pos++; | |
968 } | |
969 | |
970 g_list_free(list); | |
2579 | 971 g_free(path2); |
2313 | 972 |
973 playlist_recalc_total_time(playlist); | |
974 playlist_generate_shuffle_list(playlist); | |
975 playlistwin_update_list(playlist); | |
976 playlist_manager_update(); | |
977 return entries; | |
978 } | |
979 | |
980 guint | |
981 playlist_ins_url(Playlist * playlist, const gchar * string, | |
982 gint pos) | |
983 { | |
984 gchar *tmp; | |
985 gint i = 1, entries = 0; | |
986 gboolean first = TRUE; | |
987 guint firstpos = 0; | |
988 gboolean success = FALSE; | |
989 gchar *decoded = NULL; | |
990 | |
991 g_return_val_if_fail(playlist != NULL, 0); | |
992 g_return_val_if_fail(string != NULL, 0); | |
993 | |
994 playlistwin_update_list(playlist); | |
995 | |
996 while (*string) { | |
997 GList *node; | |
998 tmp = strchr(string, '\n'); | |
999 if (tmp) { | |
1000 if (*(tmp - 1) == '\r') | |
1001 *(tmp - 1) = '\0'; | |
1002 *tmp = '\0'; | |
1003 } | |
1004 | |
1005 decoded = g_strdup(string); | |
1006 | |
2575 | 1007 if (vfs_file_test(decoded, G_FILE_TEST_IS_DIR)) { |
2313 | 1008 i = playlist_ins_dir(playlist, decoded, pos, FALSE); |
1009 } | |
1010 else { | |
1011 if (is_playlist_name(decoded)) { | |
1012 i = playlist_load_ins(playlist, decoded, pos); | |
1013 } | |
1014 else { | |
1015 success = playlist_ins(playlist, decoded, pos); | |
1016 i = 1; | |
1017 } | |
1018 } | |
1019 | |
1020 g_free(decoded); | |
1021 | |
1022 PLAYLIST_LOCK(playlist->mutex); | |
1023 node = g_list_nth(playlist->entries, pos); | |
1024 PLAYLIST_UNLOCK(playlist->mutex); | |
1025 | |
1026 entries += i; | |
1027 | |
1028 if (first) { | |
1029 first = FALSE; | |
1030 firstpos = pos; | |
1031 } | |
1032 | |
1033 if (pos >= 0) | |
1034 pos += i; | |
1035 if (!tmp) | |
1036 break; | |
1037 | |
1038 string = tmp + 1; | |
1039 } | |
1040 | |
1041 playlist_recalc_total_time(playlist); | |
1042 playlist_generate_shuffle_list(playlist); | |
1043 playlistwin_update_list(playlist); | |
1044 | |
1045 playlist_manager_update(); | |
1046 | |
1047 return entries; | |
1048 } | |
1049 | |
1050 void | |
1051 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
1052 gint freq, gint nch) | |
1053 { | |
1054 Playlist *playlist = playlist_get_active(); | |
1055 | |
1056 g_return_if_fail(playlist != NULL); | |
1057 | |
1058 if (playlist->position) { | |
1059 g_free(playlist->position->title); | |
1060 playlist->position->title = g_strdup(title); | |
1061 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1062 |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1063 // overwrite tuple->track_name, mainly for streaming. it may incur side effects. --yaz |
2489
e56a55d07935
[svn] - revise r3986 to only override tuple->track_name on lengthless streams
nenolod
parents:
2488
diff
changeset
|
1064 if(playlist->position->tuple && length == -1){ |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1065 if(playlist->position->tuple->track_name){ |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1066 g_free(playlist->position->tuple->track_name); |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1067 } |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1068 playlist->position->tuple->track_name = g_strdup(title); |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1069 } |
2313 | 1070 } |
1071 | |
1072 playlist_recalc_total_time(playlist); | |
1073 | |
1074 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1075 |
1076 if ( playlist->position ) | |
1077 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1078 } |
1079 | |
1080 void | |
1081 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1082 gint freq, gint nch) | |
1083 { | |
1084 g_return_if_fail(playlist != NULL); | |
1085 | |
1086 if (playlist->position) { | |
1087 g_free(playlist->position->title); | |
1088 playlist->position->title = g_strdup(title); | |
1089 playlist->position->length = length; | |
1090 } | |
1091 | |
1092 playlist_recalc_total_time(playlist); | |
1093 | |
1094 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1095 |
1096 if ( playlist->position ) | |
1097 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1098 } |
1099 | |
1100 void | |
1101 playlist_check_pos_current(Playlist *playlist) | |
1102 { | |
1103 gint pos, row, bottom; | |
1104 | |
1105 if (!playlist) | |
1106 return; | |
1107 | |
1108 PLAYLIST_LOCK(playlist->mutex); | |
1109 if (!playlist->position || !playlistwin_list) { | |
1110 PLAYLIST_UNLOCK(playlist->mutex); | |
1111 return; | |
1112 } | |
1113 | |
1114 pos = g_list_index(playlist->entries, playlist->position); | |
1115 | |
1116 if (playlistwin_item_visible(pos)) { | |
1117 PLAYLIST_UNLOCK(playlist->mutex); | |
1118 return; | |
1119 } | |
1120 | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1121 bottom = MAX(0, playlist_get_length(playlist) - |
2313 | 1122 playlistwin_list->pl_num_visible); |
1123 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom); | |
1124 PLAYLIST_UNLOCK(playlist->mutex); | |
1125 playlistwin_set_toprow(row); | |
1126 g_cond_signal(cond_scan); | |
1127 } | |
1128 | |
1129 void | |
1130 playlist_next(Playlist *playlist) | |
1131 { | |
1132 GList *plist_pos_list; | |
1133 gboolean restart_playing = FALSE; | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1134 if (!playlist_get_length(playlist)) |
2313 | 1135 return; |
1136 | |
1137 PLAYLIST_LOCK(playlist->mutex); | |
1138 | |
1139 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1140 { | |
1141 playlist->position = playlist_position_before_jump; | |
1142 playlist_position_before_jump = NULL; | |
1143 } | |
1144 | |
1145 plist_pos_list = find_playlist_position_list(playlist); | |
1146 | |
1147 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
1148 PLAYLIST_UNLOCK(playlist->mutex); | |
1149 return; | |
1150 } | |
1151 | |
1152 if (playback_get_playing()) { | |
1153 /* We need to stop before changing playlist_position */ | |
1154 PLAYLIST_UNLOCK(playlist->mutex); | |
1155 ip_data.stop = TRUE; | |
1156 playback_stop(); | |
1157 ip_data.stop = FALSE; | |
1158 PLAYLIST_LOCK(playlist->mutex); | |
1159 restart_playing = TRUE; | |
1160 } | |
1161 | |
1162 plist_pos_list = find_playlist_position_list(playlist); | |
1163 if (playlist->queue != NULL) | |
1164 play_queued(playlist); | |
1165 else if (g_list_next(plist_pos_list)) | |
1166 playlist->position = g_list_next(plist_pos_list)->data; | |
1167 else if (cfg.repeat) { | |
1168 playlist->position = NULL; | |
1169 playlist_generate_shuffle_list_nolock(playlist); | |
1170 if (cfg.shuffle) | |
1171 playlist->position = playlist->shuffle->data; | |
1172 else | |
1173 playlist->position = playlist->entries->data; | |
1174 } | |
1175 PLAYLIST_UNLOCK(playlist->mutex); | |
1176 playlist_check_pos_current(playlist); | |
1177 | |
1178 if (restart_playing) | |
1179 playback_initiate(); | |
1180 else { | |
1181 mainwin_set_info_text(); | |
1182 playlistwin_update_list(playlist); | |
1183 } | |
1184 } | |
1185 | |
1186 void | |
1187 playlist_prev(Playlist *playlist) | |
1188 { | |
1189 GList *plist_pos_list; | |
1190 gboolean restart_playing = FALSE; | |
1191 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1192 if (!playlist_get_length(playlist)) |
2313 | 1193 return; |
1194 | |
1195 PLAYLIST_LOCK(playlist->mutex); | |
1196 | |
1197 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1198 { | |
1199 playlist->position = playlist_position_before_jump; | |
1200 playlist_position_before_jump = NULL; | |
1201 } | |
1202 | |
1203 plist_pos_list = find_playlist_position_list(playlist); | |
1204 | |
1205 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
1206 PLAYLIST_UNLOCK(playlist->mutex); | |
1207 return; | |
1208 } | |
1209 | |
1210 if (playback_get_playing()) { | |
1211 /* We need to stop before changing playlist_position */ | |
1212 PLAYLIST_UNLOCK(playlist->mutex); | |
1213 ip_data.stop = TRUE; | |
1214 playback_stop(); | |
1215 ip_data.stop = FALSE; | |
1216 PLAYLIST_LOCK(playlist->mutex); | |
1217 restart_playing = TRUE; | |
1218 } | |
1219 | |
1220 plist_pos_list = find_playlist_position_list(playlist); | |
1221 if (g_list_previous(plist_pos_list)) { | |
1222 playlist->position = g_list_previous(plist_pos_list)->data; | |
1223 } | |
1224 else if (cfg.repeat) { | |
1225 GList *node; | |
1226 playlist->position = NULL; | |
1227 playlist_generate_shuffle_list_nolock(playlist); | |
1228 if (cfg.shuffle) | |
1229 node = g_list_last(playlist->shuffle); | |
1230 else | |
1231 node = g_list_last(playlist->entries); | |
1232 if (node) | |
1233 playlist->position = node->data; | |
1234 } | |
1235 | |
1236 PLAYLIST_UNLOCK(playlist->mutex); | |
1237 | |
1238 playlist_check_pos_current(playlist); | |
1239 | |
1240 if (restart_playing) | |
1241 playback_initiate(); | |
1242 else { | |
1243 mainwin_set_info_text(); | |
1244 playlistwin_update_list(playlist); | |
1245 } | |
1246 } | |
1247 | |
1248 void | |
1249 playlist_queue(Playlist *playlist) | |
1250 { | |
1251 GList *list = playlist_get_selected(playlist); | |
1252 GList *it = list; | |
1253 | |
1254 PLAYLIST_LOCK(playlist->mutex); | |
1255 | |
1256 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1257 { | |
1258 /* Shuffling and this is our first manual jump. */ | |
1259 playlist_position_before_jump = playlist->position; | |
1260 } | |
1261 | |
1262 while (it) { | |
1263 GList *next = g_list_next(it); | |
1264 GList *tmp; | |
1265 | |
1266 /* XXX: WTF? --nenolod */ | |
1267 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1268 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1269 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1270 g_list_free_1(tmp); | |
1271 list = g_list_remove_link(list, it); | |
1272 g_list_free_1(it); | |
1273 } | |
1274 | |
1275 it = next; | |
1276 } | |
1277 | |
1278 playlist->queue = g_list_concat(playlist->queue, list); | |
1279 | |
1280 PLAYLIST_UNLOCK(playlist->mutex); | |
1281 | |
1282 playlist_recalc_total_time(playlist); | |
1283 playlistwin_update_list(playlist); | |
1284 } | |
1285 | |
1286 void | |
1287 playlist_queue_position(Playlist *playlist, guint pos) | |
1288 { | |
1289 GList *tmp; | |
1290 PlaylistEntry *entry; | |
1291 | |
1292 PLAYLIST_LOCK(playlist->mutex); | |
1293 | |
1294 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1295 { | |
1296 /* Shuffling and this is our first manual jump. */ | |
1297 playlist_position_before_jump = playlist->position; | |
1298 } | |
1299 | |
1300 entry = g_list_nth_data(playlist->entries, pos); | |
1301 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1302 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1303 g_list_free_1(tmp); | |
1304 } | |
1305 else | |
1306 playlist->queue = g_list_append(playlist->queue, entry); | |
1307 PLAYLIST_UNLOCK(playlist->mutex); | |
1308 | |
1309 playlist_recalc_total_time(playlist); | |
1310 playlistwin_update_list(playlist); | |
1311 } | |
1312 | |
1313 gboolean | |
1314 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1315 { | |
1316 PlaylistEntry *entry; | |
1317 GList *tmp; | |
1318 | |
1319 PLAYLIST_LOCK(playlist->mutex); | |
1320 entry = g_list_nth_data(playlist->entries, pos); | |
1321 tmp = g_list_find(playlist->queue, entry); | |
1322 PLAYLIST_UNLOCK(playlist->mutex); | |
1323 | |
1324 return tmp != NULL; | |
1325 } | |
1326 | |
1327 gint | |
1328 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1329 { | |
1330 PlaylistEntry *entry; | |
1331 gint tmp; | |
1332 | |
1333 PLAYLIST_LOCK(playlist->mutex); | |
1334 entry = g_list_nth_data(playlist->entries, pos); | |
1335 tmp = g_list_index(playlist->queue, entry); | |
1336 PLAYLIST_UNLOCK(playlist->mutex); | |
1337 | |
1338 return tmp; | |
1339 } | |
1340 | |
1341 gint | |
1342 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1343 { | |
1344 PlaylistEntry *entry; | |
1345 gint tmp; | |
1346 | |
1347 PLAYLIST_LOCK(playlist->mutex); | |
1348 entry = g_list_nth_data(playlist->queue, pos); | |
1349 tmp = g_list_index(playlist->entries, entry); | |
1350 PLAYLIST_UNLOCK(playlist->mutex); | |
1351 | |
1352 return tmp; | |
1353 } | |
1354 | |
1355 void | |
1356 playlist_clear_queue(Playlist *playlist) | |
1357 { | |
1358 PLAYLIST_LOCK(playlist->mutex); | |
1359 g_list_free(playlist->queue); | |
1360 playlist->queue = NULL; | |
1361 PLAYLIST_UNLOCK(playlist->mutex); | |
1362 | |
1363 playlist_recalc_total_time(playlist); | |
1364 playlistwin_update_list(playlist); | |
1365 } | |
1366 | |
1367 void | |
1368 playlist_queue_remove(Playlist *playlist, guint pos) | |
1369 { | |
1370 void *entry; | |
1371 | |
1372 PLAYLIST_LOCK(playlist->mutex); | |
1373 entry = g_list_nth_data(playlist->entries, pos); | |
1374 playlist->queue = g_list_remove(playlist->queue, entry); | |
1375 PLAYLIST_UNLOCK(playlist->mutex); | |
1376 | |
1377 playlistwin_update_list(playlist); | |
1378 } | |
1379 | |
1380 gint | |
1381 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1382 { | |
1383 return g_list_index(playlist->queue, entry); | |
1384 } | |
1385 | |
1386 void | |
1387 playlist_set_position(Playlist *playlist, guint pos) | |
1388 { | |
1389 GList *node; | |
1390 gboolean restart_playing = FALSE; | |
1391 | |
1392 if (!playlist) | |
1393 return; | |
1394 | |
1395 PLAYLIST_LOCK(playlist->mutex); | |
1396 | |
1397 node = g_list_nth(playlist->entries, pos); | |
1398 if (!node) { | |
1399 PLAYLIST_UNLOCK(playlist->mutex); | |
1400 return; | |
1401 } | |
1402 | |
1403 if (playback_get_playing()) { | |
1404 /* We need to stop before changing playlist_position */ | |
1405 PLAYLIST_UNLOCK(playlist->mutex); | |
1406 ip_data.stop = TRUE; | |
1407 playback_stop(); | |
1408 ip_data.stop = FALSE; | |
1409 PLAYLIST_LOCK(playlist->mutex); | |
1410 restart_playing = TRUE; | |
1411 } | |
1412 | |
1413 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1414 { | |
1415 /* Shuffling and this is our first manual jump. */ | |
1416 playlist_position_before_jump = playlist->position; | |
1417 } | |
1418 | |
1419 playlist->position = node->data; | |
1420 PLAYLIST_UNLOCK(playlist->mutex); | |
1421 playlist_check_pos_current(playlist); | |
1422 | |
1423 if (restart_playing) | |
1424 playback_initiate(); | |
1425 else { | |
1426 mainwin_set_info_text(); | |
1427 playlistwin_update_list(playlist); | |
1428 } | |
1429 } | |
1430 | |
1431 void | |
1432 playlist_eof_reached(Playlist *playlist) | |
1433 { | |
1434 GList *plist_pos_list; | |
1435 | |
1436 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1437 ip_data.stop = TRUE; | |
1438 playback_stop(); | |
1439 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1440 ip_data.stop = FALSE; | |
1441 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1442 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1443 |
2313 | 1444 PLAYLIST_LOCK(playlist->mutex); |
1445 | |
1446 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1447 { | |
1448 playlist->position = playlist_position_before_jump; | |
1449 playlist_position_before_jump = NULL; | |
1450 } | |
1451 | |
1452 plist_pos_list = find_playlist_position_list(playlist); | |
1453 | |
1454 if (cfg.no_playlist_advance) { | |
1455 PLAYLIST_UNLOCK(playlist->mutex); | |
1456 mainwin_clear_song_info(); | |
1457 if (cfg.repeat) | |
1458 playback_initiate(); | |
1459 return; | |
1460 } | |
1461 | |
1462 if (cfg.stopaftersong) { | |
1463 PLAYLIST_UNLOCK(playlist->mutex); | |
1464 mainwin_clear_song_info(); | |
1465 mainwin_set_stopaftersong(FALSE); | |
1466 return; | |
1467 } | |
1468 | |
1469 if (playlist->queue != NULL) { | |
1470 play_queued(playlist); | |
1471 } | |
1472 else if (!g_list_next(plist_pos_list)) { | |
1473 if (cfg.shuffle) { | |
1474 playlist->position = NULL; | |
1475 playlist_generate_shuffle_list_nolock(playlist); | |
1476 } | |
2380 | 1477 else if (playlist->entries != NULL) |
2313 | 1478 playlist->position = playlist->entries->data; |
1479 | |
1480 if (!cfg.repeat) { | |
1481 PLAYLIST_UNLOCK(playlist->mutex); | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1482 hook_call("playlist end reached", playlist->position); |
2313 | 1483 mainwin_clear_song_info(); |
1484 mainwin_set_info_text(); | |
1485 return; | |
1486 } | |
1487 } | |
1488 else | |
1489 playlist->position = g_list_next(plist_pos_list)->data; | |
1490 | |
1491 PLAYLIST_UNLOCK(playlist->mutex); | |
1492 | |
1493 playlist_check_pos_current(playlist); | |
1494 playback_initiate(); | |
1495 mainwin_set_info_text(); | |
1496 playlistwin_update_list(playlist); | |
1497 } | |
1498 | |
1499 gint | |
1500 playlist_queue_get_length(Playlist *playlist) | |
1501 { | |
1502 gint length; | |
1503 | |
1504 PLAYLIST_LOCK(playlist->mutex); | |
1505 length = g_list_length(playlist->queue); | |
1506 PLAYLIST_UNLOCK(playlist->mutex); | |
1507 | |
1508 return length; | |
1509 } | |
1510 | |
1511 gint | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1512 playlist_get_length(Playlist *playlist) |
2313 | 1513 { |
1514 return g_list_length(playlist->entries); | |
1515 } | |
1516 | |
1517 gchar * | |
1518 playlist_get_info_text(Playlist *playlist) | |
1519 { | |
1520 gchar *text, *title, *numbers, *length; | |
1521 | |
1522 g_return_val_if_fail(playlist != NULL, NULL); | |
1523 | |
1524 PLAYLIST_LOCK(playlist->mutex); | |
1525 if (!playlist->position) { | |
1526 PLAYLIST_UNLOCK(playlist->mutex); | |
1527 return NULL; | |
1528 } | |
1529 | |
1530 /* FIXME: there should not be a need to do additional conversion, | |
1531 * if playlist is properly maintained */ | |
1532 if (playlist->position->title) { | |
1533 title = str_to_utf8(playlist->position->title); | |
1534 } | |
1535 else { | |
1536 gchar *basename = g_path_get_basename(playlist->position->filename); | |
1537 title = filename_to_utf8(basename); | |
1538 g_free(basename); | |
1539 } | |
1540 | |
1541 /* | |
1542 * If the user don't want numbers in the playlist, don't | |
1543 * display them in other parts of XMMS | |
1544 */ | |
1545 | |
1546 if (cfg.show_numbers_in_pl) | |
1547 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1548 else | |
1549 numbers = g_strdup(""); | |
1550 | |
1551 if (playlist->position->length != -1) | |
1552 length = g_strdup_printf(" (%d:%-2.2d)", | |
1553 playlist->position->length / 60000, | |
1554 (playlist->position->length / 1000) % 60); | |
1555 else | |
1556 length = g_strdup(""); | |
1557 | |
1558 PLAYLIST_UNLOCK(playlist->mutex); | |
1559 | |
1560 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1561 | |
1562 g_free(numbers); | |
1563 g_free(title); | |
1564 g_free(length); | |
1565 | |
1566 return text; | |
1567 } | |
1568 | |
1569 gint | |
1570 playlist_get_current_length(Playlist * playlist) | |
1571 { | |
1572 gint len = 0; | |
1573 | |
1574 if (!playlist) | |
1575 return 0; | |
1576 | |
1577 if (playlist->position) | |
1578 len = playlist->position->length; | |
1579 | |
1580 return len; | |
1581 } | |
1582 | |
1583 gboolean | |
1584 playlist_save(Playlist * playlist, const gchar * filename) | |
1585 { | |
1586 PlaylistContainer *plc = NULL; | |
1587 gchar *ext; | |
1588 | |
1589 g_return_val_if_fail(playlist != NULL, FALSE); | |
1590 g_return_val_if_fail(filename != NULL, FALSE); | |
1591 | |
1592 ext = strrchr(filename, '.') + 1; | |
1593 | |
1594 playlist_set_current_name(playlist, filename); | |
1595 | |
1596 if ((plc = playlist_container_find(ext)) == NULL) | |
1597 return FALSE; | |
1598 | |
1599 if (plc->plc_write == NULL) | |
1600 return FALSE; | |
1601 | |
1602 plc->plc_write(filename, 0); | |
1603 | |
1604 return TRUE; | |
1605 } | |
1606 | |
1607 gboolean | |
1608 playlist_load(Playlist * playlist, const gchar * filename) | |
1609 { | |
1610 gboolean ret = FALSE; | |
1611 g_return_val_if_fail(playlist != NULL, FALSE); | |
1612 | |
1613 playlist->loading_playlist = TRUE; | |
1614 ret = playlist_load_ins(playlist, filename, -1); | |
1615 playlist->loading_playlist = FALSE; | |
1616 | |
1617 return ret; | |
1618 } | |
1619 | |
1620 void | |
1621 playlist_load_ins_file(Playlist *playlist, | |
1622 const gchar * filename_p, | |
1623 const gchar * playlist_name, gint pos, | |
1624 const gchar * title, gint len) | |
1625 { | |
1626 gchar *filename; | |
1627 gchar *tmp, *path; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1628 InputPlugin *dec = NULL; /* for decoder cache */ |
2313 | 1629 |
1630 g_return_if_fail(filename_p != NULL); | |
1631 g_return_if_fail(playlist != NULL); | |
1632 g_return_if_fail(playlist_name != NULL); | |
1633 | |
1634 filename = g_strchug(g_strdup(filename_p)); | |
1635 | |
1636 if(cfg.convert_slash) | |
1637 while ((tmp = strchr(filename, '\\')) != NULL) | |
1638 *tmp = '/'; | |
1639 | |
1640 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1641 path = g_strdup(playlist_name); | |
1642 if ((tmp = strrchr(path, '/'))) | |
1643 *tmp = '\0'; | |
1644 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1645 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1646 cfg.playlist_detect == TRUE)) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1647 dec = NULL; |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1648 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1649 !str_has_prefix_nocase(filename, "https://")) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1650 dec = input_check_file(filename, FALSE); |
2313 | 1651 |
1652 __playlist_ins_with_info(playlist, filename, pos, title, len, dec); | |
1653 return; | |
1654 } | |
1655 tmp = g_build_filename(path, filename, NULL); | |
1656 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1657 if (playlist->loading_playlist == TRUE && cfg.playlist_detect == TRUE) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1658 dec = NULL; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1659 else if (!str_has_prefix_nocase(tmp, "http://") && |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1660 !str_has_prefix_nocase(tmp, "https://")) |
2313 | 1661 dec = input_check_file(tmp, FALSE); |
1662 | |
1663 __playlist_ins_with_info(playlist, tmp, pos, title, len, dec); | |
1664 g_free(tmp); | |
1665 g_free(path); | |
1666 } | |
1667 else | |
1668 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1669 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1670 cfg.playlist_detect == TRUE)) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1671 dec = NULL; |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1672 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1673 !str_has_prefix_nocase(filename, "https://")) |
2313 | 1674 dec = input_check_file(filename, FALSE); |
1675 | |
1676 __playlist_ins_with_info(playlist, filename, pos, title, len, dec); | |
1677 } | |
1678 | |
1679 g_free(filename); | |
1680 } | |
1681 | |
1682 void | |
1683 playlist_load_ins_file_tuple(Playlist * playlist, | |
1684 const gchar * filename_p, | |
1685 const gchar * playlist_name, | |
1686 gint pos, | |
1687 TitleInput *tuple) | |
1688 { | |
1689 gchar *filename; | |
1690 gchar *tmp, *path; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1691 InputPlugin *dec = NULL; /* for decoder cache */ |
2313 | 1692 |
1693 g_return_if_fail(filename_p != NULL); | |
1694 g_return_if_fail(playlist_name != NULL); | |
1695 g_return_if_fail(playlist != NULL); | |
1696 | |
1697 filename = g_strchug(g_strdup(filename_p)); | |
1698 | |
1699 while ((tmp = strchr(filename, '\\')) != NULL) | |
1700 *tmp = '/'; | |
1701 | |
1702 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1703 path = g_strdup(playlist_name); | |
1704 if ((tmp = strrchr(path, '/'))) | |
1705 *tmp = '\0'; | |
1706 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1707 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1708 cfg.playlist_detect == TRUE)) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1709 dec = NULL; |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1710 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1711 !str_has_prefix_nocase(filename, "https://")) |
2313 | 1712 dec = input_check_file(filename, FALSE); |
1713 | |
1714 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | |
1715 return; | |
1716 } | |
1717 tmp = g_build_filename(path, filename, NULL); | |
1718 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1719 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1720 cfg.playlist_detect == TRUE)) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1721 dec = NULL; |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1722 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1723 !str_has_prefix_nocase(filename, "https://")) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1724 dec = input_check_file(filename, FALSE); |
2313 | 1725 |
1726 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, dec); | |
1727 g_free(tmp); | |
1728 g_free(path); | |
1729 } | |
1730 else | |
1731 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1732 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1733 cfg.playlist_detect == TRUE)) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1734 dec = NULL; |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1735 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1736 !str_has_prefix_nocase(filename, "https://")) |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1737 dec = input_check_file(filename, FALSE); |
2313 | 1738 |
1739 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | |
1740 } | |
1741 | |
1742 g_free(filename); | |
1743 } | |
1744 | |
1745 static guint | |
1746 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1747 { | |
1748 PlaylistContainer *plc; | |
1749 gchar *ext; | |
1750 | |
1751 g_return_val_if_fail(playlist != NULL, 0); | |
1752 g_return_val_if_fail(filename != NULL, 0); | |
1753 | |
1754 ext = strrchr(filename, '.') + 1; | |
1755 plc = playlist_container_find(ext); | |
1756 | |
1757 g_return_val_if_fail(plc != NULL, 0); | |
1758 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1759 | |
1760 plc->plc_read(filename, pos); | |
1761 | |
1762 playlist_generate_shuffle_list(playlist); | |
1763 playlistwin_update_list(playlist); | |
1764 | |
1765 return 1; | |
1766 } | |
1767 | |
1768 GList * | |
1769 get_playlist_nth(Playlist *playlist, guint nth) | |
1770 { | |
1771 g_warning("deprecated function get_playlist_nth() was called"); | |
1772 REQUIRE_LOCK(playlist->mutex); | |
1773 return g_list_nth(playlist->entries, nth); | |
1774 } | |
1775 | |
1776 gint | |
1777 playlist_get_position_nolock(Playlist *playlist) | |
1778 { | |
1779 if (playlist && playlist->position) | |
1780 return g_list_index(playlist->entries, playlist->position); | |
1781 return 0; | |
1782 } | |
1783 | |
1784 gint | |
1785 playlist_get_position(Playlist *playlist) | |
1786 { | |
1787 gint pos; | |
1788 | |
1789 PLAYLIST_LOCK(playlist->mutex); | |
1790 pos = playlist_get_position_nolock(playlist); | |
1791 PLAYLIST_UNLOCK(playlist->mutex); | |
1792 | |
1793 return pos; | |
1794 } | |
1795 | |
1796 gchar * | |
1797 playlist_get_filename(Playlist *playlist, guint pos) | |
1798 { | |
1799 gchar *filename; | |
1800 PlaylistEntry *entry; | |
1801 GList *node; | |
1802 | |
1803 if (!playlist) | |
1804 return NULL; | |
1805 | |
1806 PLAYLIST_LOCK(playlist->mutex); | |
1807 node = g_list_nth(playlist->entries, pos); | |
1808 if (!node) { | |
1809 PLAYLIST_UNLOCK(playlist->mutex); | |
1810 return NULL; | |
1811 } | |
1812 entry = node->data; | |
1813 | |
1814 filename = g_strdup(entry->filename); | |
1815 PLAYLIST_UNLOCK(playlist->mutex); | |
1816 | |
1817 return filename; | |
1818 } | |
1819 | |
1820 gchar * | |
1821 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1822 { | |
1823 gchar *title = NULL; | |
1824 PlaylistEntry *entry; | |
1825 GList *node; | |
1826 | |
1827 if (!playlist) | |
1828 return NULL; | |
1829 | |
1830 PLAYLIST_LOCK(playlist->mutex); | |
1831 | |
1832 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1833 PLAYLIST_UNLOCK(playlist->mutex); | |
1834 return NULL; | |
1835 } | |
1836 | |
1837 entry = node->data; | |
1838 | |
1839 /* FIXME: simplify this logic */ | |
1840 if ((entry->title == NULL && entry->length == -1) || | |
1841 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) | |
1842 { | |
1843 if (playlist_entry_get_info(entry)) | |
1844 title = entry->title; | |
1845 } | |
1846 else { | |
1847 title = entry->title; | |
1848 } | |
1849 | |
1850 PLAYLIST_UNLOCK(playlist->mutex); | |
1851 | |
1852 if (!title) { | |
1853 title = g_path_get_basename(entry->filename); | |
1854 return str_replace(title, filename_to_utf8(title)); | |
1855 } | |
1856 | |
1857 return str_to_utf8(title); | |
1858 } | |
1859 | |
1860 TitleInput * | |
1861 playlist_get_tuple(Playlist *playlist, guint pos) | |
1862 { | |
1863 PlaylistEntry *entry; | |
1864 TitleInput *tuple = NULL; | |
1865 GList *node; | |
1866 | |
1867 if (!playlist) | |
1868 return NULL; | |
1869 | |
1870 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1871 return NULL; | |
1872 } | |
1873 | |
1874 entry = (PlaylistEntry *) node->data; | |
1875 | |
1876 tuple = entry->tuple; | |
1877 | |
1878 // if no tuple or tuple with old mtime, get new one. | |
1879 if (tuple == NULL || | |
1880 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) | |
1881 { | |
1882 playlist_entry_get_info(entry); | |
1883 tuple = entry->tuple; | |
1884 } | |
1885 | |
1886 return tuple; | |
1887 } | |
1888 | |
1889 gint | |
1890 playlist_get_songtime(Playlist *playlist, guint pos) | |
1891 { | |
1892 gint song_time = -1; | |
1893 PlaylistEntry *entry; | |
1894 GList *node; | |
1895 | |
1896 if (!playlist) | |
1897 return -1; | |
1898 | |
1899 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1900 return -1; | |
1901 } | |
1902 | |
1903 entry = node->data; | |
1904 if (entry->tuple == NULL || | |
1905 (entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) { | |
1906 | |
1907 if (playlist_entry_get_info(entry)) | |
1908 song_time = entry->length; | |
1909 } | |
1910 else { | |
1911 song_time = entry->length; | |
1912 } | |
1913 | |
1914 return song_time; | |
1915 } | |
1916 | |
1917 static gint | |
1918 playlist_compare_track(PlaylistEntry * a, | |
1919 PlaylistEntry * b) | |
1920 { | |
1921 g_return_val_if_fail(a != NULL, 0); | |
1922 g_return_val_if_fail(b != NULL, 0); | |
1923 | |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1924 if(!a->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1925 playlist_entry_get_info(a); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1926 if(!b->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1927 playlist_entry_get_info(b); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1928 |
2313 | 1929 g_return_val_if_fail(a->tuple != NULL, 0); |
1930 g_return_val_if_fail(b->tuple != NULL, 0); | |
1931 | |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1932 return (a->tuple->track_number && b->tuple->track_number ? |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1933 a->tuple->track_number - b->tuple->track_number : 0); |
2313 | 1934 } |
1935 | |
1936 static gint | |
1937 playlist_compare_playlist(PlaylistEntry * a, | |
1938 PlaylistEntry * b) | |
1939 { | |
1940 const gchar *a_title = NULL, *b_title = NULL; | |
1941 | |
1942 g_return_val_if_fail(a != NULL, 0); | |
1943 g_return_val_if_fail(b != NULL, 0); | |
1944 | |
1945 if (a->title != NULL) | |
1946 a_title = a->title; | |
1947 else { | |
1948 if (strrchr(a->filename, '/')) | |
1949 a_title = strrchr(a->filename, '/') + 1; | |
1950 else | |
1951 a_title = a->filename; | |
1952 } | |
1953 | |
1954 if (b->title != NULL) | |
1955 b_title = b->title; | |
1956 else { | |
1957 if (strrchr(a->filename, '/')) | |
1958 b_title = strrchr(b->filename, '/') + 1; | |
1959 else | |
1960 b_title = b->filename; | |
1961 } | |
1962 | |
1963 return strcasecmp(a_title, b_title); | |
1964 } | |
1965 | |
1966 static gint | |
1967 playlist_compare_title(PlaylistEntry * a, | |
1968 PlaylistEntry * b) | |
1969 { | |
1970 const gchar *a_title = NULL, *b_title = NULL; | |
1971 | |
1972 g_return_val_if_fail(a != NULL, 0); | |
1973 g_return_val_if_fail(b != NULL, 0); | |
1974 | |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1975 if(!a->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1976 playlist_entry_get_info(a); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1977 if(!b->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1978 playlist_entry_get_info(b); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1979 |
2313 | 1980 if (a->tuple != NULL && a->tuple->track_name != NULL) |
1981 a_title = a->tuple->track_name; | |
1982 if (b->tuple != NULL && b->tuple->track_name != NULL) | |
1983 b_title = b->tuple->track_name; | |
1984 | |
1985 if (a_title != NULL && b_title != NULL) | |
1986 return strcasecmp(a_title, b_title); | |
1987 | |
1988 if (a->title != NULL) | |
1989 a_title = a->title; | |
1990 else { | |
1991 if (strrchr(a->filename, '/')) | |
1992 a_title = strrchr(a->filename, '/') + 1; | |
1993 else | |
1994 a_title = a->filename; | |
1995 } | |
1996 | |
1997 if (b->title != NULL) | |
1998 b_title = b->title; | |
1999 else { | |
2000 if (strrchr(a->filename, '/')) | |
2001 b_title = strrchr(b->filename, '/') + 1; | |
2002 else | |
2003 b_title = b->filename; | |
2004 } | |
2005 | |
2006 return strcasecmp(a_title, b_title); | |
2007 } | |
2008 | |
2009 static gint | |
2010 playlist_compare_artist(PlaylistEntry * a, | |
2011 PlaylistEntry * b) | |
2012 { | |
2013 const gchar *a_artist = NULL, *b_artist = NULL; | |
2014 | |
2015 g_return_val_if_fail(a != NULL, 0); | |
2016 g_return_val_if_fail(b != NULL, 0); | |
2017 | |
2018 if (a->tuple != NULL) | |
2019 playlist_entry_get_info(a); | |
2020 | |
2021 if (b->tuple != NULL) | |
2022 playlist_entry_get_info(b); | |
2023 | |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2024 if (a->tuple != NULL && a->tuple->performer != NULL) { |
2313 | 2025 a_artist = a->tuple->performer; |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2026 if (str_has_prefix_nocase(a_artist, "the ")) |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2027 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2028 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2029 |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2030 if (b->tuple != NULL && b->tuple->performer != NULL) { |
2313 | 2031 b_artist = b->tuple->performer; |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2032 if (str_has_prefix_nocase(b_artist, "the ")) |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2033 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2034 } |
2313 | 2035 |
2036 if (a_artist != NULL && b_artist != NULL) | |
2037 return strcasecmp(a_artist, b_artist); | |
2038 | |
2039 return 0; | |
2040 } | |
2041 | |
2042 static gint | |
2043 playlist_compare_filename(PlaylistEntry * a, | |
2044 PlaylistEntry * b) | |
2045 { | |
2046 gchar *a_filename, *b_filename; | |
2047 | |
2048 g_return_val_if_fail(a != NULL, 0); | |
2049 g_return_val_if_fail(b != NULL, 0); | |
2050 | |
2051 if (strrchr(a->filename, '/')) | |
2052 a_filename = strrchr(a->filename, '/') + 1; | |
2053 else | |
2054 a_filename = a->filename; | |
2055 | |
2056 if (strrchr(b->filename, '/')) | |
2057 b_filename = strrchr(b->filename, '/') + 1; | |
2058 else | |
2059 b_filename = b->filename; | |
2060 | |
2061 | |
2062 return strcasecmp(a_filename, b_filename); | |
2063 } | |
2064 | |
2065 static gint | |
2066 path_compare(const gchar * a, const gchar * b) | |
2067 { | |
2068 gchar *posa, *posb; | |
2069 gint len, ret; | |
2070 | |
2071 posa = strrchr(a, '/'); | |
2072 posb = strrchr(b, '/'); | |
2073 | |
2074 /* | |
2075 * Sort directories before files | |
2076 */ | |
2077 if (posa && posb && (posa - a != posb - b)) { | |
2078 if (posa - a > posb - b) { | |
2079 len = posb - b; | |
2080 ret = -1; | |
2081 } | |
2082 else { | |
2083 len = posa - a; | |
2084 ret = 1; | |
2085 } | |
2086 if (!strncasecmp(a, b, len)) | |
2087 return ret; | |
2088 } | |
2089 return strcasecmp(a, b); | |
2090 } | |
2091 | |
2092 static gint | |
2093 playlist_compare_path(PlaylistEntry * a, | |
2094 PlaylistEntry * b) | |
2095 { | |
2096 return path_compare(a->filename, b->filename); | |
2097 } | |
2098 | |
2099 | |
2100 static time_t | |
2101 playlist_get_mtime(const gchar *filename) | |
2102 { | |
2103 struct stat buf; | |
2104 gint rv; | |
2105 | |
2106 rv = stat(filename, &buf); | |
2107 | |
2108 if (rv == 0) { | |
2109 return buf.st_mtime; | |
2110 } else { | |
2111 return 0; //error | |
2112 } | |
2113 } | |
2114 | |
2115 | |
2116 static gint | |
2117 playlist_compare_date(PlaylistEntry * a, | |
2118 PlaylistEntry * b) | |
2119 { | |
2120 struct stat buf; | |
2121 time_t modtime; | |
2122 | |
2123 gint rv; | |
2124 | |
2125 | |
2126 rv = stat(a->filename, &buf); | |
2127 | |
2128 if (rv == 0) { | |
2129 modtime = buf.st_mtime; | |
2130 rv = stat(b->filename, &buf); | |
2131 | |
2132 if (stat(b->filename, &buf) == 0) { | |
2133 if (buf.st_mtime == modtime) | |
2134 return 0; | |
2135 else | |
2136 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2137 } | |
2138 else | |
2139 return -1; | |
2140 } | |
2141 else if (!lstat(b->filename, &buf)) | |
2142 return 1; | |
2143 else | |
2144 return playlist_compare_filename(a, b); | |
2145 } | |
2146 | |
2147 | |
2148 void | |
2149 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2150 { | |
2151 playlist_remove_dead_files(playlist); | |
2152 PLAYLIST_LOCK(playlist->mutex); | |
2153 playlist->entries = | |
2154 g_list_sort(playlist->entries, | |
2155 (GCompareFunc) playlist_compare_func_table[type]); | |
2156 PLAYLIST_UNLOCK(playlist->mutex); | |
2157 } | |
2158 | |
2159 static GList * | |
2160 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2161 { | |
2162 GList *list1, *list2; | |
2163 GList *tmp_list = NULL; | |
2164 GList *index_list = NULL; | |
2165 | |
2166 /* | |
2167 * We take all the selected entries out of the playlist, | |
2168 * sorts them, and then put them back in again. | |
2169 */ | |
2170 | |
2171 list1 = g_list_last(list); | |
2172 | |
2173 while (list1) { | |
2174 list2 = g_list_previous(list1); | |
2175 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2176 gpointer idx; | |
2177 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2178 index_list = g_list_prepend(index_list, idx); | |
2179 list = g_list_remove_link(list, list1); | |
2180 tmp_list = g_list_concat(list1, tmp_list); | |
2181 } | |
2182 list1 = list2; | |
2183 } | |
2184 | |
2185 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2186 list1 = tmp_list; | |
2187 list2 = index_list; | |
2188 | |
2189 while (list2) { | |
2190 if (!list1) { | |
2191 g_critical(G_STRLOC ": Error during list sorting. " | |
2192 "Possibly dropped some playlist-entries."); | |
2193 break; | |
2194 } | |
2195 | |
2196 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2197 | |
2198 list2 = g_list_next(list2); | |
2199 list1 = g_list_next(list1); | |
2200 } | |
2201 | |
2202 g_list_free(index_list); | |
2203 g_list_free(tmp_list); | |
2204 | |
2205 return list; | |
2206 } | |
2207 | |
2208 void | |
2209 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2210 { | |
2211 PLAYLIST_LOCK(playlist->mutex); | |
2212 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) | |
2213 playlist_compare_func_table | |
2214 [type]); | |
2215 PLAYLIST_UNLOCK(playlist->mutex); | |
2216 } | |
2217 | |
2218 void | |
2219 playlist_reverse(Playlist *playlist) | |
2220 { | |
2221 PLAYLIST_LOCK(playlist->mutex); | |
2222 playlist->entries = g_list_reverse(playlist->entries); | |
2223 PLAYLIST_UNLOCK(playlist->mutex); | |
2224 } | |
2225 | |
2226 static GList * | |
2227 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2228 { | |
2229 /* | |
2230 * Note that this doesn't make a copy of the original list. | |
2231 * The pointer to the original list is not valid after this | |
2232 * fuction is run. | |
2233 */ | |
2234 gint len = g_list_length(list); | |
2235 gint i, j; | |
2236 GList *node, **ptrs; | |
2237 | |
2238 if (!playlist) | |
2239 return NULL; | |
2240 | |
2241 REQUIRE_LOCK(playlist->mutex); | |
2242 | |
2243 if (!len) | |
2244 return NULL; | |
2245 | |
2246 ptrs = g_new(GList *, len); | |
2247 | |
2248 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2249 ptrs[i] = node; | |
2250 | |
2251 j = g_random_int_range(0, len); | |
2252 list = ptrs[j]; | |
2253 ptrs[j]->next = NULL; | |
2254 ptrs[j] = ptrs[0]; | |
2255 | |
2256 for (i = 1; i < len; i++) { | |
2257 j = g_random_int_range(0, len - i); | |
2258 list->prev = ptrs[i + j]; | |
2259 ptrs[i + j]->next = list; | |
2260 list = ptrs[i + j]; | |
2261 ptrs[i + j] = ptrs[i]; | |
2262 } | |
2263 list->prev = NULL; | |
2264 | |
2265 g_free(ptrs); | |
2266 | |
2267 return list; | |
2268 } | |
2269 | |
2270 void | |
2271 playlist_random(Playlist *playlist) | |
2272 { | |
2273 PLAYLIST_LOCK(playlist->mutex); | |
2274 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); | |
2275 PLAYLIST_UNLOCK(playlist->mutex); | |
2276 } | |
2277 | |
2278 GList * | |
2279 playlist_get_selected(Playlist *playlist) | |
2280 { | |
2281 GList *node, *list = NULL; | |
2282 gint i = 0; | |
2283 | |
2284 PLAYLIST_LOCK(playlist->mutex); | |
2285 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2286 PlaylistEntry *entry = node->data; | |
2287 if (entry->selected) | |
2288 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2289 } | |
2290 PLAYLIST_UNLOCK(playlist->mutex); | |
2291 return g_list_reverse(list); | |
2292 } | |
2293 | |
2294 void | |
2295 playlist_clear_selected(Playlist *playlist) | |
2296 { | |
2297 GList *node = NULL; | |
2298 gint i = 0; | |
2299 | |
2300 PLAYLIST_LOCK(playlist->mutex); | |
2301 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2302 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2303 } | |
2304 PLAYLIST_UNLOCK(playlist->mutex); | |
2305 playlist_recalc_total_time(playlist); | |
2306 playlist_manager_update(); | |
2307 } | |
2308 | |
2309 gint | |
2310 playlist_get_num_selected(Playlist *playlist) | |
2311 { | |
2312 GList *node; | |
2313 gint num = 0; | |
2314 | |
2315 PLAYLIST_LOCK(playlist->mutex); | |
2316 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2317 PlaylistEntry *entry = node->data; | |
2318 if (entry->selected) | |
2319 num++; | |
2320 } | |
2321 PLAYLIST_UNLOCK(playlist->mutex); | |
2322 return num; | |
2323 } | |
2324 | |
2325 | |
2326 static void | |
2327 playlist_generate_shuffle_list(Playlist *playlist) | |
2328 { | |
2329 PLAYLIST_LOCK(playlist->mutex); | |
2330 playlist_generate_shuffle_list_nolock(playlist); | |
2331 PLAYLIST_UNLOCK(playlist->mutex); | |
2332 } | |
2333 | |
2334 static void | |
2335 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2336 { | |
2337 GList *node; | |
2338 gint numsongs; | |
2339 | |
2340 if (!cfg.shuffle || !playlist) | |
2341 return; | |
2342 | |
2343 REQUIRE_LOCK(playlist->mutex); | |
2344 | |
2345 if (playlist->shuffle) { | |
2346 g_list_free(playlist->shuffle); | |
2347 playlist->shuffle = NULL; | |
2348 } | |
2349 | |
2350 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2351 numsongs = g_list_length(playlist->shuffle); | |
2352 | |
2353 if (playlist->position) { | |
2354 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2355 node = g_list_nth(playlist->shuffle, i); | |
2356 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2357 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2358 } | |
2359 } | |
2360 | |
2361 void | |
2362 playlist_fileinfo(Playlist *playlist, guint pos) | |
2363 { | |
2364 gchar *path = NULL; | |
2365 GList *node; | |
2366 PlaylistEntry *entry = NULL; | |
2367 TitleInput *tuple = NULL; | |
2368 | |
2369 PLAYLIST_LOCK(playlist->mutex); | |
2370 | |
2371 if ((node = g_list_nth(playlist->entries, pos))) | |
2372 { | |
2373 entry = node->data; | |
2374 tuple = entry->tuple; | |
2375 path = g_strdup(entry->filename); | |
2376 } | |
2377 | |
2378 PLAYLIST_UNLOCK(playlist->mutex); | |
2379 | |
2380 /* No tuple? Try to set this entry up properly. --nenolod */ | |
2381 if (entry->tuple == NULL || entry->tuple->mtime == -1 || | |
2382 entry->tuple->mtime == 0 || entry->tuple->mtime != playlist_get_mtime(entry->filename)) | |
2383 { | |
2384 playlist_entry_get_info(entry); | |
2385 tuple = entry->tuple; | |
2386 } | |
2387 | |
2388 if (tuple != NULL) | |
2389 { | |
2390 if (entry->decoder == NULL) | |
2391 entry->decoder = input_check_file(entry->filename, FALSE); /* try to find a decoder */ | |
2392 | |
2393 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2394 fileinfo_show_for_tuple(tuple); | |
2395 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2396 entry->decoder->file_info_box(path); | |
2397 else | |
2398 fileinfo_show_for_path(path); | |
2399 g_free(path); | |
2400 } | |
2401 else if (path != NULL) | |
2402 { | |
2403 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2404 entry->decoder->file_info_box(path); | |
2405 else | |
2406 fileinfo_show_for_path(path); | |
2407 g_free(path); | |
2408 } | |
2409 } | |
2410 | |
2411 void | |
2412 playlist_fileinfo_current(Playlist *playlist) | |
2413 { | |
2414 gchar *path = NULL; | |
2415 TitleInput *tuple = NULL; | |
2416 | |
2417 PLAYLIST_LOCK(playlist->mutex); | |
2418 | |
2419 if (playlist->entries && playlist->position) | |
2420 { | |
2421 path = g_strdup(playlist->position->filename); | |
2422 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2423 playlist_entry_get_info(playlist->position); | |
2424 tuple = playlist->position->tuple; | |
2425 } | |
2426 | |
2427 PLAYLIST_UNLOCK(playlist->mutex); | |
2428 | |
2429 if (tuple != NULL) | |
2430 { | |
2431 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2432 fileinfo_show_for_tuple(tuple); | |
2433 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2434 playlist->position->decoder->file_info_box(path); | |
2435 else | |
2436 fileinfo_show_for_path(path); | |
2437 g_free(path); | |
2438 } | |
2439 else if (path != NULL) | |
2440 { | |
2441 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2442 playlist->position->decoder->file_info_box(path); | |
2443 else | |
2444 fileinfo_show_for_path(path); | |
2445 g_free(path); | |
2446 } | |
2447 } | |
2448 | |
2449 | |
2450 static gboolean | |
2451 playlist_get_info_is_going(void) | |
2452 { | |
2453 gboolean result; | |
2454 | |
2455 G_LOCK(playlist_get_info_going); | |
2456 result = playlist_get_info_going; | |
2457 G_UNLOCK(playlist_get_info_going); | |
2458 | |
2459 return result; | |
2460 } | |
2461 | |
2462 static gpointer | |
2463 playlist_get_info_func(gpointer arg) | |
2464 { | |
2465 GList *node; | |
2466 gboolean update_playlistwin = FALSE; | |
2467 gboolean update_mainwin = FALSE; | |
2468 | |
2469 while (playlist_get_info_is_going()) { | |
2470 PlaylistEntry *entry; | |
2471 Playlist *playlist = playlist_get_active(); | |
2472 | |
2473 // on_load | |
2474 if (cfg.use_pl_metadata && | |
2475 cfg.get_info_on_load && | |
2476 playlist_get_info_scan_active) { | |
2477 | |
2478 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2479 entry = node->data; | |
2480 | |
2636 | 2481 if(playlist->attribute & PLAYLIST_STATIC || |
2482 (entry->tuple && entry->tuple->length > -1 && entry->tuple->mtime != -1)) { | |
2313 | 2483 update_playlistwin = TRUE; |
2484 continue; | |
2485 } | |
2486 | |
2487 if (!playlist_entry_get_info(entry)) { | |
2488 if (g_list_index(playlist->entries, entry) == -1) | |
2489 /* Entry disappeared while we looked it up. | |
2490 Restart. */ | |
2491 node = playlist->entries; | |
2492 } | |
2493 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2494 update_playlistwin = TRUE; | |
2495 if (entry == playlist->position) | |
2496 update_mainwin = TRUE; | |
2497 break; | |
2498 } | |
2499 } | |
2500 | |
2501 if (!node) { | |
2502 g_mutex_lock(mutex_scan); | |
2503 playlist_get_info_scan_active = FALSE; | |
2504 g_mutex_unlock(mutex_scan); | |
2505 } | |
2506 } // on_load | |
2507 | |
2508 // on_demand | |
2509 else if (!cfg.get_info_on_load && | |
2510 cfg.get_info_on_demand && | |
2511 cfg.playlist_visible && | |
2512 !cfg.playlist_shaded && | |
2513 cfg.use_pl_metadata) { | |
2514 | |
2515 g_mutex_lock(mutex_scan); | |
2516 playlist_get_info_scan_active = FALSE; | |
2517 g_mutex_unlock(mutex_scan); | |
2518 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2519 for (node = g_list_nth(playlist->entries, playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2520 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2521 node = g_list_next(node)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2522 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2523 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2524 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2525 if(playlist->attribute & PLAYLIST_STATIC || |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2526 (entry->tuple && entry->tuple->length > -1 && entry->tuple->mtime != -1)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2527 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2528 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2529 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2530 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2531 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2532 if (g_list_index(playlist->entries, entry) == -1) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2533 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2534 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2535 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2536 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2537 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2538 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2539 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2540 if (entry == playlist->position) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2541 update_mainwin = TRUE; |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
2542 // no need for break here since this iteration is very short. |
2313 | 2543 } |
2544 } | |
2545 } // on_demand | |
2546 else if (cfg.get_info_on_demand && | |
2547 (!cfg.playlist_visible || cfg.playlist_shaded | |
2548 || !cfg.use_pl_metadata)) | |
2549 { | |
2550 g_mutex_lock(mutex_scan); | |
2551 playlist_get_info_scan_active = FALSE; | |
2552 g_mutex_unlock(mutex_scan); | |
2553 } | |
2554 else /* not on_demand and not on_load... | |
2555 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2556 { | |
2557 g_mutex_lock(mutex_scan); | |
2558 playlist_get_info_scan_active = FALSE; | |
2559 g_mutex_unlock(mutex_scan); | |
2560 } | |
2561 | |
2562 if (update_playlistwin) { | |
2563 playlistwin_update_list(playlist); | |
2564 update_playlistwin = FALSE; | |
2565 } | |
2566 | |
2567 if (update_mainwin) { | |
2568 mainwin_set_info_text(); | |
2569 update_mainwin = FALSE; | |
2570 } | |
2571 | |
2572 if (playlist_get_info_scan_active) { | |
2573 continue; | |
2574 } | |
2575 | |
2576 g_mutex_lock(mutex_scan); | |
2577 g_cond_wait(cond_scan, mutex_scan); | |
2578 g_mutex_unlock(mutex_scan); | |
2579 | |
2580 } // while | |
2581 | |
2582 g_thread_exit(NULL); | |
2583 return NULL; | |
2584 } | |
2585 | |
2586 void | |
2587 playlist_start_get_info_thread(void) | |
2588 { | |
2589 G_LOCK(playlist_get_info_going); | |
2590 playlist_get_info_going = TRUE; | |
2591 G_UNLOCK(playlist_get_info_going); | |
2592 | |
2593 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2594 NULL, TRUE, NULL); | |
2595 } | |
2596 | |
2597 void | |
2598 playlist_stop_get_info_thread(void) | |
2599 { | |
2600 G_LOCK(playlist_get_info_going); | |
2601 playlist_get_info_going = FALSE; | |
2602 G_UNLOCK(playlist_get_info_going); | |
2603 | |
2604 g_cond_broadcast(cond_scan); | |
2605 g_thread_join(playlist_get_info_thread); | |
2606 } | |
2607 | |
2608 void | |
2609 playlist_start_get_info_scan(void) | |
2610 { | |
2611 g_mutex_lock(mutex_scan); | |
2612 playlist_get_info_scan_active = TRUE; | |
2613 g_mutex_unlock(mutex_scan); | |
2614 g_cond_signal(cond_scan); | |
2615 } | |
2616 | |
2617 void | |
2618 playlist_remove_dead_files(Playlist *playlist) | |
2619 { | |
2620 GList *node, *next_node; | |
2621 | |
2622 PLAYLIST_LOCK(playlist->mutex); | |
2623 | |
2624 for (node = playlist->entries; node; node = next_node) { | |
2625 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2626 next_node = g_list_next(node); | |
2627 | |
2628 if (!entry || !entry->filename) { | |
2629 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2630 continue; | |
2631 } | |
2632 | |
2633 /* FIXME: What about 'file:///'? */ | |
2634 /* Don't kill URLs */ | |
2635 if (strstr(entry->filename, "://")) | |
2636 continue; | |
2637 | |
2638 /* FIXME: Should test for readability */ | |
2639 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2640 continue; | |
2641 | |
2642 if (entry == playlist->position) { | |
2643 /* Don't remove the currently playing song */ | |
2644 if (playback_get_playing()) | |
2645 continue; | |
2646 | |
2647 if (next_node) | |
2648 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2649 else | |
2650 playlist->position = NULL; | |
2651 } | |
2652 | |
2653 playlist_entry_free(entry); | |
2654 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2655 } | |
2656 | |
2657 PLAYLIST_UNLOCK(playlist->mutex); | |
2658 | |
2659 playlist_generate_shuffle_list(playlist); | |
2660 playlistwin_update_list(playlist); | |
2661 playlist_recalc_total_time(playlist); | |
2662 playlist_manager_update(); | |
2663 } | |
2664 | |
2665 | |
2666 static gint | |
2667 playlist_dupscmp_title(PlaylistEntry * a, | |
2668 PlaylistEntry * b) | |
2669 { | |
2670 const gchar *a_title, *b_title; | |
2671 | |
2672 g_return_val_if_fail(a != NULL, 0); | |
2673 g_return_val_if_fail(b != NULL, 0); | |
2674 | |
2675 if (a->title) | |
2676 a_title = a->title; | |
2677 else { | |
2678 if (strrchr(a->filename, '/')) | |
2679 a_title = strrchr(a->filename, '/') + 1; | |
2680 else | |
2681 a_title = a->filename; | |
2682 } | |
2683 | |
2684 if (b->title) | |
2685 b_title = b->title; | |
2686 else { | |
2687 if (strrchr(a->filename, '/')) | |
2688 b_title = strrchr(b->filename, '/') + 1; | |
2689 else | |
2690 b_title = b->filename; | |
2691 } | |
2692 | |
2693 return strcmp(a_title, b_title); | |
2694 } | |
2695 | |
2696 static gint | |
2697 playlist_dupscmp_filename(PlaylistEntry * a, | |
2698 PlaylistEntry * b ) | |
2699 { | |
2700 gchar *a_filename, *b_filename; | |
2701 | |
2702 g_return_val_if_fail(a != NULL, 0); | |
2703 g_return_val_if_fail(b != NULL, 0); | |
2704 | |
2705 if (strrchr(a->filename, '/')) | |
2706 a_filename = strrchr(a->filename, '/') + 1; | |
2707 else | |
2708 a_filename = a->filename; | |
2709 | |
2710 if (strrchr(b->filename, '/')) | |
2711 b_filename = strrchr(b->filename, '/') + 1; | |
2712 else | |
2713 b_filename = b->filename; | |
2714 | |
2715 return strcmp(a_filename, b_filename); | |
2716 } | |
2717 | |
2718 static gint | |
2719 playlist_dupscmp_path(PlaylistEntry * a, | |
2720 PlaylistEntry * b) | |
2721 { | |
2722 /* simply compare the entire filename string */ | |
2723 return strcmp(a->filename, b->filename); | |
2724 } | |
2725 | |
2726 void | |
2727 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2728 { | |
2729 GList *node, *next_node; | |
2730 GList *node_cmp, *next_node_cmp; | |
2731 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2732 | |
2733 switch ( type ) | |
2734 { | |
2735 case PLAYLIST_DUPS_TITLE: | |
2736 dups_compare_func = playlist_dupscmp_title; | |
2737 break; | |
2738 case PLAYLIST_DUPS_PATH: | |
2739 dups_compare_func = playlist_dupscmp_path; | |
2740 break; | |
2741 case PLAYLIST_DUPS_FILENAME: | |
2742 default: | |
2743 dups_compare_func = playlist_dupscmp_filename; | |
2744 break; | |
2745 } | |
2746 | |
2747 PLAYLIST_LOCK(playlist->mutex); | |
2748 | |
2749 for (node = playlist->entries; node; node = next_node) { | |
2750 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2751 next_node = g_list_next(node); | |
2752 | |
2753 if (!entry || !entry->filename) { | |
2754 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2755 continue; | |
2756 } | |
2757 | |
2758 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2759 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2760 next_node_cmp = g_list_next(node_cmp); | |
2761 | |
2762 if (!entry_cmp || !entry_cmp->filename) { | |
2763 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2764 continue; | |
2765 } | |
2766 | |
2767 /* compare using the chosen dups_compare_func */ | |
2768 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2769 | |
2770 if (entry_cmp == playlist->position) { | |
2771 /* Don't remove the currently playing song */ | |
2772 if (playback_get_playing()) | |
2773 continue; | |
2774 | |
2775 if (next_node_cmp) | |
2776 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2777 else | |
2778 playlist->position = NULL; | |
2779 } | |
2780 | |
2781 /* check if this was the next item of the external | |
2782 loop; if true, replace it with the next of the next*/ | |
2783 if ( node_cmp == next_node ) | |
2784 next_node = g_list_next(next_node); | |
2785 | |
2786 playlist_entry_free(entry_cmp); | |
2787 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2788 } | |
2789 } | |
2790 } | |
2791 | |
2792 PLAYLIST_UNLOCK(playlist->mutex); | |
2793 | |
2794 playlistwin_update_list(playlist); | |
2795 playlist_recalc_total_time(playlist); | |
2796 | |
2797 playlist_manager_update(); | |
2798 } | |
2799 | |
2800 void | |
2801 playlist_get_total_time(Playlist * playlist, | |
2802 gulong * total_time, | |
2803 gulong * selection_time, | |
2804 gboolean * total_more, | |
2805 gboolean * selection_more) | |
2806 { | |
2807 PLAYLIST_LOCK(playlist->mutex); | |
2808 *total_time = playlist->pl_total_time; | |
2809 *selection_time = playlist->pl_selection_time; | |
2810 *total_more = playlist->pl_total_more; | |
2811 *selection_more = playlist->pl_selection_more; | |
2812 PLAYLIST_UNLOCK(playlist->mutex); | |
2813 } | |
2814 | |
2815 | |
2816 static void | |
2817 playlist_recalc_total_time_nolock(Playlist *playlist) | |
2818 { | |
2819 GList *list; | |
2820 PlaylistEntry *entry; | |
2821 | |
2822 REQUIRE_LOCK(playlist->mutex); | |
2823 | |
2824 playlist->pl_total_time = 0; | |
2825 playlist->pl_selection_time = 0; | |
2826 playlist->pl_total_more = FALSE; | |
2827 playlist->pl_selection_more = FALSE; | |
2828 | |
2829 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2830 entry = list->data; | |
2831 | |
2832 if (entry->length != -1) | |
2833 playlist->pl_total_time += entry->length / 1000; | |
2834 else | |
2835 playlist->pl_total_more = TRUE; | |
2836 | |
2837 if (entry->selected) { | |
2838 if (entry->length != -1) | |
2839 playlist->pl_selection_time += entry->length / 1000; | |
2840 else | |
2841 playlist->pl_selection_more = TRUE; | |
2842 } | |
2843 } | |
2844 } | |
2845 | |
2846 static void | |
2847 playlist_recalc_total_time(Playlist *playlist) | |
2848 { | |
2849 PLAYLIST_LOCK(playlist->mutex); | |
2850 playlist_recalc_total_time_nolock(playlist); | |
2851 PLAYLIST_UNLOCK(playlist->mutex); | |
2852 } | |
2853 | |
2854 gint | |
2855 playlist_select_search( Playlist *playlist , TitleInput *tuple , gint action ) | |
2856 { | |
2857 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2858 gboolean is_first_search = TRUE; | |
2859 gint num_of_entries_found = 0; | |
2860 | |
2861 #if defined(USE_REGEX_ONIGURUMA) | |
2862 /* set encoding for Oniguruma regex to UTF-8 */ | |
2863 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2864 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
2865 #endif | |
2866 | |
2867 PLAYLIST_LOCK(playlist->mutex); | |
2868 | |
2869 if ( tuple->track_name != NULL ) | |
2870 { | |
2871 /* match by track_name */ | |
2872 const gchar *regex_pattern = tuple->track_name; | |
2873 regex_t regex; | |
2874 #if defined(USE_REGEX_PCRE) | |
2875 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2876 #else | |
2877 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2878 #endif | |
2879 { | |
2880 GList *tfound_list = NULL; | |
2881 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2882 else entry_list = found_list; /* use found_list */ | |
2883 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2884 { | |
2885 PlaylistEntry *entry = entry_list->data; | |
2886 if ( ( entry->tuple != NULL ) && ( entry->tuple->track_name != NULL ) && | |
2887 ( regexec( ®ex , entry->tuple->track_name , 0 , NULL , 0 ) == 0 ) ) | |
2888 { | |
2889 tfound_list = g_list_append( tfound_list , entry ); | |
2890 } | |
2891 } | |
2892 g_list_free( found_list ); /* wipe old found_list */ | |
2893 found_list = tfound_list; /* move tfound_list in found_list */ | |
2894 regfree( ®ex ); | |
2895 } | |
2896 is_first_search = FALSE; | |
2897 } | |
2898 | |
2899 if ( tuple->album_name != NULL ) | |
2900 { | |
2901 /* match by album_name */ | |
2902 const gchar *regex_pattern = tuple->album_name; | |
2903 regex_t regex; | |
2904 #if defined(USE_REGEX_PCRE) | |
2905 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2906 #else | |
2907 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2908 #endif | |
2909 { | |
2910 GList *tfound_list = NULL; | |
2911 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2912 else entry_list = found_list; /* use found_list */ | |
2913 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2914 { | |
2915 PlaylistEntry *entry = entry_list->data; | |
2916 if ( ( entry->tuple != NULL ) && ( entry->tuple->album_name != NULL ) && | |
2917 ( regexec( ®ex , entry->tuple->album_name , 0 , NULL , 0 ) == 0 ) ) | |
2918 { | |
2919 tfound_list = g_list_append( tfound_list , entry ); | |
2920 } | |
2921 } | |
2922 g_list_free( found_list ); /* wipe old found_list */ | |
2923 found_list = tfound_list; /* move tfound_list in found_list */ | |
2924 regfree( ®ex ); | |
2925 } | |
2926 is_first_search = FALSE; | |
2927 } | |
2928 | |
2929 if ( tuple->performer != NULL ) | |
2930 { | |
2931 /* match by performer */ | |
2932 const gchar *regex_pattern = tuple->performer; | |
2933 regex_t regex; | |
2934 #if defined(USE_REGEX_PCRE) | |
2935 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2936 #else | |
2937 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2938 #endif | |
2939 { | |
2940 GList *tfound_list = NULL; | |
2941 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2942 else entry_list = found_list; /* use found_list */ | |
2943 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2944 { | |
2945 PlaylistEntry *entry = entry_list->data; | |
2946 if ( ( entry->tuple != NULL ) && ( entry->tuple->performer != NULL ) && | |
2947 ( regexec( ®ex , entry->tuple->performer , 0 , NULL , 0 ) == 0 ) ) | |
2948 { | |
2949 tfound_list = g_list_append( tfound_list , entry ); | |
2950 } | |
2951 } | |
2952 g_list_free( found_list ); /* wipe old found_list */ | |
2953 found_list = tfound_list; /* move tfound_list in found_list */ | |
2954 regfree( ®ex ); | |
2955 } | |
2956 is_first_search = FALSE; | |
2957 } | |
2958 | |
2959 if ( tuple->file_name != NULL ) | |
2960 { | |
2961 /* match by file_name */ | |
2962 const gchar *regex_pattern = tuple->file_name; | |
2963 regex_t regex; | |
2964 #if defined(USE_REGEX_PCRE) | |
2965 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2966 #else | |
2967 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2968 #endif | |
2969 { | |
2970 GList *tfound_list = NULL; | |
2971 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2972 else entry_list = found_list; /* use found_list */ | |
2973 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2974 { | |
2975 PlaylistEntry *entry = entry_list->data; | |
2976 if ( ( entry->tuple != NULL ) && ( entry->tuple->file_name != NULL ) && | |
2977 ( regexec( ®ex , entry->tuple->file_name , 0 , NULL , 0 ) == 0 ) ) | |
2978 { | |
2979 tfound_list = g_list_append( tfound_list , entry ); | |
2980 } | |
2981 } | |
2982 g_list_free( found_list ); /* wipe old found_list */ | |
2983 found_list = tfound_list; /* move tfound_list in found_list */ | |
2984 regfree( ®ex ); | |
2985 } | |
2986 is_first_search = FALSE; | |
2987 } | |
2988 | |
2989 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
2990 /* if some entries are still in found_list, those | |
2991 are what the user is searching for; select them */ | |
2992 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
2993 { | |
2994 PlaylistEntry *entry = sel_list->data; | |
2995 entry->selected = TRUE; | |
2996 num_of_entries_found++; | |
2997 } | |
2998 | |
2999 g_list_free( found_list ); | |
3000 | |
3001 PLAYLIST_UNLOCK(playlist->mutex); | |
3002 playlist_recalc_total_time(playlist); | |
3003 | |
3004 return num_of_entries_found; | |
3005 } | |
3006 | |
3007 void | |
3008 playlist_select_all(Playlist *playlist, gboolean set) | |
3009 { | |
3010 GList *list; | |
3011 | |
3012 PLAYLIST_LOCK(playlist->mutex); | |
3013 | |
3014 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3015 PlaylistEntry *entry = list->data; | |
3016 entry->selected = set; | |
3017 } | |
3018 | |
3019 PLAYLIST_UNLOCK(playlist->mutex); | |
3020 playlist_recalc_total_time(playlist); | |
3021 } | |
3022 | |
3023 void | |
3024 playlist_select_invert_all(Playlist *playlist) | |
3025 { | |
3026 GList *list; | |
3027 | |
3028 PLAYLIST_LOCK(playlist->mutex); | |
3029 | |
3030 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3031 PlaylistEntry *entry = list->data; | |
3032 entry->selected = !entry->selected; | |
3033 } | |
3034 | |
3035 PLAYLIST_UNLOCK(playlist->mutex); | |
3036 playlist_recalc_total_time(playlist); | |
3037 } | |
3038 | |
3039 gboolean | |
3040 playlist_select_invert(Playlist *playlist, guint pos) | |
3041 { | |
3042 GList *list; | |
3043 gboolean invert_ok = FALSE; | |
3044 | |
3045 PLAYLIST_LOCK(playlist->mutex); | |
3046 | |
3047 if ((list = g_list_nth(playlist->entries, pos))) { | |
3048 PlaylistEntry *entry = list->data; | |
3049 entry->selected = !entry->selected; | |
3050 invert_ok = TRUE; | |
3051 } | |
3052 | |
3053 PLAYLIST_UNLOCK(playlist->mutex); | |
3054 playlist_recalc_total_time(playlist); | |
3055 | |
3056 return invert_ok; | |
3057 } | |
3058 | |
3059 | |
3060 void | |
3061 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3062 { | |
3063 GList *list; | |
3064 gint i; | |
3065 | |
3066 if (min_pos > max_pos) | |
3067 SWAP(min_pos, max_pos); | |
3068 | |
3069 PLAYLIST_LOCK(playlist->mutex); | |
3070 | |
3071 list = g_list_nth(playlist->entries, min_pos); | |
3072 for (i = min_pos; i <= max_pos && list; i++) { | |
3073 PlaylistEntry *entry = list->data; | |
3074 entry->selected = select; | |
3075 list = g_list_next(list); | |
3076 } | |
3077 | |
3078 PLAYLIST_UNLOCK(playlist->mutex); | |
3079 | |
3080 playlist_recalc_total_time(playlist); | |
3081 } | |
3082 | |
3083 gboolean | |
3084 playlist_read_info_selection(Playlist *playlist) | |
3085 { | |
3086 GList *node; | |
3087 gboolean retval = FALSE; | |
3088 | |
3089 PLAYLIST_LOCK(playlist->mutex); | |
3090 | |
3091 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3092 PlaylistEntry *entry = node->data; | |
3093 if (!entry->selected) | |
3094 continue; | |
3095 | |
3096 retval = TRUE; | |
3097 | |
3098 str_replace_in(&entry->title, NULL); | |
3099 entry->length = -1; | |
3100 | |
3101 /* invalidate mtime to reread */ | |
3102 if (entry->tuple != NULL) | |
3103 entry->tuple->mtime = -1; /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ | |
3104 | |
3105 if (!playlist_entry_get_info(entry)) { | |
3106 if (g_list_index(playlist->entries, entry) == -1) | |
3107 /* Entry disappeared while we looked it up. Restart. */ | |
3108 node = playlist->entries; | |
3109 } | |
3110 } | |
3111 | |
3112 PLAYLIST_UNLOCK(playlist->mutex); | |
3113 | |
3114 playlistwin_update_list(playlist); | |
3115 playlist_recalc_total_time(playlist); | |
3116 | |
3117 return retval; | |
3118 } | |
3119 | |
3120 void | |
3121 playlist_read_info(Playlist *playlist, guint pos) | |
3122 { | |
3123 GList *node; | |
3124 | |
3125 PLAYLIST_LOCK(playlist->mutex); | |
3126 | |
3127 if ((node = g_list_nth(playlist->entries, pos))) { | |
3128 PlaylistEntry *entry = node->data; | |
3129 str_replace_in(&entry->title, NULL); | |
3130 entry->length = -1; | |
3131 playlist_entry_get_info(entry); | |
3132 } | |
3133 | |
3134 PLAYLIST_UNLOCK(playlist->mutex); | |
3135 | |
3136 playlistwin_update_list(playlist); | |
3137 playlist_recalc_total_time(playlist); | |
3138 } | |
3139 | |
3140 Playlist * | |
3141 playlist_get_active(void) | |
3142 { | |
3143 if (playlists_iter != NULL) | |
3144 return (Playlist *) playlists_iter->data; | |
3145 | |
3146 return (Playlist *) playlists->data; | |
3147 } | |
3148 | |
3149 void | |
3150 playlist_set_shuffle(gboolean shuffle) | |
3151 { | |
3152 Playlist *playlist = playlist_get_active(); | |
3153 if (!playlist) | |
3154 return; | |
3155 | |
3156 PLAYLIST_LOCK(playlist->mutex); | |
3157 | |
3158 playlist_position_before_jump = NULL; | |
3159 | |
3160 cfg.shuffle = shuffle; | |
3161 playlist_generate_shuffle_list_nolock(playlist); | |
3162 | |
3163 PLAYLIST_UNLOCK(playlist->mutex); | |
3164 } | |
3165 | |
3166 Playlist * | |
3167 playlist_new(void) | |
3168 { | |
3169 Playlist *playlist = g_new0(Playlist, 1); | |
3170 playlist->mutex = g_mutex_new(); | |
3171 playlist->loading_playlist = FALSE; | |
3172 | |
3173 playlist_set_current_name(playlist, NULL); | |
3174 playlist_clear(playlist); | |
3175 | |
3176 return playlist; | |
3177 } | |
3178 | |
3179 void | |
3180 playlist_free(Playlist *playlist) | |
3181 { | |
3182 g_mutex_free( playlist->mutex ); | |
3183 g_free( playlist ); | |
3184 return; | |
3185 } | |
3186 | |
3187 Playlist * | |
3188 playlist_new_from_selected(void) | |
3189 { | |
3190 Playlist *newpl = playlist_new(); | |
3191 Playlist *playlist = playlist_get_active(); | |
3192 GList *list = playlist_get_selected(playlist); | |
3193 | |
3194 playlist_add_playlist( newpl ); | |
3195 | |
3196 PLAYLIST_LOCK(playlist->mutex); | |
3197 | |
3198 while ( list != NULL ) | |
3199 { | |
3200 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3201 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3202 playlist_add( newpl , entry->filename ); | |
3203 list = g_list_next(list); | |
3204 } | |
3205 | |
3206 PLAYLIST_UNLOCK(playlist->mutex); | |
3207 | |
3208 playlist_recalc_total_time(newpl); | |
3209 playlistwin_update_list(playlist); | |
3210 | |
3211 return newpl; | |
3212 } | |
3213 | |
3214 const gchar * | |
3215 playlist_get_filename_to_play(Playlist *playlist) | |
3216 { | |
3217 const gchar *filename = NULL; | |
3218 | |
3219 if (!playlist) | |
3220 return NULL; | |
3221 | |
3222 PLAYLIST_LOCK(playlist->mutex); | |
3223 | |
3224 if (!playlist->position) { | |
3225 if (cfg.shuffle) | |
3226 playlist->position = playlist->shuffle->data; | |
3227 else | |
3228 playlist->position = playlist->entries->data; | |
3229 } | |
3230 | |
3231 filename = playlist->position->filename; | |
3232 | |
3233 PLAYLIST_UNLOCK(playlist->mutex); | |
3234 | |
3235 return filename; | |
3236 } | |
3237 | |
3238 PlaylistEntry * | |
3239 playlist_get_entry_to_play(Playlist *playlist) | |
3240 { | |
3241 if (!playlist) | |
3242 return NULL; | |
3243 | |
3244 PLAYLIST_LOCK(playlist->mutex); | |
3245 | |
3246 if (!playlist->position) { | |
3247 if (cfg.shuffle) | |
3248 playlist->position = playlist->shuffle->data; | |
3249 else | |
3250 playlist->position = playlist->entries->data; | |
3251 } | |
3252 | |
3253 PLAYLIST_UNLOCK(playlist->mutex); | |
3254 | |
3255 return playlist->position; | |
3256 } |