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