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