Mercurial > audlegacy
annotate audacious/playlist.c @ 1707:148b05d28ac2 trunk
[svn] - branch xspf plugin for podcasting support
author | nenolod |
---|---|
date | Fri, 15 Sep 2006 19:58:27 -0700 |
parents | 15e53bf1b389 |
children | c7c1e346bb55 |
rev | line source |
---|---|
0 | 1 /* BMP (C) GPL 2003 $top_src_dir/AUTHORS |
2 * | |
3 * based on: | |
4 * | |
5 * XMMS - Cross-platform multimedia player | |
6 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
7 * Thomas Nilsson and 4Front Technologies | |
8 * Copyright (C) 1999-2003 Haavard Kvaalen | |
9 * | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
1459 | 23 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02110-1301, USA. |
0 | 24 */ |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 # include "config.h" | |
28 #endif | |
29 | |
30 #include "playlist.h" | |
31 | |
32 #include <glib.h> | |
33 #include <glib/gprintf.h> | |
34 #include <stdlib.h> | |
35 #include <string.h> | |
36 #include <time.h> | |
37 | |
38 #include <unistd.h> | |
39 #include <sys/types.h> | |
40 #include <sys/stat.h> | |
41 #include <sys/errno.h> | |
42 | |
43 #include "input.h" | |
44 #include "main.h" | |
1653 | 45 #include "mainwin.h" |
0 | 46 #include "libaudacious/util.h" |
47 #include "libaudacious/configdb.h" | |
48 #include "libaudacious/vfs.h" | |
1653 | 49 #include "equalizer.h" |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
418
diff
changeset
|
50 #include "playback.h" |
0 | 51 #include "playlist.h" |
1550 | 52 #include "playlist_container.h" |
1653 | 53 #include "ui_playlist.h" |
0 | 54 #include "urldecode.h" |
55 #include "util.h" | |
1269 | 56 #include "ui_fileinfo.h" |
0 | 57 |
58 #include "debug.h" | |
59 | |
1251 | 60 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
0 | 61 typedef void (*PlaylistSaveFunc) (FILE * file); |
62 | |
63 PlaylistEntry *playlist_position; | |
64 G_LOCK_DEFINE(playlist); | |
65 | |
66 static GList *playlist = NULL; | |
67 static GList *shuffle_list = NULL; | |
68 static GList *queued_list = NULL; | |
69 | |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
70 /* If this is set to TRUE, we do not probe upon playlist add. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
71 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
72 * Under Audacious 0.1.x, this was not a big deal because we used |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
73 * file extension introspection instead of looking for file format magic |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
74 * strings. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
75 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
76 * Because we use file magic strings, we have to fstat a file being added |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
77 * to a playlist up to 1 * <number of input plugins installed> times. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
78 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
79 * This can get really slow now that we're looking for files to add to a |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
80 * playlist. (Up to 5 minutes for 5000 songs, etcetera.) |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
81 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
82 * So, we obviously don't want to probe while opening a large playlist |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
83 * up. Hince the boolean below. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
84 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
85 * January 7, 2006, William Pitcock <nenolod@nenolod.net> |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
86 */ |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
87 static gboolean loading_playlist = FALSE; |
0 | 88 |
89 G_LOCK_DEFINE(playlist_get_info_going); | |
90 | |
91 static gchar *playlist_current_name = NULL; | |
92 | |
93 static gboolean playlist_get_info_scan_active = FALSE; | |
94 static gboolean playlist_get_info_going = FALSE; | |
95 static GThread *playlist_get_info_thread; | |
96 | |
97 | |
98 static gint path_compare(const gchar * a, const gchar * b); | |
1251 | 99 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); |
100 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
101 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
102 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
103 static time_t playlist_get_mtime(const gchar *filename); |
1251 | 104 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); |
1415 | 105 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); |
1430
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
106 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); |
1251 | 107 |
108 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
109 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
110 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
111 |
0 | 112 static PlaylistCompareFunc playlist_compare_func_table[] = { |
113 playlist_compare_path, | |
114 playlist_compare_filename, | |
115 playlist_compare_title, | |
1251 | 116 playlist_compare_artist, |
1415 | 117 playlist_compare_date, |
1430
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
118 playlist_compare_track, |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
119 playlist_compare_playlist |
0 | 120 }; |
121 | |
122 static guint playlist_load_ins(const gchar * filename, gint pos); | |
123 | |
124 static void playlist_generate_shuffle_list(void); | |
125 static void playlist_generate_shuffle_list_nolock(void); | |
126 | |
127 static void playlist_recalc_total_time_nolock(void); | |
128 static void playlist_recalc_total_time(void); | |
129 | |
130 | |
131 PlaylistEntry * | |
132 playlist_entry_new(const gchar * filename, | |
133 const gchar * title, | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
134 const gint length, |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
135 InputPlugin * dec) |
0 | 136 { |
137 PlaylistEntry *entry; | |
138 | |
139 entry = g_new0(PlaylistEntry, 1); | |
140 entry->filename = g_strdup(filename); | |
141 entry->title = str_to_utf8(title); | |
142 entry->length = length; | |
143 entry->selected = FALSE; | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
144 entry->decoder = dec; |
0 | 145 |
146 return entry; | |
147 } | |
148 | |
149 void | |
150 playlist_entry_free(PlaylistEntry * entry) | |
151 { | |
152 if (!entry) | |
153 return; | |
154 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
155 if (entry->tuple != NULL) { |
1232 | 156 bmp_title_input_free(entry->tuple); |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
157 entry->tuple = NULL; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
158 } |
1232 | 159 |
160 if (entry->filename != NULL) | |
161 g_free(entry->filename); | |
162 | |
163 if (entry->title != NULL) | |
164 g_free(entry->title); | |
165 | |
0 | 166 g_free(entry); |
167 } | |
168 | |
169 static gboolean | |
170 playlist_entry_get_info(PlaylistEntry * entry) | |
171 { | |
1232 | 172 TitleInput *tuple; |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
173 time_t modtime = playlist_get_mtime(entry->filename); |
0 | 174 |
175 g_return_val_if_fail(entry != NULL, FALSE); | |
176 | |
1690
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
177 if (entry->decoder == NULL) |
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
178 entry->decoder = input_check_file(entry->filename, FALSE); |
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
179 |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
180 /* renew tuple if file mtime is newer than tuple mtime. */ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
181 if(entry->tuple){ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
182 if(entry->tuple->mtime == modtime) |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
183 return TRUE; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
184 else { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
185 bmp_title_input_free(entry->tuple); |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
186 entry->tuple = NULL; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
187 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
188 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
189 |
1232 | 190 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) |
191 tuple = input_get_song_tuple(entry->filename); | |
192 else | |
193 tuple = entry->decoder->get_song_tuple(entry->filename); | |
194 | |
195 if (tuple == NULL) | |
0 | 196 return FALSE; |
197 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
198 /* attach mtime */ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
199 tuple->mtime = modtime; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
200 |
0 | 201 /* entry is still around */ |
1356 | 202 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); |
1232 | 203 entry->length = tuple->length; |
204 entry->tuple = tuple; | |
0 | 205 |
206 return TRUE; | |
207 } | |
208 | |
209 const gchar * | |
210 playlist_get_current_name(void) | |
211 { | |
212 return playlist_current_name; | |
213 } | |
214 | |
215 gboolean | |
216 playlist_set_current_name(const gchar * filename) | |
217 { | |
218 g_free(playlist_current_name); | |
219 | |
220 if (!filename) { | |
221 playlist_current_name = NULL; | |
222 return FALSE; | |
223 } | |
224 | |
225 playlist_current_name = g_strdup(filename); | |
226 return TRUE; | |
227 } | |
228 | |
229 static GList * | |
230 find_playlist_position_list(void) | |
231 { | |
232 REQUIRE_STATIC_LOCK(playlist); | |
233 | |
234 if (!playlist_position) { | |
235 if (cfg.shuffle) | |
236 return shuffle_list; | |
237 else | |
238 return playlist; | |
239 } | |
240 | |
241 if (cfg.shuffle) | |
242 return g_list_find(shuffle_list, playlist_position); | |
243 else | |
244 return g_list_find(playlist, playlist_position); | |
245 } | |
246 | |
247 static void | |
248 play_queued(void) | |
249 { | |
250 GList *tmp = queued_list; | |
251 | |
252 REQUIRE_STATIC_LOCK(playlist); | |
253 | |
254 playlist_position = queued_list->data; | |
255 queued_list = g_list_remove_link(queued_list, queued_list); | |
256 g_list_free_1(tmp); | |
257 } | |
258 | |
259 void | |
260 playlist_clear(void) | |
261 { | |
905 | 262 if (bmp_playback_get_playing()) { |
263 ip_data.stop = TRUE; | |
0 | 264 bmp_playback_stop(); |
905 | 265 ip_data.stop = FALSE; |
266 } | |
0 | 267 |
268 PLAYLIST_LOCK(); | |
269 | |
270 if (playlist) { | |
271 g_list_foreach(playlist, (GFunc) playlist_entry_free, NULL); | |
272 g_list_free(playlist); | |
273 | |
274 playlist = NULL; | |
275 playlist_position = NULL; | |
276 } | |
277 | |
278 PLAYLIST_UNLOCK(); | |
279 | |
280 playlist_generate_shuffle_list(); | |
281 playlistwin_update_list(); | |
282 playlist_recalc_total_time(); | |
283 } | |
284 | |
285 void | |
286 playlist_delete_node(GList * node, gboolean * set_info_text, | |
287 gboolean * restart_playing) | |
288 { | |
289 PlaylistEntry *entry; | |
290 GList *playing_song = NULL; | |
291 | |
292 REQUIRE_STATIC_LOCK(playlist); | |
293 | |
294 /* We call g_list_find manually here because we don't want an item | |
295 * in the shuffle_list */ | |
296 | |
297 if (playlist_position) | |
298 playing_song = g_list_find(playlist, playlist_position); | |
299 | |
300 entry = PLAYLIST_ENTRY(node->data); | |
301 | |
302 if (playing_song == node) { | |
303 *set_info_text = TRUE; | |
304 | |
305 if (bmp_playback_get_playing()) { | |
306 PLAYLIST_UNLOCK(); | |
905 | 307 ip_data.stop = TRUE; |
0 | 308 bmp_playback_stop(); |
905 | 309 ip_data.stop = FALSE; |
0 | 310 PLAYLIST_LOCK(); |
311 *restart_playing = TRUE; | |
312 } | |
313 | |
314 playing_song = find_playlist_position_list(); | |
315 | |
316 if (g_list_next(playing_song)) | |
317 playlist_position = g_list_next(playing_song)->data; | |
318 else if (g_list_previous(playing_song)) | |
319 playlist_position = g_list_previous(playing_song)->data; | |
320 else | |
321 playlist_position = NULL; | |
322 | |
323 /* Make sure the entry did not disappear under us */ | |
324 if (g_list_index(playlist_get(), entry) == -1) | |
325 return; | |
326 | |
327 } | |
328 else if (g_list_position(playlist, playing_song) > | |
329 g_list_position(playlist, node)) { | |
330 *set_info_text = TRUE; | |
331 } | |
332 | |
333 shuffle_list = g_list_remove(shuffle_list, entry); | |
334 playlist = g_list_remove_link(playlist, node); | |
335 playlist_entry_free(entry); | |
336 g_list_free_1(node); | |
337 | |
338 playlist_recalc_total_time_nolock(); | |
339 } | |
340 | |
341 void | |
342 playlist_delete_index(guint pos) | |
343 { | |
344 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
345 GList *node; | |
346 | |
347 PLAYLIST_LOCK(); | |
348 | |
349 if (!playlist) { | |
350 PLAYLIST_UNLOCK(); | |
351 return; | |
352 } | |
353 | |
354 node = g_list_nth(playlist, pos); | |
355 | |
356 if (!node) { | |
357 PLAYLIST_UNLOCK(); | |
358 return; | |
359 } | |
360 | |
361 playlist_delete_node(node, &set_info_text, &restart_playing); | |
362 | |
363 PLAYLIST_UNLOCK(); | |
364 | |
365 playlist_recalc_total_time(); | |
366 | |
367 playlistwin_update_list(); | |
368 if (restart_playing) { | |
369 if (playlist_position) { | |
370 bmp_playback_initiate(); | |
371 } | |
372 else { | |
373 mainwin_clear_song_info(); | |
374 } | |
375 } | |
376 else if (set_info_text) { | |
377 mainwin_set_info_text(); | |
378 } | |
379 } | |
380 | |
381 void | |
382 playlist_delete_filenames(GList * filenames) | |
383 { | |
384 GList *node, *fnode; | |
385 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
386 | |
387 PLAYLIST_LOCK(); | |
388 | |
389 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
390 node = playlist; | |
391 | |
392 while (node) { | |
393 GList *next = g_list_next(node); | |
394 PlaylistEntry *entry = node->data; | |
395 | |
396 if (!strcmp(entry->filename, fnode->data)) | |
397 playlist_delete_node(node, &set_info_text, &restart_playing); | |
398 | |
399 node = next; | |
400 } | |
401 } | |
402 | |
403 playlist_recalc_total_time(); | |
404 PLAYLIST_UNLOCK(); | |
405 | |
406 playlistwin_update_list(); | |
407 | |
408 if (restart_playing) { | |
409 if (playlist_position) { | |
410 bmp_playback_initiate(); | |
411 } | |
412 else { | |
413 mainwin_clear_song_info(); | |
414 } | |
415 } | |
416 else if (set_info_text) { | |
417 mainwin_set_info_text(); | |
418 } | |
419 | |
420 } | |
421 | |
422 void | |
423 playlist_delete(gboolean crop) | |
424 { | |
425 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
426 GList *node, *next_node; | |
427 PlaylistEntry *entry; | |
428 | |
429 PLAYLIST_LOCK(); | |
430 | |
431 node = playlist; | |
432 | |
433 while (node) { | |
434 entry = PLAYLIST_ENTRY(node->data); | |
435 | |
436 next_node = g_list_next(node); | |
437 | |
438 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
439 playlist_delete_node(node, &set_info_text, &restart_playing); | |
440 } | |
441 | |
442 node = next_node; | |
443 } | |
444 | |
445 PLAYLIST_UNLOCK(); | |
446 | |
447 playlist_recalc_total_time(); | |
448 | |
449 if (set_info_text) { | |
450 mainwin_set_info_text(); | |
451 } | |
452 | |
453 if (restart_playing) { | |
454 if (playlist_position) { | |
455 bmp_playback_initiate(); | |
456 } | |
457 else { | |
458 mainwin_clear_song_info(); | |
459 } | |
460 } | |
461 | |
462 playlistwin_update_list(); | |
463 } | |
464 | |
465 static void | |
466 __playlist_ins_with_info(const gchar * filename, | |
467 gint pos, | |
468 const gchar * title, | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
469 gint len, |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
470 InputPlugin * dec) |
0 | 471 { |
472 g_return_if_fail(filename != NULL); | |
473 | |
474 PLAYLIST_LOCK(); | |
475 playlist = g_list_insert(playlist, | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
476 playlist_entry_new(filename, title, len, dec), |
0 | 477 pos); |
478 PLAYLIST_UNLOCK(); | |
479 | |
480 playlist_get_info_scan_active = TRUE; | |
481 } | |
482 | |
483 static void | |
1584 | 484 __playlist_ins_with_info_tuple(const gchar * filename, |
485 gint pos, | |
486 TitleInput *tuple, | |
487 InputPlugin * dec) | |
488 { | |
489 GList *node; | |
490 PlaylistEntry *entry; | |
491 | |
492 g_return_if_fail(filename != NULL); | |
493 | |
494 PLAYLIST_LOCK(); | |
495 playlist = g_list_insert(playlist, | |
496 playlist_entry_new(filename, tuple->track_name, tuple->length, dec), | |
497 pos); | |
498 | |
499 if(pos < 0 ) { | |
500 pos = g_list_length(playlist) - 1; /* last element. */ | |
501 } | |
502 | |
503 node = g_list_nth(playlist, pos); | |
504 entry = PLAYLIST_ENTRY(node->data); | |
505 | |
1587
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
506 if (tuple != NULL) { |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
507 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
508 entry->length = tuple->length; |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
509 entry->tuple = tuple; |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
510 } |
1584 | 511 |
512 PLAYLIST_UNLOCK(); | |
513 | |
514 playlist_get_info_scan_active = TRUE; | |
515 } | |
516 | |
517 static void | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
518 __playlist_ins(const gchar * filename, gint pos, InputPlugin *dec) |
0 | 519 { |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
520 __playlist_ins_with_info(filename, pos, NULL, -1, dec); |
0 | 521 playlist_recalc_total_time(); |
522 } | |
523 | |
524 gboolean | |
525 playlist_ins(const gchar * filename, gint pos) | |
526 { | |
527 gchar buf[64], *p; | |
528 gint r; | |
529 VFSFile *file; | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
530 InputPlugin *dec; |
0 | 531 |
532 if (is_playlist_name(filename)) { | |
1607
57676c0f2f33
[svn] - prevents input_check_file() working on loading playlist.
yaz
parents:
1588
diff
changeset
|
533 loading_playlist = TRUE; |
0 | 534 playlist_load_ins(filename, pos); |
1607
57676c0f2f33
[svn] - prevents input_check_file() working on loading playlist.
yaz
parents:
1588
diff
changeset
|
535 loading_playlist = FALSE; |
0 | 536 return TRUE; |
537 } | |
538 | |
1165 | 539 if (loading_playlist == TRUE || cfg.playlist_detect == TRUE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
540 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
541 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
542 dec = input_check_file(filename, TRUE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
543 |
1165 | 544 if (cfg.playlist_detect == TRUE || loading_playlist == TRUE || (loading_playlist == FALSE && dec != NULL)) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
545 { |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
546 __playlist_ins(filename, pos, dec); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
547 playlist_generate_shuffle_list(); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
548 playlistwin_update_list(); |
0 | 549 return TRUE; |
550 } | |
551 | |
552 /* Some files (typically produced by some cgi-scripts) don't have | |
553 * the correct extension. Try to recognize these files by looking | |
554 * at their content. We only check for http entries since it does | |
555 * not make sense to have file entries in a playlist fetched from | |
556 * the net. */ | |
557 | |
558 /* Some strange people put fifo's with the .mp3 extension, so we | |
559 * need to make sure it's a real file (otherwise fread() may block | |
560 * and stall the entire program) */ | |
561 | |
562 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
563 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
564 return FALSE; | |
565 | |
566 if (!(file = vfs_fopen(filename, "rb"))) | |
567 return FALSE; | |
568 | |
569 r = vfs_fread(buf, 1, sizeof(buf), file); | |
570 vfs_fclose(file); | |
571 | |
572 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
573 | |
574 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
575 playlist_load_ins(filename, pos); | |
576 return TRUE; | |
577 } | |
578 | |
579 return FALSE; | |
580 } | |
581 | |
582 /* FIXME: The next few functions are specific to Unix | |
583 * filesystems. Either abstract it away, or don't even bother checking | |
584 * at such low level */ | |
585 | |
586 typedef struct { | |
587 dev_t dev; | |
588 ino_t ino; | |
589 } DeviceInode; | |
590 | |
591 static DeviceInode * | |
592 devino_new(dev_t device, | |
593 ino_t inode) | |
594 { | |
595 DeviceInode *devino = g_new0(DeviceInode, 1); | |
596 | |
597 if (devino) | |
598 { | |
599 devino->dev = device; | |
600 devino->ino = inode; | |
601 } | |
602 | |
603 return devino; | |
604 } | |
605 | |
606 static guint | |
607 devino_hash(gconstpointer key) | |
608 { | |
609 const DeviceInode *d = key; | |
610 return d->ino; | |
611 } | |
612 | |
613 static gint | |
614 devino_compare(gconstpointer a, | |
615 gconstpointer b) | |
616 { | |
617 const DeviceInode *da = a, *db = b; | |
618 return (da->dev == db->dev && da->ino == db->ino); | |
619 } | |
620 | |
621 static gboolean | |
622 devino_destroy(gpointer key, | |
623 gpointer value, | |
624 gpointer data) | |
625 { | |
626 g_free(key); | |
627 return TRUE; | |
628 } | |
629 | |
630 static gboolean | |
631 file_is_hidden(const gchar * filename) | |
632 { | |
633 // FIXME: remove the const cast | |
634 g_return_val_if_fail(filename != NULL, FALSE); | |
635 return (g_basename((gchar *) filename)[0] == '.'); | |
636 } | |
637 | |
638 static GList * | |
639 playlist_dir_find_files(const gchar * path, | |
640 gboolean background, | |
641 GHashTable * htab) | |
642 { | |
643 GDir *dir; | |
644 GList *list = NULL, *ilist; | |
645 const gchar *dir_entry; | |
646 | |
647 struct stat statbuf; | |
648 DeviceInode *devino; | |
649 | |
650 if (!g_file_test(path, G_FILE_TEST_IS_DIR)) | |
651 return NULL; | |
652 | |
653 stat(path, &statbuf); | |
654 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
655 | |
656 if (g_hash_table_lookup(htab, devino)) { | |
657 g_free(devino); | |
658 return NULL; | |
659 } | |
660 | |
661 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
662 | |
663 if ((ilist = input_scan_dir(path))) { | |
664 GList *node; | |
665 for (node = ilist; node; node = g_list_next(node)) { | |
666 gchar *name = g_build_filename(path, node->data, NULL); | |
667 list = g_list_prepend(list, name); | |
668 g_free(node->data); | |
669 } | |
670 g_list_free(ilist); | |
671 return list; | |
672 } | |
673 | |
674 if (!(dir = g_dir_open(path, 0, NULL))) | |
675 return NULL; | |
676 | |
677 while ((dir_entry = g_dir_read_name(dir))) { | |
678 gchar *filename; | |
679 | |
680 if (file_is_hidden(dir_entry)) | |
681 continue; | |
682 | |
683 filename = g_build_filename(path, dir_entry, NULL); | |
684 | |
685 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
686 GList *sub; | |
687 sub = playlist_dir_find_files(filename, background, htab); | |
688 g_free(filename); | |
689 list = g_list_concat(list, sub); | |
690 } | |
1165 | 691 else if (cfg.playlist_detect == TRUE) |
692 list = g_list_prepend(list, filename); | |
0 | 693 else if (input_check_file(filename, TRUE)) |
694 list = g_list_prepend(list, filename); | |
695 else | |
696 g_free(filename); | |
697 | |
698 while (background && gtk_events_pending()) | |
699 gtk_main_iteration(); | |
700 } | |
701 g_dir_close(dir); | |
702 | |
703 return list; | |
704 } | |
705 | |
706 gboolean | |
707 playlist_add(const gchar * filename) | |
708 { | |
709 return playlist_ins(filename, -1); | |
710 } | |
711 | |
712 guint | |
713 playlist_add_dir(const gchar * directory) | |
714 { | |
715 return playlist_ins_dir(directory, -1, TRUE); | |
716 } | |
717 | |
718 guint | |
719 playlist_add_url(const gchar * url) | |
720 { | |
721 return playlist_ins_url(url, -1); | |
722 } | |
723 | |
724 guint | |
725 playlist_ins_dir(const gchar * path, | |
726 gint pos, | |
727 gboolean background) | |
728 { | |
729 guint entries = 0; | |
730 GList *list, *node; | |
731 GHashTable *htab; | |
732 | |
733 htab = g_hash_table_new(devino_hash, devino_compare); | |
734 | |
735 list = playlist_dir_find_files(path, background, htab); | |
736 list = g_list_sort(list, (GCompareFunc) path_compare); | |
737 | |
738 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
739 | |
740 for (node = list; node; node = g_list_next(node)) { | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
741 __playlist_ins(node->data, pos, NULL); |
0 | 742 g_free(node->data); |
743 entries++; | |
744 if (pos >= 0) | |
745 pos++; | |
746 } | |
747 | |
748 g_list_free(list); | |
749 | |
750 playlist_recalc_total_time(); | |
751 playlist_generate_shuffle_list(); | |
752 playlistwin_update_list(); | |
753 return entries; | |
754 } | |
755 | |
756 guint | |
757 playlist_ins_url(const gchar * string, | |
758 gint pos) | |
759 { | |
760 gchar *tmp; | |
761 gint i = 1, entries = 0; | |
762 gboolean first = TRUE; | |
763 guint firstpos = 0; | |
764 gboolean success = FALSE; | |
765 gchar *decoded = NULL; | |
766 | |
767 g_return_val_if_fail(string != NULL, 0); | |
768 | |
769 playlistwin_update_list(); | |
770 | |
771 while (*string) { | |
772 GList *node; | |
773 tmp = strchr(string, '\n'); | |
774 if (tmp) { | |
775 if (*(tmp - 1) == '\r') | |
776 *(tmp - 1) = '\0'; | |
777 *tmp = '\0'; | |
778 } | |
779 | |
780 if (!(decoded = xmms_urldecode_path(string))) | |
781 decoded = g_strdup(string); | |
782 | |
783 if (g_file_test(decoded, G_FILE_TEST_IS_DIR)) { | |
784 i = playlist_ins_dir(decoded, pos, FALSE); | |
785 } | |
786 else { | |
787 if (is_playlist_name(decoded)) { | |
788 i = playlist_load_ins(decoded, pos); | |
789 } | |
790 else { | |
791 success = playlist_ins(decoded, pos); | |
792 i = 1; | |
793 } | |
794 } | |
795 | |
796 g_free(decoded); | |
797 | |
798 PLAYLIST_LOCK(); | |
799 node = g_list_nth(playlist_get(), pos); | |
800 PLAYLIST_UNLOCK(); | |
801 | |
802 entries += i; | |
803 | |
804 if (first) { | |
805 first = FALSE; | |
806 firstpos = pos; | |
807 } | |
808 | |
809 if (pos >= 0) | |
810 pos += i; | |
811 if (!tmp) | |
812 break; | |
813 | |
814 string = tmp + 1; | |
815 } | |
816 | |
817 playlist_recalc_total_time(); | |
818 playlist_generate_shuffle_list(); | |
819 playlistwin_update_list(); | |
820 | |
821 return entries; | |
822 } | |
823 | |
824 void | |
825 playlist_set_info(const gchar * title, gint length, gint rate, | |
826 gint freq, gint nch) | |
827 { | |
828 PLAYLIST_LOCK(); | |
829 | |
830 if (playlist_position) { | |
831 g_free(playlist_position->title); | |
832 playlist_position->title = g_strdup(title); | |
833 playlist_position->length = length; | |
834 } | |
835 | |
836 PLAYLIST_UNLOCK(); | |
837 | |
838 playlist_recalc_total_time(); | |
839 | |
1653 | 840 mainwin_set_song_info(rate, freq, nch); |
0 | 841 } |
842 | |
843 void | |
844 playlist_check_pos_current(void) | |
845 { | |
846 gint pos, row, bottom; | |
847 | |
848 PLAYLIST_LOCK(); | |
849 if (!playlist || !playlist_position || !playlistwin_list) { | |
850 PLAYLIST_UNLOCK(); | |
851 return; | |
852 } | |
853 | |
854 pos = g_list_index(playlist, playlist_position); | |
855 | |
856 if (playlistwin_item_visible(pos)) { | |
857 PLAYLIST_UNLOCK(); | |
858 return; | |
859 } | |
860 | |
861 bottom = MAX(0, playlist_get_length_nolock() - | |
862 playlistwin_list->pl_num_visible); | |
863 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom); | |
864 PLAYLIST_UNLOCK(); | |
865 playlistwin_set_toprow(row); | |
866 } | |
867 | |
868 void | |
869 playlist_next(void) | |
870 { | |
871 GList *plist_pos_list; | |
872 gboolean restart_playing = FALSE; | |
873 | |
874 PLAYLIST_LOCK(); | |
875 if (!playlist) { | |
876 PLAYLIST_UNLOCK(); | |
877 return; | |
878 } | |
879 | |
880 plist_pos_list = find_playlist_position_list(); | |
881 | |
1026 | 882 if (!cfg.repeat && !g_list_next(plist_pos_list) && !queued_list) { |
0 | 883 PLAYLIST_UNLOCK(); |
884 return; | |
885 } | |
886 | |
887 if (bmp_playback_get_playing()) { | |
888 /* We need to stop before changing playlist_position */ | |
889 PLAYLIST_UNLOCK(); | |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
890 ip_data.stop = TRUE; |
0 | 891 bmp_playback_stop(); |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
892 ip_data.stop = FALSE; |
0 | 893 PLAYLIST_LOCK(); |
894 restart_playing = TRUE; | |
895 } | |
896 | |
897 plist_pos_list = find_playlist_position_list(); | |
898 if (queued_list) | |
899 play_queued(); | |
900 else if (g_list_next(plist_pos_list)) | |
901 playlist_position = g_list_next(plist_pos_list)->data; | |
902 else if (cfg.repeat) { | |
903 playlist_position = NULL; | |
904 playlist_generate_shuffle_list_nolock(); | |
905 if (cfg.shuffle) | |
906 playlist_position = shuffle_list->data; | |
907 else | |
908 playlist_position = playlist->data; | |
909 } | |
910 PLAYLIST_UNLOCK(); | |
911 playlist_check_pos_current(); | |
912 | |
913 if (restart_playing) | |
914 bmp_playback_initiate(); | |
915 else { | |
916 mainwin_set_info_text(); | |
917 playlistwin_update_list(); | |
918 } | |
919 } | |
920 | |
921 void | |
922 playlist_prev(void) | |
923 { | |
924 GList *plist_pos_list; | |
925 gboolean restart_playing = FALSE; | |
926 | |
927 PLAYLIST_LOCK(); | |
928 if (!playlist) { | |
929 PLAYLIST_UNLOCK(); | |
930 return; | |
931 } | |
932 | |
933 plist_pos_list = find_playlist_position_list(); | |
934 | |
935 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
936 PLAYLIST_UNLOCK(); | |
937 return; | |
938 } | |
939 | |
940 if (bmp_playback_get_playing()) { | |
941 /* We need to stop before changing playlist_position */ | |
942 PLAYLIST_UNLOCK(); | |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
943 ip_data.stop = TRUE; |
0 | 944 bmp_playback_stop(); |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
945 ip_data.stop = FALSE; |
0 | 946 PLAYLIST_LOCK(); |
947 restart_playing = TRUE; | |
948 } | |
949 | |
950 plist_pos_list = find_playlist_position_list(); | |
951 if (g_list_previous(plist_pos_list)) { | |
952 playlist_position = g_list_previous(plist_pos_list)->data; | |
953 } | |
954 else if (cfg.repeat) { | |
955 GList *node; | |
956 playlist_position = NULL; | |
957 playlist_generate_shuffle_list_nolock(); | |
958 if (cfg.shuffle) | |
959 node = g_list_last(shuffle_list); | |
960 else | |
961 node = g_list_last(playlist); | |
962 if (node) | |
963 playlist_position = node->data; | |
964 } | |
965 | |
966 PLAYLIST_UNLOCK(); | |
967 | |
968 playlist_check_pos_current(); | |
969 | |
970 if (restart_playing) | |
971 bmp_playback_initiate(); | |
972 else { | |
973 mainwin_set_info_text(); | |
974 playlistwin_update_list(); | |
975 } | |
976 } | |
977 | |
978 void | |
979 playlist_queue(void) | |
980 { | |
981 GList *list = playlist_get_selected(); | |
982 GList *it = list; | |
983 | |
984 PLAYLIST_LOCK(); | |
985 | |
986 while (it) { | |
987 GList *next = g_list_next(it); | |
988 GList *tmp; | |
989 | |
990 it->data = g_list_nth_data(playlist, GPOINTER_TO_INT(it->data)); | |
991 if ((tmp = g_list_find(queued_list, it->data))) { | |
992 queued_list = g_list_remove_link(queued_list, tmp); | |
993 g_list_free_1(tmp); | |
994 list = g_list_remove_link(list, it); | |
995 g_list_free_1(it); | |
996 } | |
997 | |
998 it = next; | |
999 } | |
1000 | |
1001 queued_list = g_list_concat(queued_list, list); | |
1002 | |
1003 PLAYLIST_UNLOCK(); | |
1004 | |
1005 playlist_recalc_total_time(); | |
1006 playlistwin_update_list(); | |
1007 } | |
1008 | |
1009 void | |
1010 playlist_queue_position(guint pos) | |
1011 { | |
1012 GList *tmp; | |
1013 PlaylistEntry *entry; | |
1014 | |
1015 PLAYLIST_LOCK(); | |
1016 entry = g_list_nth_data(playlist, pos); | |
1017 if ((tmp = g_list_find(queued_list, entry))) { | |
1018 queued_list = g_list_remove_link(queued_list, tmp); | |
1019 g_list_free_1(tmp); | |
1020 } | |
1021 else | |
1022 queued_list = g_list_append(queued_list, entry); | |
1023 PLAYLIST_UNLOCK(); | |
1024 | |
1025 playlist_recalc_total_time(); | |
1026 playlistwin_update_list(); | |
1027 } | |
1028 | |
1029 gboolean | |
1030 playlist_is_position_queued(guint pos) | |
1031 { | |
1032 PlaylistEntry *entry; | |
1033 GList *tmp; | |
1034 | |
1035 PLAYLIST_LOCK(); | |
1036 entry = g_list_nth_data(playlist, pos); | |
1037 tmp = g_list_find(queued_list, entry); | |
1038 PLAYLIST_UNLOCK(); | |
1039 | |
1040 return tmp != NULL; | |
1041 } | |
1042 | |
984 | 1043 gint |
1044 playlist_get_queue_position_number(guint pos) | |
1045 { | |
1046 PlaylistEntry *entry; | |
1047 gint tmp; | |
1048 | |
1049 PLAYLIST_LOCK(); | |
1050 entry = g_list_nth_data(playlist, pos); | |
1051 tmp = g_list_index(queued_list, entry); | |
1052 PLAYLIST_UNLOCK(); | |
1053 | |
1054 return tmp; | |
1055 } | |
1056 | |
1057 gint | |
1058 playlist_get_queue_qposition_number(guint pos) | |
1059 { | |
1060 PlaylistEntry *entry; | |
1061 gint tmp; | |
1062 | |
1063 PLAYLIST_LOCK(); | |
1064 entry = g_list_nth_data(queued_list, pos); | |
1065 tmp = g_list_index(playlist, entry); | |
1066 PLAYLIST_UNLOCK(); | |
1067 | |
1068 return tmp; | |
1069 } | |
1070 | |
0 | 1071 void |
1072 playlist_clear_queue(void) | |
1073 { | |
1074 PLAYLIST_LOCK(); | |
1075 g_list_free(queued_list); | |
1076 queued_list = NULL; | |
1077 PLAYLIST_UNLOCK(); | |
1078 | |
1079 playlist_recalc_total_time(); | |
1080 playlistwin_update_list(); | |
1081 } | |
1082 | |
1083 void | |
1084 playlist_queue_remove(guint pos) | |
1085 { | |
1086 void *entry; | |
1087 | |
1088 PLAYLIST_LOCK(); | |
1089 entry = g_list_nth_data(playlist, pos); | |
1090 queued_list = g_list_remove(queued_list, entry); | |
1091 PLAYLIST_UNLOCK(); | |
1092 | |
1093 playlistwin_update_list(); | |
1094 } | |
1095 | |
1096 gint | |
1097 playlist_get_queue_position(PlaylistEntry * entry) | |
1098 { | |
1099 return g_list_index(queued_list, entry); | |
1100 } | |
1101 | |
1102 void | |
1103 playlist_set_position(guint pos) | |
1104 { | |
1105 GList *node; | |
1106 gboolean restart_playing = FALSE; | |
1107 | |
1108 PLAYLIST_LOCK(); | |
1109 if (!playlist) { | |
1110 PLAYLIST_UNLOCK(); | |
1111 return; | |
1112 } | |
1113 | |
1114 node = g_list_nth(playlist, pos); | |
1115 if (!node) { | |
1116 PLAYLIST_UNLOCK(); | |
1117 return; | |
1118 } | |
1119 | |
1120 if (bmp_playback_get_playing()) { | |
1121 /* We need to stop before changing playlist_position */ | |
1122 PLAYLIST_UNLOCK(); | |
923 | 1123 ip_data.stop = TRUE; |
0 | 1124 bmp_playback_stop(); |
923 | 1125 ip_data.stop = FALSE; |
0 | 1126 PLAYLIST_LOCK(); |
1127 restart_playing = TRUE; | |
1128 } | |
1129 | |
1130 playlist_position = node->data; | |
1131 PLAYLIST_UNLOCK(); | |
1132 playlist_check_pos_current(); | |
1133 | |
1134 if (restart_playing) | |
1135 bmp_playback_initiate(); | |
1136 else { | |
1137 mainwin_set_info_text(); | |
1138 playlistwin_update_list(); | |
1139 } | |
1140 | |
1141 /* | |
1142 * Regenerate the shuffle list when the user set a position | |
1143 * manually | |
1144 */ | |
1145 playlist_generate_shuffle_list(); | |
1146 playlist_recalc_total_time(); | |
1147 } | |
1148 | |
1149 void | |
1150 playlist_eof_reached(void) | |
1151 { | |
1152 GList *plist_pos_list; | |
1153 | |
904
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1154 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) |
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1155 ip_data.stop = TRUE; |
0 | 1156 bmp_playback_stop(); |
904
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1157 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) |
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1158 ip_data.stop = FALSE; |
0 | 1159 |
1160 PLAYLIST_LOCK(); | |
1161 plist_pos_list = find_playlist_position_list(); | |
1162 | |
1163 if (cfg.no_playlist_advance) { | |
1164 PLAYLIST_UNLOCK(); | |
1165 mainwin_clear_song_info(); | |
1166 if (cfg.repeat) | |
1167 bmp_playback_initiate(); | |
1168 return; | |
1169 } | |
1170 | |
898 | 1171 if (cfg.stopaftersong) { |
1172 PLAYLIST_UNLOCK(); | |
1173 mainwin_clear_song_info(); | |
1174 mainwin_set_stopaftersong(FALSE); | |
1175 return; | |
1176 } | |
1177 | |
0 | 1178 if (queued_list) { |
1179 play_queued(); | |
1180 } | |
1181 else if (!g_list_next(plist_pos_list)) { | |
1182 if (cfg.shuffle) { | |
1183 playlist_position = NULL; | |
1184 playlist_generate_shuffle_list_nolock(); | |
1185 } | |
1186 else | |
1187 playlist_position = playlist->data; | |
1188 | |
1189 if (!cfg.repeat) { | |
1190 PLAYLIST_UNLOCK(); | |
1191 mainwin_clear_song_info(); | |
1192 mainwin_set_info_text(); | |
1193 return; | |
1194 } | |
1195 } | |
1196 else | |
1197 playlist_position = g_list_next(plist_pos_list)->data; | |
1198 | |
1199 PLAYLIST_UNLOCK(); | |
1200 | |
1201 playlist_check_pos_current(); | |
1202 bmp_playback_initiate(); | |
1203 mainwin_set_info_text(); | |
1204 playlistwin_update_list(); | |
1205 } | |
1206 | |
1207 gint | |
1208 playlist_get_length(void) | |
1209 { | |
1210 gint retval; | |
1211 | |
1212 PLAYLIST_LOCK(); | |
1213 retval = playlist_get_length_nolock(); | |
1214 PLAYLIST_UNLOCK(); | |
1215 | |
1216 return retval; | |
1217 } | |
1218 | |
1219 gint | |
1220 playlist_queue_get_length(void) | |
1221 { | |
1222 gint length; | |
1223 | |
1224 PLAYLIST_LOCK(); | |
1225 length = g_list_length(queued_list); | |
1226 PLAYLIST_UNLOCK(); | |
1227 | |
1228 return length; | |
1229 } | |
1230 | |
1231 gint | |
1232 playlist_get_length_nolock(void) | |
1233 { | |
1234 return g_list_length(playlist); | |
1235 } | |
1236 | |
1237 gchar * | |
1238 playlist_get_info_text(void) | |
1239 { | |
1240 gchar *text, *title, *numbers, *length; | |
1241 | |
1242 PLAYLIST_LOCK(); | |
1243 if (!playlist_position) { | |
1244 PLAYLIST_UNLOCK(); | |
1245 return NULL; | |
1246 } | |
1247 | |
1248 /* FIXME: there should not be a need to do additional conversion, | |
1249 * if playlist is properly maintained */ | |
1250 if (playlist_position->title) { | |
1251 title = str_to_utf8(playlist_position->title); | |
1252 } | |
1253 else { | |
1254 gchar *basename = g_path_get_basename(playlist_position->filename); | |
1255 title = filename_to_utf8(basename); | |
1256 g_free(basename); | |
1257 } | |
1258 | |
1259 /* | |
1260 * If the user don't want numbers in the playlist, don't | |
1261 * display them in other parts of XMMS | |
1262 */ | |
1263 | |
1264 if (cfg.show_numbers_in_pl) | |
1265 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock() + 1); | |
1266 else | |
1267 numbers = g_strdup(""); | |
1268 | |
1269 if (playlist_position->length != -1) | |
1270 length = g_strdup_printf(" (%d:%-2.2d)", | |
1271 playlist_position->length / 60000, | |
1272 (playlist_position->length / 1000) % 60); | |
1273 else | |
1274 length = g_strdup(""); | |
1275 | |
1276 PLAYLIST_UNLOCK(); | |
1277 | |
1278 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1279 | |
1280 g_free(numbers); | |
1281 g_free(title); | |
1282 g_free(length); | |
1283 | |
1284 return text; | |
1285 } | |
1286 | |
1287 gint | |
1288 playlist_get_current_length(void) | |
1289 { | |
1290 gint len = 0; | |
1291 | |
1292 PLAYLIST_LOCK(); | |
1293 if (playlist && playlist_position) | |
1294 len = playlist_position->length; | |
1295 PLAYLIST_UNLOCK(); | |
1296 | |
1297 return len; | |
1298 } | |
1299 | |
1300 gboolean | |
1553 | 1301 playlist_save(const gchar * filename) |
0 | 1302 { |
1553 | 1303 PlaylistContainer *plc = NULL; |
1304 gchar *ext; | |
0 | 1305 |
1306 g_return_val_if_fail(filename != NULL, FALSE); | |
1307 | |
1553 | 1308 ext = strrchr(filename, '.') + 1; |
1309 | |
0 | 1310 playlist_set_current_name(filename); |
1311 | |
1553 | 1312 if ((plc = playlist_container_find(ext)) == NULL) |
0 | 1313 return FALSE; |
1314 | |
1555 | 1315 if (plc->plc_write == NULL) |
1316 return FALSE; | |
1317 | |
1553 | 1318 plc->plc_write(filename, 0); |
1319 | |
1320 return TRUE; | |
0 | 1321 } |
1322 | |
1323 gboolean | |
1324 playlist_load(const gchar * filename) | |
1325 { | |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1326 gboolean ret = FALSE; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1327 |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1328 loading_playlist = TRUE; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1329 ret = playlist_load_ins(filename, -1); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1330 loading_playlist = FALSE; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1331 |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1332 return ret; |
0 | 1333 } |
1334 | |
1554 | 1335 void |
0 | 1336 playlist_load_ins_file(const gchar * filename_p, |
1337 const gchar * playlist_name, gint pos, | |
1338 const gchar * title, gint len) | |
1339 { | |
1340 gchar *filename; | |
1341 gchar *tmp, *path; | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1342 InputPlugin *dec; /* for decoder cache */ |
0 | 1343 |
1344 g_return_if_fail(filename_p != NULL); | |
1345 g_return_if_fail(playlist_name != NULL); | |
1346 | |
633
bf9bc9a514ba
[svn] Use g_strchug instead of g_strstrip during playlist load. Trailing whitespace can be a valid occurance. Closes bug #282.
chainsaw
parents:
538
diff
changeset
|
1347 filename = g_strchug(g_strdup(filename_p)); |
0 | 1348 |
944
03d141f44b4d
[svn] Convert \ path separators to /. Support was already present, but was not enabled before. Closes bug #461.
chainsaw
parents:
923
diff
changeset
|
1349 while ((tmp = strchr(filename, '\\')) != NULL) |
03d141f44b4d
[svn] Convert \ path separators to /. Support was already present, but was not enabled before. Closes bug #461.
chainsaw
parents:
923
diff
changeset
|
1350 *tmp = '/'; |
0 | 1351 |
1352 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1353 path = g_strdup(playlist_name); | |
1354 if ((tmp = strrchr(path, '/'))) | |
1355 *tmp = '\0'; | |
1356 else { | |
1163
ff71f891265b
[svn] - Allow to do format detection on demand; instead of immediately on add
nenolod
parents:
1026
diff
changeset
|
1357 if (loading_playlist != TRUE || cfg.playlist_detect == FALSE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1358 dec = input_check_file(filename, FALSE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1359 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1360 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1361 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1362 __playlist_ins_with_info(filename, pos, title, len, dec); |
0 | 1363 return; |
1364 } | |
1365 tmp = g_build_filename(path, filename, NULL); | |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1366 |
1165 | 1367 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1368 dec = input_check_file(tmp, FALSE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1369 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1370 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1371 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1372 __playlist_ins_with_info(tmp, pos, title, len, dec); |
0 | 1373 g_free(tmp); |
1374 g_free(path); | |
1375 } | |
1376 else | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1377 { |
1165 | 1378 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1379 dec = input_check_file(filename, FALSE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1380 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1381 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1382 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1383 __playlist_ins_with_info(filename, pos, title, len, dec); |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1384 } |
0 | 1385 |
1386 g_free(filename); | |
1387 } | |
1388 | |
1584 | 1389 void |
1390 playlist_load_ins_file_tuple(const gchar * filename_p, | |
1391 const gchar * playlist_name, | |
1392 gint pos, | |
1393 TitleInput *tuple) | |
1394 { | |
1395 gchar *filename; | |
1396 gchar *tmp, *path; | |
1397 InputPlugin *dec; /* for decoder cache */ | |
1398 | |
1399 g_return_if_fail(filename_p != NULL); | |
1400 g_return_if_fail(playlist_name != NULL); | |
1401 | |
1402 filename = g_strchug(g_strdup(filename_p)); | |
1403 | |
1404 while ((tmp = strchr(filename, '\\')) != NULL) | |
1405 *tmp = '/'; | |
1406 | |
1407 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1408 path = g_strdup(playlist_name); | |
1409 if ((tmp = strrchr(path, '/'))) | |
1410 *tmp = '\0'; | |
1411 else { | |
1412 if (loading_playlist != TRUE || cfg.playlist_detect == FALSE) | |
1413 dec = input_check_file(filename, FALSE); | |
1414 else | |
1415 dec = NULL; | |
1416 | |
1417 __playlist_ins_with_info_tuple(filename, pos, tuple, dec); | |
1418 return; | |
1419 } | |
1420 tmp = g_build_filename(path, filename, NULL); | |
1421 | |
1422 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1423 dec = input_check_file(tmp, FALSE); | |
1424 else | |
1425 dec = NULL; | |
1426 | |
1427 __playlist_ins_with_info_tuple(tmp, pos, tuple, dec); | |
1428 g_free(tmp); | |
1429 g_free(path); | |
1430 } | |
1431 else | |
1432 { | |
1433 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1434 dec = input_check_file(filename, FALSE); | |
1435 else | |
1436 dec = NULL; | |
1437 | |
1438 __playlist_ins_with_info_tuple(filename, pos, tuple, dec); | |
1439 } | |
1440 | |
1441 g_free(filename); | |
1442 } | |
1443 | |
0 | 1444 static guint |
1445 playlist_load_ins(const gchar * filename, gint pos) | |
1446 { | |
1554 | 1447 PlaylistContainer *plc; |
1448 gchar *ext; | |
0 | 1449 |
1450 g_return_val_if_fail(filename != NULL, 0); | |
1451 | |
1554 | 1452 ext = strrchr(filename, '.') + 1; |
1453 plc = playlist_container_find(ext); | |
1454 | |
1455 g_return_val_if_fail(plc != NULL, 0); | |
1456 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1457 | |
1560
5840d797ea02
[svn] - hmm, calling plc->load() might be a good idea!
nenolod
parents:
1559
diff
changeset
|
1458 plc->plc_read(filename, pos); |
5840d797ea02
[svn] - hmm, calling plc->load() might be a good idea!
nenolod
parents:
1559
diff
changeset
|
1459 |
1554 | 1460 playlist_generate_shuffle_list(); |
1461 playlistwin_update_list(); | |
1462 | |
1463 return 1; | |
0 | 1464 } |
1465 | |
1466 GList * | |
1467 get_playlist_nth(guint nth) | |
1468 { | |
1469 REQUIRE_STATIC_LOCK(playlist); | |
1470 return g_list_nth(playlist, nth); | |
1471 } | |
1472 | |
1473 | |
1474 GList * | |
1475 playlist_get(void) | |
1476 { | |
1477 REQUIRE_STATIC_LOCK(playlist); | |
1478 return playlist; | |
1479 } | |
1480 | |
1481 gint | |
1482 playlist_get_position_nolock(void) | |
1483 { | |
1484 if (playlist && playlist_position) | |
1485 return g_list_index(playlist, playlist_position); | |
1486 return 0; | |
1487 } | |
1488 | |
1489 gint | |
1490 playlist_get_position(void) | |
1491 { | |
1492 gint pos; | |
1493 | |
1494 PLAYLIST_LOCK(); | |
1495 pos = playlist_get_position_nolock(); | |
1496 PLAYLIST_UNLOCK(); | |
1497 | |
1498 return pos; | |
1499 } | |
1500 | |
1501 gchar * | |
1502 playlist_get_filename(guint pos) | |
1503 { | |
1504 gchar *filename; | |
1505 PlaylistEntry *entry; | |
1506 GList *node; | |
1507 | |
1508 PLAYLIST_LOCK(); | |
1509 if (!playlist) { | |
1510 PLAYLIST_UNLOCK(); | |
1511 return NULL; | |
1512 } | |
1513 node = g_list_nth(playlist, pos); | |
1514 if (!node) { | |
1515 PLAYLIST_UNLOCK(); | |
1516 return NULL; | |
1517 } | |
1518 entry = node->data; | |
1519 | |
1520 filename = g_strdup(entry->filename); | |
1521 PLAYLIST_UNLOCK(); | |
1522 | |
1523 return filename; | |
1524 } | |
1525 | |
1526 gchar * | |
1527 playlist_get_songtitle(guint pos) | |
1528 { | |
1529 gchar *title = NULL; | |
1530 PlaylistEntry *entry; | |
1531 GList *node; | |
1532 | |
1533 PLAYLIST_LOCK(); | |
1534 | |
1535 if (!playlist) { | |
1536 PLAYLIST_UNLOCK(); | |
1537 return NULL; | |
1538 } | |
1539 | |
1540 if (!(node = g_list_nth(playlist, pos))) { | |
1541 PLAYLIST_UNLOCK(); | |
1542 return NULL; | |
1543 } | |
1544 | |
1545 entry = node->data; | |
1546 | |
1547 /* FIXME: simplify this logic */ | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1548 // if (!entry->title && entry->length == -1) { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1549 if ( (!entry->title && entry->length == -1) || |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1550 (entry->tuple && (entry->tuple->mtime != playlist_get_mtime(entry->filename))) ){ |
0 | 1551 if (playlist_entry_get_info(entry)) |
1552 title = entry->title; | |
1553 } | |
1554 else { | |
1555 title = entry->title; | |
1556 } | |
1557 | |
1558 PLAYLIST_UNLOCK(); | |
1559 | |
1560 if (!title) { | |
1561 title = g_path_get_basename(entry->filename); | |
1562 return str_replace(title, filename_to_utf8(title)); | |
1563 } | |
1564 | |
1565 return str_to_utf8(title); | |
1566 } | |
1567 | |
1235 | 1568 TitleInput * |
1569 playlist_get_tuple(guint pos) | |
1570 { | |
1571 PlaylistEntry *entry; | |
1572 TitleInput *tuple = NULL; | |
1573 GList *node; | |
1574 | |
1575 PLAYLIST_LOCK(); | |
1576 | |
1577 if (!playlist) { | |
1578 PLAYLIST_UNLOCK(); | |
1579 return NULL; | |
1580 } | |
1581 | |
1582 if (!(node = g_list_nth(playlist, pos))) { | |
1583 PLAYLIST_UNLOCK(); | |
1584 return NULL; | |
1585 } | |
1586 | |
1587 entry = (PlaylistEntry *) node->data; | |
1588 | |
1589 tuple = entry->tuple; | |
1590 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1591 // if no tuple or tuple with old mtime, get new one. |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1592 if (!tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))) { |
1237
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1593 playlist_entry_get_info(entry); |
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1594 tuple = entry->tuple; |
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1595 } |
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1596 |
1235 | 1597 PLAYLIST_UNLOCK(); |
1598 | |
1599 return tuple; | |
1600 } | |
1601 | |
0 | 1602 gint |
1603 playlist_get_songtime(guint pos) | |
1604 { | |
1605 gint song_time = -1; | |
1606 PlaylistEntry *entry; | |
1607 GList *node; | |
1608 | |
1609 PLAYLIST_LOCK(); | |
1610 | |
1611 if (!playlist) { | |
1612 PLAYLIST_UNLOCK(); | |
1613 return -1; | |
1614 } | |
1615 | |
1616 if (!(node = g_list_nth(playlist, pos))) { | |
1617 PLAYLIST_UNLOCK(); | |
1618 return -1; | |
1619 } | |
1620 | |
1621 entry = node->data; | |
1622 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1623 // if (!entry->title && entry->length == -1) { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1624 if (!entry->tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))){ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1625 |
0 | 1626 if (playlist_entry_get_info(entry)) |
1627 song_time = entry->length; | |
1628 | |
1629 PLAYLIST_UNLOCK(); | |
1630 } | |
1631 else { | |
1632 song_time = entry->length; | |
1633 PLAYLIST_UNLOCK(); | |
1634 } | |
1635 | |
1636 return song_time; | |
1637 } | |
1638 | |
1639 static gint | |
1415 | 1640 playlist_compare_track(PlaylistEntry * a, |
1641 PlaylistEntry * b) | |
1642 { | |
1643 g_return_val_if_fail(a != NULL, 0); | |
1644 g_return_val_if_fail(b != NULL, 0); | |
1645 | |
1646 g_return_val_if_fail(a->tuple != NULL, 0); | |
1647 g_return_val_if_fail(b->tuple != NULL, 0); | |
1648 | |
1649 return (a->tuple->track_number - b->tuple->track_number); | |
1650 } | |
1651 | |
1652 static gint | |
1430
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1653 playlist_compare_playlist(PlaylistEntry * a, |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1654 PlaylistEntry * b) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1655 { |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1656 const gchar *a_title = NULL, *b_title = NULL; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1657 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1658 g_return_val_if_fail(a != NULL, 0); |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1659 g_return_val_if_fail(b != NULL, 0); |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1660 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1661 if (a->title != NULL) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1662 a_title = a->title; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1663 else { |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1664 if (strrchr(a->filename, '/')) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1665 a_title = strrchr(a->filename, '/') + 1; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1666 else |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1667 a_title = a->filename; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1668 } |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1669 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1670 if (b->title != NULL) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1671 b_title = b->title; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1672 else { |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1673 if (strrchr(a->filename, '/')) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1674 b_title = strrchr(b->filename, '/') + 1; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1675 else |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1676 b_title = b->filename; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1677 } |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1678 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1679 return strcasecmp(a_title, b_title); |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1680 } |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1681 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1682 static gint |
1251 | 1683 playlist_compare_title(PlaylistEntry * a, |
1684 PlaylistEntry * b) | |
0 | 1685 { |
1250 | 1686 const gchar *a_title = NULL, *b_title = NULL; |
0 | 1687 |
1688 g_return_val_if_fail(a != NULL, 0); | |
1689 g_return_val_if_fail(b != NULL, 0); | |
1690 | |
1250 | 1691 if (a->tuple != NULL && a->tuple->track_name != NULL) |
1692 a_title = a->tuple->track_name; | |
1693 if (b->tuple != NULL && b->tuple->track_name != NULL) | |
1694 b_title = b->tuple->track_name; | |
1695 | |
1251 | 1696 if (a_title != NULL && b_title != NULL) |
1250 | 1697 return strcasecmp(a_title, b_title); |
1698 | |
1699 if (a->title != NULL) | |
0 | 1700 a_title = a->title; |
1701 else { | |
1702 if (strrchr(a->filename, '/')) | |
1703 a_title = strrchr(a->filename, '/') + 1; | |
1704 else | |
1705 a_title = a->filename; | |
1706 } | |
1707 | |
1250 | 1708 if (b->title != NULL) |
0 | 1709 b_title = b->title; |
1710 else { | |
1711 if (strrchr(a->filename, '/')) | |
1712 b_title = strrchr(b->filename, '/') + 1; | |
1713 else | |
1714 b_title = b->filename; | |
1715 } | |
1716 | |
1717 return strcasecmp(a_title, b_title); | |
1718 } | |
1719 | |
1720 static gint | |
1251 | 1721 playlist_compare_artist(PlaylistEntry * a, |
1722 PlaylistEntry * b) | |
1723 { | |
1724 const gchar *a_artist = NULL, *b_artist = NULL; | |
1725 | |
1726 g_return_val_if_fail(a != NULL, 0); | |
1727 g_return_val_if_fail(b != NULL, 0); | |
1728 | |
1729 if (a->tuple != NULL) | |
1730 playlist_entry_get_info(a); | |
1731 | |
1732 if (b->tuple != NULL) | |
1733 playlist_entry_get_info(b); | |
1734 | |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1735 if (a->tuple != NULL && a->tuple->performer != NULL) |
1251 | 1736 a_artist = a->tuple->performer; |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1737 if (b->tuple != NULL && b->tuple->performer != NULL) |
1251 | 1738 b_artist = b->tuple->performer; |
1739 | |
1740 if (a_artist != NULL && b_artist != NULL) | |
1741 return strcasecmp(a_artist, b_artist); | |
1742 | |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1743 return 0; |
1251 | 1744 } |
1745 | |
1746 static gint | |
1747 playlist_compare_filename(PlaylistEntry * a, | |
1748 PlaylistEntry * b) | |
0 | 1749 { |
1750 gchar *a_filename, *b_filename; | |
1751 | |
1752 g_return_val_if_fail(a != NULL, 0); | |
1753 g_return_val_if_fail(b != NULL, 0); | |
1754 | |
1755 if (strrchr(a->filename, '/')) | |
1756 a_filename = strrchr(a->filename, '/') + 1; | |
1757 else | |
1758 a_filename = a->filename; | |
1759 | |
1760 if (strrchr(b->filename, '/')) | |
1761 b_filename = strrchr(b->filename, '/') + 1; | |
1762 else | |
1763 b_filename = b->filename; | |
1764 | |
1765 | |
1766 return strcasecmp(a_filename, b_filename); | |
1767 } | |
1768 | |
1769 static gint | |
1770 path_compare(const gchar * a, const gchar * b) | |
1771 { | |
1772 gchar *posa, *posb; | |
1773 gint len, ret; | |
1774 | |
1775 posa = strrchr(a, '/'); | |
1776 posb = strrchr(b, '/'); | |
1777 | |
1778 /* | |
1779 * Sort directories before files | |
1780 */ | |
1781 if (posa && posb && (posa - a != posb - b)) { | |
1782 if (posa - a > posb - b) { | |
1783 len = posb - b; | |
1784 ret = -1; | |
1785 } | |
1786 else { | |
1787 len = posa - a; | |
1788 ret = 1; | |
1789 } | |
1790 if (!strncasecmp(a, b, len)) | |
1791 return ret; | |
1792 } | |
1793 return strcasecmp(a, b); | |
1794 } | |
1795 | |
1796 static gint | |
1251 | 1797 playlist_compare_path(PlaylistEntry * a, |
1798 PlaylistEntry * b) | |
0 | 1799 { |
1800 return path_compare(a->filename, b->filename); | |
1801 } | |
1802 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1803 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1804 static time_t |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1805 playlist_get_mtime(const gchar *filename) |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1806 { |
1706 | 1807 struct stat buf; |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1808 gint rv; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1809 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1810 rv = stat(filename, &buf); |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1811 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1812 if (rv == 0) { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1813 return buf.st_mtime; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1814 } else { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1815 return 0; //error |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1816 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1817 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1818 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1819 |
0 | 1820 static gint |
1251 | 1821 playlist_compare_date(PlaylistEntry * a, |
1822 PlaylistEntry * b) | |
0 | 1823 { |
1824 struct stat buf; | |
1825 time_t modtime; | |
1826 | |
1827 gint rv; | |
1828 | |
1829 | |
1830 rv = stat(a->filename, &buf); | |
1831 | |
1832 if (rv == 0) { | |
1833 modtime = buf.st_mtime; | |
1834 rv = stat(b->filename, &buf); | |
1835 | |
1836 if (stat(b->filename, &buf) == 0) { | |
1837 if (buf.st_mtime == modtime) | |
1838 return 0; | |
1839 else | |
1840 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
1841 } | |
1842 else | |
1843 return -1; | |
1844 } | |
1845 else if (!lstat(b->filename, &buf)) | |
1846 return 1; | |
1847 else | |
1848 return playlist_compare_filename(a, b); | |
1849 } | |
1850 | |
1851 | |
1852 void | |
1853 playlist_sort(PlaylistSortType type) | |
1854 { | |
1855 playlist_remove_dead_files(); | |
1856 PLAYLIST_LOCK(); | |
1857 playlist = | |
1858 g_list_sort(playlist, | |
1859 (GCompareFunc) playlist_compare_func_table[type]); | |
1860 PLAYLIST_UNLOCK(); | |
1861 } | |
1862 | |
1863 static GList * | |
1864 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
1865 { | |
1866 GList *list1, *list2; | |
1867 GList *tmp_list = NULL; | |
1868 GList *index_list = NULL; | |
1869 | |
1870 /* | |
1871 * We take all the selected entries out of the playlist, | |
1872 * sorts them, and then put them back in again. | |
1873 */ | |
1874 | |
1875 list1 = g_list_last(list); | |
1876 | |
1877 while (list1) { | |
1878 list2 = g_list_previous(list1); | |
1879 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
1880 gpointer idx; | |
1881 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
1882 index_list = g_list_prepend(index_list, idx); | |
1883 list = g_list_remove_link(list, list1); | |
1884 tmp_list = g_list_concat(list1, tmp_list); | |
1885 } | |
1886 list1 = list2; | |
1887 } | |
1888 | |
1889 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
1890 list1 = tmp_list; | |
1891 list2 = index_list; | |
1892 | |
1893 while (list2) { | |
1894 if (!list1) { | |
1895 g_critical(G_STRLOC ": Error during list sorting. " | |
1896 "Possibly dropped some playlist-entries."); | |
1897 break; | |
1898 } | |
1899 | |
1900 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
1901 | |
1902 list2 = g_list_next(list2); | |
1903 list1 = g_list_next(list1); | |
1904 } | |
1905 | |
1906 g_list_free(index_list); | |
1907 g_list_free(tmp_list); | |
1908 | |
1909 return list; | |
1910 } | |
1911 | |
1912 void | |
1913 playlist_sort_selected(PlaylistSortType type) | |
1914 { | |
1915 PLAYLIST_LOCK(); | |
1916 playlist = playlist_sort_selected_generic(playlist, (GCompareFunc) | |
1917 playlist_compare_func_table | |
1918 [type]); | |
1919 PLAYLIST_UNLOCK(); | |
1920 } | |
1921 | |
1922 void | |
1923 playlist_reverse(void) | |
1924 { | |
1925 PLAYLIST_LOCK(); | |
1926 playlist = g_list_reverse(playlist); | |
1927 PLAYLIST_UNLOCK(); | |
1928 } | |
1929 | |
1930 static GList * | |
1931 playlist_shuffle_list(GList * list) | |
1932 { | |
1933 /* | |
1934 * Note that this doesn't make a copy of the original list. | |
1935 * The pointer to the original list is not valid after this | |
1936 * fuction is run. | |
1937 */ | |
1938 gint len = g_list_length(list); | |
1939 gint i, j; | |
1940 GList *node, **ptrs; | |
1941 | |
1942 REQUIRE_STATIC_LOCK(playlist); | |
1943 | |
1944 if (!len) | |
1945 return NULL; | |
1946 | |
1947 ptrs = g_new(GList *, len); | |
1948 | |
1949 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
1950 ptrs[i] = node; | |
1951 | |
1952 j = g_random_int_range(0, len); | |
1953 list = ptrs[j]; | |
1954 ptrs[j]->next = NULL; | |
1955 ptrs[j] = ptrs[0]; | |
1956 | |
1957 for (i = 1; i < len; i++) { | |
1958 j = g_random_int_range(0, len - i); | |
1959 list->prev = ptrs[i + j]; | |
1960 ptrs[i + j]->next = list; | |
1961 list = ptrs[i + j]; | |
1962 ptrs[i + j] = ptrs[i]; | |
1963 } | |
1964 list->prev = NULL; | |
1965 | |
1966 g_free(ptrs); | |
1967 | |
1968 return list; | |
1969 } | |
1970 | |
1971 void | |
1972 playlist_random(void) | |
1973 { | |
1974 PLAYLIST_LOCK(); | |
1975 playlist = playlist_shuffle_list(playlist); | |
1976 PLAYLIST_UNLOCK(); | |
1977 } | |
1978 | |
1979 GList * | |
1980 playlist_get_selected(void) | |
1981 { | |
1982 GList *node, *list = NULL; | |
1983 gint i = 0; | |
1984 | |
1985 PLAYLIST_LOCK(); | |
1986 for (node = playlist_get(); node; node = g_list_next(node), i++) { | |
1987 PlaylistEntry *entry = node->data; | |
1988 if (entry->selected) | |
1989 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
1990 } | |
1991 PLAYLIST_UNLOCK(); | |
1992 return g_list_reverse(list); | |
1993 } | |
1994 | |
1995 void | |
1996 playlist_clear_selected(void) | |
1997 { | |
1998 GList *node = NULL; | |
1999 gint i = 0; | |
2000 | |
2001 PLAYLIST_LOCK(); | |
2002 for (node = playlist_get(); node; node = g_list_next(node), i++) { | |
2003 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2004 } | |
2005 PLAYLIST_UNLOCK(); | |
2006 playlist_recalc_total_time(); | |
2007 } | |
2008 | |
2009 gint | |
2010 playlist_get_num_selected(void) | |
2011 { | |
2012 GList *node; | |
2013 gint num = 0; | |
2014 | |
2015 PLAYLIST_LOCK(); | |
2016 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2017 PlaylistEntry *entry = node->data; | |
2018 if (entry->selected) | |
2019 num++; | |
2020 } | |
2021 PLAYLIST_UNLOCK(); | |
2022 return num; | |
2023 } | |
2024 | |
2025 | |
2026 static void | |
2027 playlist_generate_shuffle_list(void) | |
2028 { | |
2029 PLAYLIST_LOCK(); | |
2030 playlist_generate_shuffle_list_nolock(); | |
2031 PLAYLIST_UNLOCK(); | |
2032 } | |
2033 | |
2034 static void | |
2035 playlist_generate_shuffle_list_nolock(void) | |
2036 { | |
2037 GList *node; | |
2038 gint numsongs; | |
2039 | |
2040 REQUIRE_STATIC_LOCK(playlist); | |
2041 | |
2042 if (shuffle_list) { | |
2043 g_list_free(shuffle_list); | |
2044 shuffle_list = NULL; | |
2045 } | |
2046 | |
2047 if (!cfg.shuffle || !playlist) | |
2048 return; | |
2049 | |
2050 shuffle_list = playlist_shuffle_list(g_list_copy(playlist)); | |
2051 numsongs = g_list_length(shuffle_list); | |
2052 | |
2053 if (playlist_position) { | |
2054 gint i = g_list_index(shuffle_list, playlist_position); | |
2055 node = g_list_nth(shuffle_list, i); | |
2056 shuffle_list = g_list_remove_link(shuffle_list, node); | |
2057 shuffle_list = g_list_prepend(shuffle_list, node->data); | |
2058 } | |
2059 } | |
2060 | |
2061 void | |
2062 playlist_fileinfo(guint pos) | |
2063 { | |
2064 gchar *path = NULL; | |
2065 GList *node; | |
1269 | 2066 PlaylistEntry *entry = NULL; |
2067 TitleInput *tuple = NULL; | |
0 | 2068 |
2069 PLAYLIST_LOCK(); | |
1269 | 2070 |
2071 if ((node = g_list_nth(playlist_get(), pos))) | |
2072 { | |
2073 entry = node->data; | |
2074 tuple = entry->tuple; | |
1516
3483fb26b9fb
[svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents:
1459
diff
changeset
|
2075 path = g_strdup(entry->filename); |
0 | 2076 } |
1269 | 2077 |
0 | 2078 PLAYLIST_UNLOCK(); |
1277
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2079 |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2080 /* No tuple? Try to set this entry up properly. --nenolod */ |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2081 // if (entry->tuple == NULL) |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2082 if (!entry->tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))) |
1277
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2083 { |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2084 playlist_entry_get_info(entry); |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2085 tuple = entry->tuple; |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2086 } |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2087 |
1269 | 2088 if (tuple != NULL) |
2089 { | |
2090 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2091 fileinfo_show_for_tuple(tuple); | |
1270 | 2092 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) |
2093 entry->decoder->file_info_box(path); | |
1269 | 2094 else |
2095 fileinfo_show_for_path(path); | |
2096 g_free(path); | |
2097 } | |
2098 else if (path != NULL) | |
2099 { | |
1270 | 2100 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) |
2101 entry->decoder->file_info_box(path); | |
2102 else | |
2103 fileinfo_show_for_path(path); | |
0 | 2104 g_free(path); |
2105 } | |
2106 } | |
2107 | |
2108 void | |
2109 playlist_fileinfo_current(void) | |
2110 { | |
2111 gchar *path = NULL; | |
1269 | 2112 TitleInput *tuple = NULL; |
0 | 2113 |
2114 PLAYLIST_LOCK(); | |
1269 | 2115 |
0 | 2116 if (playlist_get() && playlist_position) |
1269 | 2117 { |
0 | 2118 path = g_strdup(playlist_position->filename); |
1690
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
2119 if (( playlist_position->tuple == NULL ) || ( playlist_position->decoder == NULL )) |
1516
3483fb26b9fb
[svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents:
1459
diff
changeset
|
2120 playlist_entry_get_info(playlist_position); |
3483fb26b9fb
[svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents:
1459
diff
changeset
|
2121 tuple = playlist_position->tuple; |
1269 | 2122 } |
2123 | |
0 | 2124 PLAYLIST_UNLOCK(); |
2125 | |
1269 | 2126 if (tuple != NULL) |
2127 { | |
2128 if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box == NULL) | |
2129 fileinfo_show_for_tuple(tuple); | |
1270 | 2130 else if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL) |
2131 playlist_position->decoder->file_info_box(path); | |
1269 | 2132 else |
2133 fileinfo_show_for_path(path); | |
2134 g_free(path); | |
2135 } | |
2136 else if (path != NULL) | |
2137 { | |
1270 | 2138 if (playlist_position != NULL && playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL) |
2139 playlist_position->decoder->file_info_box(path); | |
2140 else | |
2141 fileinfo_show_for_path(path); | |
0 | 2142 g_free(path); |
2143 } | |
2144 } | |
2145 | |
2146 | |
2147 static gboolean | |
2148 playlist_get_info_is_going(void) | |
2149 { | |
2150 gboolean result; | |
2151 | |
2152 G_LOCK(playlist_get_info_going); | |
2153 result = playlist_get_info_going; | |
2154 G_UNLOCK(playlist_get_info_going); | |
2155 | |
2156 return result; | |
2157 } | |
2158 | |
2159 static gpointer | |
2160 playlist_get_info_func(gpointer arg) | |
2161 { | |
2162 GList *node; | |
2163 gboolean update_playlistwin = FALSE; | |
2164 gboolean update_mainwin = FALSE; | |
2165 | |
2166 while (playlist_get_info_is_going()) { | |
2167 PlaylistEntry *entry; | |
2168 | |
2169 if (cfg.use_pl_metadata && | |
2170 cfg.get_info_on_load && | |
2171 playlist_get_info_scan_active) { | |
2172 | |
2173 PLAYLIST_LOCK(); | |
2174 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2175 entry = node->data; | |
2176 | |
1706 | 2177 if(entry->tuple && entry->tuple->mtime != 0) { |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2178 continue; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2179 } |
0 | 2180 |
2181 if (!playlist_entry_get_info(entry)) { | |
2182 if (g_list_index(playlist_get(), entry) == -1) | |
2183 /* Entry disappeared while we looked it up. | |
2184 Restart. */ | |
2185 node = playlist_get(); | |
2186 } | |
2187 else if (entry->title || entry->length != -1) { | |
2188 update_playlistwin = TRUE; | |
2189 if (entry == playlist_position) | |
2190 update_mainwin = TRUE; | |
2191 break; | |
2192 } | |
2193 } | |
2194 PLAYLIST_UNLOCK(); | |
2195 | |
2196 if (!node) | |
2197 playlist_get_info_scan_active = FALSE; | |
2198 } | |
2199 else if (!cfg.get_info_on_load && | |
2200 cfg.get_info_on_demand && | |
2201 cfg.playlist_visible && | |
2202 !cfg.playlist_shaded && | |
2203 cfg.use_pl_metadata) { | |
2204 | |
2205 gboolean found = FALSE; | |
2206 | |
2207 PLAYLIST_LOCK(); | |
2208 | |
2209 if (!playlist_get()) { | |
2210 PLAYLIST_UNLOCK(); | |
2211 g_usleep(1000000); | |
2212 continue; | |
2213 } | |
2214 | |
1706 | 2215 for (node = g_list_nth(playlist_get(), playlistwin_get_toprow()); |
2216 node && playlistwin_item_visible(g_list_position(playlist_get(), node)); | |
0 | 2217 node = g_list_next(node)) { |
1706 | 2218 |
0 | 2219 entry = node->data; |
1706 | 2220 |
2221 if(entry->tuple && entry->tuple->mtime != 0) { | |
0 | 2222 continue; |
1706 | 2223 } |
0 | 2224 |
2225 if (!playlist_entry_get_info(entry)) { | |
2226 if (g_list_index(playlist_get(), entry) == -1) | |
2227 /* Entry disapeared while we | |
2228 looked it up. Restart. */ | |
2229 node = | |
2230 g_list_nth(playlist_get(), | |
2231 playlistwin_get_toprow()); | |
2232 } | |
2233 else if (entry->title || entry->length != -1) { | |
2234 update_playlistwin = TRUE; | |
2235 if (entry == playlist_position) | |
2236 update_mainwin = TRUE; | |
2237 found = TRUE; | |
2238 break; | |
2239 } | |
2240 } | |
2241 | |
2242 PLAYLIST_UNLOCK(); | |
2243 | |
2244 if (!found) { | |
2245 g_usleep(500000); | |
2246 continue; | |
2247 } | |
2248 } | |
2249 else | |
2250 g_usleep(500000); | |
2251 | |
2252 if (update_playlistwin) { | |
2253 playlistwin_update_list(); | |
2254 update_playlistwin = FALSE; | |
2255 } | |
2256 | |
2257 if (update_mainwin) { | |
2258 mainwin_set_info_text(); | |
2259 update_mainwin = FALSE; | |
2260 } | |
2261 } | |
2262 | |
2263 g_thread_exit(NULL); | |
2264 return NULL; | |
2265 } | |
2266 | |
2267 void | |
2268 playlist_start_get_info_thread(void) | |
2269 { | |
2270 playlist_get_info_going = TRUE; | |
2271 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2272 NULL, TRUE, NULL); | |
2273 } | |
2274 | |
2275 void | |
2276 playlist_stop_get_info_thread(void) | |
2277 { | |
2278 G_LOCK(playlist_get_info_going); | |
2279 playlist_get_info_going = FALSE; | |
2280 G_UNLOCK(playlist_get_info_going); | |
2281 g_thread_join(playlist_get_info_thread); | |
2282 } | |
2283 | |
2284 void | |
2285 playlist_start_get_info_scan(void) | |
2286 { | |
2287 playlist_get_info_scan_active = TRUE; | |
2288 } | |
2289 | |
2290 void | |
2291 playlist_remove_dead_files(void) | |
2292 { | |
2293 GList *node, *next_node; | |
2294 | |
2295 PLAYLIST_LOCK(); | |
2296 | |
2297 for (node = playlist; node; node = next_node) { | |
2298 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2299 next_node = g_list_next(node); | |
2300 | |
2301 if (!entry || !entry->filename) { | |
2302 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2303 continue; | |
2304 } | |
2305 | |
2306 /* FIXME: What about 'file:///'? */ | |
2307 /* Don't kill URLs */ | |
2308 if (strstr(entry->filename, "://")) | |
2309 continue; | |
2310 | |
2311 /* FIXME: Should test for readability */ | |
2312 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2313 continue; | |
2314 | |
2315 if (entry == playlist_position) { | |
2316 /* Don't remove the currently playing song */ | |
2317 if (bmp_playback_get_playing()) | |
2318 continue; | |
2319 | |
2320 if (next_node) | |
2321 playlist_position = PLAYLIST_ENTRY(next_node->data); | |
2322 else | |
2323 playlist_position = NULL; | |
2324 } | |
2325 | |
2326 playlist_entry_free(entry); | |
2327 playlist = g_list_delete_link(playlist, node); | |
2328 } | |
2329 | |
2330 PLAYLIST_UNLOCK(); | |
2331 | |
2332 playlist_generate_shuffle_list(); | |
2333 playlistwin_update_list(); | |
2334 playlist_recalc_total_time(); | |
2335 } | |
2336 | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2337 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2338 static gint |
1251 | 2339 playlist_dupscmp_title(PlaylistEntry * a, |
2340 PlaylistEntry * b) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2341 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2342 const gchar *a_title, *b_title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2343 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2344 g_return_val_if_fail(a != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2345 g_return_val_if_fail(b != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2346 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2347 if (a->title) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2348 a_title = a->title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2349 else { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2350 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2351 a_title = strrchr(a->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2352 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2353 a_title = a->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2354 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2355 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2356 if (b->title) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2357 b_title = b->title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2358 else { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2359 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2360 b_title = strrchr(b->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2361 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2362 b_title = b->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2363 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2364 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2365 return strcmp(a_title, b_title); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2366 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2367 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2368 static gint |
1251 | 2369 playlist_dupscmp_filename(PlaylistEntry * a, |
2370 PlaylistEntry * b ) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2371 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2372 gchar *a_filename, *b_filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2373 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2374 g_return_val_if_fail(a != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2375 g_return_val_if_fail(b != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2376 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2377 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2378 a_filename = strrchr(a->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2379 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2380 a_filename = a->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2381 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2382 if (strrchr(b->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2383 b_filename = strrchr(b->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2384 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2385 b_filename = b->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2386 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2387 return strcmp(a_filename, b_filename); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2388 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2389 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2390 static gint |
1251 | 2391 playlist_dupscmp_path(PlaylistEntry * a, |
2392 PlaylistEntry * b) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2393 { |
853 | 2394 /* simply compare the entire filename string */ |
2395 return strcmp(a->filename, b->filename); | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2396 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2397 |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2398 void |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2399 playlist_remove_duplicates( PlaylistDupsType type ) |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2400 { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2401 GList *node, *next_node; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2402 GList *node_cmp, *next_node_cmp; |
1251 | 2403 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2404 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2405 switch ( type ) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2406 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2407 case PLAYLIST_DUPS_TITLE: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2408 dups_compare_func = playlist_dupscmp_title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2409 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2410 case PLAYLIST_DUPS_PATH: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2411 dups_compare_func = playlist_dupscmp_path; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2412 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2413 case PLAYLIST_DUPS_FILENAME: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2414 default: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2415 dups_compare_func = playlist_dupscmp_filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2416 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2417 } |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2418 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2419 PLAYLIST_LOCK(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2420 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2421 for (node = playlist; node; node = next_node) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2422 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2423 next_node = g_list_next(node); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2424 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2425 if (!entry || !entry->filename) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2426 g_message(G_STRLOC ": Playlist entry is invalid!"); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2427 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2428 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2429 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2430 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2431 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2432 next_node_cmp = g_list_next(node_cmp); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2433 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2434 if (!entry_cmp || !entry_cmp->filename) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2435 g_message(G_STRLOC ": Playlist entry is invalid!"); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2436 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2437 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2438 |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2439 /* compare using the chosen dups_compare_func */ |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2440 if ( !dups_compare_func( entry , entry_cmp ) ) { |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2441 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2442 if (entry_cmp == playlist_position) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2443 /* Don't remove the currently playing song */ |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2444 if (bmp_playback_get_playing()) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2445 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2446 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2447 if (next_node_cmp) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2448 playlist_position = PLAYLIST_ENTRY(next_node_cmp->data); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2449 else |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2450 playlist_position = NULL; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2451 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2452 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2453 /* check if this was the next item of the external |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2454 loop; if true, replace it with the next of the next*/ |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2455 if ( node_cmp == next_node ) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2456 next_node = g_list_next(next_node); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2457 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2458 playlist_entry_free(entry_cmp); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2459 playlist = g_list_delete_link(playlist, node_cmp); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2460 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2461 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2462 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2463 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2464 PLAYLIST_UNLOCK(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2465 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2466 playlistwin_update_list(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2467 playlist_recalc_total_time(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2468 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2469 |
0 | 2470 static gulong pl_total_time = 0, pl_selection_time = 0; |
2471 static gboolean pl_total_more = FALSE, pl_selection_more = FALSE; | |
2472 | |
2473 void | |
2474 playlist_get_total_time(gulong * total_time, | |
2475 gulong * selection_time, | |
2476 gboolean * total_more, | |
2477 gboolean * selection_more) | |
2478 { | |
2479 PLAYLIST_LOCK(); | |
2480 *total_time = pl_total_time; | |
2481 *selection_time = pl_selection_time; | |
2482 *total_more = pl_total_more; | |
2483 *selection_more = pl_selection_more; | |
2484 PLAYLIST_UNLOCK(); | |
2485 } | |
2486 | |
2487 | |
2488 static void | |
2489 playlist_recalc_total_time_nolock(void) | |
2490 { | |
2491 GList *list; | |
2492 PlaylistEntry *entry; | |
2493 | |
2494 REQUIRE_STATIC_LOCK(playlist); | |
2495 | |
2496 pl_total_time = 0; | |
2497 pl_selection_time = 0; | |
2498 pl_total_more = FALSE; | |
2499 pl_selection_more = FALSE; | |
2500 | |
2501 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2502 entry = list->data; | |
2503 | |
2504 if (entry->length != -1) | |
2505 pl_total_time += entry->length / 1000; | |
2506 else | |
2507 pl_total_more = TRUE; | |
2508 | |
2509 if (entry->selected) { | |
2510 if (entry->length != -1) | |
2511 pl_selection_time += entry->length / 1000; | |
2512 else | |
2513 pl_selection_more = TRUE; | |
2514 } | |
2515 } | |
2516 } | |
2517 | |
2518 static void | |
2519 playlist_recalc_total_time(void) | |
2520 { | |
2521 PLAYLIST_LOCK(); | |
2522 playlist_recalc_total_time_nolock(); | |
2523 PLAYLIST_UNLOCK(); | |
2524 } | |
2525 | |
2526 | |
2527 void | |
2528 playlist_select_all(gboolean set) | |
2529 { | |
2530 GList *list; | |
2531 | |
2532 PLAYLIST_LOCK(); | |
2533 | |
2534 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2535 PlaylistEntry *entry = list->data; | |
2536 entry->selected = set; | |
2537 } | |
2538 | |
2539 PLAYLIST_UNLOCK(); | |
2540 playlist_recalc_total_time(); | |
2541 } | |
2542 | |
2543 void | |
2544 playlist_select_invert_all(void) | |
2545 { | |
2546 GList *list; | |
2547 | |
2548 PLAYLIST_LOCK(); | |
2549 | |
2550 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2551 PlaylistEntry *entry = list->data; | |
2552 entry->selected = !entry->selected; | |
2553 } | |
2554 | |
2555 PLAYLIST_UNLOCK(); | |
2556 playlist_recalc_total_time(); | |
2557 } | |
2558 | |
2559 gboolean | |
2560 playlist_select_invert(guint pos) | |
2561 { | |
2562 GList *list; | |
2563 gboolean invert_ok = FALSE; | |
2564 | |
2565 PLAYLIST_LOCK(); | |
2566 | |
2567 if ((list = g_list_nth(playlist_get(), pos))) { | |
2568 PlaylistEntry *entry = list->data; | |
2569 entry->selected = !entry->selected; | |
2570 invert_ok = TRUE; | |
2571 } | |
2572 | |
2573 PLAYLIST_UNLOCK(); | |
2574 playlist_recalc_total_time(); | |
2575 | |
2576 return invert_ok; | |
2577 } | |
2578 | |
2579 | |
2580 void | |
2581 playlist_select_range(gint min_pos, gint max_pos, gboolean select) | |
2582 { | |
2583 GList *list; | |
2584 gint i; | |
2585 | |
2586 if (min_pos > max_pos) | |
2587 SWAP(min_pos, max_pos); | |
2588 | |
2589 PLAYLIST_LOCK(); | |
2590 | |
2591 list = g_list_nth(playlist_get(), min_pos); | |
2592 for (i = min_pos; i <= max_pos && list; i++) { | |
2593 PlaylistEntry *entry = list->data; | |
2594 entry->selected = select; | |
2595 list = g_list_next(list); | |
2596 } | |
2597 | |
2598 PLAYLIST_UNLOCK(); | |
2599 | |
2600 playlist_recalc_total_time(); | |
2601 } | |
2602 | |
2603 gboolean | |
2604 playlist_read_info_selection(void) | |
2605 { | |
2606 GList *node; | |
2607 gboolean retval = FALSE; | |
2608 | |
2609 PLAYLIST_LOCK(); | |
2610 | |
2611 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2612 PlaylistEntry *entry = node->data; | |
2613 if (!entry->selected) | |
2614 continue; | |
2615 | |
2616 retval = TRUE; | |
2617 | |
2618 str_replace_in(&entry->title, NULL); | |
2619 entry->length = -1; | |
2620 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2621 /* invalidate mtime to reread */ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2622 entry->tuple->mtime = 0; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2623 |
0 | 2624 if (!playlist_entry_get_info(entry)) { |
2625 if (g_list_index(playlist_get(), entry) == -1) | |
2626 /* Entry disappeared while we looked it up. Restart. */ | |
2627 node = playlist_get(); | |
2628 } | |
2629 } | |
2630 | |
2631 PLAYLIST_UNLOCK(); | |
2632 | |
2633 playlistwin_update_list(); | |
2634 playlist_recalc_total_time(); | |
2635 | |
2636 return retval; | |
2637 } | |
2638 | |
2639 void | |
2640 playlist_read_info(guint pos) | |
2641 { | |
2642 GList *node; | |
2643 | |
2644 PLAYLIST_LOCK(); | |
2645 | |
2646 if ((node = g_list_nth(playlist_get(), pos))) { | |
2647 PlaylistEntry *entry = node->data; | |
2648 str_replace_in(&entry->title, NULL); | |
2649 entry->length = -1; | |
2650 playlist_entry_get_info(entry); | |
2651 } | |
2652 | |
2653 PLAYLIST_UNLOCK(); | |
2654 | |
2655 playlistwin_update_list(); | |
2656 playlist_recalc_total_time(); | |
2657 } | |
2658 | |
2659 void | |
2660 playlist_set_shuffle(gboolean shuffle) | |
2661 { | |
2662 PLAYLIST_LOCK(); | |
2663 | |
2664 cfg.shuffle = shuffle; | |
2665 playlist_generate_shuffle_list_nolock(); | |
2666 | |
2667 PLAYLIST_UNLOCK(); | |
2668 } | |
2669 | |
2670 void | |
2671 playlist_new(void) | |
2672 { | |
2673 playlist_set_current_name(NULL); | |
2674 playlist_clear(); | |
2675 mainwin_clear_song_info(); | |
2676 mainwin_set_info_text(); | |
2677 } | |
2678 | |
2679 | |
2680 const gchar * | |
2681 playlist_get_filename_to_play(void) | |
2682 { | |
2683 const gchar *filename = NULL; | |
2684 | |
2685 PLAYLIST_LOCK(); | |
2686 | |
2687 if (playlist) { | |
2688 if (!playlist_position) { | |
2689 if (cfg.shuffle) | |
2690 playlist_position = shuffle_list->data; | |
2691 else | |
2692 playlist_position = playlist->data; | |
2693 } | |
2694 | |
2695 filename = playlist_position->filename; | |
2696 } | |
2697 | |
2698 PLAYLIST_UNLOCK(); | |
2699 | |
2700 return filename; | |
2701 } | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2702 |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
397
diff
changeset
|
2703 PlaylistEntry * |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2704 playlist_get_entry_to_play(void) |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2705 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2706 PLAYLIST_LOCK(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2707 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2708 if (playlist) { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2709 if (!playlist_position) { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2710 if (cfg.shuffle) |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2711 playlist_position = shuffle_list->data; |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2712 else |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2713 playlist_position = playlist->data; |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2714 } |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2715 } |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2716 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2717 PLAYLIST_UNLOCK(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2718 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2719 return playlist_position; |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2720 } |