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