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