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