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