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