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