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