Mercurial > audlegacy
annotate audacious/playlist.c @ 1420:0aa4bee03747 trunk
[svn] - ok, move this fix down a little
author | nenolod |
---|---|
date | Tue, 18 Jul 2006 12:33:34 -0700 |
parents | 01dcb223833a |
children | 740c08db08d9 |
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 | |
23 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02111-1307, USA. | |
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 "playlist_list.h" |
54 #include "skin.h" | |
55 #include "urldecode.h" | |
56 #include "util.h" | |
1269 | 57 #include "ui_fileinfo.h" |
0 | 58 |
59 #include "debug.h" | |
60 | |
1251 | 61 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
0 | 62 typedef void (*PlaylistSaveFunc) (FILE * file); |
63 | |
64 PlaylistEntry *playlist_position; | |
65 G_LOCK_DEFINE(playlist); | |
66 | |
67 /* NOTE: match the order listed in PlaylistFormat enum */ | |
68 static const gchar *playlist_format_suffixes[] = { | |
69 ".m3u", ".pls", NULL | |
70 }; | |
71 | |
72 static GList *playlist = NULL; | |
73 static GList *shuffle_list = NULL; | |
74 static GList *queued_list = NULL; | |
75 | |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
76 /* 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
|
77 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
78 * 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
|
79 * 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
|
80 * strings. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
81 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
82 * 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
|
83 * 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
|
84 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
85 * 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
|
86 * 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
|
87 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
88 * 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
|
89 * up. Hince the boolean below. |
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 * January 7, 2006, William Pitcock <nenolod@nenolod.net> |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
92 */ |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
93 static gboolean loading_playlist = FALSE; |
0 | 94 |
95 G_LOCK_DEFINE(playlist_get_info_going); | |
96 | |
97 static gchar *playlist_current_name = NULL; | |
98 | |
99 static gboolean playlist_get_info_scan_active = FALSE; | |
100 static gboolean playlist_get_info_going = FALSE; | |
101 static GThread *playlist_get_info_thread; | |
102 | |
103 | |
104 static gint path_compare(const gchar * a, const gchar * b); | |
1251 | 105 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); |
106 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
107 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
108 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
109 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); | |
1415 | 110 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); |
1251 | 111 |
112 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
113 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
114 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
115 |
0 | 116 static PlaylistCompareFunc playlist_compare_func_table[] = { |
117 playlist_compare_path, | |
118 playlist_compare_filename, | |
119 playlist_compare_title, | |
1251 | 120 playlist_compare_artist, |
1415 | 121 playlist_compare_date, |
122 playlist_compare_track | |
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 | |
1251 | 1777 playlist_compare_title(PlaylistEntry * a, |
1778 PlaylistEntry * b) | |
0 | 1779 { |
1250 | 1780 const gchar *a_title = NULL, *b_title = NULL; |
0 | 1781 |
1782 g_return_val_if_fail(a != NULL, 0); | |
1783 g_return_val_if_fail(b != NULL, 0); | |
1784 | |
1250 | 1785 if (a->tuple != NULL && a->tuple->track_name != NULL) |
1786 a_title = a->tuple->track_name; | |
1787 if (b->tuple != NULL && b->tuple->track_name != NULL) | |
1788 b_title = b->tuple->track_name; | |
1789 | |
1251 | 1790 if (a_title != NULL && b_title != NULL) |
1250 | 1791 return strcasecmp(a_title, b_title); |
1792 | |
1793 if (a->title != NULL) | |
0 | 1794 a_title = a->title; |
1795 else { | |
1796 if (strrchr(a->filename, '/')) | |
1797 a_title = strrchr(a->filename, '/') + 1; | |
1798 else | |
1799 a_title = a->filename; | |
1800 } | |
1801 | |
1250 | 1802 if (b->title != NULL) |
0 | 1803 b_title = b->title; |
1804 else { | |
1805 if (strrchr(a->filename, '/')) | |
1806 b_title = strrchr(b->filename, '/') + 1; | |
1807 else | |
1808 b_title = b->filename; | |
1809 } | |
1810 | |
1811 return strcasecmp(a_title, b_title); | |
1812 } | |
1813 | |
1814 static gint | |
1251 | 1815 playlist_compare_artist(PlaylistEntry * a, |
1816 PlaylistEntry * b) | |
1817 { | |
1818 const gchar *a_artist = NULL, *b_artist = NULL; | |
1819 | |
1820 g_return_val_if_fail(a != NULL, 0); | |
1821 g_return_val_if_fail(b != NULL, 0); | |
1822 | |
1823 if (a->tuple != NULL) | |
1824 playlist_entry_get_info(a); | |
1825 | |
1826 if (b->tuple != NULL) | |
1827 playlist_entry_get_info(b); | |
1828 | |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1829 if (a->tuple != NULL && a->tuple->performer != NULL) |
1251 | 1830 a_artist = a->tuple->performer; |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1831 if (b->tuple != NULL && b->tuple->performer != NULL) |
1251 | 1832 b_artist = b->tuple->performer; |
1833 | |
1834 if (a_artist != NULL && b_artist != NULL) | |
1835 return strcasecmp(a_artist, b_artist); | |
1836 | |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1837 return 0; |
1251 | 1838 } |
1839 | |
1840 static gint | |
1841 playlist_compare_filename(PlaylistEntry * a, | |
1842 PlaylistEntry * b) | |
0 | 1843 { |
1844 gchar *a_filename, *b_filename; | |
1845 | |
1846 g_return_val_if_fail(a != NULL, 0); | |
1847 g_return_val_if_fail(b != NULL, 0); | |
1848 | |
1849 if (strrchr(a->filename, '/')) | |
1850 a_filename = strrchr(a->filename, '/') + 1; | |
1851 else | |
1852 a_filename = a->filename; | |
1853 | |
1854 if (strrchr(b->filename, '/')) | |
1855 b_filename = strrchr(b->filename, '/') + 1; | |
1856 else | |
1857 b_filename = b->filename; | |
1858 | |
1859 | |
1860 return strcasecmp(a_filename, b_filename); | |
1861 } | |
1862 | |
1863 static gint | |
1864 path_compare(const gchar * a, const gchar * b) | |
1865 { | |
1866 gchar *posa, *posb; | |
1867 gint len, ret; | |
1868 | |
1869 posa = strrchr(a, '/'); | |
1870 posb = strrchr(b, '/'); | |
1871 | |
1872 /* | |
1873 * Sort directories before files | |
1874 */ | |
1875 if (posa && posb && (posa - a != posb - b)) { | |
1876 if (posa - a > posb - b) { | |
1877 len = posb - b; | |
1878 ret = -1; | |
1879 } | |
1880 else { | |
1881 len = posa - a; | |
1882 ret = 1; | |
1883 } | |
1884 if (!strncasecmp(a, b, len)) | |
1885 return ret; | |
1886 } | |
1887 return strcasecmp(a, b); | |
1888 } | |
1889 | |
1890 static gint | |
1251 | 1891 playlist_compare_path(PlaylistEntry * a, |
1892 PlaylistEntry * b) | |
0 | 1893 { |
1894 return path_compare(a->filename, b->filename); | |
1895 } | |
1896 | |
1897 static gint | |
1251 | 1898 playlist_compare_date(PlaylistEntry * a, |
1899 PlaylistEntry * b) | |
0 | 1900 { |
1901 struct stat buf; | |
1902 time_t modtime; | |
1903 | |
1904 gint rv; | |
1905 | |
1906 | |
1907 rv = stat(a->filename, &buf); | |
1908 | |
1909 if (rv == 0) { | |
1910 modtime = buf.st_mtime; | |
1911 rv = stat(b->filename, &buf); | |
1912 | |
1913 if (stat(b->filename, &buf) == 0) { | |
1914 if (buf.st_mtime == modtime) | |
1915 return 0; | |
1916 else | |
1917 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
1918 } | |
1919 else | |
1920 return -1; | |
1921 } | |
1922 else if (!lstat(b->filename, &buf)) | |
1923 return 1; | |
1924 else | |
1925 return playlist_compare_filename(a, b); | |
1926 } | |
1927 | |
1928 | |
1929 void | |
1930 playlist_sort(PlaylistSortType type) | |
1931 { | |
1932 playlist_remove_dead_files(); | |
1933 PLAYLIST_LOCK(); | |
1934 playlist = | |
1935 g_list_sort(playlist, | |
1936 (GCompareFunc) playlist_compare_func_table[type]); | |
1937 PLAYLIST_UNLOCK(); | |
1938 } | |
1939 | |
1940 static GList * | |
1941 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
1942 { | |
1943 GList *list1, *list2; | |
1944 GList *tmp_list = NULL; | |
1945 GList *index_list = NULL; | |
1946 | |
1947 /* | |
1948 * We take all the selected entries out of the playlist, | |
1949 * sorts them, and then put them back in again. | |
1950 */ | |
1951 | |
1952 list1 = g_list_last(list); | |
1953 | |
1954 while (list1) { | |
1955 list2 = g_list_previous(list1); | |
1956 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
1957 gpointer idx; | |
1958 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
1959 index_list = g_list_prepend(index_list, idx); | |
1960 list = g_list_remove_link(list, list1); | |
1961 tmp_list = g_list_concat(list1, tmp_list); | |
1962 } | |
1963 list1 = list2; | |
1964 } | |
1965 | |
1966 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
1967 list1 = tmp_list; | |
1968 list2 = index_list; | |
1969 | |
1970 while (list2) { | |
1971 if (!list1) { | |
1972 g_critical(G_STRLOC ": Error during list sorting. " | |
1973 "Possibly dropped some playlist-entries."); | |
1974 break; | |
1975 } | |
1976 | |
1977 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
1978 | |
1979 list2 = g_list_next(list2); | |
1980 list1 = g_list_next(list1); | |
1981 } | |
1982 | |
1983 g_list_free(index_list); | |
1984 g_list_free(tmp_list); | |
1985 | |
1986 return list; | |
1987 } | |
1988 | |
1989 void | |
1990 playlist_sort_selected(PlaylistSortType type) | |
1991 { | |
1992 PLAYLIST_LOCK(); | |
1993 playlist = playlist_sort_selected_generic(playlist, (GCompareFunc) | |
1994 playlist_compare_func_table | |
1995 [type]); | |
1996 PLAYLIST_UNLOCK(); | |
1997 } | |
1998 | |
1999 void | |
2000 playlist_reverse(void) | |
2001 { | |
2002 PLAYLIST_LOCK(); | |
2003 playlist = g_list_reverse(playlist); | |
2004 PLAYLIST_UNLOCK(); | |
2005 } | |
2006 | |
2007 static GList * | |
2008 playlist_shuffle_list(GList * list) | |
2009 { | |
2010 /* | |
2011 * Note that this doesn't make a copy of the original list. | |
2012 * The pointer to the original list is not valid after this | |
2013 * fuction is run. | |
2014 */ | |
2015 gint len = g_list_length(list); | |
2016 gint i, j; | |
2017 GList *node, **ptrs; | |
2018 | |
2019 REQUIRE_STATIC_LOCK(playlist); | |
2020 | |
2021 if (!len) | |
2022 return NULL; | |
2023 | |
2024 ptrs = g_new(GList *, len); | |
2025 | |
2026 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2027 ptrs[i] = node; | |
2028 | |
2029 j = g_random_int_range(0, len); | |
2030 list = ptrs[j]; | |
2031 ptrs[j]->next = NULL; | |
2032 ptrs[j] = ptrs[0]; | |
2033 | |
2034 for (i = 1; i < len; i++) { | |
2035 j = g_random_int_range(0, len - i); | |
2036 list->prev = ptrs[i + j]; | |
2037 ptrs[i + j]->next = list; | |
2038 list = ptrs[i + j]; | |
2039 ptrs[i + j] = ptrs[i]; | |
2040 } | |
2041 list->prev = NULL; | |
2042 | |
2043 g_free(ptrs); | |
2044 | |
2045 return list; | |
2046 } | |
2047 | |
2048 void | |
2049 playlist_random(void) | |
2050 { | |
2051 PLAYLIST_LOCK(); | |
2052 playlist = playlist_shuffle_list(playlist); | |
2053 PLAYLIST_UNLOCK(); | |
2054 } | |
2055 | |
2056 GList * | |
2057 playlist_get_selected(void) | |
2058 { | |
2059 GList *node, *list = NULL; | |
2060 gint i = 0; | |
2061 | |
2062 PLAYLIST_LOCK(); | |
2063 for (node = playlist_get(); node; node = g_list_next(node), i++) { | |
2064 PlaylistEntry *entry = node->data; | |
2065 if (entry->selected) | |
2066 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2067 } | |
2068 PLAYLIST_UNLOCK(); | |
2069 return g_list_reverse(list); | |
2070 } | |
2071 | |
2072 void | |
2073 playlist_clear_selected(void) | |
2074 { | |
2075 GList *node = NULL; | |
2076 gint i = 0; | |
2077 | |
2078 PLAYLIST_LOCK(); | |
2079 for (node = playlist_get(); node; node = g_list_next(node), i++) { | |
2080 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2081 } | |
2082 PLAYLIST_UNLOCK(); | |
2083 playlist_recalc_total_time(); | |
2084 } | |
2085 | |
2086 gint | |
2087 playlist_get_num_selected(void) | |
2088 { | |
2089 GList *node; | |
2090 gint num = 0; | |
2091 | |
2092 PLAYLIST_LOCK(); | |
2093 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2094 PlaylistEntry *entry = node->data; | |
2095 if (entry->selected) | |
2096 num++; | |
2097 } | |
2098 PLAYLIST_UNLOCK(); | |
2099 return num; | |
2100 } | |
2101 | |
2102 | |
2103 static void | |
2104 playlist_generate_shuffle_list(void) | |
2105 { | |
2106 PLAYLIST_LOCK(); | |
2107 playlist_generate_shuffle_list_nolock(); | |
2108 PLAYLIST_UNLOCK(); | |
2109 } | |
2110 | |
2111 static void | |
2112 playlist_generate_shuffle_list_nolock(void) | |
2113 { | |
2114 GList *node; | |
2115 gint numsongs; | |
2116 | |
2117 REQUIRE_STATIC_LOCK(playlist); | |
2118 | |
2119 if (shuffle_list) { | |
2120 g_list_free(shuffle_list); | |
2121 shuffle_list = NULL; | |
2122 } | |
2123 | |
2124 if (!cfg.shuffle || !playlist) | |
2125 return; | |
2126 | |
2127 shuffle_list = playlist_shuffle_list(g_list_copy(playlist)); | |
2128 numsongs = g_list_length(shuffle_list); | |
2129 | |
2130 if (playlist_position) { | |
2131 gint i = g_list_index(shuffle_list, playlist_position); | |
2132 node = g_list_nth(shuffle_list, i); | |
2133 shuffle_list = g_list_remove_link(shuffle_list, node); | |
2134 shuffle_list = g_list_prepend(shuffle_list, node->data); | |
2135 } | |
2136 } | |
2137 | |
2138 void | |
2139 playlist_fileinfo(guint pos) | |
2140 { | |
2141 gchar *path = NULL; | |
2142 GList *node; | |
1269 | 2143 PlaylistEntry *entry = NULL; |
2144 TitleInput *tuple = NULL; | |
0 | 2145 |
2146 PLAYLIST_LOCK(); | |
1269 | 2147 |
2148 if ((node = g_list_nth(playlist_get(), pos))) | |
2149 { | |
2150 entry = node->data; | |
2151 tuple = entry->tuple; | |
2152 path = g_strdup(entry->filename); | |
0 | 2153 } |
1269 | 2154 |
0 | 2155 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
|
2156 |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2157 /* 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
|
2158 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
|
2159 { |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2160 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
|
2161 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
|
2162 } |
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
|
2163 |
1269 | 2164 if (tuple != NULL) |
2165 { | |
2166 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2167 fileinfo_show_for_tuple(tuple); | |
1270 | 2168 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) |
2169 entry->decoder->file_info_box(path); | |
1269 | 2170 else |
2171 fileinfo_show_for_path(path); | |
2172 g_free(path); | |
2173 } | |
2174 else if (path != NULL) | |
2175 { | |
1270 | 2176 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) |
2177 entry->decoder->file_info_box(path); | |
2178 else | |
2179 fileinfo_show_for_path(path); | |
0 | 2180 g_free(path); |
2181 } | |
2182 } | |
2183 | |
2184 void | |
2185 playlist_fileinfo_current(void) | |
2186 { | |
2187 gchar *path = NULL; | |
1269 | 2188 TitleInput *tuple = NULL; |
0 | 2189 |
2190 PLAYLIST_LOCK(); | |
1269 | 2191 |
0 | 2192 if (playlist_get() && playlist_position) |
1269 | 2193 { |
0 | 2194 path = g_strdup(playlist_position->filename); |
1269 | 2195 tuple = playlist_position->tuple; |
2196 } | |
2197 | |
0 | 2198 PLAYLIST_UNLOCK(); |
2199 | |
1269 | 2200 if (tuple != NULL) |
2201 { | |
2202 if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box == NULL) | |
2203 fileinfo_show_for_tuple(tuple); | |
1270 | 2204 else if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL) |
2205 playlist_position->decoder->file_info_box(path); | |
1269 | 2206 else |
2207 fileinfo_show_for_path(path); | |
2208 g_free(path); | |
2209 } | |
2210 else if (path != NULL) | |
2211 { | |
1270 | 2212 if (playlist_position != NULL && playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL) |
2213 playlist_position->decoder->file_info_box(path); | |
2214 else | |
2215 fileinfo_show_for_path(path); | |
0 | 2216 g_free(path); |
2217 } | |
2218 } | |
2219 | |
2220 | |
2221 static gboolean | |
2222 playlist_get_info_is_going(void) | |
2223 { | |
2224 gboolean result; | |
2225 | |
2226 G_LOCK(playlist_get_info_going); | |
2227 result = playlist_get_info_going; | |
2228 G_UNLOCK(playlist_get_info_going); | |
2229 | |
2230 return result; | |
2231 } | |
2232 | |
2233 static gpointer | |
2234 playlist_get_info_func(gpointer arg) | |
2235 { | |
2236 GList *node; | |
2237 gboolean update_playlistwin = FALSE; | |
2238 gboolean update_mainwin = FALSE; | |
2239 | |
2240 while (playlist_get_info_is_going()) { | |
2241 PlaylistEntry *entry; | |
2242 | |
2243 if (cfg.use_pl_metadata && | |
2244 cfg.get_info_on_load && | |
2245 playlist_get_info_scan_active) { | |
2246 | |
2247 PLAYLIST_LOCK(); | |
2248 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2249 entry = node->data; | |
2250 | |
2251 if (entry->title || entry->length != -1) | |
2252 continue; | |
2253 | |
2254 if (!playlist_entry_get_info(entry)) { | |
2255 if (g_list_index(playlist_get(), entry) == -1) | |
2256 /* Entry disappeared while we looked it up. | |
2257 Restart. */ | |
2258 node = playlist_get(); | |
2259 } | |
2260 else if (entry->title || entry->length != -1) { | |
2261 update_playlistwin = TRUE; | |
2262 if (entry == playlist_position) | |
2263 update_mainwin = TRUE; | |
2264 break; | |
2265 } | |
2266 } | |
2267 PLAYLIST_UNLOCK(); | |
2268 | |
2269 if (!node) | |
2270 playlist_get_info_scan_active = FALSE; | |
2271 } | |
2272 else if (!cfg.get_info_on_load && | |
2273 cfg.get_info_on_demand && | |
2274 cfg.playlist_visible && | |
2275 !cfg.playlist_shaded && | |
2276 cfg.use_pl_metadata) { | |
2277 | |
2278 gboolean found = FALSE; | |
2279 | |
2280 PLAYLIST_LOCK(); | |
2281 | |
2282 if (!playlist_get()) { | |
2283 PLAYLIST_UNLOCK(); | |
2284 g_usleep(1000000); | |
2285 continue; | |
2286 } | |
2287 | |
2288 for (node = | |
2289 g_list_nth(playlist_get(), playlistwin_get_toprow()); | |
2290 node | |
2291 && | |
2292 playlistwin_item_visible(g_list_position | |
2293 (playlist_get(), node)); | |
2294 node = g_list_next(node)) { | |
2295 entry = node->data; | |
2296 if (entry->title || entry->length != -1) | |
2297 continue; | |
2298 | |
2299 if (!playlist_entry_get_info(entry)) { | |
2300 if (g_list_index(playlist_get(), entry) == -1) | |
2301 /* Entry disapeared while we | |
2302 looked it up. Restart. */ | |
2303 node = | |
2304 g_list_nth(playlist_get(), | |
2305 playlistwin_get_toprow()); | |
2306 } | |
2307 else if (entry->title || entry->length != -1) { | |
2308 update_playlistwin = TRUE; | |
2309 if (entry == playlist_position) | |
2310 update_mainwin = TRUE; | |
2311 found = TRUE; | |
2312 break; | |
2313 } | |
2314 } | |
2315 | |
2316 PLAYLIST_UNLOCK(); | |
2317 | |
2318 if (!found) { | |
2319 g_usleep(500000); | |
2320 continue; | |
2321 } | |
2322 } | |
2323 else | |
2324 g_usleep(500000); | |
2325 | |
2326 if (update_playlistwin) { | |
2327 playlistwin_update_list(); | |
2328 update_playlistwin = FALSE; | |
2329 } | |
2330 | |
2331 if (update_mainwin) { | |
2332 mainwin_set_info_text(); | |
2333 update_mainwin = FALSE; | |
2334 } | |
2335 } | |
2336 | |
2337 g_thread_exit(NULL); | |
2338 return NULL; | |
2339 } | |
2340 | |
2341 void | |
2342 playlist_start_get_info_thread(void) | |
2343 { | |
2344 playlist_get_info_going = TRUE; | |
2345 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2346 NULL, TRUE, NULL); | |
2347 } | |
2348 | |
2349 void | |
2350 playlist_stop_get_info_thread(void) | |
2351 { | |
2352 G_LOCK(playlist_get_info_going); | |
2353 playlist_get_info_going = FALSE; | |
2354 G_UNLOCK(playlist_get_info_going); | |
2355 g_thread_join(playlist_get_info_thread); | |
2356 } | |
2357 | |
2358 void | |
2359 playlist_start_get_info_scan(void) | |
2360 { | |
2361 playlist_get_info_scan_active = TRUE; | |
2362 } | |
2363 | |
2364 void | |
2365 playlist_remove_dead_files(void) | |
2366 { | |
2367 GList *node, *next_node; | |
2368 | |
2369 PLAYLIST_LOCK(); | |
2370 | |
2371 for (node = playlist; node; node = next_node) { | |
2372 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2373 next_node = g_list_next(node); | |
2374 | |
2375 if (!entry || !entry->filename) { | |
2376 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2377 continue; | |
2378 } | |
2379 | |
2380 /* FIXME: What about 'file:///'? */ | |
2381 /* Don't kill URLs */ | |
2382 if (strstr(entry->filename, "://")) | |
2383 continue; | |
2384 | |
2385 /* FIXME: Should test for readability */ | |
2386 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2387 continue; | |
2388 | |
2389 if (entry == playlist_position) { | |
2390 /* Don't remove the currently playing song */ | |
2391 if (bmp_playback_get_playing()) | |
2392 continue; | |
2393 | |
2394 if (next_node) | |
2395 playlist_position = PLAYLIST_ENTRY(next_node->data); | |
2396 else | |
2397 playlist_position = NULL; | |
2398 } | |
2399 | |
2400 playlist_entry_free(entry); | |
2401 playlist = g_list_delete_link(playlist, node); | |
2402 } | |
2403 | |
2404 PLAYLIST_UNLOCK(); | |
2405 | |
2406 playlist_generate_shuffle_list(); | |
2407 playlistwin_update_list(); | |
2408 playlist_recalc_total_time(); | |
2409 } | |
2410 | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2411 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2412 static gint |
1251 | 2413 playlist_dupscmp_title(PlaylistEntry * a, |
2414 PlaylistEntry * b) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2415 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2416 const gchar *a_title, *b_title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2417 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2418 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
|
2419 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
|
2420 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2421 if (a->title) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2422 a_title = a->title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2423 else { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2424 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2425 a_title = strrchr(a->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2426 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2427 a_title = a->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2428 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2429 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2430 if (b->title) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2431 b_title = b->title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2432 else { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2433 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2434 b_title = strrchr(b->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2435 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2436 b_title = b->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2437 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2438 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2439 return strcmp(a_title, b_title); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2440 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2441 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2442 static gint |
1251 | 2443 playlist_dupscmp_filename(PlaylistEntry * a, |
2444 PlaylistEntry * b ) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2445 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2446 gchar *a_filename, *b_filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2447 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2448 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
|
2449 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
|
2450 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2451 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2452 a_filename = strrchr(a->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2453 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2454 a_filename = a->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2455 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2456 if (strrchr(b->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2457 b_filename = strrchr(b->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 b_filename = b->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 return strcmp(a_filename, b_filename); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2462 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2463 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2464 static gint |
1251 | 2465 playlist_dupscmp_path(PlaylistEntry * a, |
2466 PlaylistEntry * b) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2467 { |
853 | 2468 /* simply compare the entire filename string */ |
2469 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
|
2470 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2471 |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2472 void |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2473 playlist_remove_duplicates( PlaylistDupsType type ) |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2474 { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2475 GList *node, *next_node; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2476 GList *node_cmp, *next_node_cmp; |
1251 | 2477 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
|
2478 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2479 switch ( type ) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2480 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2481 case PLAYLIST_DUPS_TITLE: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2482 dups_compare_func = playlist_dupscmp_title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2483 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2484 case PLAYLIST_DUPS_PATH: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2485 dups_compare_func = playlist_dupscmp_path; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2486 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2487 case PLAYLIST_DUPS_FILENAME: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2488 default: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2489 dups_compare_func = playlist_dupscmp_filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2490 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2491 } |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2492 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2493 PLAYLIST_LOCK(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2494 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2495 for (node = playlist; node; node = next_node) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2496 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2497 next_node = g_list_next(node); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2498 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2499 if (!entry || !entry->filename) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2500 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
|
2501 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2502 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2503 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2504 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
|
2505 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
|
2506 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
|
2507 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2508 if (!entry_cmp || !entry_cmp->filename) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2509 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
|
2510 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2511 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2512 |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2513 /* 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
|
2514 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
|
2515 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2516 if (entry_cmp == playlist_position) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2517 /* Don't remove the currently playing song */ |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2518 if (bmp_playback_get_playing()) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2519 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2520 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2521 if (next_node_cmp) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2522 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
|
2523 else |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2524 playlist_position = NULL; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2525 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2526 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2527 /* 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
|
2528 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
|
2529 if ( node_cmp == next_node ) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2530 next_node = g_list_next(next_node); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2531 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2532 playlist_entry_free(entry_cmp); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2533 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
|
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 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2537 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2538 PLAYLIST_UNLOCK(); |
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 playlistwin_update_list(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2541 playlist_recalc_total_time(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2542 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2543 |
0 | 2544 static gulong pl_total_time = 0, pl_selection_time = 0; |
2545 static gboolean pl_total_more = FALSE, pl_selection_more = FALSE; | |
2546 | |
2547 void | |
2548 playlist_get_total_time(gulong * total_time, | |
2549 gulong * selection_time, | |
2550 gboolean * total_more, | |
2551 gboolean * selection_more) | |
2552 { | |
2553 PLAYLIST_LOCK(); | |
2554 *total_time = pl_total_time; | |
2555 *selection_time = pl_selection_time; | |
2556 *total_more = pl_total_more; | |
2557 *selection_more = pl_selection_more; | |
2558 PLAYLIST_UNLOCK(); | |
2559 } | |
2560 | |
2561 | |
2562 static void | |
2563 playlist_recalc_total_time_nolock(void) | |
2564 { | |
2565 GList *list; | |
2566 PlaylistEntry *entry; | |
2567 | |
2568 REQUIRE_STATIC_LOCK(playlist); | |
2569 | |
2570 pl_total_time = 0; | |
2571 pl_selection_time = 0; | |
2572 pl_total_more = FALSE; | |
2573 pl_selection_more = FALSE; | |
2574 | |
2575 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2576 entry = list->data; | |
2577 | |
2578 if (entry->length != -1) | |
2579 pl_total_time += entry->length / 1000; | |
2580 else | |
2581 pl_total_more = TRUE; | |
2582 | |
2583 if (entry->selected) { | |
2584 if (entry->length != -1) | |
2585 pl_selection_time += entry->length / 1000; | |
2586 else | |
2587 pl_selection_more = TRUE; | |
2588 } | |
2589 } | |
2590 } | |
2591 | |
2592 static void | |
2593 playlist_recalc_total_time(void) | |
2594 { | |
2595 PLAYLIST_LOCK(); | |
2596 playlist_recalc_total_time_nolock(); | |
2597 PLAYLIST_UNLOCK(); | |
2598 } | |
2599 | |
2600 | |
2601 void | |
2602 playlist_select_all(gboolean set) | |
2603 { | |
2604 GList *list; | |
2605 | |
2606 PLAYLIST_LOCK(); | |
2607 | |
2608 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2609 PlaylistEntry *entry = list->data; | |
2610 entry->selected = set; | |
2611 } | |
2612 | |
2613 PLAYLIST_UNLOCK(); | |
2614 playlist_recalc_total_time(); | |
2615 } | |
2616 | |
2617 void | |
2618 playlist_select_invert_all(void) | |
2619 { | |
2620 GList *list; | |
2621 | |
2622 PLAYLIST_LOCK(); | |
2623 | |
2624 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2625 PlaylistEntry *entry = list->data; | |
2626 entry->selected = !entry->selected; | |
2627 } | |
2628 | |
2629 PLAYLIST_UNLOCK(); | |
2630 playlist_recalc_total_time(); | |
2631 } | |
2632 | |
2633 gboolean | |
2634 playlist_select_invert(guint pos) | |
2635 { | |
2636 GList *list; | |
2637 gboolean invert_ok = FALSE; | |
2638 | |
2639 PLAYLIST_LOCK(); | |
2640 | |
2641 if ((list = g_list_nth(playlist_get(), pos))) { | |
2642 PlaylistEntry *entry = list->data; | |
2643 entry->selected = !entry->selected; | |
2644 invert_ok = TRUE; | |
2645 } | |
2646 | |
2647 PLAYLIST_UNLOCK(); | |
2648 playlist_recalc_total_time(); | |
2649 | |
2650 return invert_ok; | |
2651 } | |
2652 | |
2653 | |
2654 void | |
2655 playlist_select_range(gint min_pos, gint max_pos, gboolean select) | |
2656 { | |
2657 GList *list; | |
2658 gint i; | |
2659 | |
2660 if (min_pos > max_pos) | |
2661 SWAP(min_pos, max_pos); | |
2662 | |
2663 PLAYLIST_LOCK(); | |
2664 | |
2665 list = g_list_nth(playlist_get(), min_pos); | |
2666 for (i = min_pos; i <= max_pos && list; i++) { | |
2667 PlaylistEntry *entry = list->data; | |
2668 entry->selected = select; | |
2669 list = g_list_next(list); | |
2670 } | |
2671 | |
2672 PLAYLIST_UNLOCK(); | |
2673 | |
2674 playlist_recalc_total_time(); | |
2675 } | |
2676 | |
2677 gboolean | |
2678 playlist_read_info_selection(void) | |
2679 { | |
2680 GList *node; | |
2681 gboolean retval = FALSE; | |
2682 | |
2683 PLAYLIST_LOCK(); | |
2684 | |
2685 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2686 PlaylistEntry *entry = node->data; | |
2687 if (!entry->selected) | |
2688 continue; | |
2689 | |
2690 retval = TRUE; | |
2691 | |
2692 str_replace_in(&entry->title, NULL); | |
2693 entry->length = -1; | |
2694 | |
2695 if (!playlist_entry_get_info(entry)) { | |
2696 if (g_list_index(playlist_get(), entry) == -1) | |
2697 /* Entry disappeared while we looked it up. Restart. */ | |
2698 node = playlist_get(); | |
2699 } | |
2700 } | |
2701 | |
2702 PLAYLIST_UNLOCK(); | |
2703 | |
2704 playlistwin_update_list(); | |
2705 playlist_recalc_total_time(); | |
2706 | |
2707 return retval; | |
2708 } | |
2709 | |
2710 void | |
2711 playlist_read_info(guint pos) | |
2712 { | |
2713 GList *node; | |
2714 | |
2715 PLAYLIST_LOCK(); | |
2716 | |
2717 if ((node = g_list_nth(playlist_get(), pos))) { | |
2718 PlaylistEntry *entry = node->data; | |
2719 str_replace_in(&entry->title, NULL); | |
2720 entry->length = -1; | |
2721 playlist_entry_get_info(entry); | |
2722 } | |
2723 | |
2724 PLAYLIST_UNLOCK(); | |
2725 | |
2726 playlistwin_update_list(); | |
2727 playlist_recalc_total_time(); | |
2728 } | |
2729 | |
2730 void | |
2731 playlist_set_shuffle(gboolean shuffle) | |
2732 { | |
2733 PLAYLIST_LOCK(); | |
2734 | |
2735 cfg.shuffle = shuffle; | |
2736 playlist_generate_shuffle_list_nolock(); | |
2737 | |
2738 PLAYLIST_UNLOCK(); | |
2739 } | |
2740 | |
2741 void | |
2742 playlist_new(void) | |
2743 { | |
2744 playlist_set_current_name(NULL); | |
2745 playlist_clear(); | |
2746 mainwin_clear_song_info(); | |
2747 mainwin_set_info_text(); | |
2748 } | |
2749 | |
2750 | |
2751 const gchar * | |
2752 playlist_get_filename_to_play(void) | |
2753 { | |
2754 const gchar *filename = NULL; | |
2755 | |
2756 PLAYLIST_LOCK(); | |
2757 | |
2758 if (playlist) { | |
2759 if (!playlist_position) { | |
2760 if (cfg.shuffle) | |
2761 playlist_position = shuffle_list->data; | |
2762 else | |
2763 playlist_position = playlist->data; | |
2764 } | |
2765 | |
2766 filename = playlist_position->filename; | |
2767 } | |
2768 | |
2769 PLAYLIST_UNLOCK(); | |
2770 | |
2771 return filename; | |
2772 } | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2773 |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
397
diff
changeset
|
2774 PlaylistEntry * |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2775 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
|
2776 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2777 PLAYLIST_LOCK(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2778 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2779 if (playlist) { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2780 if (!playlist_position) { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2781 if (cfg.shuffle) |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2782 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
|
2783 else |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2784 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
|
2785 } |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2786 } |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2787 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2788 PLAYLIST_UNLOCK(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2789 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2790 return playlist_position; |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2791 } |