Mercurial > audlegacy
annotate src/audacious/playlist.c @ 3337:99f34db2c3fc trunk
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
- modify playlist_load_ins() to return number of new entries.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sun, 12 Aug 2007 21:21:46 +0900 |
parents | ea806daf3ef0 |
children | 71d8d93f1bad |
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"); |
3327
5296086f20cf
make preset title format work.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3298
diff
changeset
|
241 entry->title = tuple_formatter_process_string(tuple, formatter ? |
3334
ea806daf3ef0
rename xmms_get_gentitle_format() to get_gentitle_format().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3327
diff
changeset
|
242 formatter : get_gentitle_format()); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
243 entry->length = tuple_get_int(tuple, "length"); |
2313 | 244 entry->tuple = tuple; |
245 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
246 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
247 |
2313 | 248 return TRUE; |
249 } | |
250 | |
251 /* *********************** playlist selector code ************************* */ | |
252 | |
253 void | |
254 playlist_init(void) | |
255 { | |
256 Playlist *initial_pl; | |
257 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
258 /* create a heap with 1024 playlist entry nodes preallocated. --nenolod */ |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
259 playlist_entry_heap = mowgli_heap_create(sizeof(PlaylistEntry), 1024, |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
260 BH_NOW); |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
261 |
2313 | 262 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ |
263 | |
264 initial_pl = playlist_new(); | |
265 | |
266 playlist_add_playlist(initial_pl); | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
267 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
268 playlist_evlistener_init(); |
2313 | 269 } |
270 | |
271 void | |
272 playlist_add_playlist(Playlist *playlist) | |
273 { | |
274 playlists = g_list_append(playlists, playlist); | |
275 | |
276 if (playlists_iter == NULL) | |
277 playlists_iter = playlists; | |
278 | |
279 playlist_manager_update(); | |
280 } | |
281 | |
282 void | |
283 playlist_remove_playlist(Playlist *playlist) | |
284 { | |
2820 | 285 /* users suppose playback will be stopped on removing playlist */ |
286 if (playback_get_playing()) { | |
287 ip_data.stop = TRUE; | |
288 playback_stop(); | |
289 ip_data.stop = FALSE; | |
290 mainwin_clear_song_info(); | |
291 } | |
292 | |
2313 | 293 /* trying to free the last playlist simply clears and resets it */ |
294 if (g_list_length(playlists) < 2) { | |
295 playlist_clear(playlist); | |
296 playlist_set_current_name(playlist, NULL); | |
297 return; | |
298 } | |
299 | |
300 if (playlist == playlist_get_active()) | |
301 playlist_select_next(); | |
302 | |
303 /* upon removal, a playlist should be cleared and freed */ | |
304 playlists = g_list_remove(playlists, playlist); | |
305 playlist_clear(playlist); | |
306 playlist_free(playlist); | |
307 | |
308 if (playlists_iter == NULL) | |
309 playlists_iter = playlists; | |
310 | |
311 playlist_manager_update(); | |
312 } | |
313 | |
314 GList * | |
315 playlist_get_playlists(void) | |
316 { | |
317 return playlists; | |
318 } | |
319 | |
320 void | |
321 playlist_select_next(void) | |
322 { | |
323 if (playlists_iter == NULL) | |
324 playlists_iter = playlists; | |
325 | |
326 playlists_iter = g_list_next(playlists_iter); | |
327 | |
328 if (playlists_iter == NULL) | |
329 playlists_iter = playlists; | |
330 | |
331 playlistwin_update_list(playlist_get_active()); | |
332 } | |
333 | |
334 void | |
335 playlist_select_prev(void) | |
336 { | |
337 if (playlists_iter == NULL) | |
338 playlists_iter = playlists; | |
339 | |
340 playlists_iter = g_list_previous(playlists_iter); | |
341 | |
342 if (playlists_iter == NULL) | |
343 playlists_iter = playlists; | |
344 | |
345 playlistwin_update_list(playlist_get_active()); | |
346 } | |
347 | |
348 void | |
349 playlist_select_playlist(Playlist *playlist) | |
350 { | |
351 if (playlists_iter == NULL) | |
352 playlists_iter = playlists; | |
353 | |
354 playlists_iter = g_list_find(playlists, playlist); | |
355 | |
356 if (playlists_iter == NULL) | |
357 playlists_iter = playlists; | |
358 | |
359 playlistwin_update_list(playlist); | |
360 } | |
361 | |
362 /* *********************** playlist code ********************** */ | |
363 | |
364 const gchar * | |
365 playlist_get_current_name(Playlist *playlist) | |
366 { | |
367 return playlist->title; | |
368 } | |
369 | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
370 /* filename is real filename here. --yaz */ |
2313 | 371 gboolean |
372 playlist_set_current_name(Playlist *playlist, const gchar * filename) | |
373 { | |
374 if (playlist->title) | |
375 g_free(playlist->title); | |
376 | |
377 if (!filename) { | |
378 playlist->title = NULL; | |
379 return FALSE; | |
380 } | |
381 | |
2504
fcf730269639
[svn] - convert filename string to utf8 for playlist->title (closes bug #789)
giacomo
parents:
2499
diff
changeset
|
382 playlist->title = filename_to_utf8(filename); |
2313 | 383 return TRUE; |
384 } | |
385 | |
386 static GList * | |
387 find_playlist_position_list(Playlist *playlist) | |
388 { | |
389 REQUIRE_LOCK(playlist->mutex); | |
390 | |
391 if (!playlist->position) { | |
392 if (cfg.shuffle) | |
393 return playlist->shuffle; | |
394 else | |
395 return playlist->entries; | |
396 } | |
397 | |
398 if (cfg.shuffle) | |
399 return g_list_find(playlist->shuffle, playlist->position); | |
400 else | |
401 return g_list_find(playlist->entries, playlist->position); | |
402 } | |
403 | |
404 static void | |
405 play_queued(Playlist *playlist) | |
406 { | |
407 GList *tmp = playlist->queue; | |
408 | |
409 REQUIRE_LOCK( playlist->mutex ); | |
410 | |
411 playlist->position = playlist->queue->data; | |
412 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | |
413 g_list_free_1(tmp); | |
414 } | |
415 | |
416 void | |
417 playlist_clear(Playlist *playlist) | |
418 { | |
419 if (!playlist) | |
420 return; | |
421 | |
422 PLAYLIST_LOCK( playlist->mutex ); | |
423 | |
424 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); | |
425 g_list_free(playlist->entries); | |
426 playlist->position = NULL; | |
427 playlist->entries = NULL; | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
428 playlist->tail = NULL; |
2637
420ce282920d
[svn] - clear playlist attribute when playlist_clear() is called.
yaz
parents:
2636
diff
changeset
|
429 playlist->attribute = PLAYLIST_PLAIN; |
2313 | 430 |
431 PLAYLIST_UNLOCK( playlist->mutex ); | |
432 | |
433 playlist_generate_shuffle_list(playlist); | |
434 playlistwin_update_list(playlist); | |
435 playlist_recalc_total_time(playlist); | |
436 playlist_manager_update(); | |
437 } | |
438 | |
439 static void | |
440 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
441 gboolean * restart_playing) | |
442 { | |
443 PlaylistEntry *entry; | |
444 GList *playing_song = NULL; | |
445 | |
446 REQUIRE_LOCK(playlist->mutex); | |
447 | |
448 /* We call g_list_find manually here because we don't want an item | |
449 * in the shuffle_list */ | |
450 | |
451 if (playlist->position) | |
452 playing_song = g_list_find(playlist->entries, playlist->position); | |
453 | |
454 entry = PLAYLIST_ENTRY(node->data); | |
455 | |
456 if (playing_song == node) { | |
457 *set_info_text = TRUE; | |
458 | |
459 if (playback_get_playing()) { | |
460 PLAYLIST_UNLOCK(playlist->mutex); | |
461 ip_data.stop = TRUE; | |
462 playback_stop(); | |
463 ip_data.stop = FALSE; | |
464 PLAYLIST_LOCK(playlist->mutex); | |
465 *restart_playing = TRUE; | |
466 } | |
467 | |
468 playing_song = find_playlist_position_list(playlist); | |
469 | |
470 if (g_list_next(playing_song)) | |
471 playlist->position = g_list_next(playing_song)->data; | |
472 else if (g_list_previous(playing_song)) | |
473 playlist->position = g_list_previous(playing_song)->data; | |
474 else | |
475 playlist->position = NULL; | |
476 | |
477 /* Make sure the entry did not disappear under us */ | |
478 if (g_list_index(playlist->entries, entry) == -1) | |
479 return; | |
480 | |
481 } | |
482 else if (g_list_position(playlist->entries, playing_song) > | |
483 g_list_position(playlist->entries, node)) { | |
484 *set_info_text = TRUE; | |
485 } | |
486 | |
487 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
488 playlist->queue = g_list_remove(playlist->queue, entry); | |
489 playlist->entries = g_list_remove_link(playlist->entries, node); | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
490 playlist->tail = g_list_last(playlist->entries); |
2313 | 491 playlist_entry_free(entry); |
492 g_list_free_1(node); | |
493 | |
494 playlist_recalc_total_time_nolock(playlist); | |
495 } | |
496 | |
497 void | |
498 playlist_delete_index(Playlist *playlist, guint pos) | |
499 { | |
500 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
501 GList *node; | |
502 | |
503 if (!playlist) | |
504 return; | |
505 | |
506 PLAYLIST_LOCK(playlist->mutex); | |
507 | |
508 node = g_list_nth(playlist->entries, pos); | |
509 | |
510 if (!node) { | |
511 PLAYLIST_UNLOCK(playlist->mutex); | |
512 return; | |
513 } | |
514 | |
515 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
516 | |
517 PLAYLIST_UNLOCK(playlist->mutex); | |
518 | |
519 playlist_recalc_total_time(playlist); | |
520 | |
521 playlistwin_update_list(playlist); | |
522 if (restart_playing) { | |
523 if (playlist->position) { | |
524 playback_initiate(); | |
525 } | |
526 else { | |
527 mainwin_clear_song_info(); | |
528 } | |
529 } | |
530 | |
531 playlist_manager_update(); | |
532 } | |
533 | |
534 void | |
535 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
536 { | |
537 GList *node, *fnode; | |
538 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
539 | |
540 PLAYLIST_LOCK(playlist->mutex); | |
541 | |
542 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
543 node = playlist->entries; | |
544 | |
545 while (node) { | |
546 GList *next = g_list_next(node); | |
547 PlaylistEntry *entry = node->data; | |
548 | |
549 if (!strcmp(entry->filename, fnode->data)) | |
550 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
551 | |
552 node = next; | |
553 } | |
554 } | |
555 | |
2792
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
556 PLAYLIST_UNLOCK(playlist->mutex); |
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
557 |
2313 | 558 playlist_recalc_total_time(playlist); |
559 playlistwin_update_list(playlist); | |
560 | |
561 if (restart_playing) { | |
562 if (playlist->position) { | |
563 playback_initiate(); | |
564 } | |
565 else { | |
566 mainwin_clear_song_info(); | |
567 } | |
568 } | |
569 | |
570 playlist_manager_update(); | |
571 } | |
572 | |
573 void | |
574 playlist_delete(Playlist * playlist, gboolean crop) | |
575 { | |
576 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
577 GList *node, *next_node; | |
578 PlaylistEntry *entry; | |
579 | |
580 g_return_if_fail(playlist != NULL); | |
581 | |
582 PLAYLIST_LOCK(playlist->mutex); | |
583 | |
584 node = playlist->entries; | |
585 | |
586 while (node) { | |
587 entry = PLAYLIST_ENTRY(node->data); | |
588 | |
589 next_node = g_list_next(node); | |
590 | |
591 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
592 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
593 } | |
594 | |
595 node = next_node; | |
596 } | |
597 | |
598 PLAYLIST_UNLOCK(playlist->mutex); | |
599 | |
600 playlist_recalc_total_time(playlist); | |
601 | |
602 if (restart_playing) { | |
603 if (playlist->position) { | |
604 playback_initiate(); | |
605 } | |
606 else { | |
607 mainwin_clear_song_info(); | |
608 } | |
609 } | |
610 | |
611 playlistwin_update_list(playlist); | |
612 playlist_manager_update(); | |
613 } | |
614 | |
615 static void | |
616 __playlist_ins_with_info(Playlist * playlist, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
617 const gchar * filename, |
2313 | 618 gint pos, |
619 const gchar * title, | |
620 gint len, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
621 InputPlugin * dec) |
2313 | 622 { |
623 g_return_if_fail(filename != NULL); | |
624 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
625 PLAYLIST_LOCK( playlist->mutex ); |
2313 | 626 playlist->entries = g_list_insert(playlist->entries, |
627 playlist_entry_new(filename, title, len, dec), | |
628 pos); | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
629 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 630 |
631 g_mutex_lock(mutex_scan); | |
632 playlist_get_info_scan_active = TRUE; | |
633 g_mutex_unlock(mutex_scan); | |
634 g_cond_signal(cond_scan); | |
635 } | |
636 | |
637 static void | |
638 __playlist_ins_with_info_tuple(Playlist * playlist, | |
639 const gchar * filename, | |
640 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
641 Tuple *tuple, |
2313 | 642 InputPlugin * dec) |
643 { | |
644 PlaylistEntry *entry; | |
645 | |
646 g_return_if_fail(playlist != NULL); | |
647 g_return_if_fail(filename != NULL); | |
648 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
649 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
|
650 if(!playlist->tail) |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
651 playlist->tail = g_list_last(playlist->entries); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
652 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
653 PLAYLIST_LOCK( playlist->mutex ); |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
654 if(pos == -1) { // the common case |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
655 GList *element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
656 element = g_list_alloc(); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
657 element->data = entry; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
658 element->prev = playlist->tail; // NULL is allowed here. |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
659 element->next = NULL; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
660 |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
661 if(!playlist->entries) { // this is the first element |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
662 playlist->entries = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
663 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
664 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
665 else { // the rests |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
666 g_return_if_fail(playlist->tail != NULL); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
667 playlist->tail->next = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
668 playlist->tail = element; |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
669 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
670 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
671 else { |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
672 playlist->entries = g_list_insert(playlist->entries, entry, pos); |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
673 } |
2313 | 674 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
675 PLAYLIST_UNLOCK( playlist->mutex ); |
2313 | 676 if (tuple != NULL) { |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
677 const gchar *formatter = tuple_get_string(tuple, "formatter"); |
3327
5296086f20cf
make preset title format work.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3298
diff
changeset
|
678 entry->title = tuple_formatter_process_string(tuple, formatter ? |
3334
ea806daf3ef0
rename xmms_get_gentitle_format() to get_gentitle_format().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3327
diff
changeset
|
679 formatter : get_gentitle_format()); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
680 entry->length = tuple_get_int(tuple, "length"); |
2313 | 681 entry->tuple = tuple; |
682 } | |
683 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 } |
2313 | 690 } |
691 | |
692 gboolean | |
693 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
694 { | |
695 gchar buf[64], *p; | |
696 gint r; | |
697 VFSFile *file; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
698 ProbeResult *pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
699 InputPlugin *dec = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
700 Tuple *tuple = NULL; |
2313 | 701 |
702 g_return_val_if_fail(playlist != NULL, FALSE); | |
703 g_return_val_if_fail(filename != NULL, FALSE); | |
704 | |
705 if (is_playlist_name(filename)) { | |
706 playlist->loading_playlist = TRUE; | |
707 playlist_load_ins(playlist, filename, pos); | |
708 playlist->loading_playlist = FALSE; | |
709 return TRUE; | |
710 } | |
711 | |
712 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | |
713 dec = NULL; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
714 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
|
715 !str_has_prefix_nocase(filename, "https://")) |
3127
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 pr = input_check_file(filename, TRUE); |
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 if (pr) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
720 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
721 dec = pr->ip; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
722 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
723 } |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
724 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
725 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
726 } |
2313 | 727 |
2701
906caaf4737d
[svn] - fix cuesheet bug in a better way (e.g. unbreak http:// streams)
nenolod
parents:
2690
diff
changeset
|
728 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 | 729 { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
730 __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
|
731 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
|
732 playlistwin_update_list(playlist); |
2313 | 733 return TRUE; |
734 } | |
735 | |
736 /* Some files (typically produced by some cgi-scripts) don't have | |
737 * the correct extension. Try to recognize these files by looking | |
738 * at their content. We only check for http entries since it does | |
739 * not make sense to have file entries in a playlist fetched from | |
740 * the net. */ | |
741 | |
742 /* Some strange people put fifo's with the .mp3 extension, so we | |
743 * need to make sure it's a real file (otherwise fread() may block | |
744 * and stall the entire program) */ | |
745 | |
746 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
747 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
748 return FALSE; | |
749 | |
750 if (!(file = vfs_fopen(filename, "rb"))) | |
751 return FALSE; | |
752 | |
753 r = vfs_fread(buf, 1, sizeof(buf), file); | |
754 vfs_fclose(file); | |
755 | |
756 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
757 | |
758 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
759 playlist_load_ins(playlist, filename, pos); | |
760 return TRUE; | |
761 } | |
762 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
763 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
|
764 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
765 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
766 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
767 |
2313 | 768 return FALSE; |
769 } | |
770 | |
771 /* FIXME: The next few functions are specific to Unix | |
772 * filesystems. Either abstract it away, or don't even bother checking | |
773 * at such low level */ | |
774 | |
775 typedef struct { | |
776 dev_t dev; | |
777 ino_t ino; | |
778 } DeviceInode; | |
779 | |
780 static DeviceInode * | |
781 devino_new(dev_t device, | |
782 ino_t inode) | |
783 { | |
784 DeviceInode *devino = g_new0(DeviceInode, 1); | |
785 | |
786 if (devino) | |
787 { | |
788 devino->dev = device; | |
789 devino->ino = inode; | |
790 } | |
791 | |
792 return devino; | |
793 } | |
794 | |
795 static guint | |
796 devino_hash(gconstpointer key) | |
797 { | |
798 const DeviceInode *d = key; | |
799 return d->ino; | |
800 } | |
801 | |
802 static gint | |
803 devino_compare(gconstpointer a, | |
804 gconstpointer b) | |
805 { | |
806 const DeviceInode *da = a, *db = b; | |
807 return (da->dev == db->dev && da->ino == db->ino); | |
808 } | |
809 | |
810 static gboolean | |
811 devino_destroy(gpointer key, | |
812 gpointer value, | |
813 gpointer data) | |
814 { | |
815 g_free(key); | |
816 return TRUE; | |
817 } | |
818 | |
819 static gboolean | |
820 file_is_hidden(const gchar * filename) | |
821 { | |
822 g_return_val_if_fail(filename != NULL, FALSE); | |
2570 | 823 return (g_basename(filename)[0] == '.'); |
2313 | 824 } |
825 | |
826 static GList * | |
827 playlist_dir_find_files(const gchar * path, | |
828 gboolean background, | |
829 GHashTable * htab) | |
830 { | |
831 GDir *dir; | |
832 GList *list = NULL, *ilist; | |
833 const gchar *dir_entry; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
834 ProbeResult *pr = NULL; |
2313 | 835 |
836 struct stat statbuf; | |
837 DeviceInode *devino; | |
838 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
839 if (!path) |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
840 return NULL; |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
841 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
842 if (!vfs_file_test(path, G_FILE_TEST_IS_DIR)) |
2313 | 843 return NULL; |
844 | |
845 stat(path, &statbuf); | |
846 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
847 | |
848 if (g_hash_table_lookup(htab, devino)) { | |
849 g_free(devino); | |
850 return NULL; | |
851 } | |
852 | |
853 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
854 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
855 /* XXX: what the hell is this for? --nenolod */ |
2313 | 856 if ((ilist = input_scan_dir(path))) { |
857 GList *node; | |
858 for (node = ilist; node; node = g_list_next(node)) { | |
859 gchar *name = g_build_filename(path, node->data, NULL); | |
860 list = g_list_prepend(list, name); | |
861 g_free(node->data); | |
862 } | |
863 g_list_free(ilist); | |
864 return list; | |
865 } | |
866 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
867 /* g_dir_open does not handle URI, so path should come here not-urified. --giacomo */ |
2313 | 868 if (!(dir = g_dir_open(path, 0, NULL))) |
869 return NULL; | |
870 | |
871 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
|
872 gchar *filename, *tmp; |
2313 | 873 |
874 if (file_is_hidden(dir_entry)) | |
875 continue; | |
876 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
877 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
|
878 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
|
879 g_free(tmp); |
2313 | 880 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
881 if (vfs_file_test(filename, G_FILE_TEST_IS_DIR)) { |
2313 | 882 GList *sub; |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
883 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
|
884 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
|
885 g_free(dirfilename); |
2313 | 886 g_free(filename); |
887 list = g_list_concat(list, sub); | |
888 } | |
889 else if (cfg.playlist_detect == TRUE) | |
890 list = g_list_prepend(list, filename); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
891 else if ((pr = input_check_file(filename, TRUE)) != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
892 { |
2313 | 893 list = g_list_prepend(list, filename); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
894 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
895 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
896 pr = NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
897 } |
2313 | 898 else |
899 g_free(filename); | |
900 | |
901 while (background && gtk_events_pending()) | |
902 gtk_main_iteration(); | |
903 } | |
904 g_dir_close(dir); | |
905 | |
906 return list; | |
907 } | |
908 | |
909 gboolean | |
910 playlist_add(Playlist * playlist, const gchar * filename) | |
911 { | |
912 return playlist_ins(playlist, filename, -1); | |
913 } | |
914 | |
915 guint | |
916 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
917 { | |
918 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
919 } | |
920 | |
921 guint | |
922 playlist_add_url(Playlist * playlist, const gchar * url) | |
923 { | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
924 guint entries; |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
925 entries = playlist_ins_url(playlist, url, -1); |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
926 // printf("playlist_add_url: entries = %d\n", entries); |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
927 return entries; |
2313 | 928 } |
929 | |
930 guint | |
931 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
932 gint pos, | |
933 gboolean background) | |
934 { | |
935 guint entries = 0; | |
936 GList *list, *node; | |
937 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
|
938 gchar *path2 = g_filename_from_uri(path, NULL, NULL); |
2313 | 939 |
2580
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
940 if (path2 == NULL) |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
941 path2 = g_strdup(path); |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
942 |
2313 | 943 htab = g_hash_table_new(devino_hash, devino_compare); |
944 | |
2579 | 945 list = playlist_dir_find_files(path2, background, htab); |
2313 | 946 list = g_list_sort(list, (GCompareFunc) path_compare); |
947 | |
948 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
949 | |
950 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
|
951 playlist_ins(playlist, node->data, pos); |
2313 | 952 g_free(node->data); |
953 entries++; | |
954 if (pos >= 0) | |
955 pos++; | |
956 } | |
957 | |
958 g_list_free(list); | |
2579 | 959 g_free(path2); |
2313 | 960 |
961 playlist_recalc_total_time(playlist); | |
962 playlist_generate_shuffle_list(playlist); | |
963 playlistwin_update_list(playlist); | |
964 playlist_manager_update(); | |
965 return entries; | |
966 } | |
967 | |
968 guint | |
969 playlist_ins_url(Playlist * playlist, const gchar * string, | |
970 gint pos) | |
971 { | |
972 gchar *tmp; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
973 gint entries = 0; |
2313 | 974 gchar *decoded = NULL; |
975 | |
976 g_return_val_if_fail(playlist != NULL, 0); | |
977 g_return_val_if_fail(string != NULL, 0); | |
978 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
979 // playlistwin_update_list(playlist); // is this necessary? --yaz |
2313 | 980 |
981 while (*string) { | |
982 GList *node; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
983 guint i = 0; |
2313 | 984 tmp = strchr(string, '\n'); |
985 if (tmp) { | |
986 if (*(tmp - 1) == '\r') | |
987 *(tmp - 1) = '\0'; | |
988 *tmp = '\0'; | |
989 } | |
990 | |
991 decoded = g_strdup(string); | |
992 | |
2575 | 993 if (vfs_file_test(decoded, G_FILE_TEST_IS_DIR)) { |
2313 | 994 i = playlist_ins_dir(playlist, decoded, pos, FALSE); |
995 } | |
996 else { | |
997 if (is_playlist_name(decoded)) { | |
998 i = playlist_load_ins(playlist, decoded, pos); | |
999 } | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1000 else if (playlist_ins(playlist, decoded, pos)) { |
2313 | 1001 i = 1; |
1002 } | |
1003 } | |
1004 | |
1005 g_free(decoded); | |
1006 | |
1007 PLAYLIST_LOCK(playlist->mutex); | |
1008 node = g_list_nth(playlist->entries, pos); | |
1009 PLAYLIST_UNLOCK(playlist->mutex); | |
1010 | |
1011 entries += i; | |
1012 | |
1013 if (pos >= 0) | |
1014 pos += i; | |
1015 if (!tmp) | |
1016 break; | |
1017 | |
1018 string = tmp + 1; | |
1019 } | |
1020 | |
1021 playlist_recalc_total_time(playlist); | |
1022 playlist_generate_shuffle_list(playlist); | |
1023 playlistwin_update_list(playlist); | |
1024 | |
1025 playlist_manager_update(); | |
1026 | |
1027 return entries; | |
1028 } | |
1029 | |
1030 void | |
1031 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
1032 gint freq, gint nch) | |
1033 { | |
1034 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
|
1035 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
|
1036 gchar *text; |
2313 | 1037 |
3197
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1038 if(length == -1) { |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1039 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
|
1040 } |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1041 |
2313 | 1042 g_return_if_fail(playlist != NULL); |
1043 | |
1044 if (playlist->position) { | |
1045 g_free(playlist->position->title); | |
1046 playlist->position->title = g_strdup(title); | |
1047 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1048 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1049 // 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
|
1050 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
|
1051 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
|
1052 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
|
1053 } |
2313 | 1054 } |
1055 | |
1056 playlist_recalc_total_time(playlist); | |
1057 | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1058 /* broadcast a PlaylistEventInfoChange message. */ |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1059 msg = g_new0(PlaylistEventInfoChange, 1); |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1060 msg->bitrate = rate; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1061 msg->samplerate = freq; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1062 msg->channels = nch; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1063 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1064 event_queue("playlist info change", msg); |
2460 | 1065 |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1066 text = playlist_get_info_text(playlist); |
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1067 event_queue("title change", text); |
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1068 |
2460 | 1069 if ( playlist->position ) |
1070 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1071 } |
1072 | |
1073 void | |
1074 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1075 gint freq, gint nch) | |
1076 { | |
1077 g_return_if_fail(playlist != NULL); | |
1078 | |
1079 if (playlist->position) { | |
1080 g_free(playlist->position->title); | |
1081 playlist->position->title = g_strdup(title); | |
1082 playlist->position->length = length; | |
1083 } | |
1084 | |
1085 playlist_recalc_total_time(playlist); | |
1086 | |
1087 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1088 |
1089 if ( playlist->position ) | |
1090 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1091 } |
1092 | |
1093 void | |
1094 playlist_check_pos_current(Playlist *playlist) | |
1095 { | |
1096 gint pos, row, bottom; | |
1097 | |
1098 if (!playlist) | |
1099 return; | |
1100 | |
1101 PLAYLIST_LOCK(playlist->mutex); | |
1102 if (!playlist->position || !playlistwin_list) { | |
1103 PLAYLIST_UNLOCK(playlist->mutex); | |
1104 return; | |
1105 } | |
1106 | |
1107 pos = g_list_index(playlist->entries, playlist->position); | |
1108 | |
1109 if (playlistwin_item_visible(pos)) { | |
1110 PLAYLIST_UNLOCK(playlist->mutex); | |
1111 return; | |
1112 } | |
1113 | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1114 bottom = MAX(0, playlist_get_length(playlist) - |
3217 | 1115 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); |
1116 row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom); | |
2313 | 1117 PLAYLIST_UNLOCK(playlist->mutex); |
1118 playlistwin_set_toprow(row); | |
1119 g_cond_signal(cond_scan); | |
1120 } | |
1121 | |
1122 void | |
1123 playlist_next(Playlist *playlist) | |
1124 { | |
1125 GList *plist_pos_list; | |
1126 gboolean restart_playing = FALSE; | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1127 if (!playlist_get_length(playlist)) |
2313 | 1128 return; |
1129 | |
1130 PLAYLIST_LOCK(playlist->mutex); | |
1131 | |
1132 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1133 { | |
1134 playlist->position = playlist_position_before_jump; | |
1135 playlist_position_before_jump = NULL; | |
1136 } | |
1137 | |
1138 plist_pos_list = find_playlist_position_list(playlist); | |
1139 | |
1140 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
1141 PLAYLIST_UNLOCK(playlist->mutex); | |
1142 return; | |
1143 } | |
1144 | |
1145 if (playback_get_playing()) { | |
1146 /* We need to stop before changing playlist_position */ | |
1147 PLAYLIST_UNLOCK(playlist->mutex); | |
1148 ip_data.stop = TRUE; | |
1149 playback_stop(); | |
1150 ip_data.stop = FALSE; | |
1151 PLAYLIST_LOCK(playlist->mutex); | |
1152 restart_playing = TRUE; | |
1153 } | |
1154 | |
1155 plist_pos_list = find_playlist_position_list(playlist); | |
1156 if (playlist->queue != NULL) | |
1157 play_queued(playlist); | |
1158 else if (g_list_next(plist_pos_list)) | |
1159 playlist->position = g_list_next(plist_pos_list)->data; | |
1160 else if (cfg.repeat) { | |
1161 playlist->position = NULL; | |
1162 playlist_generate_shuffle_list_nolock(playlist); | |
1163 if (cfg.shuffle) | |
1164 playlist->position = playlist->shuffle->data; | |
1165 else | |
1166 playlist->position = playlist->entries->data; | |
1167 } | |
1168 PLAYLIST_UNLOCK(playlist->mutex); | |
1169 playlist_check_pos_current(playlist); | |
1170 | |
1171 if (restart_playing) | |
1172 playback_initiate(); | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1173 |
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1174 playlistwin_update_list(playlist); |
2313 | 1175 } |
1176 | |
1177 void | |
1178 playlist_prev(Playlist *playlist) | |
1179 { | |
1180 GList *plist_pos_list; | |
1181 gboolean restart_playing = FALSE; | |
1182 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1183 if (!playlist_get_length(playlist)) |
2313 | 1184 return; |
1185 | |
1186 PLAYLIST_LOCK(playlist->mutex); | |
1187 | |
1188 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1189 { | |
1190 playlist->position = playlist_position_before_jump; | |
1191 playlist_position_before_jump = NULL; | |
1192 } | |
1193 | |
1194 plist_pos_list = find_playlist_position_list(playlist); | |
1195 | |
1196 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
1197 PLAYLIST_UNLOCK(playlist->mutex); | |
1198 return; | |
1199 } | |
1200 | |
1201 if (playback_get_playing()) { | |
1202 /* We need to stop before changing playlist_position */ | |
1203 PLAYLIST_UNLOCK(playlist->mutex); | |
1204 ip_data.stop = TRUE; | |
1205 playback_stop(); | |
1206 ip_data.stop = FALSE; | |
1207 PLAYLIST_LOCK(playlist->mutex); | |
1208 restart_playing = TRUE; | |
1209 } | |
1210 | |
1211 plist_pos_list = find_playlist_position_list(playlist); | |
1212 if (g_list_previous(plist_pos_list)) { | |
1213 playlist->position = g_list_previous(plist_pos_list)->data; | |
1214 } | |
1215 else if (cfg.repeat) { | |
1216 GList *node; | |
1217 playlist->position = NULL; | |
1218 playlist_generate_shuffle_list_nolock(playlist); | |
1219 if (cfg.shuffle) | |
1220 node = g_list_last(playlist->shuffle); | |
1221 else | |
1222 node = g_list_last(playlist->entries); | |
1223 if (node) | |
1224 playlist->position = node->data; | |
1225 } | |
1226 | |
1227 PLAYLIST_UNLOCK(playlist->mutex); | |
1228 | |
1229 playlist_check_pos_current(playlist); | |
1230 | |
1231 if (restart_playing) | |
1232 playback_initiate(); | |
1233 else { | |
1234 playlistwin_update_list(playlist); | |
1235 } | |
1236 } | |
1237 | |
1238 void | |
1239 playlist_queue(Playlist *playlist) | |
1240 { | |
1241 GList *list = playlist_get_selected(playlist); | |
1242 GList *it = list; | |
1243 | |
1244 PLAYLIST_LOCK(playlist->mutex); | |
1245 | |
1246 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1247 { | |
1248 /* Shuffling and this is our first manual jump. */ | |
1249 playlist_position_before_jump = playlist->position; | |
1250 } | |
1251 | |
1252 while (it) { | |
1253 GList *next = g_list_next(it); | |
1254 GList *tmp; | |
1255 | |
1256 /* XXX: WTF? --nenolod */ | |
1257 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1258 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1259 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1260 g_list_free_1(tmp); | |
1261 list = g_list_remove_link(list, it); | |
1262 g_list_free_1(it); | |
1263 } | |
1264 | |
1265 it = next; | |
1266 } | |
1267 | |
1268 playlist->queue = g_list_concat(playlist->queue, list); | |
1269 | |
1270 PLAYLIST_UNLOCK(playlist->mutex); | |
1271 | |
1272 playlist_recalc_total_time(playlist); | |
1273 playlistwin_update_list(playlist); | |
1274 } | |
1275 | |
1276 void | |
1277 playlist_queue_position(Playlist *playlist, guint pos) | |
1278 { | |
1279 GList *tmp; | |
1280 PlaylistEntry *entry; | |
1281 | |
1282 PLAYLIST_LOCK(playlist->mutex); | |
1283 | |
1284 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1285 { | |
1286 /* Shuffling and this is our first manual jump. */ | |
1287 playlist_position_before_jump = playlist->position; | |
1288 } | |
1289 | |
1290 entry = g_list_nth_data(playlist->entries, pos); | |
1291 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1292 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1293 g_list_free_1(tmp); | |
1294 } | |
1295 else | |
1296 playlist->queue = g_list_append(playlist->queue, entry); | |
1297 PLAYLIST_UNLOCK(playlist->mutex); | |
1298 | |
1299 playlist_recalc_total_time(playlist); | |
1300 playlistwin_update_list(playlist); | |
1301 } | |
1302 | |
1303 gboolean | |
1304 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1305 { | |
1306 PlaylistEntry *entry; | |
1307 GList *tmp; | |
1308 | |
1309 PLAYLIST_LOCK(playlist->mutex); | |
1310 entry = g_list_nth_data(playlist->entries, pos); | |
1311 tmp = g_list_find(playlist->queue, entry); | |
1312 PLAYLIST_UNLOCK(playlist->mutex); | |
1313 | |
1314 return tmp != NULL; | |
1315 } | |
1316 | |
1317 gint | |
1318 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1319 { | |
1320 PlaylistEntry *entry; | |
1321 gint tmp; | |
1322 | |
1323 PLAYLIST_LOCK(playlist->mutex); | |
1324 entry = g_list_nth_data(playlist->entries, pos); | |
1325 tmp = g_list_index(playlist->queue, entry); | |
1326 PLAYLIST_UNLOCK(playlist->mutex); | |
1327 | |
1328 return tmp; | |
1329 } | |
1330 | |
1331 gint | |
1332 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1333 { | |
1334 PlaylistEntry *entry; | |
1335 gint tmp; | |
1336 | |
1337 PLAYLIST_LOCK(playlist->mutex); | |
1338 entry = g_list_nth_data(playlist->queue, pos); | |
1339 tmp = g_list_index(playlist->entries, entry); | |
1340 PLAYLIST_UNLOCK(playlist->mutex); | |
1341 | |
1342 return tmp; | |
1343 } | |
1344 | |
1345 void | |
1346 playlist_clear_queue(Playlist *playlist) | |
1347 { | |
1348 PLAYLIST_LOCK(playlist->mutex); | |
1349 g_list_free(playlist->queue); | |
1350 playlist->queue = NULL; | |
1351 PLAYLIST_UNLOCK(playlist->mutex); | |
1352 | |
1353 playlist_recalc_total_time(playlist); | |
1354 playlistwin_update_list(playlist); | |
1355 } | |
1356 | |
1357 void | |
1358 playlist_queue_remove(Playlist *playlist, guint pos) | |
1359 { | |
1360 void *entry; | |
1361 | |
1362 PLAYLIST_LOCK(playlist->mutex); | |
1363 entry = g_list_nth_data(playlist->entries, pos); | |
1364 playlist->queue = g_list_remove(playlist->queue, entry); | |
1365 PLAYLIST_UNLOCK(playlist->mutex); | |
1366 | |
1367 playlistwin_update_list(playlist); | |
1368 } | |
1369 | |
1370 gint | |
1371 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1372 { | |
1373 return g_list_index(playlist->queue, entry); | |
1374 } | |
1375 | |
1376 void | |
1377 playlist_set_position(Playlist *playlist, guint pos) | |
1378 { | |
1379 GList *node; | |
1380 gboolean restart_playing = FALSE; | |
1381 | |
1382 if (!playlist) | |
1383 return; | |
1384 | |
1385 PLAYLIST_LOCK(playlist->mutex); | |
1386 | |
1387 node = g_list_nth(playlist->entries, pos); | |
1388 if (!node) { | |
1389 PLAYLIST_UNLOCK(playlist->mutex); | |
1390 return; | |
1391 } | |
1392 | |
1393 if (playback_get_playing()) { | |
1394 /* We need to stop before changing playlist_position */ | |
1395 PLAYLIST_UNLOCK(playlist->mutex); | |
1396 ip_data.stop = TRUE; | |
1397 playback_stop(); | |
1398 ip_data.stop = FALSE; | |
1399 PLAYLIST_LOCK(playlist->mutex); | |
1400 restart_playing = TRUE; | |
1401 } | |
1402 | |
1403 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1404 { | |
1405 /* Shuffling and this is our first manual jump. */ | |
1406 playlist_position_before_jump = playlist->position; | |
1407 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1408 |
2313 | 1409 playlist->position = node->data; |
1410 PLAYLIST_UNLOCK(playlist->mutex); | |
1411 playlist_check_pos_current(playlist); | |
1412 | |
1413 if (restart_playing) | |
1414 playback_initiate(); | |
1415 else { | |
1416 playlistwin_update_list(playlist); | |
1417 } | |
1418 } | |
1419 | |
1420 void | |
1421 playlist_eof_reached(Playlist *playlist) | |
1422 { | |
1423 GList *plist_pos_list; | |
1424 | |
1425 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1426 ip_data.stop = TRUE; | |
1427 playback_stop(); | |
1428 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1429 ip_data.stop = FALSE; | |
1430 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1431 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1432 |
2313 | 1433 PLAYLIST_LOCK(playlist->mutex); |
1434 | |
1435 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1436 { | |
1437 playlist->position = playlist_position_before_jump; | |
1438 playlist_position_before_jump = NULL; | |
1439 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1440 |
2313 | 1441 plist_pos_list = find_playlist_position_list(playlist); |
1442 | |
1443 if (cfg.no_playlist_advance) { | |
1444 PLAYLIST_UNLOCK(playlist->mutex); | |
1445 mainwin_clear_song_info(); | |
1446 if (cfg.repeat) | |
1447 playback_initiate(); | |
1448 return; | |
1449 } | |
1450 | |
1451 if (cfg.stopaftersong) { | |
1452 PLAYLIST_UNLOCK(playlist->mutex); | |
1453 mainwin_clear_song_info(); | |
1454 mainwin_set_stopaftersong(FALSE); | |
1455 return; | |
1456 } | |
1457 | |
1458 if (playlist->queue != NULL) { | |
1459 play_queued(playlist); | |
1460 } | |
1461 else if (!g_list_next(plist_pos_list)) { | |
1462 if (cfg.shuffle) { | |
1463 playlist->position = NULL; | |
1464 playlist_generate_shuffle_list_nolock(playlist); | |
1465 } | |
2380 | 1466 else if (playlist->entries != NULL) |
2313 | 1467 playlist->position = playlist->entries->data; |
1468 | |
1469 if (!cfg.repeat) { | |
1470 PLAYLIST_UNLOCK(playlist->mutex); | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1471 hook_call("playlist end reached", playlist->position); |
2313 | 1472 mainwin_clear_song_info(); |
1473 return; | |
1474 } | |
1475 } | |
1476 else | |
1477 playlist->position = g_list_next(plist_pos_list)->data; | |
1478 | |
1479 PLAYLIST_UNLOCK(playlist->mutex); | |
1480 | |
1481 playlist_check_pos_current(playlist); | |
1482 playback_initiate(); | |
1483 playlistwin_update_list(playlist); | |
1484 } | |
1485 | |
1486 gint | |
1487 playlist_queue_get_length(Playlist *playlist) | |
1488 { | |
1489 gint length; | |
1490 | |
1491 PLAYLIST_LOCK(playlist->mutex); | |
1492 length = g_list_length(playlist->queue); | |
1493 PLAYLIST_UNLOCK(playlist->mutex); | |
1494 | |
1495 return length; | |
1496 } | |
1497 | |
1498 gint | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1499 playlist_get_length(Playlist *playlist) |
2313 | 1500 { |
1501 return g_list_length(playlist->entries); | |
1502 } | |
1503 | |
1504 gchar * | |
1505 playlist_get_info_text(Playlist *playlist) | |
1506 { | |
1507 gchar *text, *title, *numbers, *length; | |
1508 | |
1509 g_return_val_if_fail(playlist != NULL, NULL); | |
1510 | |
1511 PLAYLIST_LOCK(playlist->mutex); | |
1512 if (!playlist->position) { | |
1513 PLAYLIST_UNLOCK(playlist->mutex); | |
1514 return NULL; | |
1515 } | |
1516 | |
1517 /* FIXME: there should not be a need to do additional conversion, | |
1518 * if playlist is properly maintained */ | |
1519 if (playlist->position->title) { | |
1520 title = str_to_utf8(playlist->position->title); | |
1521 } | |
1522 else { | |
3097
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1523 gchar *realfn = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1524 gchar *basename = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1525 realfn = g_filename_from_uri(playlist->position->filename, NULL, NULL); |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1526 basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); |
2313 | 1527 title = filename_to_utf8(basename); |
3097
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1528 g_free(realfn); realfn = NULL; |
bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3087
diff
changeset
|
1529 g_free(basename); basename = NULL; |
2313 | 1530 } |
1531 | |
1532 /* | |
1533 * If the user don't want numbers in the playlist, don't | |
1534 * display them in other parts of XMMS | |
1535 */ | |
1536 | |
1537 if (cfg.show_numbers_in_pl) | |
1538 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1539 else | |
1540 numbers = g_strdup(""); | |
1541 | |
1542 if (playlist->position->length != -1) | |
1543 length = g_strdup_printf(" (%d:%-2.2d)", | |
1544 playlist->position->length / 60000, | |
1545 (playlist->position->length / 1000) % 60); | |
1546 else | |
1547 length = g_strdup(""); | |
1548 | |
1549 PLAYLIST_UNLOCK(playlist->mutex); | |
1550 | |
1551 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1552 | |
1553 g_free(numbers); | |
1554 g_free(title); | |
1555 g_free(length); | |
1556 | |
1557 return text; | |
1558 } | |
1559 | |
1560 gint | |
1561 playlist_get_current_length(Playlist * playlist) | |
1562 { | |
1563 gint len = 0; | |
1564 | |
1565 if (!playlist) | |
1566 return 0; | |
1567 | |
1568 if (playlist->position) | |
1569 len = playlist->position->length; | |
1570 | |
1571 return len; | |
1572 } | |
1573 | |
1574 gboolean | |
1575 playlist_save(Playlist * playlist, const gchar * filename) | |
1576 { | |
1577 PlaylistContainer *plc = NULL; | |
1578 gchar *ext; | |
1579 | |
1580 g_return_val_if_fail(playlist != NULL, FALSE); | |
1581 g_return_val_if_fail(filename != NULL, FALSE); | |
1582 | |
1583 ext = strrchr(filename, '.') + 1; | |
1584 | |
1585 playlist_set_current_name(playlist, filename); | |
1586 | |
1587 if ((plc = playlist_container_find(ext)) == NULL) | |
1588 return FALSE; | |
1589 | |
1590 if (plc->plc_write == NULL) | |
1591 return FALSE; | |
1592 | |
1593 plc->plc_write(filename, 0); | |
1594 | |
1595 return TRUE; | |
1596 } | |
1597 | |
1598 gboolean | |
1599 playlist_load(Playlist * playlist, const gchar * filename) | |
1600 { | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1601 guint ret = 0; |
2313 | 1602 g_return_val_if_fail(playlist != NULL, FALSE); |
1603 | |
1604 playlist->loading_playlist = TRUE; | |
1605 ret = playlist_load_ins(playlist, filename, -1); | |
1606 playlist->loading_playlist = FALSE; | |
1607 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1608 return ret ? TRUE : FALSE; |
2313 | 1609 } |
1610 | |
1611 void | |
1612 playlist_load_ins_file(Playlist *playlist, | |
1613 const gchar * filename_p, | |
1614 const gchar * playlist_name, gint pos, | |
1615 const gchar * title, gint len) | |
1616 { | |
1617 gchar *filename; | |
1618 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1619 ProbeResult *pr = NULL; |
2313 | 1620 |
1621 g_return_if_fail(filename_p != NULL); | |
1622 g_return_if_fail(playlist != NULL); | |
1623 g_return_if_fail(playlist_name != NULL); | |
1624 | |
1625 filename = g_strchug(g_strdup(filename_p)); | |
1626 | |
1627 if(cfg.convert_slash) | |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1628 while ((tmp = strchr(filename, '\\')) != NULL) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1629 *tmp = '/'; |
2313 | 1630 |
1631 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1632 path = g_strdup(playlist_name); | |
1633 if ((tmp = strrchr(path, '/'))) | |
1634 *tmp = '\0'; | |
1635 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1636 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1637 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1638 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1639 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1640 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1641 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1642 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1643 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1644 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1645 g_free(pr); |
2313 | 1646 return; |
1647 } | |
1648 tmp = g_build_filename(path, filename, NULL); | |
1649 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1650 if (playlist->loading_playlist == TRUE && cfg.playlist_detect == TRUE) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1651 pr = NULL; |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1652 else if (!str_has_prefix_nocase(tmp, "http://") && |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1653 !str_has_prefix_nocase(tmp, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1654 pr = input_check_file(tmp, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1655 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
1656 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
2313 | 1657 g_free(tmp); |
1658 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1659 g_free(pr); |
2313 | 1660 } |
1661 else | |
1662 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1663 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1664 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1665 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1666 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1667 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1668 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1669 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1670 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1671 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1672 g_free(pr); |
2313 | 1673 } |
1674 | |
1675 g_free(filename); | |
1676 } | |
1677 | |
1678 void | |
1679 playlist_load_ins_file_tuple(Playlist * playlist, | |
1680 const gchar * filename_p, | |
1681 const gchar * playlist_name, | |
1682 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1683 Tuple *tuple) |
2313 | 1684 { |
1685 gchar *filename; | |
1686 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1687 ProbeResult *pr = NULL; /* for decoder cache */ |
2313 | 1688 |
1689 g_return_if_fail(filename_p != NULL); | |
1690 g_return_if_fail(playlist_name != NULL); | |
1691 g_return_if_fail(playlist != NULL); | |
1692 | |
1693 filename = g_strchug(g_strdup(filename_p)); | |
1694 | |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1695 if(cfg.convert_slash) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1696 while ((tmp = strchr(filename, '\\')) != NULL) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1697 *tmp = '/'; |
2313 | 1698 |
1699 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1700 path = g_strdup(playlist_name); | |
1701 if ((tmp = strrchr(path, '/'))) | |
1702 *tmp = '\0'; | |
1703 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1704 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1705 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1706 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1707 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1708 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1709 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1710 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1711 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1712 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1713 g_free(pr); |
2313 | 1714 return; |
1715 } | |
1716 tmp = g_build_filename(path, filename, NULL); | |
1717 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1718 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1719 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1720 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1721 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1722 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1723 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1724 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1725 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
2313 | 1726 g_free(tmp); |
1727 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1728 g_free(pr); |
2313 | 1729 } |
1730 else | |
1731 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1732 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1733 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1734 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1735 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1736 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1737 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1738 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1739 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1740 g_free(pr); |
2313 | 1741 } |
1742 | |
1743 g_free(filename); | |
1744 } | |
1745 | |
1746 static guint | |
1747 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1748 { | |
1749 PlaylistContainer *plc; | |
1750 gchar *ext; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1751 gint old_len, new_len; |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1752 |
2313 | 1753 g_return_val_if_fail(playlist != NULL, 0); |
1754 g_return_val_if_fail(filename != NULL, 0); | |
1755 | |
1756 ext = strrchr(filename, '.') + 1; | |
1757 plc = playlist_container_find(ext); | |
1758 | |
1759 g_return_val_if_fail(plc != NULL, 0); | |
1760 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1761 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1762 old_len = playlist_get_length(playlist); |
2313 | 1763 plc->plc_read(filename, pos); |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1764 new_len = playlist_get_length(playlist); |
2313 | 1765 |
1766 playlist_generate_shuffle_list(playlist); | |
1767 playlistwin_update_list(playlist); | |
1768 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1769 return new_len - old_len; |
2313 | 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 } |