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