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