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