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