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