Mercurial > audlegacy
annotate src/audacious/playlist.c @ 3474:adc785ee517b trunk
Add playlist_playlists_equal for comparing entire playlists
author | Kieran Clancy <clancy.kieran+audacious@gmail.com> |
---|---|
date | Mon, 10 Sep 2007 13:45:41 +0930 |
parents | 3b26640f9fd6 |
children | 9152829f3c19 |
rev | line source |
---|---|
2313 | 1 /* Audacious |
2 * Copyright (C) 2005-2007 Audacious team. | |
3 * | |
4 * BMP (C) GPL 2003 $top_src_dir/AUTHORS | |
5 * | |
6 * based on: | |
7 * | |
8 * XMMS - Cross-platform multimedia player | |
9 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
10 * Thomas Nilsson and 4Front Technologies | |
11 * Copyright (C) 1999-2003 Haavard Kvaalen | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3097
diff
changeset
|
15 * the Free Software Foundation; under version 3 of the License. |
2313 | 16 * |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3097
diff
changeset
|
23 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
24 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
25 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
26 * Audacious or using our public API to be a derived work. |
2313 | 27 */ |
28 | |
29 #ifdef HAVE_CONFIG_H | |
30 # include "config.h" | |
31 #endif | |
32 | |
33 #include "playlist.h" | |
34 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
35 #include <mowgli.h> |
2313 | 36 #include <glib.h> |
37 #include <glib/gprintf.h> | |
38 #include <stdlib.h> | |
39 #include <string.h> | |
40 #include <time.h> | |
41 | |
42 #include <unistd.h> | |
43 #include <sys/types.h> | |
44 #include <sys/stat.h> | |
45 #include <sys/errno.h> | |
46 | |
47 #if defined(USE_REGEX_ONIGURUMA) | |
48 #include <onigposix.h> | |
49 #elif defined(USE_REGEX_PCRE) | |
50 #include <pcreposix.h> | |
51 #else | |
52 #include <regex.h> | |
53 #endif | |
54 | |
55 #include "input.h" | |
56 #include "main.h" | |
57 #include "ui_main.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2408
diff
changeset
|
58 #include "util.h" |
2717 | 59 #include "configdb.h" |
2313 | 60 #include "vfs.h" |
61 #include "ui_equalizer.h" | |
62 #include "playback.h" | |
63 #include "playlist.h" | |
64 #include "playlist_container.h" | |
2499
15a1f5ee4d1c
[svn] - playlist_manager -> ui_playlist_manager, since it's a UI component.
nenolod
parents:
2493
diff
changeset
|
65 #include "ui_playlist_manager.h" |
2313 | 66 #include "ui_playlist.h" |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
67 #include "strings.h" |
2313 | 68 #include "ui_fileinfo.h" |
69 | |
70 #include "debug.h" | |
71 | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
72 #include "hook.h" |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
73 |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
74 #include "playlist_evmessages.h" |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
75 #include "playlist_evlisteners.h" |
3217 | 76 #include "ui_skinned_playlist.h" |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
77 |
2313 | 78 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
79 typedef void (*PlaylistSaveFunc) (FILE * file); | |
80 | |
81 /* If we manually change the song, p_p_b_j will show us where to go back to */ | |
82 PlaylistEntry *playlist_position_before_jump = NULL; | |
83 | |
84 static GList *playlists = NULL; | |
85 static GList *playlists_iter; | |
86 | |
87 /* If this is set to TRUE, we do not probe upon playlist add. | |
88 * | |
89 * Under Audacious 0.1.x, this was not a big deal because we used | |
90 * file extension introspection instead of looking for file format magic | |
91 * strings. | |
92 * | |
93 * Because we use file magic strings, we have to fstat a file being added | |
94 * to a playlist up to 1 * <number of input plugins installed> times. | |
95 * | |
96 * This can get really slow now that we're looking for files to add to a | |
97 * playlist. (Up to 5 minutes for 5000 songs, etcetera.) | |
98 * | |
99 * So, we obviously don't want to probe while opening a large playlist | |
100 * up. Hince the boolean below. | |
101 * | |
102 * January 7, 2006, William Pitcock <nenolod@nenolod.net> | |
103 */ | |
104 | |
105 G_LOCK_DEFINE(playlist_get_info_going); | |
106 | |
2328 | 107 //static gchar *playlist_current_name = NULL; |
2313 | 108 |
109 static gboolean playlist_get_info_scan_active = FALSE; | |
110 static gboolean playlist_get_info_going = FALSE; | |
111 static GThread *playlist_get_info_thread; | |
112 | |
113 static gint path_compare(const gchar * a, const gchar * b); | |
114 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); | |
115 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
116 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
117 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
118 static time_t playlist_get_mtime(const gchar *filename); | |
119 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); | |
120 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); | |
121 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); | |
122 | |
123 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
124 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
125 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
126 | |
127 static PlaylistCompareFunc playlist_compare_func_table[] = { | |
128 playlist_compare_path, | |
129 playlist_compare_filename, | |
130 playlist_compare_title, | |
131 playlist_compare_artist, | |
132 playlist_compare_date, | |
133 playlist_compare_track, | |
134 playlist_compare_playlist | |
135 }; | |
136 | |
137 static guint playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos); | |
138 | |
139 static void playlist_generate_shuffle_list(Playlist *); | |
140 static void playlist_generate_shuffle_list_nolock(Playlist *); | |
141 | |
142 static void playlist_recalc_total_time_nolock(Playlist *); | |
143 static void playlist_recalc_total_time(Playlist *); | |
144 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | |
145 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
146 static mowgli_heap_t *playlist_entry_heap = NULL; |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
147 |
2313 | 148 /* *********************** playlist entry code ********************** */ |
149 | |
150 PlaylistEntry * | |
151 playlist_entry_new(const gchar * filename, | |
152 const gchar * title, | |
153 const gint length, | |
154 InputPlugin * dec) | |
155 { | |
156 PlaylistEntry *entry; | |
157 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
158 entry = mowgli_heap_alloc(playlist_entry_heap); |
2313 | 159 entry->filename = g_strdup(filename); |
160 entry->title = str_to_utf8(title); | |
161 entry->length = length; | |
162 entry->selected = FALSE; | |
163 entry->decoder = dec; | |
164 | |
165 /* only do this if we have a decoder, otherwise it just takes too long */ | |
166 if (entry->decoder) | |
167 playlist_entry_get_info(entry); | |
168 | |
169 return entry; | |
170 } | |
171 | |
172 void | |
173 playlist_entry_free(PlaylistEntry * entry) | |
174 { | |
175 if (!entry) | |
176 return; | |
177 | |
178 if (entry->tuple != NULL) { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
179 mowgli_object_unref(entry->tuple); |
2313 | 180 entry->tuple = NULL; |
181 } | |
182 | |
183 if (entry->filename != NULL) | |
184 g_free(entry->filename); | |
185 | |
186 if (entry->title != NULL) | |
187 g_free(entry->title); | |
188 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
189 mowgli_heap_free(playlist_entry_heap, entry); |
2313 | 190 } |
191 | |
192 static gboolean | |
193 playlist_entry_get_info(PlaylistEntry * entry) | |
194 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
195 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
196 ProbeResult *pr = NULL; |
2313 | 197 time_t modtime; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
198 const gchar *formatter; |
2313 | 199 |
200 g_return_val_if_fail(entry != NULL, FALSE); | |
201 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
202 if (entry->tuple == NULL || tuple_get_int(entry->tuple, "mtime") > 0 || tuple_get_int(entry->tuple, "mtime") == -1) |
2636 | 203 modtime = playlist_get_mtime(entry->filename); |
2313 | 204 else |
2636 | 205 modtime = 0; /* URI -nenolod */ |
2313 | 206 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
207 if (str_has_prefix_nocase(entry->filename, "http:") && |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
208 g_thread_self() != playlist_get_info_thread) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
209 return FALSE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
210 |
2313 | 211 if (entry->decoder == NULL) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
212 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
213 pr = input_check_file(entry->filename, FALSE); |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
214 if (pr) |
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
215 entry->decoder = pr->ip; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
216 } |
2313 | 217 |
218 /* renew tuple if file mtime is newer than tuple mtime. */ | |
219 if(entry->tuple){ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
220 if(tuple_get_int(entry->tuple, "mtime") == modtime) |
2313 | 221 return TRUE; |
222 else { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
223 mowgli_object_unref(entry->tuple); |
2313 | 224 entry->tuple = NULL; |
225 } | |
226 } | |
227 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
228 if (pr != NULL && pr->tuple != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
229 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
230 else if (entry->decoder != NULL && entry->decoder->get_song_tuple != NULL) |
2313 | 231 tuple = entry->decoder->get_song_tuple(entry->filename); |
232 | |
233 if (tuple == NULL) | |
234 return FALSE; | |
235 | |
236 /* attach mtime */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
237 tuple_associate_int(tuple, "mtime", modtime); |
2313 | 238 |
239 /* entry is still around */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
240 formatter = tuple_get_string(tuple, "formatter"); |
3349
01a241d35146
add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3348
diff
changeset
|
241 entry->title = tuple_formatter_make_title_string(tuple, formatter ? |
3334
ea806daf3ef0
rename xmms_get_gentitle_format() to get_gentitle_format().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3327
diff
changeset
|
242 formatter : get_gentitle_format()); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
243 entry->length = tuple_get_int(tuple, "length"); |
2313 | 244 entry->tuple = tuple; |
245 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
246 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
247 |
2313 | 248 return TRUE; |
249 } | |
250 | |
251 /* *********************** playlist selector code ************************* */ | |
252 | |
253 void | |
254 playlist_init(void) | |
255 { | |
256 Playlist *initial_pl; | |
257 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
258 /* create a heap with 1024 playlist entry nodes preallocated. --nenolod */ |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
259 playlist_entry_heap = mowgli_heap_create(sizeof(PlaylistEntry), 1024, |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
260 BH_NOW); |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
261 |
2313 | 262 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ |
263 | |
264 initial_pl = playlist_new(); | |
265 | |
266 playlist_add_playlist(initial_pl); | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
267 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
268 playlist_evlistener_init(); |
2313 | 269 } |
270 | |
271 void | |
272 playlist_add_playlist(Playlist *playlist) | |
273 { | |
274 playlists = g_list_append(playlists, playlist); | |
275 | |
276 if (playlists_iter == NULL) | |
277 playlists_iter = playlists; | |
278 | |
279 playlist_manager_update(); | |
280 } | |
281 | |
282 void | |
283 playlist_remove_playlist(Playlist *playlist) | |
284 { | |
3473
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
285 gboolean active; |
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
286 active = (playlist && playlist == playlist_get_active()); |
2820 | 287 /* users suppose playback will be stopped on removing playlist */ |
3473
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
288 if (active && playback_get_playing()) { |
2820 | 289 ip_data.stop = TRUE; |
290 playback_stop(); | |
291 ip_data.stop = FALSE; | |
292 mainwin_clear_song_info(); | |
293 } | |
294 | |
2313 | 295 /* trying to free the last playlist simply clears and resets it */ |
296 if (g_list_length(playlists) < 2) { | |
297 playlist_clear(playlist); | |
298 playlist_set_current_name(playlist, NULL); | |
299 return; | |
300 } | |
301 | |
3473
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
302 if (active) playlist_select_next(); |
2313 | 303 |
304 /* upon removal, a playlist should be cleared and freed */ | |
305 playlists = g_list_remove(playlists, playlist); | |
306 playlist_clear(playlist); | |
307 playlist_free(playlist); | |
308 | |
309 if (playlists_iter == NULL) | |
310 playlists_iter = playlists; | |
311 | |
312 playlist_manager_update(); | |
313 } | |
314 | |
315 GList * | |
316 playlist_get_playlists(void) | |
317 { | |
318 return playlists; | |
319 } | |
320 | |
321 void | |
322 playlist_select_next(void) | |
323 { | |
324 if (playlists_iter == NULL) | |
325 playlists_iter = playlists; | |
326 | |
327 playlists_iter = g_list_next(playlists_iter); | |
328 | |
329 if (playlists_iter == NULL) | |
330 playlists_iter = playlists; | |
331 | |
332 playlistwin_update_list(playlist_get_active()); | |
333 } | |
334 | |
335 void | |
336 playlist_select_prev(void) | |
337 { | |
338 if (playlists_iter == NULL) | |
339 playlists_iter = playlists; | |
340 | |
341 playlists_iter = g_list_previous(playlists_iter); | |
342 | |
343 if (playlists_iter == NULL) | |
344 playlists_iter = playlists; | |
345 | |
346 playlistwin_update_list(playlist_get_active()); | |
347 } | |
348 | |
349 void | |
350 playlist_select_playlist(Playlist *playlist) | |
351 { | |
352 playlists_iter = g_list_find(playlists, playlist); | |
353 | |
354 if (playlists_iter == NULL) | |
355 playlists_iter = playlists; | |
356 | |
357 playlistwin_update_list(playlist); | |
358 } | |
359 | |
360 /* *********************** playlist code ********************** */ | |
361 | |
362 const gchar * | |
363 playlist_get_current_name(Playlist *playlist) | |
364 { | |
365 return playlist->title; | |
366 } | |
367 | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
368 /* filename is real filename here. --yaz */ |
2313 | 369 gboolean |
370 playlist_set_current_name(Playlist *playlist, const gchar * filename) | |
371 { | |
372 if (playlist->title) | |
373 g_free(playlist->title); | |
374 | |
375 if (!filename) { | |
376 playlist->title = NULL; | |
377 return FALSE; | |
378 } | |
379 | |
2504
fcf730269639
[svn] - convert filename string to utf8 for playlist->title (closes bug #789)
giacomo
parents:
2499
diff
changeset
|
380 playlist->title = filename_to_utf8(filename); |
2313 | 381 return TRUE; |
382 } | |
383 | |
384 static GList * | |
385 find_playlist_position_list(Playlist *playlist) | |
386 { | |
387 REQUIRE_LOCK(playlist->mutex); | |
388 | |
389 if (!playlist->position) { | |
390 if (cfg.shuffle) | |
391 return playlist->shuffle; | |
392 else | |
393 return playlist->entries; | |
394 } | |
395 | |
396 if (cfg.shuffle) | |
397 return g_list_find(playlist->shuffle, playlist->position); | |
398 else | |
399 return g_list_find(playlist->entries, playlist->position); | |
400 } | |
401 | |
402 static void | |
403 play_queued(Playlist *playlist) | |
404 { | |
405 GList *tmp = playlist->queue; | |
406 | |
407 REQUIRE_LOCK( playlist->mutex ); | |
408 | |
409 playlist->position = playlist->queue->data; | |
410 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | |
411 g_list_free_1(tmp); | |
412 } | |
413 | |
414 void | |
415 playlist_clear(Playlist *playlist) | |
416 { | |
417 if (!playlist) | |
418 return; | |
419 | |
420 PLAYLIST_LOCK( playlist->mutex ); | |
421 | |
422 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); | |
423 g_list_free(playlist->entries); | |
424 playlist->position = NULL; | |
425 playlist->entries = NULL; | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
426 playlist->tail = NULL; |
2637
420ce282920d
[svn] - clear playlist attribute when playlist_clear() is called.
yaz
parents:
2636
diff
changeset
|
427 playlist->attribute = PLAYLIST_PLAIN; |
2313 | 428 |
429 PLAYLIST_UNLOCK( playlist->mutex ); | |
430 | |
431 playlist_generate_shuffle_list(playlist); | |
432 playlistwin_update_list(playlist); | |
433 playlist_recalc_total_time(playlist); | |
434 playlist_manager_update(); | |
435 } | |
436 | |
437 static void | |
438 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
439 gboolean * restart_playing) | |
440 { | |
441 PlaylistEntry *entry; | |
442 GList *playing_song = NULL; | |
443 | |
444 REQUIRE_LOCK(playlist->mutex); | |
445 | |
446 /* We call g_list_find manually here because we don't want an item | |
447 * in the shuffle_list */ | |
448 | |
449 if (playlist->position) | |
450 playing_song = g_list_find(playlist->entries, playlist->position); | |
451 | |
452 entry = PLAYLIST_ENTRY(node->data); | |
453 | |
454 if (playing_song == node) { | |
455 *set_info_text = TRUE; | |
456 | |
457 if (playback_get_playing()) { | |
458 PLAYLIST_UNLOCK(playlist->mutex); | |
459 ip_data.stop = TRUE; | |
460 playback_stop(); | |
461 ip_data.stop = FALSE; | |
462 PLAYLIST_LOCK(playlist->mutex); | |
463 *restart_playing = TRUE; | |
464 } | |
465 | |
466 playing_song = find_playlist_position_list(playlist); | |
467 | |
468 if (g_list_next(playing_song)) | |
469 playlist->position = g_list_next(playing_song)->data; | |
470 else if (g_list_previous(playing_song)) | |
471 playlist->position = g_list_previous(playing_song)->data; | |
472 else | |
473 playlist->position = NULL; | |
474 | |
475 /* Make sure the entry did not disappear under us */ | |
476 if (g_list_index(playlist->entries, entry) == -1) | |
477 return; | |
478 | |
479 } | |
480 else if (g_list_position(playlist->entries, playing_song) > | |
481 g_list_position(playlist->entries, node)) { | |
482 *set_info_text = TRUE; | |
483 } | |
484 | |
485 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
486 playlist->queue = g_list_remove(playlist->queue, entry); | |
487 playlist->entries = g_list_remove_link(playlist->entries, node); | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
488 playlist->tail = g_list_last(playlist->entries); |
2313 | 489 playlist_entry_free(entry); |
490 g_list_free_1(node); | |
491 | |
492 playlist_recalc_total_time_nolock(playlist); | |
493 } | |
494 | |
495 void | |
496 playlist_delete_index(Playlist *playlist, guint pos) | |
497 { | |
498 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
499 GList *node; | |
500 | |
501 if (!playlist) | |
502 return; | |
503 | |
504 PLAYLIST_LOCK(playlist->mutex); | |
505 | |
506 node = g_list_nth(playlist->entries, pos); | |
507 | |
508 if (!node) { | |
509 PLAYLIST_UNLOCK(playlist->mutex); | |
510 return; | |
511 } | |
512 | |
513 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
514 | |
515 PLAYLIST_UNLOCK(playlist->mutex); | |
516 | |
517 playlist_recalc_total_time(playlist); | |
518 | |
519 playlistwin_update_list(playlist); | |
520 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
521 if (playlist->position) |
2313 | 522 playback_initiate(); |
523 else { | |
524 mainwin_clear_song_info(); | |
525 } | |
526 } | |
527 | |
528 playlist_manager_update(); | |
529 } | |
530 | |
531 void | |
532 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
533 { | |
534 GList *node, *fnode; | |
535 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
536 | |
537 PLAYLIST_LOCK(playlist->mutex); | |
538 | |
539 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
540 node = playlist->entries; | |
541 | |
542 while (node) { | |
543 GList *next = g_list_next(node); | |
544 PlaylistEntry *entry = node->data; | |
545 | |
546 if (!strcmp(entry->filename, fnode->data)) | |
547 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
548 | |
549 node = next; | |
550 } | |
551 } | |
552 | |
2792
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
553 PLAYLIST_UNLOCK(playlist->mutex); |
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
554 |
2313 | 555 playlist_recalc_total_time(playlist); |
556 playlistwin_update_list(playlist); | |
557 | |
558 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
559 if (playlist->position) |
2313 | 560 playback_initiate(); |
561 else { | |
562 mainwin_clear_song_info(); | |
563 } | |
564 } | |
565 | |
566 playlist_manager_update(); | |
567 } | |
568 | |
569 void | |
570 playlist_delete(Playlist * playlist, gboolean crop) | |
571 { | |
572 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
573 GList *node, *next_node; | |
574 PlaylistEntry *entry; | |
575 | |
576 g_return_if_fail(playlist != NULL); | |
577 | |
578 PLAYLIST_LOCK(playlist->mutex); | |
579 | |
580 node = playlist->entries; | |
581 | |
582 while (node) { | |
583 entry = PLAYLIST_ENTRY(node->data); | |
584 | |
585 next_node = g_list_next(node); | |
586 | |
587 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
588 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
589 } | |
590 | |
591 node = next_node; | |
592 } | |
593 | |
594 PLAYLIST_UNLOCK(playlist->mutex); | |
595 | |
596 playlist_recalc_total_time(playlist); | |
597 | |
598 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
599 if (playlist->position) |
2313 | 600 playback_initiate(); |
601 else { | |
602 mainwin_clear_song_info(); | |
603 } | |
604 } | |
605 | |
606 playlistwin_update_list(playlist); | |
607 playlist_manager_update(); | |
608 } | |
609 | |
610 static void | |
611 __playlist_ins_with_info(Playlist * playlist, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
612 const gchar * filename, |
2313 | 613 gint pos, |
614 const gchar * title, | |
615 gint len, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
616 InputPlugin * dec) |
2313 | 617 { |
618 g_return_if_fail(filename != NULL); | |
619 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
620 PLAYLIST_LOCK( playlist->mutex ); |
2313 | 621 playlist->entries = g_list_insert(playlist->entries, |
622 playlist_entry_new(filename, title, len, dec), | |
623 pos); | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
624 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 625 |
626 g_mutex_lock(mutex_scan); | |
627 playlist_get_info_scan_active = TRUE; | |
628 g_mutex_unlock(mutex_scan); | |
629 g_cond_signal(cond_scan); | |
630 } | |
631 | |
632 static void | |
633 __playlist_ins_with_info_tuple(Playlist * playlist, | |
634 const gchar * filename, | |
635 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
636 Tuple *tuple, |
2313 | 637 InputPlugin * dec) |
638 { | |
639 PlaylistEntry *entry; | |
640 | |
641 g_return_if_fail(playlist != NULL); | |
642 g_return_if_fail(filename != NULL); | |
643 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
644 entry = playlist_entry_new(filename, tuple ? tuple_get_string(tuple, "title") : NULL, tuple ? tuple_get_int(tuple, "length") : -1, dec); |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
645 if(!playlist->tail) |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
646 playlist->tail = g_list_last(playlist->entries); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
647 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
648 PLAYLIST_LOCK( playlist->mutex ); |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
649 if(pos == -1) { // the common case |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
650 GList *element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
651 element = g_list_alloc(); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
652 element->data = entry; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
653 element->prev = playlist->tail; // NULL is allowed here. |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
654 element->next = NULL; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
655 |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
656 if(!playlist->entries) { // this is the first element |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
657 playlist->entries = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
658 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
659 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
660 else { // the rests |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
661 g_return_if_fail(playlist->tail != NULL); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
662 playlist->tail->next = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
663 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
664 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
665 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
666 else { |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
667 playlist->entries = g_list_insert(playlist->entries, entry, pos); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
668 } |
2313 | 669 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
670 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 671 if (tuple != NULL) { |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
672 const gchar *formatter = tuple_get_string(tuple, "formatter"); |
3349
01a241d35146
add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3348
diff
changeset
|
673 entry->title = tuple_formatter_make_title_string(tuple, formatter ? |
3334
ea806daf3ef0
rename xmms_get_gentitle_format() to get_gentitle_format().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3327
diff
changeset
|
674 formatter : get_gentitle_format()); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
675 entry->length = tuple_get_int(tuple, "length"); |
2313 | 676 entry->tuple = tuple; |
677 } | |
678 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
679 if(tuple != NULL && tuple_get_int(tuple, "mtime") == -1) { // kick the scanner thread only if mtime = -1 (uninitialized). |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
680 g_mutex_lock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
681 playlist_get_info_scan_active = TRUE; |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
682 g_mutex_unlock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
683 g_cond_signal(cond_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
684 } |
2313 | 685 } |
686 | |
687 gboolean | |
688 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
689 { | |
690 gchar buf[64], *p; | |
691 gint r; | |
692 VFSFile *file; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
693 ProbeResult *pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
694 InputPlugin *dec = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
695 Tuple *tuple = NULL; |
2313 | 696 |
697 g_return_val_if_fail(playlist != NULL, FALSE); | |
698 g_return_val_if_fail(filename != NULL, FALSE); | |
699 | |
700 if (is_playlist_name(filename)) { | |
701 playlist->loading_playlist = TRUE; | |
702 playlist_load_ins(playlist, filename, pos); | |
703 playlist->loading_playlist = FALSE; | |
704 return TRUE; | |
705 } | |
706 | |
707 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | |
708 dec = NULL; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
709 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
710 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
711 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
712 pr = input_check_file(filename, TRUE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
713 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
714 if (pr) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
715 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
716 dec = pr->ip; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
717 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
718 } |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
719 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
720 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
721 } |
2313 | 722 |
2701
906caaf4737d
[svn] - fix cuesheet bug in a better way (e.g. unbreak http:// streams)
nenolod
parents:
2690
diff
changeset
|
723 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || (playlist->loading_playlist == FALSE && dec != NULL) || (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && str_has_prefix_nocase(filename, "http"))) |
2313 | 724 { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
725 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
726 playlist_generate_shuffle_list(playlist); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
727 playlistwin_update_list(playlist); |
2313 | 728 return TRUE; |
729 } | |
730 | |
731 /* Some files (typically produced by some cgi-scripts) don't have | |
732 * the correct extension. Try to recognize these files by looking | |
733 * at their content. We only check for http entries since it does | |
734 * not make sense to have file entries in a playlist fetched from | |
735 * the net. */ | |
736 | |
737 /* Some strange people put fifo's with the .mp3 extension, so we | |
738 * need to make sure it's a real file (otherwise fread() may block | |
739 * and stall the entire program) */ | |
740 | |
741 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
742 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
743 return FALSE; | |
744 | |
745 if (!(file = vfs_fopen(filename, "rb"))) | |
746 return FALSE; | |
747 | |
748 r = vfs_fread(buf, 1, sizeof(buf), file); | |
749 vfs_fclose(file); | |
750 | |
751 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
752 | |
753 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
754 playlist_load_ins(playlist, filename, pos); | |
755 return TRUE; | |
756 } | |
757 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
758 if (r > 6 && str_has_prefix_nocase(p, "https:")) { |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
759 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
760 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
761 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
762 |
2313 | 763 return FALSE; |
764 } | |
765 | |
766 /* FIXME: The next few functions are specific to Unix | |
767 * filesystems. Either abstract it away, or don't even bother checking | |
768 * at such low level */ | |
769 | |
770 typedef struct { | |
771 dev_t dev; | |
772 ino_t ino; | |
773 } DeviceInode; | |
774 | |
775 static DeviceInode * | |
776 devino_new(dev_t device, | |
777 ino_t inode) | |
778 { | |
779 DeviceInode *devino = g_new0(DeviceInode, 1); | |
780 | |
781 if (devino) | |
782 { | |
783 devino->dev = device; | |
784 devino->ino = inode; | |
785 } | |
786 | |
787 return devino; | |
788 } | |
789 | |
790 static guint | |
791 devino_hash(gconstpointer key) | |
792 { | |
793 const DeviceInode *d = key; | |
794 return d->ino; | |
795 } | |
796 | |
797 static gint | |
798 devino_compare(gconstpointer a, | |
799 gconstpointer b) | |
800 { | |
801 const DeviceInode *da = a, *db = b; | |
802 return (da->dev == db->dev && da->ino == db->ino); | |
803 } | |
804 | |
805 static gboolean | |
806 devino_destroy(gpointer key, | |
807 gpointer value, | |
808 gpointer data) | |
809 { | |
810 g_free(key); | |
811 return TRUE; | |
812 } | |
813 | |
814 static gboolean | |
815 file_is_hidden(const gchar * filename) | |
816 { | |
817 g_return_val_if_fail(filename != NULL, FALSE); | |
2570 | 818 return (g_basename(filename)[0] == '.'); |
2313 | 819 } |
820 | |
821 static GList * | |
822 playlist_dir_find_files(const gchar * path, | |
823 gboolean background, | |
824 GHashTable * htab) | |
825 { | |
826 GDir *dir; | |
827 GList *list = NULL, *ilist; | |
828 const gchar *dir_entry; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
829 ProbeResult *pr = NULL; |
2313 | 830 |
831 struct stat statbuf; | |
832 DeviceInode *devino; | |
833 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
834 if (!path) |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
835 return NULL; |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
836 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
837 if (!vfs_file_test(path, G_FILE_TEST_IS_DIR)) |
2313 | 838 return NULL; |
839 | |
840 stat(path, &statbuf); | |
841 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
842 | |
843 if (g_hash_table_lookup(htab, devino)) { | |
844 g_free(devino); | |
845 return NULL; | |
846 } | |
847 | |
848 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
849 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
850 /* XXX: what the hell is this for? --nenolod */ |
2313 | 851 if ((ilist = input_scan_dir(path))) { |
852 GList *node; | |
853 for (node = ilist; node; node = g_list_next(node)) { | |
854 gchar *name = g_build_filename(path, node->data, NULL); | |
855 list = g_list_prepend(list, name); | |
856 g_free(node->data); | |
857 } | |
858 g_list_free(ilist); | |
859 return list; | |
860 } | |
861 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
862 /* g_dir_open does not handle URI, so path should come here not-urified. --giacomo */ |
2313 | 863 if (!(dir = g_dir_open(path, 0, NULL))) |
864 return NULL; | |
865 | |
866 while ((dir_entry = g_dir_read_name(dir))) { | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
867 gchar *filename, *tmp; |
2313 | 868 |
869 if (file_is_hidden(dir_entry)) | |
870 continue; | |
871 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
872 tmp = g_build_filename(path, dir_entry, NULL); |
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
873 filename = g_filename_to_uri(tmp, NULL, NULL); |
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
874 g_free(tmp); |
2313 | 875 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
876 if (vfs_file_test(filename, G_FILE_TEST_IS_DIR)) { |
2313 | 877 GList *sub; |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
878 gchar *dirfilename = g_filename_from_uri(filename, NULL, NULL); |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
879 sub = playlist_dir_find_files(dirfilename, background, htab); |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
880 g_free(dirfilename); |
2313 | 881 g_free(filename); |
882 list = g_list_concat(list, sub); | |
883 } | |
884 else if (cfg.playlist_detect == TRUE) | |
885 list = g_list_prepend(list, filename); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
886 else if ((pr = input_check_file(filename, TRUE)) != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
887 { |
2313 | 888 list = g_list_prepend(list, filename); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
889 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
890 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
891 pr = NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
892 } |
2313 | 893 else |
894 g_free(filename); | |
895 | |
896 while (background && gtk_events_pending()) | |
897 gtk_main_iteration(); | |
898 } | |
899 g_dir_close(dir); | |
900 | |
901 return list; | |
902 } | |
903 | |
904 gboolean | |
905 playlist_add(Playlist * playlist, const gchar * filename) | |
906 { | |
907 return playlist_ins(playlist, filename, -1); | |
908 } | |
909 | |
910 guint | |
911 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
912 { | |
913 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
914 } | |
915 | |
916 guint | |
917 playlist_add_url(Playlist * playlist, const gchar * url) | |
918 { | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
919 guint entries; |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
920 entries = playlist_ins_url(playlist, url, -1); |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
921 // printf("playlist_add_url: entries = %d\n", entries); |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
922 return entries; |
2313 | 923 } |
924 | |
925 guint | |
926 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
927 gint pos, | |
928 gboolean background) | |
929 { | |
930 guint entries = 0; | |
931 GList *list, *node; | |
932 GHashTable *htab; | |
2978
f4971c7d6384
Remove inlined urldecoding functions and use g_filename_from_uri() instead where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2976
diff
changeset
|
933 gchar *path2 = g_filename_from_uri(path, NULL, NULL); |
2313 | 934 |
2580
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
935 if (path2 == NULL) |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
936 path2 = g_strdup(path); |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
937 |
2313 | 938 htab = g_hash_table_new(devino_hash, devino_compare); |
939 | |
2579 | 940 list = playlist_dir_find_files(path2, background, htab); |
2313 | 941 list = g_list_sort(list, (GCompareFunc) path_compare); |
942 | |
943 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
944 | |
945 for (node = list; node; node = g_list_next(node)) { | |
3129
f416657ee9b7
Call playlist_ins() instead of __playlist_ins().
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
946 playlist_ins(playlist, node->data, pos); |
2313 | 947 g_free(node->data); |
948 entries++; | |
949 if (pos >= 0) | |
950 pos++; | |
951 } | |
952 | |
953 g_list_free(list); | |
2579 | 954 g_free(path2); |
2313 | 955 |
956 playlist_recalc_total_time(playlist); | |
957 playlist_generate_shuffle_list(playlist); | |
958 playlistwin_update_list(playlist); | |
959 playlist_manager_update(); | |
960 return entries; | |
961 } | |
962 | |
963 guint | |
964 playlist_ins_url(Playlist * playlist, const gchar * string, | |
965 gint pos) | |
966 { | |
967 gchar *tmp; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
968 gint entries = 0; |
2313 | 969 gchar *decoded = NULL; |
970 | |
971 g_return_val_if_fail(playlist != NULL, 0); | |
972 g_return_val_if_fail(string != NULL, 0); | |
973 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
974 // playlistwin_update_list(playlist); // is this necessary? --yaz |
2313 | 975 |
976 while (*string) { | |
977 GList *node; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
978 guint i = 0; |
2313 | 979 tmp = strchr(string, '\n'); |
980 if (tmp) { | |
981 if (*(tmp - 1) == '\r') | |
982 *(tmp - 1) = '\0'; | |
983 *tmp = '\0'; | |
984 } | |
985 | |
986 decoded = g_strdup(string); | |
987 | |
2575 | 988 if (vfs_file_test(decoded, G_FILE_TEST_IS_DIR)) { |
2313 | 989 i = playlist_ins_dir(playlist, decoded, pos, FALSE); |
990 } | |
991 else { | |
992 if (is_playlist_name(decoded)) { | |
993 i = playlist_load_ins(playlist, decoded, pos); | |
994 } | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
995 else if (playlist_ins(playlist, decoded, pos)) { |
2313 | 996 i = 1; |
997 } | |
998 } | |
999 | |
1000 g_free(decoded); | |
1001 | |
1002 PLAYLIST_LOCK(playlist->mutex); | |
1003 node = g_list_nth(playlist->entries, pos); | |
1004 PLAYLIST_UNLOCK(playlist->mutex); | |
1005 | |
1006 entries += i; | |
1007 | |
1008 if (pos >= 0) | |
1009 pos += i; | |
1010 if (!tmp) | |
1011 break; | |
1012 | |
1013 string = tmp + 1; | |
1014 } | |
1015 | |
1016 playlist_recalc_total_time(playlist); | |
1017 playlist_generate_shuffle_list(playlist); | |
1018 playlistwin_update_list(playlist); | |
1019 | |
1020 playlist_manager_update(); | |
1021 | |
1022 return entries; | |
1023 } | |
1024 | |
1025 void | |
1026 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
1027 gint freq, gint nch) | |
1028 { | |
1029 Playlist *playlist = playlist_get_active(); | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1030 PlaylistEventInfoChange *msg; |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1031 gchar *text; |
2313 | 1032 |
3197
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1033 if(length == -1) { |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1034 event_queue("hide seekbar", (gpointer)0xdeadbeef); // event_queue hates NULL --yaz |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1035 } |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1036 |
2313 | 1037 g_return_if_fail(playlist != NULL); |
1038 | |
1039 if (playlist->position) { | |
1040 g_free(playlist->position->title); | |
1041 playlist->position->title = g_strdup(title); | |
1042 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1043 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1044 // overwrite tuple::title, mainly for streaming. it may incur side effects. --yaz |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1045 if(playlist->position->tuple && tuple_get_int(playlist->position->tuple, "length") == -1){ |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1046 tuple_disassociate(playlist->position->tuple, "title"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1047 tuple_associate_string(playlist->position->tuple, "title", title); |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1048 } |
2313 | 1049 } |
1050 | |
1051 playlist_recalc_total_time(playlist); | |
1052 | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1053 /* broadcast a PlaylistEventInfoChange message. */ |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1054 msg = g_new0(PlaylistEventInfoChange, 1); |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1055 msg->bitrate = rate; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1056 msg->samplerate = freq; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1057 msg->channels = nch; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1058 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1059 event_queue("playlist info change", msg); |
2460 | 1060 |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1061 text = playlist_get_info_text(playlist); |
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1062 event_queue("title change", text); |
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1063 |
2460 | 1064 if ( playlist->position ) |
1065 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1066 } |
1067 | |
1068 void | |
1069 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1070 gint freq, gint nch) | |
1071 { | |
1072 g_return_if_fail(playlist != NULL); | |
1073 | |
1074 if (playlist->position) { | |
1075 g_free(playlist->position->title); | |
1076 playlist->position->title = g_strdup(title); | |
1077 playlist->position->length = length; | |
1078 } | |
1079 | |
1080 playlist_recalc_total_time(playlist); | |
1081 | |
1082 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1083 |
1084 if ( playlist->position ) | |
1085 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1086 } |
1087 | |
1088 void | |
1089 playlist_check_pos_current(Playlist *playlist) | |
1090 { | |
1091 gint pos, row, bottom; | |
1092 | |
1093 if (!playlist) | |
1094 return; | |
1095 | |
1096 PLAYLIST_LOCK(playlist->mutex); | |
1097 if (!playlist->position || !playlistwin_list) { | |
1098 PLAYLIST_UNLOCK(playlist->mutex); | |
1099 return; | |
1100 } | |
1101 | |
1102 pos = g_list_index(playlist->entries, playlist->position); | |
1103 | |
1104 if (playlistwin_item_visible(pos)) { | |
1105 PLAYLIST_UNLOCK(playlist->mutex); | |
1106 return; | |
1107 } | |
1108 | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1109 bottom = MAX(0, playlist_get_length(playlist) - |
3217 | 1110 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); |
1111 row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom); | |
2313 | 1112 PLAYLIST_UNLOCK(playlist->mutex); |
1113 playlistwin_set_toprow(row); | |
1114 g_cond_signal(cond_scan); | |
1115 } | |
1116 | |
1117 void | |
1118 playlist_next(Playlist *playlist) | |
1119 { | |
1120 GList *plist_pos_list; | |
1121 gboolean restart_playing = FALSE; | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1122 if (!playlist_get_length(playlist)) |
2313 | 1123 return; |
1124 | |
1125 PLAYLIST_LOCK(playlist->mutex); | |
1126 | |
1127 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1128 { | |
1129 playlist->position = playlist_position_before_jump; | |
1130 playlist_position_before_jump = NULL; | |
1131 } | |
1132 | |
1133 plist_pos_list = find_playlist_position_list(playlist); | |
1134 | |
1135 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
1136 PLAYLIST_UNLOCK(playlist->mutex); | |
1137 return; | |
1138 } | |
1139 | |
1140 if (playback_get_playing()) { | |
1141 /* We need to stop before changing playlist_position */ | |
1142 PLAYLIST_UNLOCK(playlist->mutex); | |
1143 ip_data.stop = TRUE; | |
1144 playback_stop(); | |
1145 ip_data.stop = FALSE; | |
1146 PLAYLIST_LOCK(playlist->mutex); | |
1147 restart_playing = TRUE; | |
1148 } | |
1149 | |
1150 plist_pos_list = find_playlist_position_list(playlist); | |
1151 if (playlist->queue != NULL) | |
1152 play_queued(playlist); | |
1153 else if (g_list_next(plist_pos_list)) | |
1154 playlist->position = g_list_next(plist_pos_list)->data; | |
1155 else if (cfg.repeat) { | |
1156 playlist->position = NULL; | |
1157 playlist_generate_shuffle_list_nolock(playlist); | |
1158 if (cfg.shuffle) | |
1159 playlist->position = playlist->shuffle->data; | |
1160 else | |
1161 playlist->position = playlist->entries->data; | |
1162 } | |
1163 PLAYLIST_UNLOCK(playlist->mutex); | |
1164 playlist_check_pos_current(playlist); | |
1165 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1166 if (restart_playing) |
2313 | 1167 playback_initiate(); |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1168 |
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1169 playlistwin_update_list(playlist); |
2313 | 1170 } |
1171 | |
1172 void | |
1173 playlist_prev(Playlist *playlist) | |
1174 { | |
1175 GList *plist_pos_list; | |
1176 gboolean restart_playing = FALSE; | |
1177 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1178 if (!playlist_get_length(playlist)) |
2313 | 1179 return; |
1180 | |
1181 PLAYLIST_LOCK(playlist->mutex); | |
1182 | |
1183 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1184 { | |
1185 playlist->position = playlist_position_before_jump; | |
1186 playlist_position_before_jump = NULL; | |
1187 } | |
1188 | |
1189 plist_pos_list = find_playlist_position_list(playlist); | |
1190 | |
1191 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
1192 PLAYLIST_UNLOCK(playlist->mutex); | |
1193 return; | |
1194 } | |
1195 | |
1196 if (playback_get_playing()) { | |
1197 /* We need to stop before changing playlist_position */ | |
1198 PLAYLIST_UNLOCK(playlist->mutex); | |
1199 ip_data.stop = TRUE; | |
1200 playback_stop(); | |
1201 ip_data.stop = FALSE; | |
1202 PLAYLIST_LOCK(playlist->mutex); | |
1203 restart_playing = TRUE; | |
1204 } | |
1205 | |
1206 plist_pos_list = find_playlist_position_list(playlist); | |
1207 if (g_list_previous(plist_pos_list)) { | |
1208 playlist->position = g_list_previous(plist_pos_list)->data; | |
1209 } | |
1210 else if (cfg.repeat) { | |
1211 GList *node; | |
1212 playlist->position = NULL; | |
1213 playlist_generate_shuffle_list_nolock(playlist); | |
1214 if (cfg.shuffle) | |
1215 node = g_list_last(playlist->shuffle); | |
1216 else | |
1217 node = g_list_last(playlist->entries); | |
1218 if (node) | |
1219 playlist->position = node->data; | |
1220 } | |
1221 | |
1222 PLAYLIST_UNLOCK(playlist->mutex); | |
1223 | |
1224 playlist_check_pos_current(playlist); | |
1225 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1226 if (restart_playing) |
2313 | 1227 playback_initiate(); |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1228 else |
2313 | 1229 playlistwin_update_list(playlist); |
1230 } | |
1231 | |
1232 void | |
1233 playlist_queue(Playlist *playlist) | |
1234 { | |
1235 GList *list = playlist_get_selected(playlist); | |
1236 GList *it = list; | |
1237 | |
1238 PLAYLIST_LOCK(playlist->mutex); | |
1239 | |
1240 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1241 { | |
1242 /* Shuffling and this is our first manual jump. */ | |
1243 playlist_position_before_jump = playlist->position; | |
1244 } | |
1245 | |
1246 while (it) { | |
1247 GList *next = g_list_next(it); | |
1248 GList *tmp; | |
1249 | |
1250 /* XXX: WTF? --nenolod */ | |
1251 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1252 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1253 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1254 g_list_free_1(tmp); | |
1255 list = g_list_remove_link(list, it); | |
1256 g_list_free_1(it); | |
1257 } | |
1258 | |
1259 it = next; | |
1260 } | |
1261 | |
1262 playlist->queue = g_list_concat(playlist->queue, list); | |
1263 | |
1264 PLAYLIST_UNLOCK(playlist->mutex); | |
1265 | |
1266 playlist_recalc_total_time(playlist); | |
1267 playlistwin_update_list(playlist); | |
1268 } | |
1269 | |
1270 void | |
1271 playlist_queue_position(Playlist *playlist, guint pos) | |
1272 { | |
1273 GList *tmp; | |
1274 PlaylistEntry *entry; | |
1275 | |
1276 PLAYLIST_LOCK(playlist->mutex); | |
1277 | |
1278 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1279 { | |
1280 /* Shuffling and this is our first manual jump. */ | |
1281 playlist_position_before_jump = playlist->position; | |
1282 } | |
1283 | |
1284 entry = g_list_nth_data(playlist->entries, pos); | |
1285 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1286 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1287 g_list_free_1(tmp); | |
1288 } | |
1289 else | |
1290 playlist->queue = g_list_append(playlist->queue, entry); | |
1291 PLAYLIST_UNLOCK(playlist->mutex); | |
1292 | |
1293 playlist_recalc_total_time(playlist); | |
1294 playlistwin_update_list(playlist); | |
1295 } | |
1296 | |
1297 gboolean | |
1298 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1299 { | |
1300 PlaylistEntry *entry; | |
1301 GList *tmp; | |
1302 | |
1303 PLAYLIST_LOCK(playlist->mutex); | |
1304 entry = g_list_nth_data(playlist->entries, pos); | |
1305 tmp = g_list_find(playlist->queue, entry); | |
1306 PLAYLIST_UNLOCK(playlist->mutex); | |
1307 | |
1308 return tmp != NULL; | |
1309 } | |
1310 | |
1311 gint | |
1312 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1313 { | |
1314 PlaylistEntry *entry; | |
1315 gint tmp; | |
1316 | |
1317 PLAYLIST_LOCK(playlist->mutex); | |
1318 entry = g_list_nth_data(playlist->entries, pos); | |
1319 tmp = g_list_index(playlist->queue, entry); | |
1320 PLAYLIST_UNLOCK(playlist->mutex); | |
1321 | |
1322 return tmp; | |
1323 } | |
1324 | |
1325 gint | |
1326 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1327 { | |
1328 PlaylistEntry *entry; | |
1329 gint tmp; | |
1330 | |
1331 PLAYLIST_LOCK(playlist->mutex); | |
1332 entry = g_list_nth_data(playlist->queue, pos); | |
1333 tmp = g_list_index(playlist->entries, entry); | |
1334 PLAYLIST_UNLOCK(playlist->mutex); | |
1335 | |
1336 return tmp; | |
1337 } | |
1338 | |
1339 void | |
1340 playlist_clear_queue(Playlist *playlist) | |
1341 { | |
1342 PLAYLIST_LOCK(playlist->mutex); | |
1343 g_list_free(playlist->queue); | |
1344 playlist->queue = NULL; | |
1345 PLAYLIST_UNLOCK(playlist->mutex); | |
1346 | |
1347 playlist_recalc_total_time(playlist); | |
1348 playlistwin_update_list(playlist); | |
1349 } | |
1350 | |
1351 void | |
1352 playlist_queue_remove(Playlist *playlist, guint pos) | |
1353 { | |
1354 void *entry; | |
1355 | |
1356 PLAYLIST_LOCK(playlist->mutex); | |
1357 entry = g_list_nth_data(playlist->entries, pos); | |
1358 playlist->queue = g_list_remove(playlist->queue, entry); | |
1359 PLAYLIST_UNLOCK(playlist->mutex); | |
1360 | |
1361 playlistwin_update_list(playlist); | |
1362 } | |
1363 | |
1364 gint | |
1365 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1366 { | |
1367 return g_list_index(playlist->queue, entry); | |
1368 } | |
1369 | |
1370 void | |
1371 playlist_set_position(Playlist *playlist, guint pos) | |
1372 { | |
1373 GList *node; | |
1374 gboolean restart_playing = FALSE; | |
1375 | |
1376 if (!playlist) | |
1377 return; | |
1378 | |
1379 PLAYLIST_LOCK(playlist->mutex); | |
1380 | |
1381 node = g_list_nth(playlist->entries, pos); | |
1382 if (!node) { | |
1383 PLAYLIST_UNLOCK(playlist->mutex); | |
1384 return; | |
1385 } | |
1386 | |
1387 if (playback_get_playing()) { | |
1388 /* We need to stop before changing playlist_position */ | |
1389 PLAYLIST_UNLOCK(playlist->mutex); | |
1390 ip_data.stop = TRUE; | |
1391 playback_stop(); | |
1392 ip_data.stop = FALSE; | |
1393 PLAYLIST_LOCK(playlist->mutex); | |
1394 restart_playing = TRUE; | |
1395 } | |
1396 | |
1397 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1398 { | |
1399 /* Shuffling and this is our first manual jump. */ | |
1400 playlist_position_before_jump = playlist->position; | |
1401 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1402 |
2313 | 1403 playlist->position = node->data; |
1404 PLAYLIST_UNLOCK(playlist->mutex); | |
1405 playlist_check_pos_current(playlist); | |
1406 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1407 if (restart_playing) |
2313 | 1408 playback_initiate(); |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1409 else |
2313 | 1410 playlistwin_update_list(playlist); |
1411 } | |
1412 | |
1413 void | |
1414 playlist_eof_reached(Playlist *playlist) | |
1415 { | |
1416 GList *plist_pos_list; | |
1417 | |
1418 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1419 ip_data.stop = TRUE; | |
1420 playback_stop(); | |
1421 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1422 ip_data.stop = FALSE; | |
1423 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1424 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1425 |
2313 | 1426 PLAYLIST_LOCK(playlist->mutex); |
1427 | |
1428 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1429 { | |
1430 playlist->position = playlist_position_before_jump; | |
1431 playlist_position_before_jump = NULL; | |
1432 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1433 |
2313 | 1434 plist_pos_list = find_playlist_position_list(playlist); |
1435 | |
1436 if (cfg.no_playlist_advance) { | |
1437 PLAYLIST_UNLOCK(playlist->mutex); | |
1438 mainwin_clear_song_info(); | |
1439 if (cfg.repeat) | |
1440 playback_initiate(); | |
1441 return; | |
1442 } | |
1443 | |
1444 if (cfg.stopaftersong) { | |
1445 PLAYLIST_UNLOCK(playlist->mutex); | |
1446 mainwin_clear_song_info(); | |
1447 mainwin_set_stopaftersong(FALSE); | |
1448 return; | |
1449 } | |
1450 | |
1451 if (playlist->queue != NULL) { | |
1452 play_queued(playlist); | |
1453 } | |
1454 else if (!g_list_next(plist_pos_list)) { | |
1455 if (cfg.shuffle) { | |
1456 playlist->position = NULL; | |
1457 playlist_generate_shuffle_list_nolock(playlist); | |
1458 } | |
2380 | 1459 else if (playlist->entries != NULL) |
2313 | 1460 playlist->position = playlist->entries->data; |
1461 | |
1462 if (!cfg.repeat) { | |
1463 PLAYLIST_UNLOCK(playlist->mutex); | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1464 hook_call("playlist end reached", playlist->position); |
2313 | 1465 mainwin_clear_song_info(); |
1466 return; | |
1467 } | |
1468 } | |
1469 else | |
1470 playlist->position = g_list_next(plist_pos_list)->data; | |
1471 | |
1472 PLAYLIST_UNLOCK(playlist->mutex); | |
1473 | |
1474 playlist_check_pos_current(playlist); | |
1475 playback_initiate(); | |
1476 playlistwin_update_list(playlist); | |
1477 } | |
1478 | |
1479 gint | |
1480 playlist_queue_get_length(Playlist *playlist) | |
1481 { | |
1482 gint length; | |
1483 | |
1484 PLAYLIST_LOCK(playlist->mutex); | |
1485 length = g_list_length(playlist->queue); | |
1486 PLAYLIST_UNLOCK(playlist->mutex); | |
1487 | |
1488 return length; | |
1489 } | |
1490 | |
1491 gint | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1492 playlist_get_length(Playlist *playlist) |
2313 | 1493 { |
1494 return g_list_length(playlist->entries); | |
1495 } | |
1496 | |
1497 gchar * | |
1498 playlist_get_info_text(Playlist *playlist) | |
1499 { | |
1500 gchar *text, *title, *numbers, *length; | |
1501 | |
1502 g_return_val_if_fail(playlist != NULL, NULL); | |
1503 | |
1504 PLAYLIST_LOCK(playlist->mutex); | |
1505 if (!playlist->position) { | |
1506 PLAYLIST_UNLOCK(playlist->mutex); | |
1507 return NULL; | |
1508 } | |
1509 | |
1510 /* FIXME: there should not be a need to do additional conversion, | |
1511 * if playlist is properly maintained */ | |
1512 if (playlist->position->title) { | |
1513 title = str_to_utf8(playlist->position->title); | |
1514 } | |
1515 else { | |
3097
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1516 gchar *realfn = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1517 gchar *basename = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1518 realfn = g_filename_from_uri(playlist->position->filename, NULL, NULL); |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1519 basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); |
2313 | 1520 title = filename_to_utf8(basename); |
3097
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1521 g_free(realfn); realfn = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1522 g_free(basename); basename = NULL; |
2313 | 1523 } |
1524 | |
1525 /* | |
1526 * If the user don't want numbers in the playlist, don't | |
1527 * display them in other parts of XMMS | |
1528 */ | |
1529 | |
1530 if (cfg.show_numbers_in_pl) | |
1531 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1532 else | |
1533 numbers = g_strdup(""); | |
1534 | |
1535 if (playlist->position->length != -1) | |
1536 length = g_strdup_printf(" (%d:%-2.2d)", | |
1537 playlist->position->length / 60000, | |
1538 (playlist->position->length / 1000) % 60); | |
1539 else | |
1540 length = g_strdup(""); | |
1541 | |
1542 PLAYLIST_UNLOCK(playlist->mutex); | |
1543 | |
1544 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1545 | |
1546 g_free(numbers); | |
1547 g_free(title); | |
1548 g_free(length); | |
1549 | |
1550 return text; | |
1551 } | |
1552 | |
1553 gint | |
1554 playlist_get_current_length(Playlist * playlist) | |
1555 { | |
1556 gint len = 0; | |
1557 | |
1558 if (!playlist) | |
1559 return 0; | |
1560 | |
1561 if (playlist->position) | |
1562 len = playlist->position->length; | |
1563 | |
1564 return len; | |
1565 } | |
1566 | |
1567 gboolean | |
1568 playlist_save(Playlist * playlist, const gchar * filename) | |
1569 { | |
1570 PlaylistContainer *plc = NULL; | |
1571 gchar *ext; | |
1572 | |
1573 g_return_val_if_fail(playlist != NULL, FALSE); | |
1574 g_return_val_if_fail(filename != NULL, FALSE); | |
1575 | |
1576 ext = strrchr(filename, '.') + 1; | |
1577 | |
3401
ae30eb582a66
Only set playlist name to filename if it didn't already have a name
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3383
diff
changeset
|
1578 if (!playlist->title || !playlist->title[0]) |
ae30eb582a66
Only set playlist name to filename if it didn't already have a name
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3383
diff
changeset
|
1579 playlist_set_current_name(playlist, filename); |
2313 | 1580 |
1581 if ((plc = playlist_container_find(ext)) == NULL) | |
1582 return FALSE; | |
1583 | |
1584 if (plc->plc_write == NULL) | |
1585 return FALSE; | |
1586 | |
1587 plc->plc_write(filename, 0); | |
1588 | |
1589 return TRUE; | |
1590 } | |
1591 | |
1592 gboolean | |
1593 playlist_load(Playlist * playlist, const gchar * filename) | |
1594 { | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1595 guint ret = 0; |
2313 | 1596 g_return_val_if_fail(playlist != NULL, FALSE); |
1597 | |
1598 playlist->loading_playlist = TRUE; | |
1599 ret = playlist_load_ins(playlist, filename, -1); | |
1600 playlist->loading_playlist = FALSE; | |
1601 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1602 return ret ? TRUE : FALSE; |
2313 | 1603 } |
1604 | |
1605 void | |
1606 playlist_load_ins_file(Playlist *playlist, | |
1607 const gchar * filename_p, | |
1608 const gchar * playlist_name, gint pos, | |
1609 const gchar * title, gint len) | |
1610 { | |
1611 gchar *filename; | |
1612 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1613 ProbeResult *pr = NULL; |
2313 | 1614 |
1615 g_return_if_fail(filename_p != NULL); | |
1616 g_return_if_fail(playlist != NULL); | |
1617 g_return_if_fail(playlist_name != NULL); | |
1618 | |
1619 filename = g_strchug(g_strdup(filename_p)); | |
1620 | |
1621 if(cfg.convert_slash) | |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1622 while ((tmp = strchr(filename, '\\')) != NULL) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1623 *tmp = '/'; |
2313 | 1624 |
1625 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1626 path = g_strdup(playlist_name); | |
1627 if ((tmp = strrchr(path, '/'))) | |
1628 *tmp = '\0'; | |
1629 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1630 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1631 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1632 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1633 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1634 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1635 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1636 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1637 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1638 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1639 g_free(pr); |
2313 | 1640 return; |
1641 } | |
1642 tmp = g_build_filename(path, filename, NULL); | |
1643 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1644 if (playlist->loading_playlist == TRUE && cfg.playlist_detect == TRUE) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1645 pr = NULL; |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1646 else if (!str_has_prefix_nocase(tmp, "http://") && |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1647 !str_has_prefix_nocase(tmp, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1648 pr = input_check_file(tmp, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1649 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
1650 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
2313 | 1651 g_free(tmp); |
1652 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1653 g_free(pr); |
2313 | 1654 } |
1655 else | |
1656 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1657 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1658 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1659 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1660 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1661 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1662 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1663 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1664 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1665 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1666 g_free(pr); |
2313 | 1667 } |
1668 | |
1669 g_free(filename); | |
1670 } | |
1671 | |
1672 void | |
1673 playlist_load_ins_file_tuple(Playlist * playlist, | |
1674 const gchar * filename_p, | |
1675 const gchar * playlist_name, | |
1676 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1677 Tuple *tuple) |
2313 | 1678 { |
1679 gchar *filename; | |
1680 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1681 ProbeResult *pr = NULL; /* for decoder cache */ |
2313 | 1682 |
1683 g_return_if_fail(filename_p != NULL); | |
1684 g_return_if_fail(playlist_name != NULL); | |
1685 g_return_if_fail(playlist != NULL); | |
1686 | |
1687 filename = g_strchug(g_strdup(filename_p)); | |
1688 | |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1689 if(cfg.convert_slash) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1690 while ((tmp = strchr(filename, '\\')) != NULL) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1691 *tmp = '/'; |
2313 | 1692 |
1693 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1694 path = g_strdup(playlist_name); | |
1695 if ((tmp = strrchr(path, '/'))) | |
1696 *tmp = '\0'; | |
1697 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1698 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1699 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1700 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1701 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1702 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1703 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1704 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1705 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1706 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1707 g_free(pr); |
2313 | 1708 return; |
1709 } | |
1710 tmp = g_build_filename(path, filename, NULL); | |
1711 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1712 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1713 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1714 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1715 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1716 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1717 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1718 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1719 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
2313 | 1720 g_free(tmp); |
1721 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1722 g_free(pr); |
2313 | 1723 } |
1724 else | |
1725 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1726 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1727 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1728 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1729 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1730 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1731 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1732 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1733 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1734 g_free(pr); |
2313 | 1735 } |
1736 | |
1737 g_free(filename); | |
1738 } | |
1739 | |
1740 static guint | |
1741 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1742 { | |
1743 PlaylistContainer *plc; | |
3383
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1744 GList *old_iter; |
2313 | 1745 gchar *ext; |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1746 gint old_len, new_len; |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1747 |
2313 | 1748 g_return_val_if_fail(playlist != NULL, 0); |
1749 g_return_val_if_fail(filename != NULL, 0); | |
1750 | |
1751 ext = strrchr(filename, '.') + 1; | |
1752 plc = playlist_container_find(ext); | |
1753 | |
1754 g_return_val_if_fail(plc != NULL, 0); | |
1755 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1756 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1757 old_len = playlist_get_length(playlist); |
3383
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1758 /* make sure it adds files to the right playlist */ |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1759 if (playlist != playlist_get_active()) { |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1760 old_iter = playlists_iter; |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1761 playlists_iter = g_list_find(playlists, playlist); |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1762 if (!playlists_iter) playlists_iter = playlists; |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1763 plc->plc_read(filename, pos); |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1764 playlists_iter = old_iter; |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1765 } else { |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1766 plc->plc_read(filename, pos); |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1767 } |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1768 new_len = playlist_get_length(playlist); |
2313 | 1769 |
1770 playlist_generate_shuffle_list(playlist); | |
1771 playlistwin_update_list(playlist); | |
1772 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1773 return new_len - old_len; |
2313 | 1774 } |
1775 | |
1776 GList * | |
1777 get_playlist_nth(Playlist *playlist, guint nth) | |
1778 { | |
1779 g_warning("deprecated function get_playlist_nth() was called"); | |
1780 REQUIRE_LOCK(playlist->mutex); | |
1781 return g_list_nth(playlist->entries, nth); | |
1782 } | |
1783 | |
1784 gint | |
1785 playlist_get_position_nolock(Playlist *playlist) | |
1786 { | |
1787 if (playlist && playlist->position) | |
1788 return g_list_index(playlist->entries, playlist->position); | |
1789 return 0; | |
1790 } | |
1791 | |
1792 gint | |
1793 playlist_get_position(Playlist *playlist) | |
1794 { | |
1795 gint pos; | |
1796 | |
1797 PLAYLIST_LOCK(playlist->mutex); | |
1798 pos = playlist_get_position_nolock(playlist); | |
1799 PLAYLIST_UNLOCK(playlist->mutex); | |
1800 | |
1801 return pos; | |
1802 } | |
1803 | |
1804 gchar * | |
1805 playlist_get_filename(Playlist *playlist, guint pos) | |
1806 { | |
1807 gchar *filename; | |
1808 PlaylistEntry *entry; | |
1809 GList *node; | |
1810 | |
1811 if (!playlist) | |
1812 return NULL; | |
1813 | |
1814 PLAYLIST_LOCK(playlist->mutex); | |
1815 node = g_list_nth(playlist->entries, pos); | |
1816 if (!node) { | |
1817 PLAYLIST_UNLOCK(playlist->mutex); | |
1818 return NULL; | |
1819 } | |
1820 entry = node->data; | |
1821 | |
1822 filename = g_strdup(entry->filename); | |
1823 PLAYLIST_UNLOCK(playlist->mutex); | |
1824 | |
1825 return filename; | |
1826 } | |
1827 | |
1828 gchar * | |
1829 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1830 { | |
1831 gchar *title = NULL; | |
1832 PlaylistEntry *entry; | |
1833 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1834 time_t mtime; |
2313 | 1835 |
1836 if (!playlist) | |
1837 return NULL; | |
1838 | |
1839 PLAYLIST_LOCK(playlist->mutex); | |
1840 | |
1841 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1842 PLAYLIST_UNLOCK(playlist->mutex); | |
1843 return NULL; | |
1844 } | |
1845 | |
1846 entry = node->data; | |
1847 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1848 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1849 mtime = tuple_get_int(entry->tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1850 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1851 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1852 |
2313 | 1853 /* FIXME: simplify this logic */ |
1854 if ((entry->title == NULL && entry->length == -1) || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1855 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1856 { |
1857 if (playlist_entry_get_info(entry)) | |
1858 title = entry->title; | |
1859 } | |
1860 else { | |
1861 title = entry->title; | |
1862 } | |
1863 | |
1864 PLAYLIST_UNLOCK(playlist->mutex); | |
1865 | |
1866 if (!title) { | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1867 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1868 realfn = g_filename_from_uri(entry->filename, NULL, NULL); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1869 title = g_path_get_basename(realfn ? realfn : entry->filename); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1870 g_free(realfn); realfn = NULL; |
2313 | 1871 return str_replace(title, filename_to_utf8(title)); |
1872 } | |
1873 | |
1874 return str_to_utf8(title); | |
1875 } | |
1876 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1877 Tuple * |
2313 | 1878 playlist_get_tuple(Playlist *playlist, guint pos) |
1879 { | |
1880 PlaylistEntry *entry; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1881 Tuple *tuple = NULL; |
2313 | 1882 GList *node; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1883 time_t mtime; |
2313 | 1884 |
1885 if (!playlist) | |
1886 return NULL; | |
1887 | |
1888 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1889 return NULL; | |
1890 } | |
1891 | |
1892 entry = (PlaylistEntry *) node->data; | |
1893 | |
1894 tuple = entry->tuple; | |
1895 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1896 if (tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1897 mtime = tuple_get_int(tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1898 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1899 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1900 |
2313 | 1901 // if no tuple or tuple with old mtime, get new one. |
1902 if (tuple == NULL || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1903 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1904 { |
1905 playlist_entry_get_info(entry); | |
1906 tuple = entry->tuple; | |
1907 } | |
1908 | |
1909 return tuple; | |
1910 } | |
1911 | |
1912 gint | |
1913 playlist_get_songtime(Playlist *playlist, guint pos) | |
1914 { | |
1915 gint song_time = -1; | |
1916 PlaylistEntry *entry; | |
1917 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1918 time_t mtime; |
2313 | 1919 |
1920 if (!playlist) | |
1921 return -1; | |
1922 | |
1923 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1924 return -1; | |
1925 } | |
1926 | |
1927 entry = node->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1928 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1929 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1930 mtime = tuple_get_int(entry->tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1931 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1932 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1933 |
2313 | 1934 if (entry->tuple == NULL || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1935 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { |
2313 | 1936 |
1937 if (playlist_entry_get_info(entry)) | |
1938 song_time = entry->length; | |
1939 } | |
1940 else { | |
1941 song_time = entry->length; | |
1942 } | |
1943 | |
1944 return song_time; | |
1945 } | |
1946 | |
1947 static gint | |
1948 playlist_compare_track(PlaylistEntry * a, | |
1949 PlaylistEntry * b) | |
1950 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1951 gint tracknumber_a; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1952 gint tracknumber_b; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1953 |
2313 | 1954 g_return_val_if_fail(a != NULL, 0); |
1955 g_return_val_if_fail(b != NULL, 0); | |
1956 | |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1957 if(!a->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1958 playlist_entry_get_info(a); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1959 if(!b->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1960 playlist_entry_get_info(b); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
1961 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1962 if (a->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1963 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1964 if (b->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1965 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1966 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1967 tracknumber_a = tuple_get_int(a->tuple, "track-number"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1968 tracknumber_b = tuple_get_int(b->tuple, "track-number"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1969 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1970 return (tracknumber_a && tracknumber_b ? |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1971 tracknumber_a - tracknumber_b : 0); |
2313 | 1972 } |
1973 | |
1974 static gint | |
1975 playlist_compare_playlist(PlaylistEntry * a, | |
1976 PlaylistEntry * b) | |
1977 { | |
1978 const gchar *a_title = NULL, *b_title = NULL; | |
1979 | |
1980 g_return_val_if_fail(a != NULL, 0); | |
1981 g_return_val_if_fail(b != NULL, 0); | |
1982 | |
1983 if (a->title != NULL) | |
1984 a_title = a->title; | |
1985 else { | |
1986 if (strrchr(a->filename, '/')) | |
1987 a_title = strrchr(a->filename, '/') + 1; | |
1988 else | |
1989 a_title = a->filename; | |
1990 } | |
1991 | |
1992 if (b->title != NULL) | |
1993 b_title = b->title; | |
1994 else { | |
1995 if (strrchr(a->filename, '/')) | |
1996 b_title = strrchr(b->filename, '/') + 1; | |
1997 else | |
1998 b_title = b->filename; | |
1999 } | |
2000 | |
2001 return strcasecmp(a_title, b_title); | |
2002 } | |
2003 | |
2004 static gint | |
2005 playlist_compare_title(PlaylistEntry * a, | |
2006 PlaylistEntry * b) | |
2007 { | |
2008 const gchar *a_title = NULL, *b_title = NULL; | |
2009 | |
2010 g_return_val_if_fail(a != NULL, 0); | |
2011 g_return_val_if_fail(b != NULL, 0); | |
2012 | |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2013 if(!a->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2014 playlist_entry_get_info(a); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2015 if(!b->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2016 playlist_entry_get_info(b); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2017 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2018 if (a->tuple != NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2019 a_title = tuple_get_string(a->tuple, "title"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2020 if (b->tuple != NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2021 b_title = tuple_get_string(b->tuple, "title"); |
2313 | 2022 |
2023 if (a_title != NULL && b_title != NULL) | |
2024 return strcasecmp(a_title, b_title); | |
2025 | |
2026 if (a->title != NULL) | |
2027 a_title = a->title; | |
2028 else { | |
2029 if (strrchr(a->filename, '/')) | |
2030 a_title = strrchr(a->filename, '/') + 1; | |
2031 else | |
2032 a_title = a->filename; | |
2033 } | |
2034 | |
2035 if (b->title != NULL) | |
2036 b_title = b->title; | |
2037 else { | |
2038 if (strrchr(a->filename, '/')) | |
2039 b_title = strrchr(b->filename, '/') + 1; | |
2040 else | |
2041 b_title = b->filename; | |
2042 } | |
2043 | |
2044 return strcasecmp(a_title, b_title); | |
2045 } | |
2046 | |
2047 static gint | |
2048 playlist_compare_artist(PlaylistEntry * a, | |
2049 PlaylistEntry * b) | |
2050 { | |
2051 const gchar *a_artist = NULL, *b_artist = NULL; | |
2052 | |
2053 g_return_val_if_fail(a != NULL, 0); | |
2054 g_return_val_if_fail(b != NULL, 0); | |
2055 | |
2056 if (a->tuple != NULL) | |
2057 playlist_entry_get_info(a); | |
2058 | |
2059 if (b->tuple != NULL) | |
2060 playlist_entry_get_info(b); | |
2061 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2062 if (a->tuple != NULL) { |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2063 a_artist = tuple_get_string(a->tuple, "artist"); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2064 if (str_has_prefix_nocase(a_artist, "the ")) |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2065 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2066 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2067 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2068 if (b->tuple != NULL) { |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2069 b_artist = tuple_get_string(b->tuple, "artist"); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2070 if (str_has_prefix_nocase(b_artist, "the ")) |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2071 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2072 } |
2313 | 2073 |
2074 if (a_artist != NULL && b_artist != NULL) | |
2075 return strcasecmp(a_artist, b_artist); | |
2076 | |
2077 return 0; | |
2078 } | |
2079 | |
2080 static gint | |
2081 playlist_compare_filename(PlaylistEntry * a, | |
2082 PlaylistEntry * b) | |
2083 { | |
2084 gchar *a_filename, *b_filename; | |
2085 | |
2086 g_return_val_if_fail(a != NULL, 0); | |
2087 g_return_val_if_fail(b != NULL, 0); | |
2088 | |
2089 if (strrchr(a->filename, '/')) | |
2090 a_filename = strrchr(a->filename, '/') + 1; | |
2091 else | |
2092 a_filename = a->filename; | |
2093 | |
2094 if (strrchr(b->filename, '/')) | |
2095 b_filename = strrchr(b->filename, '/') + 1; | |
2096 else | |
2097 b_filename = b->filename; | |
2098 | |
2099 | |
2100 return strcasecmp(a_filename, b_filename); | |
2101 } | |
2102 | |
2103 static gint | |
2104 path_compare(const gchar * a, const gchar * b) | |
2105 { | |
2106 gchar *posa, *posb; | |
2107 gint len, ret; | |
2108 | |
2109 posa = strrchr(a, '/'); | |
2110 posb = strrchr(b, '/'); | |
2111 | |
2112 /* | |
2113 * Sort directories before files | |
2114 */ | |
2115 if (posa && posb && (posa - a != posb - b)) { | |
2116 if (posa - a > posb - b) { | |
2117 len = posb - b; | |
2118 ret = -1; | |
2119 } | |
2120 else { | |
2121 len = posa - a; | |
2122 ret = 1; | |
2123 } | |
2124 if (!strncasecmp(a, b, len)) | |
2125 return ret; | |
2126 } | |
2127 return strcasecmp(a, b); | |
2128 } | |
2129 | |
2130 static gint | |
2131 playlist_compare_path(PlaylistEntry * a, | |
2132 PlaylistEntry * b) | |
2133 { | |
2134 return path_compare(a->filename, b->filename); | |
2135 } | |
2136 | |
2137 | |
2138 static time_t | |
2139 playlist_get_mtime(const gchar *filename) | |
2140 { | |
2141 struct stat buf; | |
2142 gint rv; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2143 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2144 |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2145 /* stat() does not accept file:// --yaz */ |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2146 realfn = g_filename_from_uri(filename, NULL, NULL); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2147 rv = stat(realfn ? realfn : filename, &buf); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2148 g_free(realfn); realfn = NULL; |
2313 | 2149 |
2150 if (rv == 0) { | |
2151 return buf.st_mtime; | |
2152 } else { | |
2153 return 0; //error | |
2154 } | |
2155 } | |
2156 | |
2157 | |
2158 static gint | |
2159 playlist_compare_date(PlaylistEntry * a, | |
2160 PlaylistEntry * b) | |
2161 { | |
2162 struct stat buf; | |
2163 time_t modtime; | |
2164 | |
2165 gint rv; | |
2166 | |
2167 | |
2168 rv = stat(a->filename, &buf); | |
2169 | |
2170 if (rv == 0) { | |
2171 modtime = buf.st_mtime; | |
2172 rv = stat(b->filename, &buf); | |
2173 | |
2174 if (stat(b->filename, &buf) == 0) { | |
2175 if (buf.st_mtime == modtime) | |
2176 return 0; | |
2177 else | |
2178 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2179 } | |
2180 else | |
2181 return -1; | |
2182 } | |
2183 else if (!lstat(b->filename, &buf)) | |
2184 return 1; | |
2185 else | |
2186 return playlist_compare_filename(a, b); | |
2187 } | |
2188 | |
2189 | |
2190 void | |
2191 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2192 { | |
2193 playlist_remove_dead_files(playlist); | |
2194 PLAYLIST_LOCK(playlist->mutex); | |
2195 playlist->entries = | |
2196 g_list_sort(playlist->entries, | |
2197 (GCompareFunc) playlist_compare_func_table[type]); | |
2198 PLAYLIST_UNLOCK(playlist->mutex); | |
2199 } | |
2200 | |
2201 static GList * | |
2202 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2203 { | |
2204 GList *list1, *list2; | |
2205 GList *tmp_list = NULL; | |
2206 GList *index_list = NULL; | |
2207 | |
2208 /* | |
2209 * We take all the selected entries out of the playlist, | |
2210 * sorts them, and then put them back in again. | |
2211 */ | |
2212 | |
2213 list1 = g_list_last(list); | |
2214 | |
2215 while (list1) { | |
2216 list2 = g_list_previous(list1); | |
2217 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2218 gpointer idx; | |
2219 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2220 index_list = g_list_prepend(index_list, idx); | |
2221 list = g_list_remove_link(list, list1); | |
2222 tmp_list = g_list_concat(list1, tmp_list); | |
2223 } | |
2224 list1 = list2; | |
2225 } | |
2226 | |
2227 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2228 list1 = tmp_list; | |
2229 list2 = index_list; | |
2230 | |
2231 while (list2) { | |
2232 if (!list1) { | |
2233 g_critical(G_STRLOC ": Error during list sorting. " | |
2234 "Possibly dropped some playlist-entries."); | |
2235 break; | |
2236 } | |
2237 | |
2238 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2239 | |
2240 list2 = g_list_next(list2); | |
2241 list1 = g_list_next(list1); | |
2242 } | |
2243 | |
2244 g_list_free(index_list); | |
2245 g_list_free(tmp_list); | |
2246 | |
2247 return list; | |
2248 } | |
2249 | |
2250 void | |
2251 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2252 { | |
2253 PLAYLIST_LOCK(playlist->mutex); | |
2254 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) | |
2255 playlist_compare_func_table | |
2256 [type]); | |
2257 PLAYLIST_UNLOCK(playlist->mutex); | |
2258 } | |
2259 | |
2260 void | |
2261 playlist_reverse(Playlist *playlist) | |
2262 { | |
2263 PLAYLIST_LOCK(playlist->mutex); | |
2264 playlist->entries = g_list_reverse(playlist->entries); | |
2265 PLAYLIST_UNLOCK(playlist->mutex); | |
2266 } | |
2267 | |
2268 static GList * | |
2269 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2270 { | |
2271 /* | |
2272 * Note that this doesn't make a copy of the original list. | |
2273 * The pointer to the original list is not valid after this | |
2274 * fuction is run. | |
2275 */ | |
2276 gint len = g_list_length(list); | |
2277 gint i, j; | |
2278 GList *node, **ptrs; | |
2279 | |
2280 if (!playlist) | |
2281 return NULL; | |
2282 | |
2283 REQUIRE_LOCK(playlist->mutex); | |
2284 | |
2285 if (!len) | |
2286 return NULL; | |
2287 | |
2288 ptrs = g_new(GList *, len); | |
2289 | |
2290 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2291 ptrs[i] = node; | |
2292 | |
2293 j = g_random_int_range(0, len); | |
2294 list = ptrs[j]; | |
2295 ptrs[j]->next = NULL; | |
2296 ptrs[j] = ptrs[0]; | |
2297 | |
2298 for (i = 1; i < len; i++) { | |
2299 j = g_random_int_range(0, len - i); | |
2300 list->prev = ptrs[i + j]; | |
2301 ptrs[i + j]->next = list; | |
2302 list = ptrs[i + j]; | |
2303 ptrs[i + j] = ptrs[i]; | |
2304 } | |
2305 list->prev = NULL; | |
2306 | |
2307 g_free(ptrs); | |
2308 | |
2309 return list; | |
2310 } | |
2311 | |
2312 void | |
2313 playlist_random(Playlist *playlist) | |
2314 { | |
2315 PLAYLIST_LOCK(playlist->mutex); | |
2316 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); | |
2317 PLAYLIST_UNLOCK(playlist->mutex); | |
2318 } | |
2319 | |
2320 GList * | |
2321 playlist_get_selected(Playlist *playlist) | |
2322 { | |
2323 GList *node, *list = NULL; | |
2324 gint i = 0; | |
2325 | |
2326 PLAYLIST_LOCK(playlist->mutex); | |
2327 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2328 PlaylistEntry *entry = node->data; | |
2329 if (entry->selected) | |
2330 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2331 } | |
2332 PLAYLIST_UNLOCK(playlist->mutex); | |
2333 return g_list_reverse(list); | |
2334 } | |
2335 | |
2336 void | |
2337 playlist_clear_selected(Playlist *playlist) | |
2338 { | |
2339 GList *node = NULL; | |
2340 gint i = 0; | |
2341 | |
2342 PLAYLIST_LOCK(playlist->mutex); | |
2343 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2344 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2345 } | |
2346 PLAYLIST_UNLOCK(playlist->mutex); | |
2347 playlist_recalc_total_time(playlist); | |
2348 playlist_manager_update(); | |
2349 } | |
2350 | |
2351 gint | |
2352 playlist_get_num_selected(Playlist *playlist) | |
2353 { | |
2354 GList *node; | |
2355 gint num = 0; | |
2356 | |
2357 PLAYLIST_LOCK(playlist->mutex); | |
2358 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2359 PlaylistEntry *entry = node->data; | |
2360 if (entry->selected) | |
2361 num++; | |
2362 } | |
2363 PLAYLIST_UNLOCK(playlist->mutex); | |
2364 return num; | |
2365 } | |
2366 | |
2367 | |
2368 static void | |
2369 playlist_generate_shuffle_list(Playlist *playlist) | |
2370 { | |
2371 PLAYLIST_LOCK(playlist->mutex); | |
2372 playlist_generate_shuffle_list_nolock(playlist); | |
2373 PLAYLIST_UNLOCK(playlist->mutex); | |
2374 } | |
2375 | |
2376 static void | |
2377 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2378 { | |
2379 GList *node; | |
2380 gint numsongs; | |
2381 | |
2382 if (!cfg.shuffle || !playlist) | |
2383 return; | |
2384 | |
2385 REQUIRE_LOCK(playlist->mutex); | |
2386 | |
2387 if (playlist->shuffle) { | |
2388 g_list_free(playlist->shuffle); | |
2389 playlist->shuffle = NULL; | |
2390 } | |
2391 | |
2392 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2393 numsongs = g_list_length(playlist->shuffle); | |
2394 | |
2395 if (playlist->position) { | |
2396 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2397 node = g_list_nth(playlist->shuffle, i); | |
2398 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2399 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2400 } | |
2401 } | |
2402 | |
2403 void | |
2404 playlist_fileinfo(Playlist *playlist, guint pos) | |
2405 { | |
2406 gchar *path = NULL; | |
2407 GList *node; | |
2408 PlaylistEntry *entry = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2409 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2410 ProbeResult *pr = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2411 time_t mtime; |
2313 | 2412 |
2413 PLAYLIST_LOCK(playlist->mutex); | |
2414 | |
2415 if ((node = g_list_nth(playlist->entries, pos))) | |
2416 { | |
2417 entry = node->data; | |
2418 tuple = entry->tuple; | |
2419 path = g_strdup(entry->filename); | |
2420 } | |
2421 | |
2422 PLAYLIST_UNLOCK(playlist->mutex); | |
2423 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2424 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2425 mtime = tuple_get_int(entry->tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2426 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2427 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2428 |
2313 | 2429 /* No tuple? Try to set this entry up properly. --nenolod */ |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2430 if (entry->tuple == NULL || mtime == -1 || |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2431 mtime == 0 || mtime != playlist_get_mtime(entry->filename)) |
2313 | 2432 { |
2433 playlist_entry_get_info(entry); | |
2434 tuple = entry->tuple; | |
2435 } | |
2436 | |
2437 if (tuple != NULL) | |
2438 { | |
2439 if (entry->decoder == NULL) | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2440 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2441 pr = input_check_file(entry->filename, FALSE); /* try to find a decoder */ |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2442 entry->decoder = pr ? pr->ip : NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2443 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2444 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2445 } |
2313 | 2446 |
2447 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2448 fileinfo_show_for_tuple(tuple); | |
2449 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2450 entry->decoder->file_info_box(path); | |
2451 else | |
2452 fileinfo_show_for_path(path); | |
2453 g_free(path); | |
2454 } | |
2455 else if (path != NULL) | |
2456 { | |
2457 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2458 entry->decoder->file_info_box(path); | |
2459 else | |
2460 fileinfo_show_for_path(path); | |
2461 g_free(path); | |
2462 } | |
2463 } | |
2464 | |
2465 void | |
2466 playlist_fileinfo_current(Playlist *playlist) | |
2467 { | |
2468 gchar *path = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2469 Tuple *tuple = NULL; |
2313 | 2470 |
2471 PLAYLIST_LOCK(playlist->mutex); | |
2472 | |
2473 if (playlist->entries && playlist->position) | |
2474 { | |
2475 path = g_strdup(playlist->position->filename); | |
2476 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2477 playlist_entry_get_info(playlist->position); | |
2478 tuple = playlist->position->tuple; | |
2479 } | |
2480 | |
2481 PLAYLIST_UNLOCK(playlist->mutex); | |
2482 | |
2483 if (tuple != NULL) | |
2484 { | |
2485 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2486 fileinfo_show_for_tuple(tuple); | |
2487 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2488 playlist->position->decoder->file_info_box(path); | |
2489 else | |
2490 fileinfo_show_for_path(path); | |
2491 g_free(path); | |
2492 } | |
2493 else if (path != NULL) | |
2494 { | |
2495 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2496 playlist->position->decoder->file_info_box(path); | |
2497 else | |
2498 fileinfo_show_for_path(path); | |
2499 g_free(path); | |
2500 } | |
2501 } | |
2502 | |
2503 | |
2504 static gboolean | |
2505 playlist_get_info_is_going(void) | |
2506 { | |
2507 gboolean result; | |
2508 | |
2509 G_LOCK(playlist_get_info_going); | |
2510 result = playlist_get_info_going; | |
2511 G_UNLOCK(playlist_get_info_going); | |
2512 | |
2513 return result; | |
2514 } | |
2515 | |
3360
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2516 static gboolean |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2517 playlist_request_win_update(gpointer unused) |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2518 { |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2519 Playlist *playlist = playlist_get_active(); |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2520 playlistwin_update_list(playlist); |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2521 return FALSE; /* to be called only once */ |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2522 } |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2523 |
2313 | 2524 static gpointer |
2525 playlist_get_info_func(gpointer arg) | |
2526 { | |
2527 GList *node; | |
2528 gboolean update_playlistwin = FALSE; | |
2529 | |
2530 while (playlist_get_info_is_going()) { | |
2531 PlaylistEntry *entry; | |
2532 Playlist *playlist = playlist_get_active(); | |
2533 | |
2534 // on_load | |
2535 if (cfg.use_pl_metadata && | |
2536 cfg.get_info_on_load && | |
2537 playlist_get_info_scan_active) { | |
2538 | |
2539 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2540 entry = node->data; | |
2541 | |
2636 | 2542 if(playlist->attribute & PLAYLIST_STATIC || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2543 (entry->tuple && tuple_get_int(entry->tuple, "length") > -1 && tuple_get_int(entry->tuple, "mtime") != -1)) { |
2313 | 2544 update_playlistwin = TRUE; |
2545 continue; | |
2546 } | |
2547 | |
2548 if (!playlist_entry_get_info(entry)) { | |
2549 if (g_list_index(playlist->entries, entry) == -1) | |
2550 /* Entry disappeared while we looked it up. | |
2551 Restart. */ | |
2552 node = playlist->entries; | |
2553 } | |
2554 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2555 update_playlistwin = TRUE; | |
2556 break; | |
2557 } | |
2558 } | |
2559 | |
2560 if (!node) { | |
2561 g_mutex_lock(mutex_scan); | |
2562 playlist_get_info_scan_active = FALSE; | |
2563 g_mutex_unlock(mutex_scan); | |
2564 } | |
2565 } // on_load | |
2566 | |
2567 // on_demand | |
2568 else if (!cfg.get_info_on_load && | |
2569 cfg.get_info_on_demand && | |
2570 cfg.playlist_visible && | |
2571 !cfg.playlist_shaded && | |
2572 cfg.use_pl_metadata) { | |
2573 | |
2574 g_mutex_lock(mutex_scan); | |
2575 playlist_get_info_scan_active = FALSE; | |
2576 g_mutex_unlock(mutex_scan); | |
2577 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2578 for (node = g_list_nth(playlist->entries, playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2579 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2580 node = g_list_next(node)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2581 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2582 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2583 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2584 if(playlist->attribute & PLAYLIST_STATIC || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2585 (entry->tuple && tuple_get_int(entry->tuple, "length") > -1 && tuple_get_int(entry->tuple, "mtime") != -1)) { |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2586 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2587 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2588 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2589 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2590 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2591 if (g_list_index(playlist->entries, entry) == -1) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2592 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2593 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2594 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2595 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2596 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2597 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2598 update_playlistwin = TRUE; |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
2599 // no need for break here since this iteration is very short. |
2313 | 2600 } |
2601 } | |
2602 } // on_demand | |
2603 else if (cfg.get_info_on_demand && | |
2604 (!cfg.playlist_visible || cfg.playlist_shaded | |
2605 || !cfg.use_pl_metadata)) | |
2606 { | |
2607 g_mutex_lock(mutex_scan); | |
2608 playlist_get_info_scan_active = FALSE; | |
2609 g_mutex_unlock(mutex_scan); | |
2610 } | |
2611 else /* not on_demand and not on_load... | |
2612 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2613 { | |
2614 g_mutex_lock(mutex_scan); | |
2615 playlist_get_info_scan_active = FALSE; | |
2616 g_mutex_unlock(mutex_scan); | |
2617 } | |
2618 | |
2619 if (update_playlistwin) { | |
3360
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2620 /* we are in a different thread, so we can't do UI updates directly; |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2621 instead, schedule a playlist update in the main loop --giacomo */ |
8430c3911856
playlist_get_info_func works in a different thread, so trying to do UI updates from it eventually leads to UI freeze; fixed to schedule those updates in the main loop instead of doing them directly
Giacomo Lozito <james@develia.org>
parents:
3349
diff
changeset
|
2622 g_idle_add_full(G_PRIORITY_HIGH_IDLE, playlist_request_win_update, NULL, NULL); |
2313 | 2623 update_playlistwin = FALSE; |
2624 } | |
2625 | |
2626 if (playlist_get_info_scan_active) { | |
2627 continue; | |
2628 } | |
2629 | |
2630 g_mutex_lock(mutex_scan); | |
2631 g_cond_wait(cond_scan, mutex_scan); | |
2632 g_mutex_unlock(mutex_scan); | |
2633 | |
2634 } // while | |
2635 | |
2636 g_thread_exit(NULL); | |
2637 return NULL; | |
2638 } | |
2639 | |
2640 void | |
2641 playlist_start_get_info_thread(void) | |
2642 { | |
2643 G_LOCK(playlist_get_info_going); | |
2644 playlist_get_info_going = TRUE; | |
2645 G_UNLOCK(playlist_get_info_going); | |
2646 | |
2647 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2648 NULL, TRUE, NULL); | |
2649 } | |
2650 | |
2651 void | |
2652 playlist_stop_get_info_thread(void) | |
2653 { | |
2654 G_LOCK(playlist_get_info_going); | |
2655 playlist_get_info_going = FALSE; | |
2656 G_UNLOCK(playlist_get_info_going); | |
2657 | |
2658 g_cond_broadcast(cond_scan); | |
2659 g_thread_join(playlist_get_info_thread); | |
2660 } | |
2661 | |
2662 void | |
2663 playlist_start_get_info_scan(void) | |
2664 { | |
2665 g_mutex_lock(mutex_scan); | |
2666 playlist_get_info_scan_active = TRUE; | |
2667 g_mutex_unlock(mutex_scan); | |
2668 g_cond_signal(cond_scan); | |
2669 } | |
2670 | |
2671 void | |
2672 playlist_remove_dead_files(Playlist *playlist) | |
2673 { | |
2674 GList *node, *next_node; | |
2675 | |
2676 PLAYLIST_LOCK(playlist->mutex); | |
2677 | |
2678 for (node = playlist->entries; node; node = next_node) { | |
2679 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2680 next_node = g_list_next(node); | |
2681 | |
2682 if (!entry || !entry->filename) { | |
2683 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2684 continue; | |
2685 } | |
2686 | |
2687 /* FIXME: What about 'file:///'? */ | |
2688 /* Don't kill URLs */ | |
2689 if (strstr(entry->filename, "://")) | |
2690 continue; | |
2691 | |
2692 /* FIXME: Should test for readability */ | |
2693 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2694 continue; | |
2695 | |
2696 if (entry == playlist->position) { | |
2697 /* Don't remove the currently playing song */ | |
2698 if (playback_get_playing()) | |
2699 continue; | |
2700 | |
2701 if (next_node) | |
2702 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2703 else | |
2704 playlist->position = NULL; | |
2705 } | |
2706 | |
2707 playlist_entry_free(entry); | |
2708 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2709 } | |
2710 | |
2711 PLAYLIST_UNLOCK(playlist->mutex); | |
2712 | |
2713 playlist_generate_shuffle_list(playlist); | |
2714 playlistwin_update_list(playlist); | |
2715 playlist_recalc_total_time(playlist); | |
2716 playlist_manager_update(); | |
2717 } | |
2718 | |
2719 | |
2720 static gint | |
2721 playlist_dupscmp_title(PlaylistEntry * a, | |
2722 PlaylistEntry * b) | |
2723 { | |
2724 const gchar *a_title, *b_title; | |
2725 | |
2726 g_return_val_if_fail(a != NULL, 0); | |
2727 g_return_val_if_fail(b != NULL, 0); | |
2728 | |
2729 if (a->title) | |
2730 a_title = a->title; | |
2731 else { | |
2732 if (strrchr(a->filename, '/')) | |
2733 a_title = strrchr(a->filename, '/') + 1; | |
2734 else | |
2735 a_title = a->filename; | |
2736 } | |
2737 | |
2738 if (b->title) | |
2739 b_title = b->title; | |
2740 else { | |
2741 if (strrchr(a->filename, '/')) | |
2742 b_title = strrchr(b->filename, '/') + 1; | |
2743 else | |
2744 b_title = b->filename; | |
2745 } | |
2746 | |
2747 return strcmp(a_title, b_title); | |
2748 } | |
2749 | |
2750 static gint | |
2751 playlist_dupscmp_filename(PlaylistEntry * a, | |
2752 PlaylistEntry * b ) | |
2753 { | |
2754 gchar *a_filename, *b_filename; | |
2755 | |
2756 g_return_val_if_fail(a != NULL, 0); | |
2757 g_return_val_if_fail(b != NULL, 0); | |
2758 | |
2759 if (strrchr(a->filename, '/')) | |
2760 a_filename = strrchr(a->filename, '/') + 1; | |
2761 else | |
2762 a_filename = a->filename; | |
2763 | |
2764 if (strrchr(b->filename, '/')) | |
2765 b_filename = strrchr(b->filename, '/') + 1; | |
2766 else | |
2767 b_filename = b->filename; | |
2768 | |
2769 return strcmp(a_filename, b_filename); | |
2770 } | |
2771 | |
2772 static gint | |
2773 playlist_dupscmp_path(PlaylistEntry * a, | |
2774 PlaylistEntry * b) | |
2775 { | |
2776 /* simply compare the entire filename string */ | |
2777 return strcmp(a->filename, b->filename); | |
2778 } | |
2779 | |
2780 void | |
2781 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2782 { | |
2783 GList *node, *next_node; | |
2784 GList *node_cmp, *next_node_cmp; | |
2785 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2786 | |
2787 switch ( type ) | |
2788 { | |
2789 case PLAYLIST_DUPS_TITLE: | |
2790 dups_compare_func = playlist_dupscmp_title; | |
2791 break; | |
2792 case PLAYLIST_DUPS_PATH: | |
2793 dups_compare_func = playlist_dupscmp_path; | |
2794 break; | |
2795 case PLAYLIST_DUPS_FILENAME: | |
2796 default: | |
2797 dups_compare_func = playlist_dupscmp_filename; | |
2798 break; | |
2799 } | |
2800 | |
2801 PLAYLIST_LOCK(playlist->mutex); | |
2802 | |
2803 for (node = playlist->entries; node; node = next_node) { | |
2804 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2805 next_node = g_list_next(node); | |
2806 | |
2807 if (!entry || !entry->filename) { | |
2808 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2809 continue; | |
2810 } | |
2811 | |
2812 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2813 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2814 next_node_cmp = g_list_next(node_cmp); | |
2815 | |
2816 if (!entry_cmp || !entry_cmp->filename) { | |
2817 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2818 continue; | |
2819 } | |
2820 | |
2821 /* compare using the chosen dups_compare_func */ | |
2822 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2823 | |
2824 if (entry_cmp == playlist->position) { | |
2825 /* Don't remove the currently playing song */ | |
2826 if (playback_get_playing()) | |
2827 continue; | |
2828 | |
2829 if (next_node_cmp) | |
2830 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2831 else | |
2832 playlist->position = NULL; | |
2833 } | |
2834 | |
2835 /* check if this was the next item of the external | |
2836 loop; if true, replace it with the next of the next*/ | |
2837 if ( node_cmp == next_node ) | |
2838 next_node = g_list_next(next_node); | |
2839 | |
2840 playlist_entry_free(entry_cmp); | |
2841 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2842 } | |
2843 } | |
2844 } | |
2845 | |
2846 PLAYLIST_UNLOCK(playlist->mutex); | |
2847 | |
2848 playlistwin_update_list(playlist); | |
2849 playlist_recalc_total_time(playlist); | |
2850 | |
2851 playlist_manager_update(); | |
2852 } | |
2853 | |
2854 void | |
2855 playlist_get_total_time(Playlist * playlist, | |
2856 gulong * total_time, | |
2857 gulong * selection_time, | |
2858 gboolean * total_more, | |
2859 gboolean * selection_more) | |
2860 { | |
2861 PLAYLIST_LOCK(playlist->mutex); | |
2862 *total_time = playlist->pl_total_time; | |
2863 *selection_time = playlist->pl_selection_time; | |
2864 *total_more = playlist->pl_total_more; | |
2865 *selection_more = playlist->pl_selection_more; | |
2866 PLAYLIST_UNLOCK(playlist->mutex); | |
2867 } | |
2868 | |
2869 | |
2870 static void | |
2871 playlist_recalc_total_time_nolock(Playlist *playlist) | |
2872 { | |
2873 GList *list; | |
2874 PlaylistEntry *entry; | |
2875 | |
2876 REQUIRE_LOCK(playlist->mutex); | |
2877 | |
2878 playlist->pl_total_time = 0; | |
2879 playlist->pl_selection_time = 0; | |
2880 playlist->pl_total_more = FALSE; | |
2881 playlist->pl_selection_more = FALSE; | |
2882 | |
2883 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2884 entry = list->data; | |
2885 | |
2886 if (entry->length != -1) | |
2887 playlist->pl_total_time += entry->length / 1000; | |
2888 else | |
2889 playlist->pl_total_more = TRUE; | |
2890 | |
2891 if (entry->selected) { | |
2892 if (entry->length != -1) | |
2893 playlist->pl_selection_time += entry->length / 1000; | |
2894 else | |
2895 playlist->pl_selection_more = TRUE; | |
2896 } | |
2897 } | |
2898 } | |
2899 | |
2900 static void | |
2901 playlist_recalc_total_time(Playlist *playlist) | |
2902 { | |
2903 PLAYLIST_LOCK(playlist->mutex); | |
2904 playlist_recalc_total_time_nolock(playlist); | |
2905 PLAYLIST_UNLOCK(playlist->mutex); | |
2906 } | |
2907 | |
2908 gint | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2909 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) |
2313 | 2910 { |
2911 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2912 gboolean is_first_search = TRUE; | |
2913 gint num_of_entries_found = 0; | |
2914 | |
2915 #if defined(USE_REGEX_ONIGURUMA) | |
2916 /* set encoding for Oniguruma regex to UTF-8 */ | |
2917 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2918 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
2919 #endif | |
2920 | |
2921 PLAYLIST_LOCK(playlist->mutex); | |
2922 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2923 if ( tuple_get_string(tuple, "title") != NULL ) |
2313 | 2924 { |
2925 /* match by track_name */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2926 const gchar *regex_pattern = tuple_get_string(tuple, "title"); |
2313 | 2927 regex_t regex; |
2928 #if defined(USE_REGEX_PCRE) | |
2929 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2930 #else | |
2931 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2932 #endif | |
2933 { | |
2934 GList *tfound_list = NULL; | |
2935 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2936 else entry_list = found_list; /* use found_list */ | |
2937 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2938 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2939 const gchar *track_name = tuple_get_string( tuple, "title" ); |
2313 | 2940 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2941 if ( ( entry->tuple != NULL ) && ( track_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2942 ( regexec( ®ex , track_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2943 { |
2944 tfound_list = g_list_append( tfound_list , entry ); | |
2945 } | |
2946 } | |
2947 g_list_free( found_list ); /* wipe old found_list */ | |
2948 found_list = tfound_list; /* move tfound_list in found_list */ | |
2949 regfree( ®ex ); | |
2950 } | |
2951 is_first_search = FALSE; | |
2952 } | |
2953 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2954 if ( tuple_get_string(tuple, "album") != NULL ) |
2313 | 2955 { |
2956 /* match by album_name */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2957 const gchar *regex_pattern = tuple_get_string(tuple, "album"); |
2313 | 2958 regex_t regex; |
2959 #if defined(USE_REGEX_PCRE) | |
2960 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2961 #else | |
2962 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2963 #endif | |
2964 { | |
2965 GList *tfound_list = NULL; | |
2966 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2967 else entry_list = found_list; /* use found_list */ | |
2968 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2969 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2970 const gchar *album_name = tuple_get_string( tuple, "album" ); |
2313 | 2971 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2972 if ( ( entry->tuple != NULL ) && ( album_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2973 ( regexec( ®ex , album_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2974 { |
2975 tfound_list = g_list_append( tfound_list , entry ); | |
2976 } | |
2977 } | |
2978 g_list_free( found_list ); /* wipe old found_list */ | |
2979 found_list = tfound_list; /* move tfound_list in found_list */ | |
2980 regfree( ®ex ); | |
2981 } | |
2982 is_first_search = FALSE; | |
2983 } | |
2984 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2985 if ( tuple_get_string(tuple, "artist") != NULL ) |
2313 | 2986 { |
2987 /* match by performer */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2988 const gchar *regex_pattern = tuple_get_string(tuple, "artist"); |
2313 | 2989 regex_t regex; |
2990 #if defined(USE_REGEX_PCRE) | |
2991 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2992 #else | |
2993 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2994 #endif | |
2995 { | |
2996 GList *tfound_list = NULL; | |
2997 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2998 else entry_list = found_list; /* use found_list */ | |
2999 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3000 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3001 const gchar *performer = tuple_get_string( tuple, "performer" ); |
2313 | 3002 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3003 if ( ( entry->tuple != NULL ) && ( performer != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3004 ( regexec( ®ex , performer , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3005 { |
3006 tfound_list = g_list_append( tfound_list , entry ); | |
3007 } | |
3008 } | |
3009 g_list_free( found_list ); /* wipe old found_list */ | |
3010 found_list = tfound_list; /* move tfound_list in found_list */ | |
3011 regfree( ®ex ); | |
3012 } | |
3013 is_first_search = FALSE; | |
3014 } | |
3015 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3016 if ( tuple_get_string(tuple, "file-name") != NULL ) |
2313 | 3017 { |
3018 /* match by file_name */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3019 const gchar *regex_pattern = tuple_get_string(tuple, "file-name"); |
2313 | 3020 regex_t regex; |
3021 #if defined(USE_REGEX_PCRE) | |
3022 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
3023 #else | |
3024 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
3025 #endif | |
3026 { | |
3027 GList *tfound_list = NULL; | |
3028 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3029 else entry_list = found_list; /* use found_list */ | |
3030 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3031 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3032 const gchar *file_name = tuple_get_string( tuple, "file-name" ); |
2313 | 3033 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3034 if ( ( entry->tuple != NULL ) && ( file_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3035 ( regexec( ®ex , file_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3036 { |
3037 tfound_list = g_list_append( tfound_list , entry ); | |
3038 } | |
3039 } | |
3040 g_list_free( found_list ); /* wipe old found_list */ | |
3041 found_list = tfound_list; /* move tfound_list in found_list */ | |
3042 regfree( ®ex ); | |
3043 } | |
3044 is_first_search = FALSE; | |
3045 } | |
3046 | |
3047 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
3048 /* if some entries are still in found_list, those | |
3049 are what the user is searching for; select them */ | |
3050 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
3051 { | |
3052 PlaylistEntry *entry = sel_list->data; | |
3053 entry->selected = TRUE; | |
3054 num_of_entries_found++; | |
3055 } | |
3056 | |
3057 g_list_free( found_list ); | |
3058 | |
3059 PLAYLIST_UNLOCK(playlist->mutex); | |
3060 playlist_recalc_total_time(playlist); | |
3061 | |
3062 return num_of_entries_found; | |
3063 } | |
3064 | |
3065 void | |
3066 playlist_select_all(Playlist *playlist, gboolean set) | |
3067 { | |
3068 GList *list; | |
3069 | |
3070 PLAYLIST_LOCK(playlist->mutex); | |
3071 | |
3072 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3073 PlaylistEntry *entry = list->data; | |
3074 entry->selected = set; | |
3075 } | |
3076 | |
3077 PLAYLIST_UNLOCK(playlist->mutex); | |
3078 playlist_recalc_total_time(playlist); | |
3079 } | |
3080 | |
3081 void | |
3082 playlist_select_invert_all(Playlist *playlist) | |
3083 { | |
3084 GList *list; | |
3085 | |
3086 PLAYLIST_LOCK(playlist->mutex); | |
3087 | |
3088 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3089 PlaylistEntry *entry = list->data; | |
3090 entry->selected = !entry->selected; | |
3091 } | |
3092 | |
3093 PLAYLIST_UNLOCK(playlist->mutex); | |
3094 playlist_recalc_total_time(playlist); | |
3095 } | |
3096 | |
3097 gboolean | |
3098 playlist_select_invert(Playlist *playlist, guint pos) | |
3099 { | |
3100 GList *list; | |
3101 gboolean invert_ok = FALSE; | |
3102 | |
3103 PLAYLIST_LOCK(playlist->mutex); | |
3104 | |
3105 if ((list = g_list_nth(playlist->entries, pos))) { | |
3106 PlaylistEntry *entry = list->data; | |
3107 entry->selected = !entry->selected; | |
3108 invert_ok = TRUE; | |
3109 } | |
3110 | |
3111 PLAYLIST_UNLOCK(playlist->mutex); | |
3112 playlist_recalc_total_time(playlist); | |
3113 | |
3114 return invert_ok; | |
3115 } | |
3116 | |
3117 | |
3118 void | |
3119 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3120 { | |
3121 GList *list; | |
3122 gint i; | |
3123 | |
3124 if (min_pos > max_pos) | |
3125 SWAP(min_pos, max_pos); | |
3126 | |
3127 PLAYLIST_LOCK(playlist->mutex); | |
3128 | |
3129 list = g_list_nth(playlist->entries, min_pos); | |
3130 for (i = min_pos; i <= max_pos && list; i++) { | |
3131 PlaylistEntry *entry = list->data; | |
3132 entry->selected = select; | |
3133 list = g_list_next(list); | |
3134 } | |
3135 | |
3136 PLAYLIST_UNLOCK(playlist->mutex); | |
3137 | |
3138 playlist_recalc_total_time(playlist); | |
3139 } | |
3140 | |
3141 gboolean | |
3142 playlist_read_info_selection(Playlist *playlist) | |
3143 { | |
3144 GList *node; | |
3145 gboolean retval = FALSE; | |
3146 | |
3147 PLAYLIST_LOCK(playlist->mutex); | |
3148 | |
3149 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3150 PlaylistEntry *entry = node->data; | |
3151 if (!entry->selected) | |
3152 continue; | |
3153 | |
3154 retval = TRUE; | |
3155 | |
3156 str_replace_in(&entry->title, NULL); | |
3157 entry->length = -1; | |
3158 | |
3159 /* invalidate mtime to reread */ | |
3160 if (entry->tuple != NULL) | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3161 tuple_associate_int(entry->tuple, "mtime", -1); /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
2313 | 3162 |
3163 if (!playlist_entry_get_info(entry)) { | |
3164 if (g_list_index(playlist->entries, entry) == -1) | |
3165 /* Entry disappeared while we looked it up. Restart. */ | |
3166 node = playlist->entries; | |
3167 } | |
3168 } | |
3169 | |
3170 PLAYLIST_UNLOCK(playlist->mutex); | |
3171 | |
3172 playlistwin_update_list(playlist); | |
3173 playlist_recalc_total_time(playlist); | |
3174 | |
3175 return retval; | |
3176 } | |
3177 | |
3178 void | |
3179 playlist_read_info(Playlist *playlist, guint pos) | |
3180 { | |
3181 GList *node; | |
3182 | |
3183 PLAYLIST_LOCK(playlist->mutex); | |
3184 | |
3185 if ((node = g_list_nth(playlist->entries, pos))) { | |
3186 PlaylistEntry *entry = node->data; | |
3187 str_replace_in(&entry->title, NULL); | |
3188 entry->length = -1; | |
3189 playlist_entry_get_info(entry); | |
3190 } | |
3191 | |
3192 PLAYLIST_UNLOCK(playlist->mutex); | |
3193 | |
3194 playlistwin_update_list(playlist); | |
3195 playlist_recalc_total_time(playlist); | |
3196 } | |
3197 | |
3198 Playlist * | |
3199 playlist_get_active(void) | |
3200 { | |
3201 if (playlists_iter != NULL) | |
3202 return (Playlist *) playlists_iter->data; | |
3203 | |
2736 | 3204 if (playlists) |
3205 return (Playlist *) playlists->data; | |
3206 | |
3207 return NULL; | |
2313 | 3208 } |
3209 | |
3210 void | |
3211 playlist_set_shuffle(gboolean shuffle) | |
3212 { | |
3213 Playlist *playlist = playlist_get_active(); | |
3214 if (!playlist) | |
3215 return; | |
3216 | |
3217 PLAYLIST_LOCK(playlist->mutex); | |
3218 | |
3219 playlist_position_before_jump = NULL; | |
3220 | |
3221 cfg.shuffle = shuffle; | |
3222 playlist_generate_shuffle_list_nolock(playlist); | |
3223 | |
3224 PLAYLIST_UNLOCK(playlist->mutex); | |
3225 } | |
3226 | |
3227 Playlist * | |
3228 playlist_new(void) | |
3229 { | |
3230 Playlist *playlist = g_new0(Playlist, 1); | |
3231 playlist->mutex = g_mutex_new(); | |
3232 playlist->loading_playlist = FALSE; | |
3233 | |
3234 playlist_set_current_name(playlist, NULL); | |
3235 playlist_clear(playlist); | |
3236 | |
3237 return playlist; | |
3238 } | |
3239 | |
3240 void | |
3241 playlist_free(Playlist *playlist) | |
3242 { | |
3243 g_mutex_free( playlist->mutex ); | |
3244 g_free( playlist ); | |
3245 return; | |
3246 } | |
3247 | |
3248 Playlist * | |
3249 playlist_new_from_selected(void) | |
3250 { | |
3251 Playlist *newpl = playlist_new(); | |
3252 Playlist *playlist = playlist_get_active(); | |
3253 GList *list = playlist_get_selected(playlist); | |
3254 | |
3255 playlist_add_playlist( newpl ); | |
3256 | |
3257 PLAYLIST_LOCK(playlist->mutex); | |
3258 | |
3259 while ( list != NULL ) | |
3260 { | |
3261 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3262 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3263 playlist_add( newpl , entry->filename ); | |
3264 list = g_list_next(list); | |
3265 } | |
3266 | |
3267 PLAYLIST_UNLOCK(playlist->mutex); | |
3268 | |
3269 playlist_recalc_total_time(newpl); | |
3270 playlistwin_update_list(playlist); | |
3271 | |
3272 return newpl; | |
3273 } | |
3274 | |
3275 const gchar * | |
3276 playlist_get_filename_to_play(Playlist *playlist) | |
3277 { | |
3278 const gchar *filename = NULL; | |
3279 | |
3280 if (!playlist) | |
3281 return NULL; | |
3282 | |
3283 PLAYLIST_LOCK(playlist->mutex); | |
3284 | |
3285 if (!playlist->position) { | |
3286 if (cfg.shuffle) | |
3287 playlist->position = playlist->shuffle->data; | |
3288 else | |
3289 playlist->position = playlist->entries->data; | |
3290 } | |
3291 | |
3292 filename = playlist->position->filename; | |
3293 | |
3294 PLAYLIST_UNLOCK(playlist->mutex); | |
3295 | |
3296 return filename; | |
3297 } | |
3298 | |
3299 PlaylistEntry * | |
3300 playlist_get_entry_to_play(Playlist *playlist) | |
3301 { | |
3302 if (!playlist) | |
3303 return NULL; | |
3304 | |
3305 PLAYLIST_LOCK(playlist->mutex); | |
3306 | |
3307 if (!playlist->position) { | |
3308 if (cfg.shuffle) | |
3309 playlist->position = playlist->shuffle->data; | |
3310 else | |
3311 playlist->position = playlist->entries->data; | |
3312 } | |
3313 | |
3314 PLAYLIST_UNLOCK(playlist->mutex); | |
3315 | |
3316 return playlist->position; | |
3317 } | |
3474
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3318 |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3319 gboolean |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3320 playlist_playlists_equal(Playlist *p1, Playlist *p2) |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3321 { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3322 GList *l1, *l2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3323 PlaylistEntry *e1, *e2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3324 if (!p1 || !p2) return FALSE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3325 l1 = p1->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3326 l2 = p2->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3327 do { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3328 if (!l1 && !l2) break; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3329 if (!l1 || !l2) return FALSE; /* different length */ |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3330 e1 = (PlaylistEntry *) l1->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3331 e2 = (PlaylistEntry *) l2->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3332 if (strcmp(e1->filename, e2->filename) != 0) return FALSE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3333 l1 = l1->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3334 l2 = l2->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3335 } while(1); |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3336 return TRUE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3337 } |