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