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