Mercurial > audlegacy
annotate src/audacious/playlist.c @ 3476:9152829f3c19 trunk
Allow non-active playlist to be saved to file
author | Kieran Clancy <clancy.kieran+audacious@gmail.com> |
---|---|
date | Mon, 10 Sep 2007 13:47:16 +0930 |
parents | adc785ee517b |
children | 57f4971b7086 |
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; | |
3476
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1571 GList *old_iter; |
2313 | 1572 gchar *ext; |
1573 | |
1574 g_return_val_if_fail(playlist != NULL, FALSE); | |
1575 g_return_val_if_fail(filename != NULL, FALSE); | |
1576 | |
1577 ext = strrchr(filename, '.') + 1; | |
1578 | |
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
|
1579 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
|
1580 playlist_set_current_name(playlist, filename); |
2313 | 1581 |
1582 if ((plc = playlist_container_find(ext)) == NULL) | |
1583 return FALSE; | |
1584 | |
1585 if (plc->plc_write == NULL) | |
1586 return FALSE; | |
1587 | |
3476
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1588 /* Save the right playlist to disk */ |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1589 if (playlist != playlist_get_active()) { |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1590 old_iter = playlists_iter; |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1591 playlists_iter = g_list_find(playlists, playlist); |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1592 if(!playlists_iter) playlists_iter = old_iter; |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1593 plc->plc_write(filename, 0); |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1594 playlists_iter = old_iter; |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1595 } else { |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1596 plc->plc_write(filename, 0); |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1597 } |
2313 | 1598 |
1599 return TRUE; | |
1600 } | |
1601 | |
1602 gboolean | |
1603 playlist_load(Playlist * playlist, const gchar * filename) | |
1604 { | |
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
|
1605 guint ret = 0; |
2313 | 1606 g_return_val_if_fail(playlist != NULL, FALSE); |
1607 | |
1608 playlist->loading_playlist = TRUE; | |
1609 ret = playlist_load_ins(playlist, filename, -1); | |
1610 playlist->loading_playlist = FALSE; | |
1611 | |
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
|
1612 return ret ? TRUE : FALSE; |
2313 | 1613 } |
1614 | |
1615 void | |
1616 playlist_load_ins_file(Playlist *playlist, | |
1617 const gchar * filename_p, | |
1618 const gchar * playlist_name, gint pos, | |
1619 const gchar * title, gint len) | |
1620 { | |
1621 gchar *filename; | |
1622 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1623 ProbeResult *pr = NULL; |
2313 | 1624 |
1625 g_return_if_fail(filename_p != NULL); | |
1626 g_return_if_fail(playlist != NULL); | |
1627 g_return_if_fail(playlist_name != NULL); | |
1628 | |
1629 filename = g_strchug(g_strdup(filename_p)); | |
1630 | |
1631 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
|
1632 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
|
1633 *tmp = '/'; |
2313 | 1634 |
1635 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1636 path = g_strdup(playlist_name); | |
1637 if ((tmp = strrchr(path, '/'))) | |
1638 *tmp = '\0'; | |
1639 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1640 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1641 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1642 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1643 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
|
1644 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1645 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1646 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1647 __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
|
1648 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1649 g_free(pr); |
2313 | 1650 return; |
1651 } | |
1652 tmp = g_build_filename(path, filename, NULL); | |
1653 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1654 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
|
1655 pr = NULL; |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1656 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
|
1657 !str_has_prefix_nocase(tmp, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1658 pr = input_check_file(tmp, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1659 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
1660 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
2313 | 1661 g_free(tmp); |
1662 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1663 g_free(pr); |
2313 | 1664 } |
1665 else | |
1666 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1667 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1668 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1669 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1670 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
|
1671 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1672 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1673 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1674 __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
|
1675 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1676 g_free(pr); |
2313 | 1677 } |
1678 | |
1679 g_free(filename); | |
1680 } | |
1681 | |
1682 void | |
1683 playlist_load_ins_file_tuple(Playlist * playlist, | |
1684 const gchar * filename_p, | |
1685 const gchar * playlist_name, | |
1686 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1687 Tuple *tuple) |
2313 | 1688 { |
1689 gchar *filename; | |
1690 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1691 ProbeResult *pr = NULL; /* for decoder cache */ |
2313 | 1692 |
1693 g_return_if_fail(filename_p != NULL); | |
1694 g_return_if_fail(playlist_name != NULL); | |
1695 g_return_if_fail(playlist != NULL); | |
1696 | |
1697 filename = g_strchug(g_strdup(filename_p)); | |
1698 | |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1699 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
|
1700 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
|
1701 *tmp = '/'; |
2313 | 1702 |
1703 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1704 path = g_strdup(playlist_name); | |
1705 if ((tmp = strrchr(path, '/'))) | |
1706 *tmp = '\0'; | |
1707 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1708 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1709 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1710 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1711 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
|
1712 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1713 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1714 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1715 __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
|
1716 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1717 g_free(pr); |
2313 | 1718 return; |
1719 } | |
1720 tmp = g_build_filename(path, filename, NULL); | |
1721 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1722 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1723 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1724 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1725 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
|
1726 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1727 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1728 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1729 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
2313 | 1730 g_free(tmp); |
1731 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1732 g_free(pr); |
2313 | 1733 } |
1734 else | |
1735 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1736 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1737 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1738 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1739 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
|
1740 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1741 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1742 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1743 __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
|
1744 g_free(pr); |
2313 | 1745 } |
1746 | |
1747 g_free(filename); | |
1748 } | |
1749 | |
1750 static guint | |
1751 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1752 { | |
1753 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
|
1754 GList *old_iter; |
2313 | 1755 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
|
1756 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
|
1757 |
2313 | 1758 g_return_val_if_fail(playlist != NULL, 0); |
1759 g_return_val_if_fail(filename != NULL, 0); | |
1760 | |
1761 ext = strrchr(filename, '.') + 1; | |
1762 plc = playlist_container_find(ext); | |
1763 | |
1764 g_return_val_if_fail(plc != NULL, 0); | |
1765 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1766 | |
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
|
1767 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
|
1768 /* 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
|
1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 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
|
1774 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
|
1775 } 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
|
1776 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
|
1777 } |
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
|
1778 new_len = playlist_get_length(playlist); |
2313 | 1779 |
1780 playlist_generate_shuffle_list(playlist); | |
1781 playlistwin_update_list(playlist); | |
1782 | |
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
|
1783 return new_len - old_len; |
2313 | 1784 } |
1785 | |
1786 GList * | |
1787 get_playlist_nth(Playlist *playlist, guint nth) | |
1788 { | |
1789 g_warning("deprecated function get_playlist_nth() was called"); | |
1790 REQUIRE_LOCK(playlist->mutex); | |
1791 return g_list_nth(playlist->entries, nth); | |
1792 } | |
1793 | |
1794 gint | |
1795 playlist_get_position_nolock(Playlist *playlist) | |
1796 { | |
1797 if (playlist && playlist->position) | |
1798 return g_list_index(playlist->entries, playlist->position); | |
1799 return 0; | |
1800 } | |
1801 | |
1802 gint | |
1803 playlist_get_position(Playlist *playlist) | |
1804 { | |
1805 gint pos; | |
1806 | |
1807 PLAYLIST_LOCK(playlist->mutex); | |
1808 pos = playlist_get_position_nolock(playlist); | |
1809 PLAYLIST_UNLOCK(playlist->mutex); | |
1810 | |
1811 return pos; | |
1812 } | |
1813 | |
1814 gchar * | |
1815 playlist_get_filename(Playlist *playlist, guint pos) | |
1816 { | |
1817 gchar *filename; | |
1818 PlaylistEntry *entry; | |
1819 GList *node; | |
1820 | |
1821 if (!playlist) | |
1822 return NULL; | |
1823 | |
1824 PLAYLIST_LOCK(playlist->mutex); | |
1825 node = g_list_nth(playlist->entries, pos); | |
1826 if (!node) { | |
1827 PLAYLIST_UNLOCK(playlist->mutex); | |
1828 return NULL; | |
1829 } | |
1830 entry = node->data; | |
1831 | |
1832 filename = g_strdup(entry->filename); | |
1833 PLAYLIST_UNLOCK(playlist->mutex); | |
1834 | |
1835 return filename; | |
1836 } | |
1837 | |
1838 gchar * | |
1839 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1840 { | |
1841 gchar *title = NULL; | |
1842 PlaylistEntry *entry; | |
1843 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1844 time_t mtime; |
2313 | 1845 |
1846 if (!playlist) | |
1847 return NULL; | |
1848 | |
1849 PLAYLIST_LOCK(playlist->mutex); | |
1850 | |
1851 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1852 PLAYLIST_UNLOCK(playlist->mutex); | |
1853 return NULL; | |
1854 } | |
1855 | |
1856 entry = node->data; | |
1857 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1858 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1859 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
|
1860 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1861 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1862 |
2313 | 1863 /* FIXME: simplify this logic */ |
1864 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
|
1865 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1866 { |
1867 if (playlist_entry_get_info(entry)) | |
1868 title = entry->title; | |
1869 } | |
1870 else { | |
1871 title = entry->title; | |
1872 } | |
1873 | |
1874 PLAYLIST_UNLOCK(playlist->mutex); | |
1875 | |
1876 if (!title) { | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1877 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1878 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
|
1879 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
|
1880 g_free(realfn); realfn = NULL; |
2313 | 1881 return str_replace(title, filename_to_utf8(title)); |
1882 } | |
1883 | |
1884 return str_to_utf8(title); | |
1885 } | |
1886 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1887 Tuple * |
2313 | 1888 playlist_get_tuple(Playlist *playlist, guint pos) |
1889 { | |
1890 PlaylistEntry *entry; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1891 Tuple *tuple = NULL; |
2313 | 1892 GList *node; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1893 time_t mtime; |
2313 | 1894 |
1895 if (!playlist) | |
1896 return NULL; | |
1897 | |
1898 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1899 return NULL; | |
1900 } | |
1901 | |
1902 entry = (PlaylistEntry *) node->data; | |
1903 | |
1904 tuple = entry->tuple; | |
1905 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1906 if (tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1907 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
|
1908 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1909 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1910 |
2313 | 1911 // if no tuple or tuple with old mtime, get new one. |
1912 if (tuple == NULL || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1913 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1914 { |
1915 playlist_entry_get_info(entry); | |
1916 tuple = entry->tuple; | |
1917 } | |
1918 | |
1919 return tuple; | |
1920 } | |
1921 | |
1922 gint | |
1923 playlist_get_songtime(Playlist *playlist, guint pos) | |
1924 { | |
1925 gint song_time = -1; | |
1926 PlaylistEntry *entry; | |
1927 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1928 time_t mtime; |
2313 | 1929 |
1930 if (!playlist) | |
1931 return -1; | |
1932 | |
1933 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1934 return -1; | |
1935 } | |
1936 | |
1937 entry = node->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1938 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1939 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1940 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
|
1941 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1942 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1943 |
2313 | 1944 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
|
1945 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { |
2313 | 1946 |
1947 if (playlist_entry_get_info(entry)) | |
1948 song_time = entry->length; | |
1949 } | |
1950 else { | |
1951 song_time = entry->length; | |
1952 } | |
1953 | |
1954 return song_time; | |
1955 } | |
1956 | |
1957 static gint | |
1958 playlist_compare_track(PlaylistEntry * a, | |
1959 PlaylistEntry * b) | |
1960 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1961 gint tracknumber_a; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1962 gint tracknumber_b; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1963 |
2313 | 1964 g_return_val_if_fail(a != NULL, 0); |
1965 g_return_val_if_fail(b != NULL, 0); | |
1966 | |
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
|
1967 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
|
1968 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
|
1969 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
|
1970 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
|
1971 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1972 if (a->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1973 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1974 if (b->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1975 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1976 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1977 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
|
1978 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
|
1979 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1980 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
|
1981 tracknumber_a - tracknumber_b : 0); |
2313 | 1982 } |
1983 | |
1984 static gint | |
1985 playlist_compare_playlist(PlaylistEntry * a, | |
1986 PlaylistEntry * b) | |
1987 { | |
1988 const gchar *a_title = NULL, *b_title = NULL; | |
1989 | |
1990 g_return_val_if_fail(a != NULL, 0); | |
1991 g_return_val_if_fail(b != NULL, 0); | |
1992 | |
1993 if (a->title != NULL) | |
1994 a_title = a->title; | |
1995 else { | |
1996 if (strrchr(a->filename, '/')) | |
1997 a_title = strrchr(a->filename, '/') + 1; | |
1998 else | |
1999 a_title = a->filename; | |
2000 } | |
2001 | |
2002 if (b->title != NULL) | |
2003 b_title = b->title; | |
2004 else { | |
2005 if (strrchr(a->filename, '/')) | |
2006 b_title = strrchr(b->filename, '/') + 1; | |
2007 else | |
2008 b_title = b->filename; | |
2009 } | |
2010 | |
2011 return strcasecmp(a_title, b_title); | |
2012 } | |
2013 | |
2014 static gint | |
2015 playlist_compare_title(PlaylistEntry * a, | |
2016 PlaylistEntry * b) | |
2017 { | |
2018 const gchar *a_title = NULL, *b_title = NULL; | |
2019 | |
2020 g_return_val_if_fail(a != NULL, 0); | |
2021 g_return_val_if_fail(b != NULL, 0); | |
2022 | |
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
|
2023 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
|
2024 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
|
2025 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
|
2026 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
|
2027 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2028 if (a->tuple != NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2029 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
|
2030 if (b->tuple != NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2031 b_title = tuple_get_string(b->tuple, "title"); |
2313 | 2032 |
2033 if (a_title != NULL && b_title != NULL) | |
2034 return strcasecmp(a_title, b_title); | |
2035 | |
2036 if (a->title != NULL) | |
2037 a_title = a->title; | |
2038 else { | |
2039 if (strrchr(a->filename, '/')) | |
2040 a_title = strrchr(a->filename, '/') + 1; | |
2041 else | |
2042 a_title = a->filename; | |
2043 } | |
2044 | |
2045 if (b->title != NULL) | |
2046 b_title = b->title; | |
2047 else { | |
2048 if (strrchr(a->filename, '/')) | |
2049 b_title = strrchr(b->filename, '/') + 1; | |
2050 else | |
2051 b_title = b->filename; | |
2052 } | |
2053 | |
2054 return strcasecmp(a_title, b_title); | |
2055 } | |
2056 | |
2057 static gint | |
2058 playlist_compare_artist(PlaylistEntry * a, | |
2059 PlaylistEntry * b) | |
2060 { | |
2061 const gchar *a_artist = NULL, *b_artist = NULL; | |
2062 | |
2063 g_return_val_if_fail(a != NULL, 0); | |
2064 g_return_val_if_fail(b != NULL, 0); | |
2065 | |
2066 if (a->tuple != NULL) | |
2067 playlist_entry_get_info(a); | |
2068 | |
2069 if (b->tuple != NULL) | |
2070 playlist_entry_get_info(b); | |
2071 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2072 if (a->tuple != NULL) { |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2073 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
|
2074 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
|
2075 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2076 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2077 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2078 if (b->tuple != NULL) { |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2079 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
|
2080 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
|
2081 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2082 } |
2313 | 2083 |
2084 if (a_artist != NULL && b_artist != NULL) | |
2085 return strcasecmp(a_artist, b_artist); | |
2086 | |
2087 return 0; | |
2088 } | |
2089 | |
2090 static gint | |
2091 playlist_compare_filename(PlaylistEntry * a, | |
2092 PlaylistEntry * b) | |
2093 { | |
2094 gchar *a_filename, *b_filename; | |
2095 | |
2096 g_return_val_if_fail(a != NULL, 0); | |
2097 g_return_val_if_fail(b != NULL, 0); | |
2098 | |
2099 if (strrchr(a->filename, '/')) | |
2100 a_filename = strrchr(a->filename, '/') + 1; | |
2101 else | |
2102 a_filename = a->filename; | |
2103 | |
2104 if (strrchr(b->filename, '/')) | |
2105 b_filename = strrchr(b->filename, '/') + 1; | |
2106 else | |
2107 b_filename = b->filename; | |
2108 | |
2109 | |
2110 return strcasecmp(a_filename, b_filename); | |
2111 } | |
2112 | |
2113 static gint | |
2114 path_compare(const gchar * a, const gchar * b) | |
2115 { | |
2116 gchar *posa, *posb; | |
2117 gint len, ret; | |
2118 | |
2119 posa = strrchr(a, '/'); | |
2120 posb = strrchr(b, '/'); | |
2121 | |
2122 /* | |
2123 * Sort directories before files | |
2124 */ | |
2125 if (posa && posb && (posa - a != posb - b)) { | |
2126 if (posa - a > posb - b) { | |
2127 len = posb - b; | |
2128 ret = -1; | |
2129 } | |
2130 else { | |
2131 len = posa - a; | |
2132 ret = 1; | |
2133 } | |
2134 if (!strncasecmp(a, b, len)) | |
2135 return ret; | |
2136 } | |
2137 return strcasecmp(a, b); | |
2138 } | |
2139 | |
2140 static gint | |
2141 playlist_compare_path(PlaylistEntry * a, | |
2142 PlaylistEntry * b) | |
2143 { | |
2144 return path_compare(a->filename, b->filename); | |
2145 } | |
2146 | |
2147 | |
2148 static time_t | |
2149 playlist_get_mtime(const gchar *filename) | |
2150 { | |
2151 struct stat buf; | |
2152 gint rv; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2153 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2154 |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2155 /* 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
|
2156 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
|
2157 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
|
2158 g_free(realfn); realfn = NULL; |
2313 | 2159 |
2160 if (rv == 0) { | |
2161 return buf.st_mtime; | |
2162 } else { | |
2163 return 0; //error | |
2164 } | |
2165 } | |
2166 | |
2167 | |
2168 static gint | |
2169 playlist_compare_date(PlaylistEntry * a, | |
2170 PlaylistEntry * b) | |
2171 { | |
2172 struct stat buf; | |
2173 time_t modtime; | |
2174 | |
2175 gint rv; | |
2176 | |
2177 | |
2178 rv = stat(a->filename, &buf); | |
2179 | |
2180 if (rv == 0) { | |
2181 modtime = buf.st_mtime; | |
2182 rv = stat(b->filename, &buf); | |
2183 | |
2184 if (stat(b->filename, &buf) == 0) { | |
2185 if (buf.st_mtime == modtime) | |
2186 return 0; | |
2187 else | |
2188 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2189 } | |
2190 else | |
2191 return -1; | |
2192 } | |
2193 else if (!lstat(b->filename, &buf)) | |
2194 return 1; | |
2195 else | |
2196 return playlist_compare_filename(a, b); | |
2197 } | |
2198 | |
2199 | |
2200 void | |
2201 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2202 { | |
2203 playlist_remove_dead_files(playlist); | |
2204 PLAYLIST_LOCK(playlist->mutex); | |
2205 playlist->entries = | |
2206 g_list_sort(playlist->entries, | |
2207 (GCompareFunc) playlist_compare_func_table[type]); | |
2208 PLAYLIST_UNLOCK(playlist->mutex); | |
2209 } | |
2210 | |
2211 static GList * | |
2212 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2213 { | |
2214 GList *list1, *list2; | |
2215 GList *tmp_list = NULL; | |
2216 GList *index_list = NULL; | |
2217 | |
2218 /* | |
2219 * We take all the selected entries out of the playlist, | |
2220 * sorts them, and then put them back in again. | |
2221 */ | |
2222 | |
2223 list1 = g_list_last(list); | |
2224 | |
2225 while (list1) { | |
2226 list2 = g_list_previous(list1); | |
2227 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2228 gpointer idx; | |
2229 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2230 index_list = g_list_prepend(index_list, idx); | |
2231 list = g_list_remove_link(list, list1); | |
2232 tmp_list = g_list_concat(list1, tmp_list); | |
2233 } | |
2234 list1 = list2; | |
2235 } | |
2236 | |
2237 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2238 list1 = tmp_list; | |
2239 list2 = index_list; | |
2240 | |
2241 while (list2) { | |
2242 if (!list1) { | |
2243 g_critical(G_STRLOC ": Error during list sorting. " | |
2244 "Possibly dropped some playlist-entries."); | |
2245 break; | |
2246 } | |
2247 | |
2248 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2249 | |
2250 list2 = g_list_next(list2); | |
2251 list1 = g_list_next(list1); | |
2252 } | |
2253 | |
2254 g_list_free(index_list); | |
2255 g_list_free(tmp_list); | |
2256 | |
2257 return list; | |
2258 } | |
2259 | |
2260 void | |
2261 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2262 { | |
2263 PLAYLIST_LOCK(playlist->mutex); | |
2264 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) | |
2265 playlist_compare_func_table | |
2266 [type]); | |
2267 PLAYLIST_UNLOCK(playlist->mutex); | |
2268 } | |
2269 | |
2270 void | |
2271 playlist_reverse(Playlist *playlist) | |
2272 { | |
2273 PLAYLIST_LOCK(playlist->mutex); | |
2274 playlist->entries = g_list_reverse(playlist->entries); | |
2275 PLAYLIST_UNLOCK(playlist->mutex); | |
2276 } | |
2277 | |
2278 static GList * | |
2279 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2280 { | |
2281 /* | |
2282 * Note that this doesn't make a copy of the original list. | |
2283 * The pointer to the original list is not valid after this | |
2284 * fuction is run. | |
2285 */ | |
2286 gint len = g_list_length(list); | |
2287 gint i, j; | |
2288 GList *node, **ptrs; | |
2289 | |
2290 if (!playlist) | |
2291 return NULL; | |
2292 | |
2293 REQUIRE_LOCK(playlist->mutex); | |
2294 | |
2295 if (!len) | |
2296 return NULL; | |
2297 | |
2298 ptrs = g_new(GList *, len); | |
2299 | |
2300 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2301 ptrs[i] = node; | |
2302 | |
2303 j = g_random_int_range(0, len); | |
2304 list = ptrs[j]; | |
2305 ptrs[j]->next = NULL; | |
2306 ptrs[j] = ptrs[0]; | |
2307 | |
2308 for (i = 1; i < len; i++) { | |
2309 j = g_random_int_range(0, len - i); | |
2310 list->prev = ptrs[i + j]; | |
2311 ptrs[i + j]->next = list; | |
2312 list = ptrs[i + j]; | |
2313 ptrs[i + j] = ptrs[i]; | |
2314 } | |
2315 list->prev = NULL; | |
2316 | |
2317 g_free(ptrs); | |
2318 | |
2319 return list; | |
2320 } | |
2321 | |
2322 void | |
2323 playlist_random(Playlist *playlist) | |
2324 { | |
2325 PLAYLIST_LOCK(playlist->mutex); | |
2326 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); | |
2327 PLAYLIST_UNLOCK(playlist->mutex); | |
2328 } | |
2329 | |
2330 GList * | |
2331 playlist_get_selected(Playlist *playlist) | |
2332 { | |
2333 GList *node, *list = NULL; | |
2334 gint i = 0; | |
2335 | |
2336 PLAYLIST_LOCK(playlist->mutex); | |
2337 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2338 PlaylistEntry *entry = node->data; | |
2339 if (entry->selected) | |
2340 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2341 } | |
2342 PLAYLIST_UNLOCK(playlist->mutex); | |
2343 return g_list_reverse(list); | |
2344 } | |
2345 | |
2346 void | |
2347 playlist_clear_selected(Playlist *playlist) | |
2348 { | |
2349 GList *node = NULL; | |
2350 gint i = 0; | |
2351 | |
2352 PLAYLIST_LOCK(playlist->mutex); | |
2353 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2354 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2355 } | |
2356 PLAYLIST_UNLOCK(playlist->mutex); | |
2357 playlist_recalc_total_time(playlist); | |
2358 playlist_manager_update(); | |
2359 } | |
2360 | |
2361 gint | |
2362 playlist_get_num_selected(Playlist *playlist) | |
2363 { | |
2364 GList *node; | |
2365 gint num = 0; | |
2366 | |
2367 PLAYLIST_LOCK(playlist->mutex); | |
2368 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2369 PlaylistEntry *entry = node->data; | |
2370 if (entry->selected) | |
2371 num++; | |
2372 } | |
2373 PLAYLIST_UNLOCK(playlist->mutex); | |
2374 return num; | |
2375 } | |
2376 | |
2377 | |
2378 static void | |
2379 playlist_generate_shuffle_list(Playlist *playlist) | |
2380 { | |
2381 PLAYLIST_LOCK(playlist->mutex); | |
2382 playlist_generate_shuffle_list_nolock(playlist); | |
2383 PLAYLIST_UNLOCK(playlist->mutex); | |
2384 } | |
2385 | |
2386 static void | |
2387 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2388 { | |
2389 GList *node; | |
2390 gint numsongs; | |
2391 | |
2392 if (!cfg.shuffle || !playlist) | |
2393 return; | |
2394 | |
2395 REQUIRE_LOCK(playlist->mutex); | |
2396 | |
2397 if (playlist->shuffle) { | |
2398 g_list_free(playlist->shuffle); | |
2399 playlist->shuffle = NULL; | |
2400 } | |
2401 | |
2402 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2403 numsongs = g_list_length(playlist->shuffle); | |
2404 | |
2405 if (playlist->position) { | |
2406 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2407 node = g_list_nth(playlist->shuffle, i); | |
2408 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2409 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2410 } | |
2411 } | |
2412 | |
2413 void | |
2414 playlist_fileinfo(Playlist *playlist, guint pos) | |
2415 { | |
2416 gchar *path = NULL; | |
2417 GList *node; | |
2418 PlaylistEntry *entry = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2419 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2420 ProbeResult *pr = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2421 time_t mtime; |
2313 | 2422 |
2423 PLAYLIST_LOCK(playlist->mutex); | |
2424 | |
2425 if ((node = g_list_nth(playlist->entries, pos))) | |
2426 { | |
2427 entry = node->data; | |
2428 tuple = entry->tuple; | |
2429 path = g_strdup(entry->filename); | |
2430 } | |
2431 | |
2432 PLAYLIST_UNLOCK(playlist->mutex); | |
2433 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2434 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2435 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
|
2436 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2437 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2438 |
2313 | 2439 /* 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
|
2440 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
|
2441 mtime == 0 || mtime != playlist_get_mtime(entry->filename)) |
2313 | 2442 { |
2443 playlist_entry_get_info(entry); | |
2444 tuple = entry->tuple; | |
2445 } | |
2446 | |
2447 if (tuple != NULL) | |
2448 { | |
2449 if (entry->decoder == NULL) | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2450 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2451 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
|
2452 entry->decoder = pr ? pr->ip : NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2453 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2454 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2455 } |
2313 | 2456 |
2457 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2458 fileinfo_show_for_tuple(tuple); | |
2459 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2460 entry->decoder->file_info_box(path); | |
2461 else | |
2462 fileinfo_show_for_path(path); | |
2463 g_free(path); | |
2464 } | |
2465 else if (path != NULL) | |
2466 { | |
2467 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2468 entry->decoder->file_info_box(path); | |
2469 else | |
2470 fileinfo_show_for_path(path); | |
2471 g_free(path); | |
2472 } | |
2473 } | |
2474 | |
2475 void | |
2476 playlist_fileinfo_current(Playlist *playlist) | |
2477 { | |
2478 gchar *path = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2479 Tuple *tuple = NULL; |
2313 | 2480 |
2481 PLAYLIST_LOCK(playlist->mutex); | |
2482 | |
2483 if (playlist->entries && playlist->position) | |
2484 { | |
2485 path = g_strdup(playlist->position->filename); | |
2486 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2487 playlist_entry_get_info(playlist->position); | |
2488 tuple = playlist->position->tuple; | |
2489 } | |
2490 | |
2491 PLAYLIST_UNLOCK(playlist->mutex); | |
2492 | |
2493 if (tuple != NULL) | |
2494 { | |
2495 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2496 fileinfo_show_for_tuple(tuple); | |
2497 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2498 playlist->position->decoder->file_info_box(path); | |
2499 else | |
2500 fileinfo_show_for_path(path); | |
2501 g_free(path); | |
2502 } | |
2503 else if (path != NULL) | |
2504 { | |
2505 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2506 playlist->position->decoder->file_info_box(path); | |
2507 else | |
2508 fileinfo_show_for_path(path); | |
2509 g_free(path); | |
2510 } | |
2511 } | |
2512 | |
2513 | |
2514 static gboolean | |
2515 playlist_get_info_is_going(void) | |
2516 { | |
2517 gboolean result; | |
2518 | |
2519 G_LOCK(playlist_get_info_going); | |
2520 result = playlist_get_info_going; | |
2521 G_UNLOCK(playlist_get_info_going); | |
2522 | |
2523 return result; | |
2524 } | |
2525 | |
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
|
2526 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
|
2527 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
|
2528 { |
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
|
2529 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
|
2530 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
|
2531 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
|
2532 } |
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
|
2533 |
2313 | 2534 static gpointer |
2535 playlist_get_info_func(gpointer arg) | |
2536 { | |
2537 GList *node; | |
2538 gboolean update_playlistwin = FALSE; | |
2539 | |
2540 while (playlist_get_info_is_going()) { | |
2541 PlaylistEntry *entry; | |
2542 Playlist *playlist = playlist_get_active(); | |
2543 | |
2544 // on_load | |
2545 if (cfg.use_pl_metadata && | |
2546 cfg.get_info_on_load && | |
2547 playlist_get_info_scan_active) { | |
2548 | |
2549 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2550 entry = node->data; | |
2551 | |
2636 | 2552 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
|
2553 (entry->tuple && tuple_get_int(entry->tuple, "length") > -1 && tuple_get_int(entry->tuple, "mtime") != -1)) { |
2313 | 2554 update_playlistwin = TRUE; |
2555 continue; | |
2556 } | |
2557 | |
2558 if (!playlist_entry_get_info(entry)) { | |
2559 if (g_list_index(playlist->entries, entry) == -1) | |
2560 /* Entry disappeared while we looked it up. | |
2561 Restart. */ | |
2562 node = playlist->entries; | |
2563 } | |
2564 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2565 update_playlistwin = TRUE; | |
2566 break; | |
2567 } | |
2568 } | |
2569 | |
2570 if (!node) { | |
2571 g_mutex_lock(mutex_scan); | |
2572 playlist_get_info_scan_active = FALSE; | |
2573 g_mutex_unlock(mutex_scan); | |
2574 } | |
2575 } // on_load | |
2576 | |
2577 // on_demand | |
2578 else if (!cfg.get_info_on_load && | |
2579 cfg.get_info_on_demand && | |
2580 cfg.playlist_visible && | |
2581 !cfg.playlist_shaded && | |
2582 cfg.use_pl_metadata) { | |
2583 | |
2584 g_mutex_lock(mutex_scan); | |
2585 playlist_get_info_scan_active = FALSE; | |
2586 g_mutex_unlock(mutex_scan); | |
2587 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2588 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
|
2589 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
|
2590 node = g_list_next(node)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2591 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2592 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2593 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2594 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
|
2595 (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
|
2596 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2597 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2598 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2599 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2600 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2601 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
|
2602 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2603 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2604 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2605 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2606 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2607 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
|
2608 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
|
2609 // no need for break here since this iteration is very short. |
2313 | 2610 } |
2611 } | |
2612 } // on_demand | |
2613 else if (cfg.get_info_on_demand && | |
2614 (!cfg.playlist_visible || cfg.playlist_shaded | |
2615 || !cfg.use_pl_metadata)) | |
2616 { | |
2617 g_mutex_lock(mutex_scan); | |
2618 playlist_get_info_scan_active = FALSE; | |
2619 g_mutex_unlock(mutex_scan); | |
2620 } | |
2621 else /* not on_demand and not on_load... | |
2622 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2623 { | |
2624 g_mutex_lock(mutex_scan); | |
2625 playlist_get_info_scan_active = FALSE; | |
2626 g_mutex_unlock(mutex_scan); | |
2627 } | |
2628 | |
2629 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
|
2630 /* 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
|
2631 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
|
2632 g_idle_add_full(G_PRIORITY_HIGH_IDLE, playlist_request_win_update, NULL, NULL); |
2313 | 2633 update_playlistwin = FALSE; |
2634 } | |
2635 | |
2636 if (playlist_get_info_scan_active) { | |
2637 continue; | |
2638 } | |
2639 | |
2640 g_mutex_lock(mutex_scan); | |
2641 g_cond_wait(cond_scan, mutex_scan); | |
2642 g_mutex_unlock(mutex_scan); | |
2643 | |
2644 } // while | |
2645 | |
2646 g_thread_exit(NULL); | |
2647 return NULL; | |
2648 } | |
2649 | |
2650 void | |
2651 playlist_start_get_info_thread(void) | |
2652 { | |
2653 G_LOCK(playlist_get_info_going); | |
2654 playlist_get_info_going = TRUE; | |
2655 G_UNLOCK(playlist_get_info_going); | |
2656 | |
2657 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2658 NULL, TRUE, NULL); | |
2659 } | |
2660 | |
2661 void | |
2662 playlist_stop_get_info_thread(void) | |
2663 { | |
2664 G_LOCK(playlist_get_info_going); | |
2665 playlist_get_info_going = FALSE; | |
2666 G_UNLOCK(playlist_get_info_going); | |
2667 | |
2668 g_cond_broadcast(cond_scan); | |
2669 g_thread_join(playlist_get_info_thread); | |
2670 } | |
2671 | |
2672 void | |
2673 playlist_start_get_info_scan(void) | |
2674 { | |
2675 g_mutex_lock(mutex_scan); | |
2676 playlist_get_info_scan_active = TRUE; | |
2677 g_mutex_unlock(mutex_scan); | |
2678 g_cond_signal(cond_scan); | |
2679 } | |
2680 | |
2681 void | |
2682 playlist_remove_dead_files(Playlist *playlist) | |
2683 { | |
2684 GList *node, *next_node; | |
2685 | |
2686 PLAYLIST_LOCK(playlist->mutex); | |
2687 | |
2688 for (node = playlist->entries; node; node = next_node) { | |
2689 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2690 next_node = g_list_next(node); | |
2691 | |
2692 if (!entry || !entry->filename) { | |
2693 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2694 continue; | |
2695 } | |
2696 | |
2697 /* FIXME: What about 'file:///'? */ | |
2698 /* Don't kill URLs */ | |
2699 if (strstr(entry->filename, "://")) | |
2700 continue; | |
2701 | |
2702 /* FIXME: Should test for readability */ | |
2703 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2704 continue; | |
2705 | |
2706 if (entry == playlist->position) { | |
2707 /* Don't remove the currently playing song */ | |
2708 if (playback_get_playing()) | |
2709 continue; | |
2710 | |
2711 if (next_node) | |
2712 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2713 else | |
2714 playlist->position = NULL; | |
2715 } | |
2716 | |
2717 playlist_entry_free(entry); | |
2718 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2719 } | |
2720 | |
2721 PLAYLIST_UNLOCK(playlist->mutex); | |
2722 | |
2723 playlist_generate_shuffle_list(playlist); | |
2724 playlistwin_update_list(playlist); | |
2725 playlist_recalc_total_time(playlist); | |
2726 playlist_manager_update(); | |
2727 } | |
2728 | |
2729 | |
2730 static gint | |
2731 playlist_dupscmp_title(PlaylistEntry * a, | |
2732 PlaylistEntry * b) | |
2733 { | |
2734 const gchar *a_title, *b_title; | |
2735 | |
2736 g_return_val_if_fail(a != NULL, 0); | |
2737 g_return_val_if_fail(b != NULL, 0); | |
2738 | |
2739 if (a->title) | |
2740 a_title = a->title; | |
2741 else { | |
2742 if (strrchr(a->filename, '/')) | |
2743 a_title = strrchr(a->filename, '/') + 1; | |
2744 else | |
2745 a_title = a->filename; | |
2746 } | |
2747 | |
2748 if (b->title) | |
2749 b_title = b->title; | |
2750 else { | |
2751 if (strrchr(a->filename, '/')) | |
2752 b_title = strrchr(b->filename, '/') + 1; | |
2753 else | |
2754 b_title = b->filename; | |
2755 } | |
2756 | |
2757 return strcmp(a_title, b_title); | |
2758 } | |
2759 | |
2760 static gint | |
2761 playlist_dupscmp_filename(PlaylistEntry * a, | |
2762 PlaylistEntry * b ) | |
2763 { | |
2764 gchar *a_filename, *b_filename; | |
2765 | |
2766 g_return_val_if_fail(a != NULL, 0); | |
2767 g_return_val_if_fail(b != NULL, 0); | |
2768 | |
2769 if (strrchr(a->filename, '/')) | |
2770 a_filename = strrchr(a->filename, '/') + 1; | |
2771 else | |
2772 a_filename = a->filename; | |
2773 | |
2774 if (strrchr(b->filename, '/')) | |
2775 b_filename = strrchr(b->filename, '/') + 1; | |
2776 else | |
2777 b_filename = b->filename; | |
2778 | |
2779 return strcmp(a_filename, b_filename); | |
2780 } | |
2781 | |
2782 static gint | |
2783 playlist_dupscmp_path(PlaylistEntry * a, | |
2784 PlaylistEntry * b) | |
2785 { | |
2786 /* simply compare the entire filename string */ | |
2787 return strcmp(a->filename, b->filename); | |
2788 } | |
2789 | |
2790 void | |
2791 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2792 { | |
2793 GList *node, *next_node; | |
2794 GList *node_cmp, *next_node_cmp; | |
2795 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2796 | |
2797 switch ( type ) | |
2798 { | |
2799 case PLAYLIST_DUPS_TITLE: | |
2800 dups_compare_func = playlist_dupscmp_title; | |
2801 break; | |
2802 case PLAYLIST_DUPS_PATH: | |
2803 dups_compare_func = playlist_dupscmp_path; | |
2804 break; | |
2805 case PLAYLIST_DUPS_FILENAME: | |
2806 default: | |
2807 dups_compare_func = playlist_dupscmp_filename; | |
2808 break; | |
2809 } | |
2810 | |
2811 PLAYLIST_LOCK(playlist->mutex); | |
2812 | |
2813 for (node = playlist->entries; node; node = next_node) { | |
2814 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2815 next_node = g_list_next(node); | |
2816 | |
2817 if (!entry || !entry->filename) { | |
2818 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2819 continue; | |
2820 } | |
2821 | |
2822 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2823 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2824 next_node_cmp = g_list_next(node_cmp); | |
2825 | |
2826 if (!entry_cmp || !entry_cmp->filename) { | |
2827 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2828 continue; | |
2829 } | |
2830 | |
2831 /* compare using the chosen dups_compare_func */ | |
2832 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2833 | |
2834 if (entry_cmp == playlist->position) { | |
2835 /* Don't remove the currently playing song */ | |
2836 if (playback_get_playing()) | |
2837 continue; | |
2838 | |
2839 if (next_node_cmp) | |
2840 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2841 else | |
2842 playlist->position = NULL; | |
2843 } | |
2844 | |
2845 /* check if this was the next item of the external | |
2846 loop; if true, replace it with the next of the next*/ | |
2847 if ( node_cmp == next_node ) | |
2848 next_node = g_list_next(next_node); | |
2849 | |
2850 playlist_entry_free(entry_cmp); | |
2851 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2852 } | |
2853 } | |
2854 } | |
2855 | |
2856 PLAYLIST_UNLOCK(playlist->mutex); | |
2857 | |
2858 playlistwin_update_list(playlist); | |
2859 playlist_recalc_total_time(playlist); | |
2860 | |
2861 playlist_manager_update(); | |
2862 } | |
2863 | |
2864 void | |
2865 playlist_get_total_time(Playlist * playlist, | |
2866 gulong * total_time, | |
2867 gulong * selection_time, | |
2868 gboolean * total_more, | |
2869 gboolean * selection_more) | |
2870 { | |
2871 PLAYLIST_LOCK(playlist->mutex); | |
2872 *total_time = playlist->pl_total_time; | |
2873 *selection_time = playlist->pl_selection_time; | |
2874 *total_more = playlist->pl_total_more; | |
2875 *selection_more = playlist->pl_selection_more; | |
2876 PLAYLIST_UNLOCK(playlist->mutex); | |
2877 } | |
2878 | |
2879 | |
2880 static void | |
2881 playlist_recalc_total_time_nolock(Playlist *playlist) | |
2882 { | |
2883 GList *list; | |
2884 PlaylistEntry *entry; | |
2885 | |
2886 REQUIRE_LOCK(playlist->mutex); | |
2887 | |
2888 playlist->pl_total_time = 0; | |
2889 playlist->pl_selection_time = 0; | |
2890 playlist->pl_total_more = FALSE; | |
2891 playlist->pl_selection_more = FALSE; | |
2892 | |
2893 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2894 entry = list->data; | |
2895 | |
2896 if (entry->length != -1) | |
2897 playlist->pl_total_time += entry->length / 1000; | |
2898 else | |
2899 playlist->pl_total_more = TRUE; | |
2900 | |
2901 if (entry->selected) { | |
2902 if (entry->length != -1) | |
2903 playlist->pl_selection_time += entry->length / 1000; | |
2904 else | |
2905 playlist->pl_selection_more = TRUE; | |
2906 } | |
2907 } | |
2908 } | |
2909 | |
2910 static void | |
2911 playlist_recalc_total_time(Playlist *playlist) | |
2912 { | |
2913 PLAYLIST_LOCK(playlist->mutex); | |
2914 playlist_recalc_total_time_nolock(playlist); | |
2915 PLAYLIST_UNLOCK(playlist->mutex); | |
2916 } | |
2917 | |
2918 gint | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2919 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) |
2313 | 2920 { |
2921 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2922 gboolean is_first_search = TRUE; | |
2923 gint num_of_entries_found = 0; | |
2924 | |
2925 #if defined(USE_REGEX_ONIGURUMA) | |
2926 /* set encoding for Oniguruma regex to UTF-8 */ | |
2927 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2928 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
2929 #endif | |
2930 | |
2931 PLAYLIST_LOCK(playlist->mutex); | |
2932 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2933 if ( tuple_get_string(tuple, "title") != NULL ) |
2313 | 2934 { |
2935 /* 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
|
2936 const gchar *regex_pattern = tuple_get_string(tuple, "title"); |
2313 | 2937 regex_t regex; |
2938 #if defined(USE_REGEX_PCRE) | |
2939 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2940 #else | |
2941 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2942 #endif | |
2943 { | |
2944 GList *tfound_list = NULL; | |
2945 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2946 else entry_list = found_list; /* use found_list */ | |
2947 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2948 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2949 const gchar *track_name = tuple_get_string( tuple, "title" ); |
2313 | 2950 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
|
2951 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
|
2952 ( regexec( ®ex , track_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2953 { |
2954 tfound_list = g_list_append( tfound_list , entry ); | |
2955 } | |
2956 } | |
2957 g_list_free( found_list ); /* wipe old found_list */ | |
2958 found_list = tfound_list; /* move tfound_list in found_list */ | |
2959 regfree( ®ex ); | |
2960 } | |
2961 is_first_search = FALSE; | |
2962 } | |
2963 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2964 if ( tuple_get_string(tuple, "album") != NULL ) |
2313 | 2965 { |
2966 /* 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
|
2967 const gchar *regex_pattern = tuple_get_string(tuple, "album"); |
2313 | 2968 regex_t regex; |
2969 #if defined(USE_REGEX_PCRE) | |
2970 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2971 #else | |
2972 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2973 #endif | |
2974 { | |
2975 GList *tfound_list = NULL; | |
2976 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2977 else entry_list = found_list; /* use found_list */ | |
2978 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2979 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2980 const gchar *album_name = tuple_get_string( tuple, "album" ); |
2313 | 2981 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
|
2982 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
|
2983 ( regexec( ®ex , album_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2984 { |
2985 tfound_list = g_list_append( tfound_list , entry ); | |
2986 } | |
2987 } | |
2988 g_list_free( found_list ); /* wipe old found_list */ | |
2989 found_list = tfound_list; /* move tfound_list in found_list */ | |
2990 regfree( ®ex ); | |
2991 } | |
2992 is_first_search = FALSE; | |
2993 } | |
2994 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2995 if ( tuple_get_string(tuple, "artist") != NULL ) |
2313 | 2996 { |
2997 /* match by performer */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2998 const gchar *regex_pattern = tuple_get_string(tuple, "artist"); |
2313 | 2999 regex_t regex; |
3000 #if defined(USE_REGEX_PCRE) | |
3001 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
3002 #else | |
3003 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
3004 #endif | |
3005 { | |
3006 GList *tfound_list = NULL; | |
3007 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3008 else entry_list = found_list; /* use found_list */ | |
3009 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3010 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3011 const gchar *performer = tuple_get_string( tuple, "performer" ); |
2313 | 3012 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
|
3013 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
|
3014 ( regexec( ®ex , performer , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3015 { |
3016 tfound_list = g_list_append( tfound_list , entry ); | |
3017 } | |
3018 } | |
3019 g_list_free( found_list ); /* wipe old found_list */ | |
3020 found_list = tfound_list; /* move tfound_list in found_list */ | |
3021 regfree( ®ex ); | |
3022 } | |
3023 is_first_search = FALSE; | |
3024 } | |
3025 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3026 if ( tuple_get_string(tuple, "file-name") != NULL ) |
2313 | 3027 { |
3028 /* 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
|
3029 const gchar *regex_pattern = tuple_get_string(tuple, "file-name"); |
2313 | 3030 regex_t regex; |
3031 #if defined(USE_REGEX_PCRE) | |
3032 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
3033 #else | |
3034 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
3035 #endif | |
3036 { | |
3037 GList *tfound_list = NULL; | |
3038 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3039 else entry_list = found_list; /* use found_list */ | |
3040 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3041 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3042 const gchar *file_name = tuple_get_string( tuple, "file-name" ); |
2313 | 3043 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
|
3044 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
|
3045 ( regexec( ®ex , file_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3046 { |
3047 tfound_list = g_list_append( tfound_list , entry ); | |
3048 } | |
3049 } | |
3050 g_list_free( found_list ); /* wipe old found_list */ | |
3051 found_list = tfound_list; /* move tfound_list in found_list */ | |
3052 regfree( ®ex ); | |
3053 } | |
3054 is_first_search = FALSE; | |
3055 } | |
3056 | |
3057 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
3058 /* if some entries are still in found_list, those | |
3059 are what the user is searching for; select them */ | |
3060 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
3061 { | |
3062 PlaylistEntry *entry = sel_list->data; | |
3063 entry->selected = TRUE; | |
3064 num_of_entries_found++; | |
3065 } | |
3066 | |
3067 g_list_free( found_list ); | |
3068 | |
3069 PLAYLIST_UNLOCK(playlist->mutex); | |
3070 playlist_recalc_total_time(playlist); | |
3071 | |
3072 return num_of_entries_found; | |
3073 } | |
3074 | |
3075 void | |
3076 playlist_select_all(Playlist *playlist, gboolean set) | |
3077 { | |
3078 GList *list; | |
3079 | |
3080 PLAYLIST_LOCK(playlist->mutex); | |
3081 | |
3082 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3083 PlaylistEntry *entry = list->data; | |
3084 entry->selected = set; | |
3085 } | |
3086 | |
3087 PLAYLIST_UNLOCK(playlist->mutex); | |
3088 playlist_recalc_total_time(playlist); | |
3089 } | |
3090 | |
3091 void | |
3092 playlist_select_invert_all(Playlist *playlist) | |
3093 { | |
3094 GList *list; | |
3095 | |
3096 PLAYLIST_LOCK(playlist->mutex); | |
3097 | |
3098 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3099 PlaylistEntry *entry = list->data; | |
3100 entry->selected = !entry->selected; | |
3101 } | |
3102 | |
3103 PLAYLIST_UNLOCK(playlist->mutex); | |
3104 playlist_recalc_total_time(playlist); | |
3105 } | |
3106 | |
3107 gboolean | |
3108 playlist_select_invert(Playlist *playlist, guint pos) | |
3109 { | |
3110 GList *list; | |
3111 gboolean invert_ok = FALSE; | |
3112 | |
3113 PLAYLIST_LOCK(playlist->mutex); | |
3114 | |
3115 if ((list = g_list_nth(playlist->entries, pos))) { | |
3116 PlaylistEntry *entry = list->data; | |
3117 entry->selected = !entry->selected; | |
3118 invert_ok = TRUE; | |
3119 } | |
3120 | |
3121 PLAYLIST_UNLOCK(playlist->mutex); | |
3122 playlist_recalc_total_time(playlist); | |
3123 | |
3124 return invert_ok; | |
3125 } | |
3126 | |
3127 | |
3128 void | |
3129 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3130 { | |
3131 GList *list; | |
3132 gint i; | |
3133 | |
3134 if (min_pos > max_pos) | |
3135 SWAP(min_pos, max_pos); | |
3136 | |
3137 PLAYLIST_LOCK(playlist->mutex); | |
3138 | |
3139 list = g_list_nth(playlist->entries, min_pos); | |
3140 for (i = min_pos; i <= max_pos && list; i++) { | |
3141 PlaylistEntry *entry = list->data; | |
3142 entry->selected = select; | |
3143 list = g_list_next(list); | |
3144 } | |
3145 | |
3146 PLAYLIST_UNLOCK(playlist->mutex); | |
3147 | |
3148 playlist_recalc_total_time(playlist); | |
3149 } | |
3150 | |
3151 gboolean | |
3152 playlist_read_info_selection(Playlist *playlist) | |
3153 { | |
3154 GList *node; | |
3155 gboolean retval = FALSE; | |
3156 | |
3157 PLAYLIST_LOCK(playlist->mutex); | |
3158 | |
3159 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3160 PlaylistEntry *entry = node->data; | |
3161 if (!entry->selected) | |
3162 continue; | |
3163 | |
3164 retval = TRUE; | |
3165 | |
3166 str_replace_in(&entry->title, NULL); | |
3167 entry->length = -1; | |
3168 | |
3169 /* invalidate mtime to reread */ | |
3170 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
|
3171 tuple_associate_int(entry->tuple, "mtime", -1); /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
2313 | 3172 |
3173 if (!playlist_entry_get_info(entry)) { | |
3174 if (g_list_index(playlist->entries, entry) == -1) | |
3175 /* Entry disappeared while we looked it up. Restart. */ | |
3176 node = playlist->entries; | |
3177 } | |
3178 } | |
3179 | |
3180 PLAYLIST_UNLOCK(playlist->mutex); | |
3181 | |
3182 playlistwin_update_list(playlist); | |
3183 playlist_recalc_total_time(playlist); | |
3184 | |
3185 return retval; | |
3186 } | |
3187 | |
3188 void | |
3189 playlist_read_info(Playlist *playlist, guint pos) | |
3190 { | |
3191 GList *node; | |
3192 | |
3193 PLAYLIST_LOCK(playlist->mutex); | |
3194 | |
3195 if ((node = g_list_nth(playlist->entries, pos))) { | |
3196 PlaylistEntry *entry = node->data; | |
3197 str_replace_in(&entry->title, NULL); | |
3198 entry->length = -1; | |
3199 playlist_entry_get_info(entry); | |
3200 } | |
3201 | |
3202 PLAYLIST_UNLOCK(playlist->mutex); | |
3203 | |
3204 playlistwin_update_list(playlist); | |
3205 playlist_recalc_total_time(playlist); | |
3206 } | |
3207 | |
3208 Playlist * | |
3209 playlist_get_active(void) | |
3210 { | |
3211 if (playlists_iter != NULL) | |
3212 return (Playlist *) playlists_iter->data; | |
3213 | |
2736 | 3214 if (playlists) |
3215 return (Playlist *) playlists->data; | |
3216 | |
3217 return NULL; | |
2313 | 3218 } |
3219 | |
3220 void | |
3221 playlist_set_shuffle(gboolean shuffle) | |
3222 { | |
3223 Playlist *playlist = playlist_get_active(); | |
3224 if (!playlist) | |
3225 return; | |
3226 | |
3227 PLAYLIST_LOCK(playlist->mutex); | |
3228 | |
3229 playlist_position_before_jump = NULL; | |
3230 | |
3231 cfg.shuffle = shuffle; | |
3232 playlist_generate_shuffle_list_nolock(playlist); | |
3233 | |
3234 PLAYLIST_UNLOCK(playlist->mutex); | |
3235 } | |
3236 | |
3237 Playlist * | |
3238 playlist_new(void) | |
3239 { | |
3240 Playlist *playlist = g_new0(Playlist, 1); | |
3241 playlist->mutex = g_mutex_new(); | |
3242 playlist->loading_playlist = FALSE; | |
3243 | |
3244 playlist_set_current_name(playlist, NULL); | |
3245 playlist_clear(playlist); | |
3246 | |
3247 return playlist; | |
3248 } | |
3249 | |
3250 void | |
3251 playlist_free(Playlist *playlist) | |
3252 { | |
3253 g_mutex_free( playlist->mutex ); | |
3254 g_free( playlist ); | |
3255 return; | |
3256 } | |
3257 | |
3258 Playlist * | |
3259 playlist_new_from_selected(void) | |
3260 { | |
3261 Playlist *newpl = playlist_new(); | |
3262 Playlist *playlist = playlist_get_active(); | |
3263 GList *list = playlist_get_selected(playlist); | |
3264 | |
3265 playlist_add_playlist( newpl ); | |
3266 | |
3267 PLAYLIST_LOCK(playlist->mutex); | |
3268 | |
3269 while ( list != NULL ) | |
3270 { | |
3271 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3272 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3273 playlist_add( newpl , entry->filename ); | |
3274 list = g_list_next(list); | |
3275 } | |
3276 | |
3277 PLAYLIST_UNLOCK(playlist->mutex); | |
3278 | |
3279 playlist_recalc_total_time(newpl); | |
3280 playlistwin_update_list(playlist); | |
3281 | |
3282 return newpl; | |
3283 } | |
3284 | |
3285 const gchar * | |
3286 playlist_get_filename_to_play(Playlist *playlist) | |
3287 { | |
3288 const gchar *filename = NULL; | |
3289 | |
3290 if (!playlist) | |
3291 return NULL; | |
3292 | |
3293 PLAYLIST_LOCK(playlist->mutex); | |
3294 | |
3295 if (!playlist->position) { | |
3296 if (cfg.shuffle) | |
3297 playlist->position = playlist->shuffle->data; | |
3298 else | |
3299 playlist->position = playlist->entries->data; | |
3300 } | |
3301 | |
3302 filename = playlist->position->filename; | |
3303 | |
3304 PLAYLIST_UNLOCK(playlist->mutex); | |
3305 | |
3306 return filename; | |
3307 } | |
3308 | |
3309 PlaylistEntry * | |
3310 playlist_get_entry_to_play(Playlist *playlist) | |
3311 { | |
3312 if (!playlist) | |
3313 return NULL; | |
3314 | |
3315 PLAYLIST_LOCK(playlist->mutex); | |
3316 | |
3317 if (!playlist->position) { | |
3318 if (cfg.shuffle) | |
3319 playlist->position = playlist->shuffle->data; | |
3320 else | |
3321 playlist->position = playlist->entries->data; | |
3322 } | |
3323 | |
3324 PLAYLIST_UNLOCK(playlist->mutex); | |
3325 | |
3326 return playlist->position; | |
3327 } | |
3474
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3328 |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3329 gboolean |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3330 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
|
3331 { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3332 GList *l1, *l2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3333 PlaylistEntry *e1, *e2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3334 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
|
3335 l1 = p1->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3336 l2 = p2->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3337 do { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3338 if (!l1 && !l2) break; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3339 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
|
3340 e1 = (PlaylistEntry *) l1->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3341 e2 = (PlaylistEntry *) l2->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3342 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
|
3343 l1 = l1->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3344 l2 = l2->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3345 } while(1); |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3346 return TRUE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3347 } |