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