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