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