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