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