Mercurial > audlegacy
annotate src/audacious/playlist.c @ 3320:3a3f43afd9a0 trunk
plugin-customizable menu entries: added AUDACIOUS_MENU_PLAYLIST_RCLICK to manage custom entries for the playlist right-click menu
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Sat, 11 Aug 2007 00:24:20 +0200 |
parents | f985357757e0 |
children | 5296086f20cf |
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) { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
179 mowgli_object_unref(entry->tuple); |
2313 | 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 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
195 Tuple *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; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
198 const gchar *formatter; |
2313 | 199 |
200 g_return_val_if_fail(entry != NULL, FALSE); | |
201 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
202 if (entry->tuple == NULL || tuple_get_int(entry->tuple, "mtime") > 0 || tuple_get_int(entry->tuple, "mtime") == -1) |
2636 | 203 modtime = playlist_get_mtime(entry->filename); |
2313 | 204 else |
2636 | 205 modtime = 0; /* URI -nenolod */ |
2313 | 206 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
207 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
|
208 g_thread_self() != playlist_get_info_thread) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
209 return FALSE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
210 |
2313 | 211 if (entry->decoder == NULL) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
212 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
213 pr = input_check_file(entry->filename, FALSE); |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
214 if (pr) |
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
215 entry->decoder = pr->ip; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
216 } |
2313 | 217 |
218 /* renew tuple if file mtime is newer than tuple mtime. */ | |
219 if(entry->tuple){ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
220 if(tuple_get_int(entry->tuple, "mtime") == modtime) |
2313 | 221 return TRUE; |
222 else { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
223 mowgli_object_unref(entry->tuple); |
2313 | 224 entry->tuple = NULL; |
225 } | |
226 } | |
227 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
228 if (pr != NULL && pr->tuple != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
229 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
230 else if (entry->decoder != NULL && entry->decoder->get_song_tuple != NULL) |
2313 | 231 tuple = entry->decoder->get_song_tuple(entry->filename); |
232 | |
233 if (tuple == NULL) | |
234 return FALSE; | |
235 | |
236 /* attach mtime */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
237 tuple_associate_int(tuple, "mtime", modtime); |
2313 | 238 |
239 /* entry is still around */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
240 formatter = tuple_get_string(tuple, "formatter"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
241 entry->title = tuple_formatter_process_string(tuple, formatter ? formatter : cfg.gentitle_format); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
242 entry->length = tuple_get_int(tuple, "length"); |
2313 | 243 entry->tuple = tuple; |
244 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
245 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
246 |
2313 | 247 return TRUE; |
248 } | |
249 | |
250 /* *********************** playlist selector code ************************* */ | |
251 | |
252 void | |
253 playlist_init(void) | |
254 { | |
255 Playlist *initial_pl; | |
256 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
257 /* create a heap with 1024 playlist entry nodes preallocated. --nenolod */ |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
258 playlist_entry_heap = mowgli_heap_create(sizeof(PlaylistEntry), 1024, |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
259 BH_NOW); |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
260 |
2313 | 261 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ |
262 | |
263 initial_pl = playlist_new(); | |
264 | |
265 playlist_add_playlist(initial_pl); | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
266 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
267 playlist_evlistener_init(); |
2313 | 268 } |
269 | |
270 void | |
271 playlist_add_playlist(Playlist *playlist) | |
272 { | |
273 playlists = g_list_append(playlists, playlist); | |
274 | |
275 if (playlists_iter == NULL) | |
276 playlists_iter = playlists; | |
277 | |
278 playlist_manager_update(); | |
279 } | |
280 | |
281 void | |
282 playlist_remove_playlist(Playlist *playlist) | |
283 { | |
2820 | 284 /* users suppose playback will be stopped on removing playlist */ |
285 if (playback_get_playing()) { | |
286 ip_data.stop = TRUE; | |
287 playback_stop(); | |
288 ip_data.stop = FALSE; | |
289 mainwin_clear_song_info(); | |
290 } | |
291 | |
2313 | 292 /* trying to free the last playlist simply clears and resets it */ |
293 if (g_list_length(playlists) < 2) { | |
294 playlist_clear(playlist); | |
295 playlist_set_current_name(playlist, NULL); | |
296 return; | |
297 } | |
298 | |
299 if (playlist == playlist_get_active()) | |
300 playlist_select_next(); | |
301 | |
302 /* upon removal, a playlist should be cleared and freed */ | |
303 playlists = g_list_remove(playlists, playlist); | |
304 playlist_clear(playlist); | |
305 playlist_free(playlist); | |
306 | |
307 if (playlists_iter == NULL) | |
308 playlists_iter = playlists; | |
309 | |
310 playlist_manager_update(); | |
311 } | |
312 | |
313 GList * | |
314 playlist_get_playlists(void) | |
315 { | |
316 return playlists; | |
317 } | |
318 | |
319 void | |
320 playlist_select_next(void) | |
321 { | |
322 if (playlists_iter == NULL) | |
323 playlists_iter = playlists; | |
324 | |
325 playlists_iter = g_list_next(playlists_iter); | |
326 | |
327 if (playlists_iter == NULL) | |
328 playlists_iter = playlists; | |
329 | |
330 playlistwin_update_list(playlist_get_active()); | |
331 } | |
332 | |
333 void | |
334 playlist_select_prev(void) | |
335 { | |
336 if (playlists_iter == NULL) | |
337 playlists_iter = playlists; | |
338 | |
339 playlists_iter = g_list_previous(playlists_iter); | |
340 | |
341 if (playlists_iter == NULL) | |
342 playlists_iter = playlists; | |
343 | |
344 playlistwin_update_list(playlist_get_active()); | |
345 } | |
346 | |
347 void | |
348 playlist_select_playlist(Playlist *playlist) | |
349 { | |
350 if (playlists_iter == NULL) | |
351 playlists_iter = playlists; | |
352 | |
353 playlists_iter = g_list_find(playlists, playlist); | |
354 | |
355 if (playlists_iter == NULL) | |
356 playlists_iter = playlists; | |
357 | |
358 playlistwin_update_list(playlist); | |
359 } | |
360 | |
361 /* *********************** playlist code ********************** */ | |
362 | |
363 const gchar * | |
364 playlist_get_current_name(Playlist *playlist) | |
365 { | |
366 return playlist->title; | |
367 } | |
368 | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
369 /* filename is real filename here. --yaz */ |
2313 | 370 gboolean |
371 playlist_set_current_name(Playlist *playlist, const gchar * filename) | |
372 { | |
373 if (playlist->title) | |
374 g_free(playlist->title); | |
375 | |
376 if (!filename) { | |
377 playlist->title = NULL; | |
378 return FALSE; | |
379 } | |
380 | |
2504
fcf730269639
[svn] - convert filename string to utf8 for playlist->title (closes bug #789)
giacomo
parents:
2499
diff
changeset
|
381 playlist->title = filename_to_utf8(filename); |
2313 | 382 return TRUE; |
383 } | |
384 | |
385 static GList * | |
386 find_playlist_position_list(Playlist *playlist) | |
387 { | |
388 REQUIRE_LOCK(playlist->mutex); | |
389 | |
390 if (!playlist->position) { | |
391 if (cfg.shuffle) | |
392 return playlist->shuffle; | |
393 else | |
394 return playlist->entries; | |
395 } | |
396 | |
397 if (cfg.shuffle) | |
398 return g_list_find(playlist->shuffle, playlist->position); | |
399 else | |
400 return g_list_find(playlist->entries, playlist->position); | |
401 } | |
402 | |
403 static void | |
404 play_queued(Playlist *playlist) | |
405 { | |
406 GList *tmp = playlist->queue; | |
407 | |
408 REQUIRE_LOCK( playlist->mutex ); | |
409 | |
410 playlist->position = playlist->queue->data; | |
411 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | |
412 g_list_free_1(tmp); | |
413 } | |
414 | |
415 void | |
416 playlist_clear(Playlist *playlist) | |
417 { | |
418 if (!playlist) | |
419 return; | |
420 | |
421 PLAYLIST_LOCK( playlist->mutex ); | |
422 | |
423 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); | |
424 g_list_free(playlist->entries); | |
425 playlist->position = NULL; | |
426 playlist->entries = NULL; | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
427 playlist->tail = NULL; |
2637
420ce282920d
[svn] - clear playlist attribute when playlist_clear() is called.
yaz
parents:
2636
diff
changeset
|
428 playlist->attribute = PLAYLIST_PLAIN; |
2313 | 429 |
430 PLAYLIST_UNLOCK( playlist->mutex ); | |
431 | |
432 playlist_generate_shuffle_list(playlist); | |
433 playlistwin_update_list(playlist); | |
434 playlist_recalc_total_time(playlist); | |
435 playlist_manager_update(); | |
436 } | |
437 | |
438 static void | |
439 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
440 gboolean * restart_playing) | |
441 { | |
442 PlaylistEntry *entry; | |
443 GList *playing_song = NULL; | |
444 | |
445 REQUIRE_LOCK(playlist->mutex); | |
446 | |
447 /* We call g_list_find manually here because we don't want an item | |
448 * in the shuffle_list */ | |
449 | |
450 if (playlist->position) | |
451 playing_song = g_list_find(playlist->entries, playlist->position); | |
452 | |
453 entry = PLAYLIST_ENTRY(node->data); | |
454 | |
455 if (playing_song == node) { | |
456 *set_info_text = TRUE; | |
457 | |
458 if (playback_get_playing()) { | |
459 PLAYLIST_UNLOCK(playlist->mutex); | |
460 ip_data.stop = TRUE; | |
461 playback_stop(); | |
462 ip_data.stop = FALSE; | |
463 PLAYLIST_LOCK(playlist->mutex); | |
464 *restart_playing = TRUE; | |
465 } | |
466 | |
467 playing_song = find_playlist_position_list(playlist); | |
468 | |
469 if (g_list_next(playing_song)) | |
470 playlist->position = g_list_next(playing_song)->data; | |
471 else if (g_list_previous(playing_song)) | |
472 playlist->position = g_list_previous(playing_song)->data; | |
473 else | |
474 playlist->position = NULL; | |
475 | |
476 /* Make sure the entry did not disappear under us */ | |
477 if (g_list_index(playlist->entries, entry) == -1) | |
478 return; | |
479 | |
480 } | |
481 else if (g_list_position(playlist->entries, playing_song) > | |
482 g_list_position(playlist->entries, node)) { | |
483 *set_info_text = TRUE; | |
484 } | |
485 | |
486 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
487 playlist->queue = g_list_remove(playlist->queue, entry); | |
488 playlist->entries = g_list_remove_link(playlist->entries, node); | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
489 playlist->tail = g_list_last(playlist->entries); |
2313 | 490 playlist_entry_free(entry); |
491 g_list_free_1(node); | |
492 | |
493 playlist_recalc_total_time_nolock(playlist); | |
494 } | |
495 | |
496 void | |
497 playlist_delete_index(Playlist *playlist, guint pos) | |
498 { | |
499 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
500 GList *node; | |
501 | |
502 if (!playlist) | |
503 return; | |
504 | |
505 PLAYLIST_LOCK(playlist->mutex); | |
506 | |
507 node = g_list_nth(playlist->entries, pos); | |
508 | |
509 if (!node) { | |
510 PLAYLIST_UNLOCK(playlist->mutex); | |
511 return; | |
512 } | |
513 | |
514 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
515 | |
516 PLAYLIST_UNLOCK(playlist->mutex); | |
517 | |
518 playlist_recalc_total_time(playlist); | |
519 | |
520 playlistwin_update_list(playlist); | |
521 if (restart_playing) { | |
522 if (playlist->position) { | |
523 playback_initiate(); | |
524 } | |
525 else { | |
526 mainwin_clear_song_info(); | |
527 } | |
528 } | |
529 | |
530 playlist_manager_update(); | |
531 } | |
532 | |
533 void | |
534 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
535 { | |
536 GList *node, *fnode; | |
537 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
538 | |
539 PLAYLIST_LOCK(playlist->mutex); | |
540 | |
541 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
542 node = playlist->entries; | |
543 | |
544 while (node) { | |
545 GList *next = g_list_next(node); | |
546 PlaylistEntry *entry = node->data; | |
547 | |
548 if (!strcmp(entry->filename, fnode->data)) | |
549 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
550 | |
551 node = next; | |
552 } | |
553 } | |
554 | |
2792
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
555 PLAYLIST_UNLOCK(playlist->mutex); |
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
556 |
2313 | 557 playlist_recalc_total_time(playlist); |
558 playlistwin_update_list(playlist); | |
559 | |
560 if (restart_playing) { | |
561 if (playlist->position) { | |
562 playback_initiate(); | |
563 } | |
564 else { | |
565 mainwin_clear_song_info(); | |
566 } | |
567 } | |
568 | |
569 playlist_manager_update(); | |
570 } | |
571 | |
572 void | |
573 playlist_delete(Playlist * playlist, gboolean crop) | |
574 { | |
575 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
576 GList *node, *next_node; | |
577 PlaylistEntry *entry; | |
578 | |
579 g_return_if_fail(playlist != NULL); | |
580 | |
581 PLAYLIST_LOCK(playlist->mutex); | |
582 | |
583 node = playlist->entries; | |
584 | |
585 while (node) { | |
586 entry = PLAYLIST_ENTRY(node->data); | |
587 | |
588 next_node = g_list_next(node); | |
589 | |
590 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
591 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
592 } | |
593 | |
594 node = next_node; | |
595 } | |
596 | |
597 PLAYLIST_UNLOCK(playlist->mutex); | |
598 | |
599 playlist_recalc_total_time(playlist); | |
600 | |
601 if (restart_playing) { | |
602 if (playlist->position) { | |
603 playback_initiate(); | |
604 } | |
605 else { | |
606 mainwin_clear_song_info(); | |
607 } | |
608 } | |
609 | |
610 playlistwin_update_list(playlist); | |
611 playlist_manager_update(); | |
612 } | |
613 | |
614 static void | |
615 __playlist_ins_with_info(Playlist * playlist, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
616 const gchar * filename, |
2313 | 617 gint pos, |
618 const gchar * title, | |
619 gint len, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
620 InputPlugin * dec) |
2313 | 621 { |
622 g_return_if_fail(filename != NULL); | |
623 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
624 PLAYLIST_LOCK( playlist->mutex ); |
2313 | 625 playlist->entries = g_list_insert(playlist->entries, |
626 playlist_entry_new(filename, title, len, dec), | |
627 pos); | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
628 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 629 |
630 g_mutex_lock(mutex_scan); | |
631 playlist_get_info_scan_active = TRUE; | |
632 g_mutex_unlock(mutex_scan); | |
633 g_cond_signal(cond_scan); | |
634 } | |
635 | |
636 static void | |
637 __playlist_ins_with_info_tuple(Playlist * playlist, | |
638 const gchar * filename, | |
639 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
640 Tuple *tuple, |
2313 | 641 InputPlugin * dec) |
642 { | |
643 PlaylistEntry *entry; | |
644 | |
645 g_return_if_fail(playlist != NULL); | |
646 g_return_if_fail(filename != NULL); | |
647 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
648 entry = playlist_entry_new(filename, tuple ? tuple_get_string(tuple, "title") : NULL, tuple ? tuple_get_int(tuple, "length") : -1, dec); |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
649 if(!playlist->tail) |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
650 playlist->tail = g_list_last(playlist->entries); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
651 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
652 PLAYLIST_LOCK( playlist->mutex ); |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
653 if(pos == -1) { // the common case |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
654 GList *element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
655 element = g_list_alloc(); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
656 element->data = entry; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
657 element->prev = playlist->tail; // NULL is allowed here. |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
658 element->next = NULL; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
659 |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
660 if(!playlist->entries) { // this is the first element |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
661 playlist->entries = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
662 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
663 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
664 else { // the rests |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
665 g_return_if_fail(playlist->tail != NULL); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
666 playlist->tail->next = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
667 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
668 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
669 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
670 else { |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
671 playlist->entries = g_list_insert(playlist->entries, entry, pos); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
672 } |
2313 | 673 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
674 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 675 if (tuple != NULL) { |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
676 const gchar *formatter = tuple_get_string(tuple, "formatter"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
677 entry->title = tuple_formatter_process_string(tuple, formatter ? formatter : cfg.gentitle_format); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
678 entry->length = tuple_get_int(tuple, "length"); |
2313 | 679 entry->tuple = tuple; |
680 } | |
681 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
682 if(tuple != NULL && tuple_get_int(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; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
698 Tuple *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 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1052 // overwrite tuple::title, mainly for streaming. it may incur side effects. --yaz |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1053 if(playlist->position->tuple && tuple_get_int(playlist->position->tuple, "length") == -1){ |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1054 tuple_disassociate(playlist->position->tuple, "title"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1055 tuple_associate_string(playlist->position->tuple, "title", title); |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1056 } |
2313 | 1057 } |
1058 | |
1059 playlist_recalc_total_time(playlist); | |
1060 | |
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
|
1061 /* 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 |
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 event_queue("playlist info change", msg); |
2460 | 1068 |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1069 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
|
1070 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
|
1071 |
2460 | 1072 if ( playlist->position ) |
1073 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1074 } |
1075 | |
1076 void | |
1077 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1078 gint freq, gint nch) | |
1079 { | |
1080 g_return_if_fail(playlist != NULL); | |
1081 | |
1082 if (playlist->position) { | |
1083 g_free(playlist->position->title); | |
1084 playlist->position->title = g_strdup(title); | |
1085 playlist->position->length = length; | |
1086 } | |
1087 | |
1088 playlist_recalc_total_time(playlist); | |
1089 | |
1090 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1091 |
1092 if ( playlist->position ) | |
1093 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1094 } |
1095 | |
1096 void | |
1097 playlist_check_pos_current(Playlist *playlist) | |
1098 { | |
1099 gint pos, row, bottom; | |
1100 | |
1101 if (!playlist) | |
1102 return; | |
1103 | |
1104 PLAYLIST_LOCK(playlist->mutex); | |
1105 if (!playlist->position || !playlistwin_list) { | |
1106 PLAYLIST_UNLOCK(playlist->mutex); | |
1107 return; | |
1108 } | |
1109 | |
1110 pos = g_list_index(playlist->entries, playlist->position); | |
1111 | |
1112 if (playlistwin_item_visible(pos)) { | |
1113 PLAYLIST_UNLOCK(playlist->mutex); | |
1114 return; | |
1115 } | |
1116 | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1117 bottom = MAX(0, playlist_get_length(playlist) - |
3217 | 1118 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); |
1119 row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom); | |
2313 | 1120 PLAYLIST_UNLOCK(playlist->mutex); |
1121 playlistwin_set_toprow(row); | |
1122 g_cond_signal(cond_scan); | |
1123 } | |
1124 | |
1125 void | |
1126 playlist_next(Playlist *playlist) | |
1127 { | |
1128 GList *plist_pos_list; | |
1129 gboolean restart_playing = FALSE; | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1130 if (!playlist_get_length(playlist)) |
2313 | 1131 return; |
1132 | |
1133 PLAYLIST_LOCK(playlist->mutex); | |
1134 | |
1135 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1136 { | |
1137 playlist->position = playlist_position_before_jump; | |
1138 playlist_position_before_jump = NULL; | |
1139 } | |
1140 | |
1141 plist_pos_list = find_playlist_position_list(playlist); | |
1142 | |
1143 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
1144 PLAYLIST_UNLOCK(playlist->mutex); | |
1145 return; | |
1146 } | |
1147 | |
1148 if (playback_get_playing()) { | |
1149 /* We need to stop before changing playlist_position */ | |
1150 PLAYLIST_UNLOCK(playlist->mutex); | |
1151 ip_data.stop = TRUE; | |
1152 playback_stop(); | |
1153 ip_data.stop = FALSE; | |
1154 PLAYLIST_LOCK(playlist->mutex); | |
1155 restart_playing = TRUE; | |
1156 } | |
1157 | |
1158 plist_pos_list = find_playlist_position_list(playlist); | |
1159 if (playlist->queue != NULL) | |
1160 play_queued(playlist); | |
1161 else if (g_list_next(plist_pos_list)) | |
1162 playlist->position = g_list_next(plist_pos_list)->data; | |
1163 else if (cfg.repeat) { | |
1164 playlist->position = NULL; | |
1165 playlist_generate_shuffle_list_nolock(playlist); | |
1166 if (cfg.shuffle) | |
1167 playlist->position = playlist->shuffle->data; | |
1168 else | |
1169 playlist->position = playlist->entries->data; | |
1170 } | |
1171 PLAYLIST_UNLOCK(playlist->mutex); | |
1172 playlist_check_pos_current(playlist); | |
1173 | |
1174 if (restart_playing) | |
1175 playback_initiate(); | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1176 |
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1177 playlistwin_update_list(playlist); |
2313 | 1178 } |
1179 | |
1180 void | |
1181 playlist_prev(Playlist *playlist) | |
1182 { | |
1183 GList *plist_pos_list; | |
1184 gboolean restart_playing = FALSE; | |
1185 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1186 if (!playlist_get_length(playlist)) |
2313 | 1187 return; |
1188 | |
1189 PLAYLIST_LOCK(playlist->mutex); | |
1190 | |
1191 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1192 { | |
1193 playlist->position = playlist_position_before_jump; | |
1194 playlist_position_before_jump = NULL; | |
1195 } | |
1196 | |
1197 plist_pos_list = find_playlist_position_list(playlist); | |
1198 | |
1199 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
1200 PLAYLIST_UNLOCK(playlist->mutex); | |
1201 return; | |
1202 } | |
1203 | |
1204 if (playback_get_playing()) { | |
1205 /* We need to stop before changing playlist_position */ | |
1206 PLAYLIST_UNLOCK(playlist->mutex); | |
1207 ip_data.stop = TRUE; | |
1208 playback_stop(); | |
1209 ip_data.stop = FALSE; | |
1210 PLAYLIST_LOCK(playlist->mutex); | |
1211 restart_playing = TRUE; | |
1212 } | |
1213 | |
1214 plist_pos_list = find_playlist_position_list(playlist); | |
1215 if (g_list_previous(plist_pos_list)) { | |
1216 playlist->position = g_list_previous(plist_pos_list)->data; | |
1217 } | |
1218 else if (cfg.repeat) { | |
1219 GList *node; | |
1220 playlist->position = NULL; | |
1221 playlist_generate_shuffle_list_nolock(playlist); | |
1222 if (cfg.shuffle) | |
1223 node = g_list_last(playlist->shuffle); | |
1224 else | |
1225 node = g_list_last(playlist->entries); | |
1226 if (node) | |
1227 playlist->position = node->data; | |
1228 } | |
1229 | |
1230 PLAYLIST_UNLOCK(playlist->mutex); | |
1231 | |
1232 playlist_check_pos_current(playlist); | |
1233 | |
1234 if (restart_playing) | |
1235 playback_initiate(); | |
1236 else { | |
1237 playlistwin_update_list(playlist); | |
1238 } | |
1239 } | |
1240 | |
1241 void | |
1242 playlist_queue(Playlist *playlist) | |
1243 { | |
1244 GList *list = playlist_get_selected(playlist); | |
1245 GList *it = list; | |
1246 | |
1247 PLAYLIST_LOCK(playlist->mutex); | |
1248 | |
1249 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1250 { | |
1251 /* Shuffling and this is our first manual jump. */ | |
1252 playlist_position_before_jump = playlist->position; | |
1253 } | |
1254 | |
1255 while (it) { | |
1256 GList *next = g_list_next(it); | |
1257 GList *tmp; | |
1258 | |
1259 /* XXX: WTF? --nenolod */ | |
1260 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1261 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1262 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1263 g_list_free_1(tmp); | |
1264 list = g_list_remove_link(list, it); | |
1265 g_list_free_1(it); | |
1266 } | |
1267 | |
1268 it = next; | |
1269 } | |
1270 | |
1271 playlist->queue = g_list_concat(playlist->queue, list); | |
1272 | |
1273 PLAYLIST_UNLOCK(playlist->mutex); | |
1274 | |
1275 playlist_recalc_total_time(playlist); | |
1276 playlistwin_update_list(playlist); | |
1277 } | |
1278 | |
1279 void | |
1280 playlist_queue_position(Playlist *playlist, guint pos) | |
1281 { | |
1282 GList *tmp; | |
1283 PlaylistEntry *entry; | |
1284 | |
1285 PLAYLIST_LOCK(playlist->mutex); | |
1286 | |
1287 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1288 { | |
1289 /* Shuffling and this is our first manual jump. */ | |
1290 playlist_position_before_jump = playlist->position; | |
1291 } | |
1292 | |
1293 entry = g_list_nth_data(playlist->entries, pos); | |
1294 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1295 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1296 g_list_free_1(tmp); | |
1297 } | |
1298 else | |
1299 playlist->queue = g_list_append(playlist->queue, entry); | |
1300 PLAYLIST_UNLOCK(playlist->mutex); | |
1301 | |
1302 playlist_recalc_total_time(playlist); | |
1303 playlistwin_update_list(playlist); | |
1304 } | |
1305 | |
1306 gboolean | |
1307 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1308 { | |
1309 PlaylistEntry *entry; | |
1310 GList *tmp; | |
1311 | |
1312 PLAYLIST_LOCK(playlist->mutex); | |
1313 entry = g_list_nth_data(playlist->entries, pos); | |
1314 tmp = g_list_find(playlist->queue, entry); | |
1315 PLAYLIST_UNLOCK(playlist->mutex); | |
1316 | |
1317 return tmp != NULL; | |
1318 } | |
1319 | |
1320 gint | |
1321 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1322 { | |
1323 PlaylistEntry *entry; | |
1324 gint tmp; | |
1325 | |
1326 PLAYLIST_LOCK(playlist->mutex); | |
1327 entry = g_list_nth_data(playlist->entries, pos); | |
1328 tmp = g_list_index(playlist->queue, entry); | |
1329 PLAYLIST_UNLOCK(playlist->mutex); | |
1330 | |
1331 return tmp; | |
1332 } | |
1333 | |
1334 gint | |
1335 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1336 { | |
1337 PlaylistEntry *entry; | |
1338 gint tmp; | |
1339 | |
1340 PLAYLIST_LOCK(playlist->mutex); | |
1341 entry = g_list_nth_data(playlist->queue, pos); | |
1342 tmp = g_list_index(playlist->entries, entry); | |
1343 PLAYLIST_UNLOCK(playlist->mutex); | |
1344 | |
1345 return tmp; | |
1346 } | |
1347 | |
1348 void | |
1349 playlist_clear_queue(Playlist *playlist) | |
1350 { | |
1351 PLAYLIST_LOCK(playlist->mutex); | |
1352 g_list_free(playlist->queue); | |
1353 playlist->queue = NULL; | |
1354 PLAYLIST_UNLOCK(playlist->mutex); | |
1355 | |
1356 playlist_recalc_total_time(playlist); | |
1357 playlistwin_update_list(playlist); | |
1358 } | |
1359 | |
1360 void | |
1361 playlist_queue_remove(Playlist *playlist, guint pos) | |
1362 { | |
1363 void *entry; | |
1364 | |
1365 PLAYLIST_LOCK(playlist->mutex); | |
1366 entry = g_list_nth_data(playlist->entries, pos); | |
1367 playlist->queue = g_list_remove(playlist->queue, entry); | |
1368 PLAYLIST_UNLOCK(playlist->mutex); | |
1369 | |
1370 playlistwin_update_list(playlist); | |
1371 } | |
1372 | |
1373 gint | |
1374 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1375 { | |
1376 return g_list_index(playlist->queue, entry); | |
1377 } | |
1378 | |
1379 void | |
1380 playlist_set_position(Playlist *playlist, guint pos) | |
1381 { | |
1382 GList *node; | |
1383 gboolean restart_playing = FALSE; | |
1384 | |
1385 if (!playlist) | |
1386 return; | |
1387 | |
1388 PLAYLIST_LOCK(playlist->mutex); | |
1389 | |
1390 node = g_list_nth(playlist->entries, pos); | |
1391 if (!node) { | |
1392 PLAYLIST_UNLOCK(playlist->mutex); | |
1393 return; | |
1394 } | |
1395 | |
1396 if (playback_get_playing()) { | |
1397 /* We need to stop before changing playlist_position */ | |
1398 PLAYLIST_UNLOCK(playlist->mutex); | |
1399 ip_data.stop = TRUE; | |
1400 playback_stop(); | |
1401 ip_data.stop = FALSE; | |
1402 PLAYLIST_LOCK(playlist->mutex); | |
1403 restart_playing = TRUE; | |
1404 } | |
1405 | |
1406 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1407 { | |
1408 /* Shuffling and this is our first manual jump. */ | |
1409 playlist_position_before_jump = playlist->position; | |
1410 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1411 |
2313 | 1412 playlist->position = node->data; |
1413 PLAYLIST_UNLOCK(playlist->mutex); | |
1414 playlist_check_pos_current(playlist); | |
1415 | |
1416 if (restart_playing) | |
1417 playback_initiate(); | |
1418 else { | |
1419 playlistwin_update_list(playlist); | |
1420 } | |
1421 } | |
1422 | |
1423 void | |
1424 playlist_eof_reached(Playlist *playlist) | |
1425 { | |
1426 GList *plist_pos_list; | |
1427 | |
1428 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1429 ip_data.stop = TRUE; | |
1430 playback_stop(); | |
1431 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1432 ip_data.stop = FALSE; | |
1433 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1434 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1435 |
2313 | 1436 PLAYLIST_LOCK(playlist->mutex); |
1437 | |
1438 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1439 { | |
1440 playlist->position = playlist_position_before_jump; | |
1441 playlist_position_before_jump = NULL; | |
1442 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1443 |
2313 | 1444 plist_pos_list = find_playlist_position_list(playlist); |
1445 | |
1446 if (cfg.no_playlist_advance) { | |
1447 PLAYLIST_UNLOCK(playlist->mutex); | |
1448 mainwin_clear_song_info(); | |
1449 if (cfg.repeat) | |
1450 playback_initiate(); | |
1451 return; | |
1452 } | |
1453 | |
1454 if (cfg.stopaftersong) { | |
1455 PLAYLIST_UNLOCK(playlist->mutex); | |
1456 mainwin_clear_song_info(); | |
1457 mainwin_set_stopaftersong(FALSE); | |
1458 return; | |
1459 } | |
1460 | |
1461 if (playlist->queue != NULL) { | |
1462 play_queued(playlist); | |
1463 } | |
1464 else if (!g_list_next(plist_pos_list)) { | |
1465 if (cfg.shuffle) { | |
1466 playlist->position = NULL; | |
1467 playlist_generate_shuffle_list_nolock(playlist); | |
1468 } | |
2380 | 1469 else if (playlist->entries != NULL) |
2313 | 1470 playlist->position = playlist->entries->data; |
1471 | |
1472 if (!cfg.repeat) { | |
1473 PLAYLIST_UNLOCK(playlist->mutex); | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1474 hook_call("playlist end reached", playlist->position); |
2313 | 1475 mainwin_clear_song_info(); |
1476 return; | |
1477 } | |
1478 } | |
1479 else | |
1480 playlist->position = g_list_next(plist_pos_list)->data; | |
1481 | |
1482 PLAYLIST_UNLOCK(playlist->mutex); | |
1483 | |
1484 playlist_check_pos_current(playlist); | |
1485 playback_initiate(); | |
1486 playlistwin_update_list(playlist); | |
1487 } | |
1488 | |
1489 gint | |
1490 playlist_queue_get_length(Playlist *playlist) | |
1491 { | |
1492 gint length; | |
1493 | |
1494 PLAYLIST_LOCK(playlist->mutex); | |
1495 length = g_list_length(playlist->queue); | |
1496 PLAYLIST_UNLOCK(playlist->mutex); | |
1497 | |
1498 return length; | |
1499 } | |
1500 | |
1501 gint | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1502 playlist_get_length(Playlist *playlist) |
2313 | 1503 { |
1504 return g_list_length(playlist->entries); | |
1505 } | |
1506 | |
1507 gchar * | |
1508 playlist_get_info_text(Playlist *playlist) | |
1509 { | |
1510 gchar *text, *title, *numbers, *length; | |
1511 | |
1512 g_return_val_if_fail(playlist != NULL, NULL); | |
1513 | |
1514 PLAYLIST_LOCK(playlist->mutex); | |
1515 if (!playlist->position) { | |
1516 PLAYLIST_UNLOCK(playlist->mutex); | |
1517 return NULL; | |
1518 } | |
1519 | |
1520 /* FIXME: there should not be a need to do additional conversion, | |
1521 * if playlist is properly maintained */ | |
1522 if (playlist->position->title) { | |
1523 title = str_to_utf8(playlist->position->title); | |
1524 } | |
1525 else { | |
3097
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1526 gchar *realfn = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1527 gchar *basename = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1528 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
|
1529 basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); |
2313 | 1530 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
|
1531 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
|
1532 g_free(basename); basename = NULL; |
2313 | 1533 } |
1534 | |
1535 /* | |
1536 * If the user don't want numbers in the playlist, don't | |
1537 * display them in other parts of XMMS | |
1538 */ | |
1539 | |
1540 if (cfg.show_numbers_in_pl) | |
1541 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1542 else | |
1543 numbers = g_strdup(""); | |
1544 | |
1545 if (playlist->position->length != -1) | |
1546 length = g_strdup_printf(" (%d:%-2.2d)", | |
1547 playlist->position->length / 60000, | |
1548 (playlist->position->length / 1000) % 60); | |
1549 else | |
1550 length = g_strdup(""); | |
1551 | |
1552 PLAYLIST_UNLOCK(playlist->mutex); | |
1553 | |
1554 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1555 | |
1556 g_free(numbers); | |
1557 g_free(title); | |
1558 g_free(length); | |
1559 | |
1560 return text; | |
1561 } | |
1562 | |
1563 gint | |
1564 playlist_get_current_length(Playlist * playlist) | |
1565 { | |
1566 gint len = 0; | |
1567 | |
1568 if (!playlist) | |
1569 return 0; | |
1570 | |
1571 if (playlist->position) | |
1572 len = playlist->position->length; | |
1573 | |
1574 return len; | |
1575 } | |
1576 | |
1577 gboolean | |
1578 playlist_save(Playlist * playlist, const gchar * filename) | |
1579 { | |
1580 PlaylistContainer *plc = NULL; | |
1581 gchar *ext; | |
1582 | |
1583 g_return_val_if_fail(playlist != NULL, FALSE); | |
1584 g_return_val_if_fail(filename != NULL, FALSE); | |
1585 | |
1586 ext = strrchr(filename, '.') + 1; | |
1587 | |
1588 playlist_set_current_name(playlist, filename); | |
1589 | |
1590 if ((plc = playlist_container_find(ext)) == NULL) | |
1591 return FALSE; | |
1592 | |
1593 if (plc->plc_write == NULL) | |
1594 return FALSE; | |
1595 | |
1596 plc->plc_write(filename, 0); | |
1597 | |
1598 return TRUE; | |
1599 } | |
1600 | |
1601 gboolean | |
1602 playlist_load(Playlist * playlist, const gchar * filename) | |
1603 { | |
1604 gboolean ret = FALSE; | |
1605 g_return_val_if_fail(playlist != NULL, FALSE); | |
1606 | |
1607 playlist->loading_playlist = TRUE; | |
1608 ret = playlist_load_ins(playlist, filename, -1); | |
1609 playlist->loading_playlist = FALSE; | |
1610 | |
1611 return ret; | |
1612 } | |
1613 | |
1614 void | |
1615 playlist_load_ins_file(Playlist *playlist, | |
1616 const gchar * filename_p, | |
1617 const gchar * playlist_name, gint pos, | |
1618 const gchar * title, gint len) | |
1619 { | |
1620 gchar *filename; | |
1621 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1622 ProbeResult *pr = NULL; |
2313 | 1623 |
1624 g_return_if_fail(filename_p != NULL); | |
1625 g_return_if_fail(playlist != NULL); | |
1626 g_return_if_fail(playlist_name != NULL); | |
1627 | |
1628 filename = g_strchug(g_strdup(filename_p)); | |
1629 | |
1630 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
|
1631 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
|
1632 *tmp = '/'; |
2313 | 1633 |
1634 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1635 path = g_strdup(playlist_name); | |
1636 if ((tmp = strrchr(path, '/'))) | |
1637 *tmp = '\0'; | |
1638 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1639 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1640 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1641 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1642 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
|
1643 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1644 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1645 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1646 __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
|
1647 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1648 g_free(pr); |
2313 | 1649 return; |
1650 } | |
1651 tmp = g_build_filename(path, filename, NULL); | |
1652 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1653 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
|
1654 pr = NULL; |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1655 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
|
1656 !str_has_prefix_nocase(tmp, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1657 pr = input_check_file(tmp, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1658 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
1659 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
2313 | 1660 g_free(tmp); |
1661 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1662 g_free(pr); |
2313 | 1663 } |
1664 else | |
1665 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1666 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1667 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1668 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1669 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
|
1670 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1671 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1672 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1673 __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
|
1674 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1675 g_free(pr); |
2313 | 1676 } |
1677 | |
1678 g_free(filename); | |
1679 } | |
1680 | |
1681 void | |
1682 playlist_load_ins_file_tuple(Playlist * playlist, | |
1683 const gchar * filename_p, | |
1684 const gchar * playlist_name, | |
1685 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1686 Tuple *tuple) |
2313 | 1687 { |
1688 gchar *filename; | |
1689 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1690 ProbeResult *pr = NULL; /* for decoder cache */ |
2313 | 1691 |
1692 g_return_if_fail(filename_p != NULL); | |
1693 g_return_if_fail(playlist_name != NULL); | |
1694 g_return_if_fail(playlist != NULL); | |
1695 | |
1696 filename = g_strchug(g_strdup(filename_p)); | |
1697 | |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1698 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
|
1699 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
|
1700 *tmp = '/'; |
2313 | 1701 |
1702 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1703 path = g_strdup(playlist_name); | |
1704 if ((tmp = strrchr(path, '/'))) | |
1705 *tmp = '\0'; | |
1706 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1707 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1708 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1709 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1710 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
|
1711 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1712 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1713 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1714 __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
|
1715 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1716 g_free(pr); |
2313 | 1717 return; |
1718 } | |
1719 tmp = g_build_filename(path, filename, NULL); | |
1720 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1721 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1722 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1723 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1724 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
|
1725 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1726 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1727 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1728 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
2313 | 1729 g_free(tmp); |
1730 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1731 g_free(pr); |
2313 | 1732 } |
1733 else | |
1734 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1735 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1736 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1737 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1738 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
|
1739 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1740 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1741 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1742 __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
|
1743 g_free(pr); |
2313 | 1744 } |
1745 | |
1746 g_free(filename); | |
1747 } | |
1748 | |
1749 static guint | |
1750 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1751 { | |
1752 PlaylistContainer *plc; | |
1753 gchar *ext; | |
1754 | |
1755 g_return_val_if_fail(playlist != NULL, 0); | |
1756 g_return_val_if_fail(filename != NULL, 0); | |
1757 | |
1758 ext = strrchr(filename, '.') + 1; | |
1759 plc = playlist_container_find(ext); | |
1760 | |
1761 g_return_val_if_fail(plc != NULL, 0); | |
1762 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1763 | |
1764 plc->plc_read(filename, pos); | |
1765 | |
1766 playlist_generate_shuffle_list(playlist); | |
1767 playlistwin_update_list(playlist); | |
1768 | |
1769 return 1; | |
1770 } | |
1771 | |
1772 GList * | |
1773 get_playlist_nth(Playlist *playlist, guint nth) | |
1774 { | |
1775 g_warning("deprecated function get_playlist_nth() was called"); | |
1776 REQUIRE_LOCK(playlist->mutex); | |
1777 return g_list_nth(playlist->entries, nth); | |
1778 } | |
1779 | |
1780 gint | |
1781 playlist_get_position_nolock(Playlist *playlist) | |
1782 { | |
1783 if (playlist && playlist->position) | |
1784 return g_list_index(playlist->entries, playlist->position); | |
1785 return 0; | |
1786 } | |
1787 | |
1788 gint | |
1789 playlist_get_position(Playlist *playlist) | |
1790 { | |
1791 gint pos; | |
1792 | |
1793 PLAYLIST_LOCK(playlist->mutex); | |
1794 pos = playlist_get_position_nolock(playlist); | |
1795 PLAYLIST_UNLOCK(playlist->mutex); | |
1796 | |
1797 return pos; | |
1798 } | |
1799 | |
1800 gchar * | |
1801 playlist_get_filename(Playlist *playlist, guint pos) | |
1802 { | |
1803 gchar *filename; | |
1804 PlaylistEntry *entry; | |
1805 GList *node; | |
1806 | |
1807 if (!playlist) | |
1808 return NULL; | |
1809 | |
1810 PLAYLIST_LOCK(playlist->mutex); | |
1811 node = g_list_nth(playlist->entries, pos); | |
1812 if (!node) { | |
1813 PLAYLIST_UNLOCK(playlist->mutex); | |
1814 return NULL; | |
1815 } | |
1816 entry = node->data; | |
1817 | |
1818 filename = g_strdup(entry->filename); | |
1819 PLAYLIST_UNLOCK(playlist->mutex); | |
1820 | |
1821 return filename; | |
1822 } | |
1823 | |
1824 gchar * | |
1825 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1826 { | |
1827 gchar *title = NULL; | |
1828 PlaylistEntry *entry; | |
1829 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1830 time_t mtime; |
2313 | 1831 |
1832 if (!playlist) | |
1833 return NULL; | |
1834 | |
1835 PLAYLIST_LOCK(playlist->mutex); | |
1836 | |
1837 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1838 PLAYLIST_UNLOCK(playlist->mutex); | |
1839 return NULL; | |
1840 } | |
1841 | |
1842 entry = node->data; | |
1843 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1844 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1845 mtime = tuple_get_int(entry->tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1846 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1847 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1848 |
2313 | 1849 /* FIXME: simplify this logic */ |
1850 if ((entry->title == NULL && entry->length == -1) || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1851 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1852 { |
1853 if (playlist_entry_get_info(entry)) | |
1854 title = entry->title; | |
1855 } | |
1856 else { | |
1857 title = entry->title; | |
1858 } | |
1859 | |
1860 PLAYLIST_UNLOCK(playlist->mutex); | |
1861 | |
1862 if (!title) { | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1863 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1864 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
|
1865 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
|
1866 g_free(realfn); realfn = NULL; |
2313 | 1867 return str_replace(title, filename_to_utf8(title)); |
1868 } | |
1869 | |
1870 return str_to_utf8(title); | |
1871 } | |
1872 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1873 Tuple * |
2313 | 1874 playlist_get_tuple(Playlist *playlist, guint pos) |
1875 { | |
1876 PlaylistEntry *entry; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1877 Tuple *tuple = NULL; |
2313 | 1878 GList *node; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1879 time_t mtime; |
2313 | 1880 |
1881 if (!playlist) | |
1882 return NULL; | |
1883 | |
1884 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1885 return NULL; | |
1886 } | |
1887 | |
1888 entry = (PlaylistEntry *) node->data; | |
1889 | |
1890 tuple = entry->tuple; | |
1891 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1892 if (tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1893 mtime = tuple_get_int(tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1894 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1895 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1896 |
2313 | 1897 // if no tuple or tuple with old mtime, get new one. |
1898 if (tuple == NULL || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1899 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1900 { |
1901 playlist_entry_get_info(entry); | |
1902 tuple = entry->tuple; | |
1903 } | |
1904 | |
1905 return tuple; | |
1906 } | |
1907 | |
1908 gint | |
1909 playlist_get_songtime(Playlist *playlist, guint pos) | |
1910 { | |
1911 gint song_time = -1; | |
1912 PlaylistEntry *entry; | |
1913 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1914 time_t mtime; |
2313 | 1915 |
1916 if (!playlist) | |
1917 return -1; | |
1918 | |
1919 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1920 return -1; | |
1921 } | |
1922 | |
1923 entry = node->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1924 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1925 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1926 mtime = tuple_get_int(entry->tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1927 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1928 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1929 |
2313 | 1930 if (entry->tuple == NULL || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1931 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { |
2313 | 1932 |
1933 if (playlist_entry_get_info(entry)) | |
1934 song_time = entry->length; | |
1935 } | |
1936 else { | |
1937 song_time = entry->length; | |
1938 } | |
1939 | |
1940 return song_time; | |
1941 } | |
1942 | |
1943 static gint | |
1944 playlist_compare_track(PlaylistEntry * a, | |
1945 PlaylistEntry * b) | |
1946 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1947 gint tracknumber_a; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1948 gint tracknumber_b; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1949 |
2313 | 1950 g_return_val_if_fail(a != NULL, 0); |
1951 g_return_val_if_fail(b != NULL, 0); | |
1952 | |
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
|
1953 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
|
1954 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
|
1955 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
|
1956 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
|
1957 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1958 if (a->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1959 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1960 if (b->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1961 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1962 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1963 tracknumber_a = tuple_get_int(a->tuple, "track-number"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1964 tracknumber_b = tuple_get_int(b->tuple, "track-number"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1965 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1966 return (tracknumber_a && tracknumber_b ? |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1967 tracknumber_a - tracknumber_b : 0); |
2313 | 1968 } |
1969 | |
1970 static gint | |
1971 playlist_compare_playlist(PlaylistEntry * a, | |
1972 PlaylistEntry * b) | |
1973 { | |
1974 const gchar *a_title = NULL, *b_title = NULL; | |
1975 | |
1976 g_return_val_if_fail(a != NULL, 0); | |
1977 g_return_val_if_fail(b != NULL, 0); | |
1978 | |
1979 if (a->title != NULL) | |
1980 a_title = a->title; | |
1981 else { | |
1982 if (strrchr(a->filename, '/')) | |
1983 a_title = strrchr(a->filename, '/') + 1; | |
1984 else | |
1985 a_title = a->filename; | |
1986 } | |
1987 | |
1988 if (b->title != NULL) | |
1989 b_title = b->title; | |
1990 else { | |
1991 if (strrchr(a->filename, '/')) | |
1992 b_title = strrchr(b->filename, '/') + 1; | |
1993 else | |
1994 b_title = b->filename; | |
1995 } | |
1996 | |
1997 return strcasecmp(a_title, b_title); | |
1998 } | |
1999 | |
2000 static gint | |
2001 playlist_compare_title(PlaylistEntry * a, | |
2002 PlaylistEntry * b) | |
2003 { | |
2004 const gchar *a_title = NULL, *b_title = NULL; | |
2005 | |
2006 g_return_val_if_fail(a != NULL, 0); | |
2007 g_return_val_if_fail(b != NULL, 0); | |
2008 | |
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
|
2009 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
|
2010 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
|
2011 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
|
2012 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
|
2013 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2014 if (a->tuple != NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2015 a_title = tuple_get_string(a->tuple, "title"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2016 if (b->tuple != NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2017 b_title = tuple_get_string(b->tuple, "title"); |
2313 | 2018 |
2019 if (a_title != NULL && b_title != NULL) | |
2020 return strcasecmp(a_title, b_title); | |
2021 | |
2022 if (a->title != NULL) | |
2023 a_title = a->title; | |
2024 else { | |
2025 if (strrchr(a->filename, '/')) | |
2026 a_title = strrchr(a->filename, '/') + 1; | |
2027 else | |
2028 a_title = a->filename; | |
2029 } | |
2030 | |
2031 if (b->title != NULL) | |
2032 b_title = b->title; | |
2033 else { | |
2034 if (strrchr(a->filename, '/')) | |
2035 b_title = strrchr(b->filename, '/') + 1; | |
2036 else | |
2037 b_title = b->filename; | |
2038 } | |
2039 | |
2040 return strcasecmp(a_title, b_title); | |
2041 } | |
2042 | |
2043 static gint | |
2044 playlist_compare_artist(PlaylistEntry * a, | |
2045 PlaylistEntry * b) | |
2046 { | |
2047 const gchar *a_artist = NULL, *b_artist = NULL; | |
2048 | |
2049 g_return_val_if_fail(a != NULL, 0); | |
2050 g_return_val_if_fail(b != NULL, 0); | |
2051 | |
2052 if (a->tuple != NULL) | |
2053 playlist_entry_get_info(a); | |
2054 | |
2055 if (b->tuple != NULL) | |
2056 playlist_entry_get_info(b); | |
2057 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2058 if (a->tuple != NULL) { |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2059 a_artist = tuple_get_string(a->tuple, "artist"); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2060 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
|
2061 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2062 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2063 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2064 if (b->tuple != NULL) { |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2065 b_artist = tuple_get_string(b->tuple, "artist"); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2066 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
|
2067 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2068 } |
2313 | 2069 |
2070 if (a_artist != NULL && b_artist != NULL) | |
2071 return strcasecmp(a_artist, b_artist); | |
2072 | |
2073 return 0; | |
2074 } | |
2075 | |
2076 static gint | |
2077 playlist_compare_filename(PlaylistEntry * a, | |
2078 PlaylistEntry * b) | |
2079 { | |
2080 gchar *a_filename, *b_filename; | |
2081 | |
2082 g_return_val_if_fail(a != NULL, 0); | |
2083 g_return_val_if_fail(b != NULL, 0); | |
2084 | |
2085 if (strrchr(a->filename, '/')) | |
2086 a_filename = strrchr(a->filename, '/') + 1; | |
2087 else | |
2088 a_filename = a->filename; | |
2089 | |
2090 if (strrchr(b->filename, '/')) | |
2091 b_filename = strrchr(b->filename, '/') + 1; | |
2092 else | |
2093 b_filename = b->filename; | |
2094 | |
2095 | |
2096 return strcasecmp(a_filename, b_filename); | |
2097 } | |
2098 | |
2099 static gint | |
2100 path_compare(const gchar * a, const gchar * b) | |
2101 { | |
2102 gchar *posa, *posb; | |
2103 gint len, ret; | |
2104 | |
2105 posa = strrchr(a, '/'); | |
2106 posb = strrchr(b, '/'); | |
2107 | |
2108 /* | |
2109 * Sort directories before files | |
2110 */ | |
2111 if (posa && posb && (posa - a != posb - b)) { | |
2112 if (posa - a > posb - b) { | |
2113 len = posb - b; | |
2114 ret = -1; | |
2115 } | |
2116 else { | |
2117 len = posa - a; | |
2118 ret = 1; | |
2119 } | |
2120 if (!strncasecmp(a, b, len)) | |
2121 return ret; | |
2122 } | |
2123 return strcasecmp(a, b); | |
2124 } | |
2125 | |
2126 static gint | |
2127 playlist_compare_path(PlaylistEntry * a, | |
2128 PlaylistEntry * b) | |
2129 { | |
2130 return path_compare(a->filename, b->filename); | |
2131 } | |
2132 | |
2133 | |
2134 static time_t | |
2135 playlist_get_mtime(const gchar *filename) | |
2136 { | |
2137 struct stat buf; | |
2138 gint rv; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2139 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2140 |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2141 /* 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
|
2142 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
|
2143 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
|
2144 g_free(realfn); realfn = NULL; |
2313 | 2145 |
2146 if (rv == 0) { | |
2147 return buf.st_mtime; | |
2148 } else { | |
2149 return 0; //error | |
2150 } | |
2151 } | |
2152 | |
2153 | |
2154 static gint | |
2155 playlist_compare_date(PlaylistEntry * a, | |
2156 PlaylistEntry * b) | |
2157 { | |
2158 struct stat buf; | |
2159 time_t modtime; | |
2160 | |
2161 gint rv; | |
2162 | |
2163 | |
2164 rv = stat(a->filename, &buf); | |
2165 | |
2166 if (rv == 0) { | |
2167 modtime = buf.st_mtime; | |
2168 rv = stat(b->filename, &buf); | |
2169 | |
2170 if (stat(b->filename, &buf) == 0) { | |
2171 if (buf.st_mtime == modtime) | |
2172 return 0; | |
2173 else | |
2174 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2175 } | |
2176 else | |
2177 return -1; | |
2178 } | |
2179 else if (!lstat(b->filename, &buf)) | |
2180 return 1; | |
2181 else | |
2182 return playlist_compare_filename(a, b); | |
2183 } | |
2184 | |
2185 | |
2186 void | |
2187 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2188 { | |
2189 playlist_remove_dead_files(playlist); | |
2190 PLAYLIST_LOCK(playlist->mutex); | |
2191 playlist->entries = | |
2192 g_list_sort(playlist->entries, | |
2193 (GCompareFunc) playlist_compare_func_table[type]); | |
2194 PLAYLIST_UNLOCK(playlist->mutex); | |
2195 } | |
2196 | |
2197 static GList * | |
2198 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2199 { | |
2200 GList *list1, *list2; | |
2201 GList *tmp_list = NULL; | |
2202 GList *index_list = NULL; | |
2203 | |
2204 /* | |
2205 * We take all the selected entries out of the playlist, | |
2206 * sorts them, and then put them back in again. | |
2207 */ | |
2208 | |
2209 list1 = g_list_last(list); | |
2210 | |
2211 while (list1) { | |
2212 list2 = g_list_previous(list1); | |
2213 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2214 gpointer idx; | |
2215 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2216 index_list = g_list_prepend(index_list, idx); | |
2217 list = g_list_remove_link(list, list1); | |
2218 tmp_list = g_list_concat(list1, tmp_list); | |
2219 } | |
2220 list1 = list2; | |
2221 } | |
2222 | |
2223 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2224 list1 = tmp_list; | |
2225 list2 = index_list; | |
2226 | |
2227 while (list2) { | |
2228 if (!list1) { | |
2229 g_critical(G_STRLOC ": Error during list sorting. " | |
2230 "Possibly dropped some playlist-entries."); | |
2231 break; | |
2232 } | |
2233 | |
2234 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2235 | |
2236 list2 = g_list_next(list2); | |
2237 list1 = g_list_next(list1); | |
2238 } | |
2239 | |
2240 g_list_free(index_list); | |
2241 g_list_free(tmp_list); | |
2242 | |
2243 return list; | |
2244 } | |
2245 | |
2246 void | |
2247 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2248 { | |
2249 PLAYLIST_LOCK(playlist->mutex); | |
2250 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) | |
2251 playlist_compare_func_table | |
2252 [type]); | |
2253 PLAYLIST_UNLOCK(playlist->mutex); | |
2254 } | |
2255 | |
2256 void | |
2257 playlist_reverse(Playlist *playlist) | |
2258 { | |
2259 PLAYLIST_LOCK(playlist->mutex); | |
2260 playlist->entries = g_list_reverse(playlist->entries); | |
2261 PLAYLIST_UNLOCK(playlist->mutex); | |
2262 } | |
2263 | |
2264 static GList * | |
2265 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2266 { | |
2267 /* | |
2268 * Note that this doesn't make a copy of the original list. | |
2269 * The pointer to the original list is not valid after this | |
2270 * fuction is run. | |
2271 */ | |
2272 gint len = g_list_length(list); | |
2273 gint i, j; | |
2274 GList *node, **ptrs; | |
2275 | |
2276 if (!playlist) | |
2277 return NULL; | |
2278 | |
2279 REQUIRE_LOCK(playlist->mutex); | |
2280 | |
2281 if (!len) | |
2282 return NULL; | |
2283 | |
2284 ptrs = g_new(GList *, len); | |
2285 | |
2286 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2287 ptrs[i] = node; | |
2288 | |
2289 j = g_random_int_range(0, len); | |
2290 list = ptrs[j]; | |
2291 ptrs[j]->next = NULL; | |
2292 ptrs[j] = ptrs[0]; | |
2293 | |
2294 for (i = 1; i < len; i++) { | |
2295 j = g_random_int_range(0, len - i); | |
2296 list->prev = ptrs[i + j]; | |
2297 ptrs[i + j]->next = list; | |
2298 list = ptrs[i + j]; | |
2299 ptrs[i + j] = ptrs[i]; | |
2300 } | |
2301 list->prev = NULL; | |
2302 | |
2303 g_free(ptrs); | |
2304 | |
2305 return list; | |
2306 } | |
2307 | |
2308 void | |
2309 playlist_random(Playlist *playlist) | |
2310 { | |
2311 PLAYLIST_LOCK(playlist->mutex); | |
2312 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); | |
2313 PLAYLIST_UNLOCK(playlist->mutex); | |
2314 } | |
2315 | |
2316 GList * | |
2317 playlist_get_selected(Playlist *playlist) | |
2318 { | |
2319 GList *node, *list = NULL; | |
2320 gint i = 0; | |
2321 | |
2322 PLAYLIST_LOCK(playlist->mutex); | |
2323 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2324 PlaylistEntry *entry = node->data; | |
2325 if (entry->selected) | |
2326 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2327 } | |
2328 PLAYLIST_UNLOCK(playlist->mutex); | |
2329 return g_list_reverse(list); | |
2330 } | |
2331 | |
2332 void | |
2333 playlist_clear_selected(Playlist *playlist) | |
2334 { | |
2335 GList *node = NULL; | |
2336 gint i = 0; | |
2337 | |
2338 PLAYLIST_LOCK(playlist->mutex); | |
2339 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2340 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2341 } | |
2342 PLAYLIST_UNLOCK(playlist->mutex); | |
2343 playlist_recalc_total_time(playlist); | |
2344 playlist_manager_update(); | |
2345 } | |
2346 | |
2347 gint | |
2348 playlist_get_num_selected(Playlist *playlist) | |
2349 { | |
2350 GList *node; | |
2351 gint num = 0; | |
2352 | |
2353 PLAYLIST_LOCK(playlist->mutex); | |
2354 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2355 PlaylistEntry *entry = node->data; | |
2356 if (entry->selected) | |
2357 num++; | |
2358 } | |
2359 PLAYLIST_UNLOCK(playlist->mutex); | |
2360 return num; | |
2361 } | |
2362 | |
2363 | |
2364 static void | |
2365 playlist_generate_shuffle_list(Playlist *playlist) | |
2366 { | |
2367 PLAYLIST_LOCK(playlist->mutex); | |
2368 playlist_generate_shuffle_list_nolock(playlist); | |
2369 PLAYLIST_UNLOCK(playlist->mutex); | |
2370 } | |
2371 | |
2372 static void | |
2373 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2374 { | |
2375 GList *node; | |
2376 gint numsongs; | |
2377 | |
2378 if (!cfg.shuffle || !playlist) | |
2379 return; | |
2380 | |
2381 REQUIRE_LOCK(playlist->mutex); | |
2382 | |
2383 if (playlist->shuffle) { | |
2384 g_list_free(playlist->shuffle); | |
2385 playlist->shuffle = NULL; | |
2386 } | |
2387 | |
2388 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2389 numsongs = g_list_length(playlist->shuffle); | |
2390 | |
2391 if (playlist->position) { | |
2392 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2393 node = g_list_nth(playlist->shuffle, i); | |
2394 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2395 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2396 } | |
2397 } | |
2398 | |
2399 void | |
2400 playlist_fileinfo(Playlist *playlist, guint pos) | |
2401 { | |
2402 gchar *path = NULL; | |
2403 GList *node; | |
2404 PlaylistEntry *entry = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2405 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2406 ProbeResult *pr = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2407 time_t mtime; |
2313 | 2408 |
2409 PLAYLIST_LOCK(playlist->mutex); | |
2410 | |
2411 if ((node = g_list_nth(playlist->entries, pos))) | |
2412 { | |
2413 entry = node->data; | |
2414 tuple = entry->tuple; | |
2415 path = g_strdup(entry->filename); | |
2416 } | |
2417 | |
2418 PLAYLIST_UNLOCK(playlist->mutex); | |
2419 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2420 if (entry->tuple) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2421 mtime = tuple_get_int(entry->tuple, "mtime"); |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2422 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2423 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2424 |
2313 | 2425 /* No tuple? Try to set this entry up properly. --nenolod */ |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2426 if (entry->tuple == NULL || mtime == -1 || |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2427 mtime == 0 || mtime != playlist_get_mtime(entry->filename)) |
2313 | 2428 { |
2429 playlist_entry_get_info(entry); | |
2430 tuple = entry->tuple; | |
2431 } | |
2432 | |
2433 if (tuple != NULL) | |
2434 { | |
2435 if (entry->decoder == NULL) | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2436 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2437 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
|
2438 entry->decoder = pr ? pr->ip : NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2439 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2440 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2441 } |
2313 | 2442 |
2443 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2444 fileinfo_show_for_tuple(tuple); | |
2445 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2446 entry->decoder->file_info_box(path); | |
2447 else | |
2448 fileinfo_show_for_path(path); | |
2449 g_free(path); | |
2450 } | |
2451 else if (path != NULL) | |
2452 { | |
2453 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2454 entry->decoder->file_info_box(path); | |
2455 else | |
2456 fileinfo_show_for_path(path); | |
2457 g_free(path); | |
2458 } | |
2459 } | |
2460 | |
2461 void | |
2462 playlist_fileinfo_current(Playlist *playlist) | |
2463 { | |
2464 gchar *path = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2465 Tuple *tuple = NULL; |
2313 | 2466 |
2467 PLAYLIST_LOCK(playlist->mutex); | |
2468 | |
2469 if (playlist->entries && playlist->position) | |
2470 { | |
2471 path = g_strdup(playlist->position->filename); | |
2472 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2473 playlist_entry_get_info(playlist->position); | |
2474 tuple = playlist->position->tuple; | |
2475 } | |
2476 | |
2477 PLAYLIST_UNLOCK(playlist->mutex); | |
2478 | |
2479 if (tuple != NULL) | |
2480 { | |
2481 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2482 fileinfo_show_for_tuple(tuple); | |
2483 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2484 playlist->position->decoder->file_info_box(path); | |
2485 else | |
2486 fileinfo_show_for_path(path); | |
2487 g_free(path); | |
2488 } | |
2489 else if (path != NULL) | |
2490 { | |
2491 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2492 playlist->position->decoder->file_info_box(path); | |
2493 else | |
2494 fileinfo_show_for_path(path); | |
2495 g_free(path); | |
2496 } | |
2497 } | |
2498 | |
2499 | |
2500 static gboolean | |
2501 playlist_get_info_is_going(void) | |
2502 { | |
2503 gboolean result; | |
2504 | |
2505 G_LOCK(playlist_get_info_going); | |
2506 result = playlist_get_info_going; | |
2507 G_UNLOCK(playlist_get_info_going); | |
2508 | |
2509 return result; | |
2510 } | |
2511 | |
2512 static gpointer | |
2513 playlist_get_info_func(gpointer arg) | |
2514 { | |
2515 GList *node; | |
2516 gboolean update_playlistwin = FALSE; | |
2517 | |
2518 while (playlist_get_info_is_going()) { | |
2519 PlaylistEntry *entry; | |
2520 Playlist *playlist = playlist_get_active(); | |
2521 | |
2522 // on_load | |
2523 if (cfg.use_pl_metadata && | |
2524 cfg.get_info_on_load && | |
2525 playlist_get_info_scan_active) { | |
2526 | |
2527 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2528 entry = node->data; | |
2529 | |
2636 | 2530 if(playlist->attribute & PLAYLIST_STATIC || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2531 (entry->tuple && tuple_get_int(entry->tuple, "length") > -1 && tuple_get_int(entry->tuple, "mtime") != -1)) { |
2313 | 2532 update_playlistwin = TRUE; |
2533 continue; | |
2534 } | |
2535 | |
2536 if (!playlist_entry_get_info(entry)) { | |
2537 if (g_list_index(playlist->entries, entry) == -1) | |
2538 /* Entry disappeared while we looked it up. | |
2539 Restart. */ | |
2540 node = playlist->entries; | |
2541 } | |
2542 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2543 update_playlistwin = TRUE; | |
2544 break; | |
2545 } | |
2546 } | |
2547 | |
2548 if (!node) { | |
2549 g_mutex_lock(mutex_scan); | |
2550 playlist_get_info_scan_active = FALSE; | |
2551 g_mutex_unlock(mutex_scan); | |
2552 } | |
2553 } // on_load | |
2554 | |
2555 // on_demand | |
2556 else if (!cfg.get_info_on_load && | |
2557 cfg.get_info_on_demand && | |
2558 cfg.playlist_visible && | |
2559 !cfg.playlist_shaded && | |
2560 cfg.use_pl_metadata) { | |
2561 | |
2562 g_mutex_lock(mutex_scan); | |
2563 playlist_get_info_scan_active = FALSE; | |
2564 g_mutex_unlock(mutex_scan); | |
2565 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2566 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
|
2567 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
|
2568 node = g_list_next(node)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2569 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2570 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2571 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2572 if(playlist->attribute & PLAYLIST_STATIC || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2573 (entry->tuple && tuple_get_int(entry->tuple, "length") > -1 && tuple_get_int(entry->tuple, "mtime") != -1)) { |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2574 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2575 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2576 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2577 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2578 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2579 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
|
2580 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2581 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2582 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2583 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2584 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2585 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
|
2586 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
|
2587 // no need for break here since this iteration is very short. |
2313 | 2588 } |
2589 } | |
2590 } // on_demand | |
2591 else if (cfg.get_info_on_demand && | |
2592 (!cfg.playlist_visible || cfg.playlist_shaded | |
2593 || !cfg.use_pl_metadata)) | |
2594 { | |
2595 g_mutex_lock(mutex_scan); | |
2596 playlist_get_info_scan_active = FALSE; | |
2597 g_mutex_unlock(mutex_scan); | |
2598 } | |
2599 else /* not on_demand and not on_load... | |
2600 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2601 { | |
2602 g_mutex_lock(mutex_scan); | |
2603 playlist_get_info_scan_active = FALSE; | |
2604 g_mutex_unlock(mutex_scan); | |
2605 } | |
2606 | |
2607 if (update_playlistwin) { | |
2608 playlistwin_update_list(playlist); | |
2609 update_playlistwin = FALSE; | |
2610 } | |
2611 | |
2612 if (playlist_get_info_scan_active) { | |
2613 continue; | |
2614 } | |
2615 | |
2616 g_mutex_lock(mutex_scan); | |
2617 g_cond_wait(cond_scan, mutex_scan); | |
2618 g_mutex_unlock(mutex_scan); | |
2619 | |
2620 } // while | |
2621 | |
2622 g_thread_exit(NULL); | |
2623 return NULL; | |
2624 } | |
2625 | |
2626 void | |
2627 playlist_start_get_info_thread(void) | |
2628 { | |
2629 G_LOCK(playlist_get_info_going); | |
2630 playlist_get_info_going = TRUE; | |
2631 G_UNLOCK(playlist_get_info_going); | |
2632 | |
2633 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2634 NULL, TRUE, NULL); | |
2635 } | |
2636 | |
2637 void | |
2638 playlist_stop_get_info_thread(void) | |
2639 { | |
2640 G_LOCK(playlist_get_info_going); | |
2641 playlist_get_info_going = FALSE; | |
2642 G_UNLOCK(playlist_get_info_going); | |
2643 | |
2644 g_cond_broadcast(cond_scan); | |
2645 g_thread_join(playlist_get_info_thread); | |
2646 } | |
2647 | |
2648 void | |
2649 playlist_start_get_info_scan(void) | |
2650 { | |
2651 g_mutex_lock(mutex_scan); | |
2652 playlist_get_info_scan_active = TRUE; | |
2653 g_mutex_unlock(mutex_scan); | |
2654 g_cond_signal(cond_scan); | |
2655 } | |
2656 | |
2657 void | |
2658 playlist_remove_dead_files(Playlist *playlist) | |
2659 { | |
2660 GList *node, *next_node; | |
2661 | |
2662 PLAYLIST_LOCK(playlist->mutex); | |
2663 | |
2664 for (node = playlist->entries; node; node = next_node) { | |
2665 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2666 next_node = g_list_next(node); | |
2667 | |
2668 if (!entry || !entry->filename) { | |
2669 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2670 continue; | |
2671 } | |
2672 | |
2673 /* FIXME: What about 'file:///'? */ | |
2674 /* Don't kill URLs */ | |
2675 if (strstr(entry->filename, "://")) | |
2676 continue; | |
2677 | |
2678 /* FIXME: Should test for readability */ | |
2679 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2680 continue; | |
2681 | |
2682 if (entry == playlist->position) { | |
2683 /* Don't remove the currently playing song */ | |
2684 if (playback_get_playing()) | |
2685 continue; | |
2686 | |
2687 if (next_node) | |
2688 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2689 else | |
2690 playlist->position = NULL; | |
2691 } | |
2692 | |
2693 playlist_entry_free(entry); | |
2694 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2695 } | |
2696 | |
2697 PLAYLIST_UNLOCK(playlist->mutex); | |
2698 | |
2699 playlist_generate_shuffle_list(playlist); | |
2700 playlistwin_update_list(playlist); | |
2701 playlist_recalc_total_time(playlist); | |
2702 playlist_manager_update(); | |
2703 } | |
2704 | |
2705 | |
2706 static gint | |
2707 playlist_dupscmp_title(PlaylistEntry * a, | |
2708 PlaylistEntry * b) | |
2709 { | |
2710 const gchar *a_title, *b_title; | |
2711 | |
2712 g_return_val_if_fail(a != NULL, 0); | |
2713 g_return_val_if_fail(b != NULL, 0); | |
2714 | |
2715 if (a->title) | |
2716 a_title = a->title; | |
2717 else { | |
2718 if (strrchr(a->filename, '/')) | |
2719 a_title = strrchr(a->filename, '/') + 1; | |
2720 else | |
2721 a_title = a->filename; | |
2722 } | |
2723 | |
2724 if (b->title) | |
2725 b_title = b->title; | |
2726 else { | |
2727 if (strrchr(a->filename, '/')) | |
2728 b_title = strrchr(b->filename, '/') + 1; | |
2729 else | |
2730 b_title = b->filename; | |
2731 } | |
2732 | |
2733 return strcmp(a_title, b_title); | |
2734 } | |
2735 | |
2736 static gint | |
2737 playlist_dupscmp_filename(PlaylistEntry * a, | |
2738 PlaylistEntry * b ) | |
2739 { | |
2740 gchar *a_filename, *b_filename; | |
2741 | |
2742 g_return_val_if_fail(a != NULL, 0); | |
2743 g_return_val_if_fail(b != NULL, 0); | |
2744 | |
2745 if (strrchr(a->filename, '/')) | |
2746 a_filename = strrchr(a->filename, '/') + 1; | |
2747 else | |
2748 a_filename = a->filename; | |
2749 | |
2750 if (strrchr(b->filename, '/')) | |
2751 b_filename = strrchr(b->filename, '/') + 1; | |
2752 else | |
2753 b_filename = b->filename; | |
2754 | |
2755 return strcmp(a_filename, b_filename); | |
2756 } | |
2757 | |
2758 static gint | |
2759 playlist_dupscmp_path(PlaylistEntry * a, | |
2760 PlaylistEntry * b) | |
2761 { | |
2762 /* simply compare the entire filename string */ | |
2763 return strcmp(a->filename, b->filename); | |
2764 } | |
2765 | |
2766 void | |
2767 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2768 { | |
2769 GList *node, *next_node; | |
2770 GList *node_cmp, *next_node_cmp; | |
2771 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2772 | |
2773 switch ( type ) | |
2774 { | |
2775 case PLAYLIST_DUPS_TITLE: | |
2776 dups_compare_func = playlist_dupscmp_title; | |
2777 break; | |
2778 case PLAYLIST_DUPS_PATH: | |
2779 dups_compare_func = playlist_dupscmp_path; | |
2780 break; | |
2781 case PLAYLIST_DUPS_FILENAME: | |
2782 default: | |
2783 dups_compare_func = playlist_dupscmp_filename; | |
2784 break; | |
2785 } | |
2786 | |
2787 PLAYLIST_LOCK(playlist->mutex); | |
2788 | |
2789 for (node = playlist->entries; node; node = next_node) { | |
2790 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2791 next_node = g_list_next(node); | |
2792 | |
2793 if (!entry || !entry->filename) { | |
2794 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2795 continue; | |
2796 } | |
2797 | |
2798 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2799 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2800 next_node_cmp = g_list_next(node_cmp); | |
2801 | |
2802 if (!entry_cmp || !entry_cmp->filename) { | |
2803 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2804 continue; | |
2805 } | |
2806 | |
2807 /* compare using the chosen dups_compare_func */ | |
2808 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2809 | |
2810 if (entry_cmp == playlist->position) { | |
2811 /* Don't remove the currently playing song */ | |
2812 if (playback_get_playing()) | |
2813 continue; | |
2814 | |
2815 if (next_node_cmp) | |
2816 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2817 else | |
2818 playlist->position = NULL; | |
2819 } | |
2820 | |
2821 /* check if this was the next item of the external | |
2822 loop; if true, replace it with the next of the next*/ | |
2823 if ( node_cmp == next_node ) | |
2824 next_node = g_list_next(next_node); | |
2825 | |
2826 playlist_entry_free(entry_cmp); | |
2827 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2828 } | |
2829 } | |
2830 } | |
2831 | |
2832 PLAYLIST_UNLOCK(playlist->mutex); | |
2833 | |
2834 playlistwin_update_list(playlist); | |
2835 playlist_recalc_total_time(playlist); | |
2836 | |
2837 playlist_manager_update(); | |
2838 } | |
2839 | |
2840 void | |
2841 playlist_get_total_time(Playlist * playlist, | |
2842 gulong * total_time, | |
2843 gulong * selection_time, | |
2844 gboolean * total_more, | |
2845 gboolean * selection_more) | |
2846 { | |
2847 PLAYLIST_LOCK(playlist->mutex); | |
2848 *total_time = playlist->pl_total_time; | |
2849 *selection_time = playlist->pl_selection_time; | |
2850 *total_more = playlist->pl_total_more; | |
2851 *selection_more = playlist->pl_selection_more; | |
2852 PLAYLIST_UNLOCK(playlist->mutex); | |
2853 } | |
2854 | |
2855 | |
2856 static void | |
2857 playlist_recalc_total_time_nolock(Playlist *playlist) | |
2858 { | |
2859 GList *list; | |
2860 PlaylistEntry *entry; | |
2861 | |
2862 REQUIRE_LOCK(playlist->mutex); | |
2863 | |
2864 playlist->pl_total_time = 0; | |
2865 playlist->pl_selection_time = 0; | |
2866 playlist->pl_total_more = FALSE; | |
2867 playlist->pl_selection_more = FALSE; | |
2868 | |
2869 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2870 entry = list->data; | |
2871 | |
2872 if (entry->length != -1) | |
2873 playlist->pl_total_time += entry->length / 1000; | |
2874 else | |
2875 playlist->pl_total_more = TRUE; | |
2876 | |
2877 if (entry->selected) { | |
2878 if (entry->length != -1) | |
2879 playlist->pl_selection_time += entry->length / 1000; | |
2880 else | |
2881 playlist->pl_selection_more = TRUE; | |
2882 } | |
2883 } | |
2884 } | |
2885 | |
2886 static void | |
2887 playlist_recalc_total_time(Playlist *playlist) | |
2888 { | |
2889 PLAYLIST_LOCK(playlist->mutex); | |
2890 playlist_recalc_total_time_nolock(playlist); | |
2891 PLAYLIST_UNLOCK(playlist->mutex); | |
2892 } | |
2893 | |
2894 gint | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2895 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) |
2313 | 2896 { |
2897 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2898 gboolean is_first_search = TRUE; | |
2899 gint num_of_entries_found = 0; | |
2900 | |
2901 #if defined(USE_REGEX_ONIGURUMA) | |
2902 /* set encoding for Oniguruma regex to UTF-8 */ | |
2903 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2904 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
2905 #endif | |
2906 | |
2907 PLAYLIST_LOCK(playlist->mutex); | |
2908 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2909 if ( tuple_get_string(tuple, "title") != NULL ) |
2313 | 2910 { |
2911 /* match by track_name */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2912 const gchar *regex_pattern = tuple_get_string(tuple, "title"); |
2313 | 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 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2925 const gchar *track_name = tuple_get_string( tuple, "title" ); |
2313 | 2926 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2927 if ( ( entry->tuple != NULL ) && ( track_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2928 ( regexec( ®ex , track_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2929 { |
2930 tfound_list = g_list_append( tfound_list , entry ); | |
2931 } | |
2932 } | |
2933 g_list_free( found_list ); /* wipe old found_list */ | |
2934 found_list = tfound_list; /* move tfound_list in found_list */ | |
2935 regfree( ®ex ); | |
2936 } | |
2937 is_first_search = FALSE; | |
2938 } | |
2939 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2940 if ( tuple_get_string(tuple, "album") != NULL ) |
2313 | 2941 { |
2942 /* match by album_name */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2943 const gchar *regex_pattern = tuple_get_string(tuple, "album"); |
2313 | 2944 regex_t regex; |
2945 #if defined(USE_REGEX_PCRE) | |
2946 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2947 #else | |
2948 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2949 #endif | |
2950 { | |
2951 GList *tfound_list = NULL; | |
2952 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2953 else entry_list = found_list; /* use found_list */ | |
2954 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2955 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2956 const gchar *album_name = tuple_get_string( tuple, "album" ); |
2313 | 2957 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2958 if ( ( entry->tuple != NULL ) && ( album_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2959 ( regexec( ®ex , album_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2960 { |
2961 tfound_list = g_list_append( tfound_list , entry ); | |
2962 } | |
2963 } | |
2964 g_list_free( found_list ); /* wipe old found_list */ | |
2965 found_list = tfound_list; /* move tfound_list in found_list */ | |
2966 regfree( ®ex ); | |
2967 } | |
2968 is_first_search = FALSE; | |
2969 } | |
2970 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2971 if ( tuple_get_string(tuple, "artist") != NULL ) |
2313 | 2972 { |
2973 /* match by performer */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2974 const gchar *regex_pattern = tuple_get_string(tuple, "artist"); |
2313 | 2975 regex_t regex; |
2976 #if defined(USE_REGEX_PCRE) | |
2977 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2978 #else | |
2979 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2980 #endif | |
2981 { | |
2982 GList *tfound_list = NULL; | |
2983 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2984 else entry_list = found_list; /* use found_list */ | |
2985 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2986 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2987 const gchar *performer = tuple_get_string( tuple, "performer" ); |
2313 | 2988 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2989 if ( ( entry->tuple != NULL ) && ( performer != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2990 ( regexec( ®ex , performer , 0 , NULL , 0 ) == 0 ) ) |
2313 | 2991 { |
2992 tfound_list = g_list_append( tfound_list , entry ); | |
2993 } | |
2994 } | |
2995 g_list_free( found_list ); /* wipe old found_list */ | |
2996 found_list = tfound_list; /* move tfound_list in found_list */ | |
2997 regfree( ®ex ); | |
2998 } | |
2999 is_first_search = FALSE; | |
3000 } | |
3001 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3002 if ( tuple_get_string(tuple, "file-name") != NULL ) |
2313 | 3003 { |
3004 /* match by file_name */ | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3005 const gchar *regex_pattern = tuple_get_string(tuple, "file-name"); |
2313 | 3006 regex_t regex; |
3007 #if defined(USE_REGEX_PCRE) | |
3008 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
3009 #else | |
3010 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
3011 #endif | |
3012 { | |
3013 GList *tfound_list = NULL; | |
3014 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3015 else entry_list = found_list; /* use found_list */ | |
3016 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3017 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3018 const gchar *file_name = tuple_get_string( tuple, "file-name" ); |
2313 | 3019 PlaylistEntry *entry = entry_list->data; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3020 if ( ( entry->tuple != NULL ) && ( file_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3021 ( regexec( ®ex , file_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3022 { |
3023 tfound_list = g_list_append( tfound_list , entry ); | |
3024 } | |
3025 } | |
3026 g_list_free( found_list ); /* wipe old found_list */ | |
3027 found_list = tfound_list; /* move tfound_list in found_list */ | |
3028 regfree( ®ex ); | |
3029 } | |
3030 is_first_search = FALSE; | |
3031 } | |
3032 | |
3033 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
3034 /* if some entries are still in found_list, those | |
3035 are what the user is searching for; select them */ | |
3036 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
3037 { | |
3038 PlaylistEntry *entry = sel_list->data; | |
3039 entry->selected = TRUE; | |
3040 num_of_entries_found++; | |
3041 } | |
3042 | |
3043 g_list_free( found_list ); | |
3044 | |
3045 PLAYLIST_UNLOCK(playlist->mutex); | |
3046 playlist_recalc_total_time(playlist); | |
3047 | |
3048 return num_of_entries_found; | |
3049 } | |
3050 | |
3051 void | |
3052 playlist_select_all(Playlist *playlist, gboolean set) | |
3053 { | |
3054 GList *list; | |
3055 | |
3056 PLAYLIST_LOCK(playlist->mutex); | |
3057 | |
3058 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3059 PlaylistEntry *entry = list->data; | |
3060 entry->selected = set; | |
3061 } | |
3062 | |
3063 PLAYLIST_UNLOCK(playlist->mutex); | |
3064 playlist_recalc_total_time(playlist); | |
3065 } | |
3066 | |
3067 void | |
3068 playlist_select_invert_all(Playlist *playlist) | |
3069 { | |
3070 GList *list; | |
3071 | |
3072 PLAYLIST_LOCK(playlist->mutex); | |
3073 | |
3074 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3075 PlaylistEntry *entry = list->data; | |
3076 entry->selected = !entry->selected; | |
3077 } | |
3078 | |
3079 PLAYLIST_UNLOCK(playlist->mutex); | |
3080 playlist_recalc_total_time(playlist); | |
3081 } | |
3082 | |
3083 gboolean | |
3084 playlist_select_invert(Playlist *playlist, guint pos) | |
3085 { | |
3086 GList *list; | |
3087 gboolean invert_ok = FALSE; | |
3088 | |
3089 PLAYLIST_LOCK(playlist->mutex); | |
3090 | |
3091 if ((list = g_list_nth(playlist->entries, pos))) { | |
3092 PlaylistEntry *entry = list->data; | |
3093 entry->selected = !entry->selected; | |
3094 invert_ok = TRUE; | |
3095 } | |
3096 | |
3097 PLAYLIST_UNLOCK(playlist->mutex); | |
3098 playlist_recalc_total_time(playlist); | |
3099 | |
3100 return invert_ok; | |
3101 } | |
3102 | |
3103 | |
3104 void | |
3105 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3106 { | |
3107 GList *list; | |
3108 gint i; | |
3109 | |
3110 if (min_pos > max_pos) | |
3111 SWAP(min_pos, max_pos); | |
3112 | |
3113 PLAYLIST_LOCK(playlist->mutex); | |
3114 | |
3115 list = g_list_nth(playlist->entries, min_pos); | |
3116 for (i = min_pos; i <= max_pos && list; i++) { | |
3117 PlaylistEntry *entry = list->data; | |
3118 entry->selected = select; | |
3119 list = g_list_next(list); | |
3120 } | |
3121 | |
3122 PLAYLIST_UNLOCK(playlist->mutex); | |
3123 | |
3124 playlist_recalc_total_time(playlist); | |
3125 } | |
3126 | |
3127 gboolean | |
3128 playlist_read_info_selection(Playlist *playlist) | |
3129 { | |
3130 GList *node; | |
3131 gboolean retval = FALSE; | |
3132 | |
3133 PLAYLIST_LOCK(playlist->mutex); | |
3134 | |
3135 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3136 PlaylistEntry *entry = node->data; | |
3137 if (!entry->selected) | |
3138 continue; | |
3139 | |
3140 retval = TRUE; | |
3141 | |
3142 str_replace_in(&entry->title, NULL); | |
3143 entry->length = -1; | |
3144 | |
3145 /* invalidate mtime to reread */ | |
3146 if (entry->tuple != NULL) | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3147 tuple_associate_int(entry->tuple, "mtime", -1); /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
2313 | 3148 |
3149 if (!playlist_entry_get_info(entry)) { | |
3150 if (g_list_index(playlist->entries, entry) == -1) | |
3151 /* Entry disappeared while we looked it up. Restart. */ | |
3152 node = playlist->entries; | |
3153 } | |
3154 } | |
3155 | |
3156 PLAYLIST_UNLOCK(playlist->mutex); | |
3157 | |
3158 playlistwin_update_list(playlist); | |
3159 playlist_recalc_total_time(playlist); | |
3160 | |
3161 return retval; | |
3162 } | |
3163 | |
3164 void | |
3165 playlist_read_info(Playlist *playlist, guint pos) | |
3166 { | |
3167 GList *node; | |
3168 | |
3169 PLAYLIST_LOCK(playlist->mutex); | |
3170 | |
3171 if ((node = g_list_nth(playlist->entries, pos))) { | |
3172 PlaylistEntry *entry = node->data; | |
3173 str_replace_in(&entry->title, NULL); | |
3174 entry->length = -1; | |
3175 playlist_entry_get_info(entry); | |
3176 } | |
3177 | |
3178 PLAYLIST_UNLOCK(playlist->mutex); | |
3179 | |
3180 playlistwin_update_list(playlist); | |
3181 playlist_recalc_total_time(playlist); | |
3182 } | |
3183 | |
3184 Playlist * | |
3185 playlist_get_active(void) | |
3186 { | |
3187 if (playlists_iter != NULL) | |
3188 return (Playlist *) playlists_iter->data; | |
3189 | |
2736 | 3190 if (playlists) |
3191 return (Playlist *) playlists->data; | |
3192 | |
3193 return NULL; | |
2313 | 3194 } |
3195 | |
3196 void | |
3197 playlist_set_shuffle(gboolean shuffle) | |
3198 { | |
3199 Playlist *playlist = playlist_get_active(); | |
3200 if (!playlist) | |
3201 return; | |
3202 | |
3203 PLAYLIST_LOCK(playlist->mutex); | |
3204 | |
3205 playlist_position_before_jump = NULL; | |
3206 | |
3207 cfg.shuffle = shuffle; | |
3208 playlist_generate_shuffle_list_nolock(playlist); | |
3209 | |
3210 PLAYLIST_UNLOCK(playlist->mutex); | |
3211 } | |
3212 | |
3213 Playlist * | |
3214 playlist_new(void) | |
3215 { | |
3216 Playlist *playlist = g_new0(Playlist, 1); | |
3217 playlist->mutex = g_mutex_new(); | |
3218 playlist->loading_playlist = FALSE; | |
3219 | |
3220 playlist_set_current_name(playlist, NULL); | |
3221 playlist_clear(playlist); | |
3222 | |
3223 return playlist; | |
3224 } | |
3225 | |
3226 void | |
3227 playlist_free(Playlist *playlist) | |
3228 { | |
3229 g_mutex_free( playlist->mutex ); | |
3230 g_free( playlist ); | |
3231 return; | |
3232 } | |
3233 | |
3234 Playlist * | |
3235 playlist_new_from_selected(void) | |
3236 { | |
3237 Playlist *newpl = playlist_new(); | |
3238 Playlist *playlist = playlist_get_active(); | |
3239 GList *list = playlist_get_selected(playlist); | |
3240 | |
3241 playlist_add_playlist( newpl ); | |
3242 | |
3243 PLAYLIST_LOCK(playlist->mutex); | |
3244 | |
3245 while ( list != NULL ) | |
3246 { | |
3247 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3248 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3249 playlist_add( newpl , entry->filename ); | |
3250 list = g_list_next(list); | |
3251 } | |
3252 | |
3253 PLAYLIST_UNLOCK(playlist->mutex); | |
3254 | |
3255 playlist_recalc_total_time(newpl); | |
3256 playlistwin_update_list(playlist); | |
3257 | |
3258 return newpl; | |
3259 } | |
3260 | |
3261 const gchar * | |
3262 playlist_get_filename_to_play(Playlist *playlist) | |
3263 { | |
3264 const gchar *filename = NULL; | |
3265 | |
3266 if (!playlist) | |
3267 return NULL; | |
3268 | |
3269 PLAYLIST_LOCK(playlist->mutex); | |
3270 | |
3271 if (!playlist->position) { | |
3272 if (cfg.shuffle) | |
3273 playlist->position = playlist->shuffle->data; | |
3274 else | |
3275 playlist->position = playlist->entries->data; | |
3276 } | |
3277 | |
3278 filename = playlist->position->filename; | |
3279 | |
3280 PLAYLIST_UNLOCK(playlist->mutex); | |
3281 | |
3282 return filename; | |
3283 } | |
3284 | |
3285 PlaylistEntry * | |
3286 playlist_get_entry_to_play(Playlist *playlist) | |
3287 { | |
3288 if (!playlist) | |
3289 return NULL; | |
3290 | |
3291 PLAYLIST_LOCK(playlist->mutex); | |
3292 | |
3293 if (!playlist->position) { | |
3294 if (cfg.shuffle) | |
3295 playlist->position = playlist->shuffle->data; | |
3296 else | |
3297 playlist->position = playlist->entries->data; | |
3298 } | |
3299 | |
3300 PLAYLIST_UNLOCK(playlist->mutex); | |
3301 | |
3302 return playlist->position; | |
3303 } |