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