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