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