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