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