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