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