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