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