Mercurial > audlegacy
annotate src/audacious/playlist.c @ 3639:8b1c6c301d7f
Branch merge.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 25 Sep 2007 23:49:11 +0300 |
parents | 8d2f06fc841c |
children | d5309028af21 |
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; |
2313 | 454 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
455 PLAYLIST_UNLOCK(playlist); |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
456 } |
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 void |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
459 playlist_clear(Playlist *playlist) |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
460 { |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
461 if (!playlist) |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
462 return; |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
463 |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
464 playlist_clear_only(playlist); |
2313 | 465 playlist_generate_shuffle_list(playlist); |
466 playlistwin_update_list(playlist); | |
467 playlist_recalc_total_time(playlist); | |
468 playlist_manager_update(); | |
469 } | |
470 | |
471 static void | |
472 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
473 gboolean * restart_playing) | |
474 { | |
475 PlaylistEntry *entry; | |
476 GList *playing_song = NULL; | |
477 | |
478 REQUIRE_LOCK(playlist->mutex); | |
479 | |
480 /* We call g_list_find manually here because we don't want an item | |
481 * in the shuffle_list */ | |
482 | |
483 if (playlist->position) | |
484 playing_song = g_list_find(playlist->entries, playlist->position); | |
485 | |
486 entry = PLAYLIST_ENTRY(node->data); | |
487 | |
488 if (playing_song == node) { | |
489 *set_info_text = TRUE; | |
490 | |
491 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
|
492 PLAYLIST_UNLOCK(playlist); |
2313 | 493 ip_data.stop = TRUE; |
494 playback_stop(); | |
495 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
|
496 PLAYLIST_LOCK(playlist); |
2313 | 497 *restart_playing = TRUE; |
498 } | |
499 | |
500 playing_song = find_playlist_position_list(playlist); | |
501 | |
502 if (g_list_next(playing_song)) | |
503 playlist->position = g_list_next(playing_song)->data; | |
504 else if (g_list_previous(playing_song)) | |
505 playlist->position = g_list_previous(playing_song)->data; | |
506 else | |
507 playlist->position = NULL; | |
508 | |
509 /* Make sure the entry did not disappear under us */ | |
510 if (g_list_index(playlist->entries, entry) == -1) | |
511 return; | |
512 | |
513 } | |
514 else if (g_list_position(playlist->entries, playing_song) > | |
515 g_list_position(playlist->entries, node)) { | |
516 *set_info_text = TRUE; | |
517 } | |
518 | |
519 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
520 playlist->queue = g_list_remove(playlist->queue, entry); | |
521 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
|
522 playlist->tail = g_list_last(playlist->entries); |
2313 | 523 playlist_entry_free(entry); |
524 g_list_free_1(node); | |
525 | |
526 playlist_recalc_total_time_nolock(playlist); | |
527 } | |
528 | |
529 void | |
530 playlist_delete_index(Playlist *playlist, guint pos) | |
531 { | |
532 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
533 GList *node; | |
534 | |
535 if (!playlist) | |
536 return; | |
537 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
538 PLAYLIST_LOCK(playlist); |
2313 | 539 |
540 node = g_list_nth(playlist->entries, pos); | |
541 | |
542 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
|
543 PLAYLIST_UNLOCK(playlist); |
2313 | 544 return; |
545 } | |
546 | |
547 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
548 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
549 PLAYLIST_UNLOCK(playlist); |
2313 | 550 |
551 playlist_recalc_total_time(playlist); | |
552 | |
553 playlistwin_update_list(playlist); | |
554 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
555 if (playlist->position) |
2313 | 556 playback_initiate(); |
3635 | 557 else |
2313 | 558 mainwin_clear_song_info(); |
559 } | |
560 | |
561 playlist_manager_update(); | |
562 } | |
563 | |
564 void | |
565 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
566 { | |
567 GList *node, *fnode; | |
568 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
569 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
570 PLAYLIST_LOCK(playlist); |
2313 | 571 |
572 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
573 node = playlist->entries; | |
574 | |
575 while (node) { | |
576 GList *next = g_list_next(node); | |
577 PlaylistEntry *entry = node->data; | |
578 | |
579 if (!strcmp(entry->filename, fnode->data)) | |
580 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
581 | |
582 node = next; | |
583 } | |
584 } | |
585 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
586 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
|
587 |
2313 | 588 playlist_recalc_total_time(playlist); |
589 playlistwin_update_list(playlist); | |
590 | |
591 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
592 if (playlist->position) |
2313 | 593 playback_initiate(); |
3635 | 594 else |
2313 | 595 mainwin_clear_song_info(); |
596 } | |
597 | |
598 playlist_manager_update(); | |
599 } | |
600 | |
601 void | |
602 playlist_delete(Playlist * playlist, gboolean crop) | |
603 { | |
604 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
605 GList *node, *next_node; | |
606 PlaylistEntry *entry; | |
607 | |
608 g_return_if_fail(playlist != NULL); | |
609 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
610 PLAYLIST_LOCK(playlist); |
2313 | 611 |
612 node = playlist->entries; | |
613 | |
614 while (node) { | |
615 entry = PLAYLIST_ENTRY(node->data); | |
616 | |
617 next_node = g_list_next(node); | |
618 | |
619 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
620 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
621 } | |
622 | |
623 node = next_node; | |
624 } | |
625 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
626 PLAYLIST_UNLOCK(playlist); |
2313 | 627 |
628 playlist_recalc_total_time(playlist); | |
629 | |
630 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
631 if (playlist->position) |
2313 | 632 playback_initiate(); |
3635 | 633 else |
2313 | 634 mainwin_clear_song_info(); |
635 } | |
636 | |
637 playlistwin_update_list(playlist); | |
638 playlist_manager_update(); | |
639 } | |
640 | |
641 static void | |
642 __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
|
643 const gchar * filename, |
2313 | 644 gint pos, |
645 const gchar * title, | |
646 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
|
647 InputPlugin * dec) |
2313 | 648 { |
649 g_return_if_fail(filename != NULL); | |
650 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
651 PLAYLIST_LOCK(playlist); |
2313 | 652 playlist->entries = g_list_insert(playlist->entries, |
653 playlist_entry_new(filename, title, len, dec), | |
654 pos); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
655 PLAYLIST_UNLOCK(playlist); |
2313 | 656 |
657 g_mutex_lock(mutex_scan); | |
658 playlist_get_info_scan_active = TRUE; | |
659 g_mutex_unlock(mutex_scan); | |
660 g_cond_signal(cond_scan); | |
661 } | |
662 | |
663 static void | |
664 __playlist_ins_with_info_tuple(Playlist * playlist, | |
665 const gchar * filename, | |
666 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
667 Tuple *tuple, |
2313 | 668 InputPlugin * dec) |
669 { | |
670 PlaylistEntry *entry; | |
3633
8c4633438785
Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3621
diff
changeset
|
671 Tuple *main_tuple = NULL; |
3635 | 672 gint nsubtunes = 0, i = 0; |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
673 gboolean add_flag = TRUE; |
2313 | 674 |
675 g_return_if_fail(playlist != NULL); | |
676 g_return_if_fail(filename != NULL); | |
677 | |
3635 | 678 if (tuple != NULL) { |
679 nsubtunes = tuple->nsubtunes; | |
680 if (nsubtunes > 0) { | |
3633
8c4633438785
Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3621
diff
changeset
|
681 main_tuple = tuple; |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
682 i = 1; |
2548
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
683 } |
68d1e9761cc5
[svn] - highly experimental code to speed up loading huge playlist. let me know if it breaks something.
yaz
parents:
2545
diff
changeset
|
684 } |
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
|
685 |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
686 for (; add_flag && i <= nsubtunes; i++) { |
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
|
687 gchar *filename_entry; |
3635 | 688 |
689 if (nsubtunes > 0) { | |
3633
8c4633438785
Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3621
diff
changeset
|
690 filename_entry = g_strdup_printf("%s?%d", filename, main_tuple->subtunes[i]); |
3635 | 691 /* We're dealing with subtune, let's ask again tuple information |
692 * to plugin, by passing the ?subtune suffix; this way we get | |
693 * specific subtune information in the tuple, if available. | |
694 */ | |
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
|
695 tuple = dec->get_song_tuple(filename_entry); |
3635 | 696 } 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
|
697 filename_entry = g_strdup(filename); |
3583 | 698 |
699 | |
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 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
|
701 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
|
702 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
|
703 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
|
704 |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
705 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
|
706 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
|
707 |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
708 PLAYLIST_LOCK(playlist); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
709 |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
710 if ((pos == -1) && (i < 2)) { // the common case |
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 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 |
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 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
|
718 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
|
719 playlist->tail = element; |
3635 | 720 } else { // the rests |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
721 if (playlist->tail != NULL) { |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
722 playlist->tail->next = element; |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
723 playlist->tail = element; |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
724 } else |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
725 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
|
726 } |
3635 | 727 } 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
|
728 playlist->entries = g_list_insert(playlist->entries, entry, pos); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
729 } |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
730 |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
731 PLAYLIST_UNLOCK(playlist); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
732 |
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 } |
2313 | 740 } |
3633
8c4633438785
Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3621
diff
changeset
|
741 |
8c4633438785
Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3621
diff
changeset
|
742 if (main_tuple) |
8c4633438785
Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3621
diff
changeset
|
743 tuple_free(main_tuple); |
2313 | 744 |
3635 | 745 if (tuple != NULL && tuple_get_int(tuple, FIELD_MTIME, NULL) == -1) { |
746 // 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
|
747 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
|
748 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
|
749 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
|
750 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
|
751 } |
2313 | 752 } |
753 | |
754 gboolean | |
755 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
756 { | |
757 gchar buf[64], *p; | |
758 gint r; | |
759 VFSFile *file; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
760 ProbeResult *pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
761 InputPlugin *dec = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
762 Tuple *tuple = NULL; |
2313 | 763 |
764 g_return_val_if_fail(playlist != NULL, FALSE); | |
765 g_return_val_if_fail(filename != NULL, FALSE); | |
766 | |
767 if (is_playlist_name(filename)) { | |
768 playlist->loading_playlist = TRUE; | |
769 playlist_load_ins(playlist, filename, pos); | |
770 playlist->loading_playlist = FALSE; | |
771 return TRUE; | |
772 } | |
773 | |
774 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | |
775 dec = NULL; | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
776 else if (!str_has_prefix_nocase(filename, "http://") && |
3635 | 777 !str_has_prefix_nocase(filename, "https://")) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
778 pr = input_check_file(filename, TRUE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
779 |
3635 | 780 if (pr) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
781 dec = pr->ip; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
782 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
783 } |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
784 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
785 } |
2313 | 786 |
3635 | 787 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || |
788 (playlist->loading_playlist == FALSE && dec != NULL) || | |
789 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && | |
790 str_has_prefix_nocase(filename, "http"))) { | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
791 __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
|
792 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
|
793 playlistwin_update_list(playlist); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
794 playlist_manager_update(); |
2313 | 795 return TRUE; |
796 } | |
797 | |
798 /* Some files (typically produced by some cgi-scripts) don't have | |
799 * the correct extension. Try to recognize these files by looking | |
800 * at their content. We only check for http entries since it does | |
801 * not make sense to have file entries in a playlist fetched from | |
802 * the net. */ | |
803 | |
804 /* Some strange people put fifo's with the .mp3 extension, so we | |
805 * need to make sure it's a real file (otherwise fread() may block | |
806 * and stall the entire program) */ | |
807 | |
808 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
809 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
810 return FALSE; | |
811 | |
3635 | 812 if ((file = vfs_fopen(filename, "rb")) == NULL) |
2313 | 813 return FALSE; |
814 | |
815 r = vfs_fread(buf, 1, sizeof(buf), file); | |
816 vfs_fclose(file); | |
817 | |
818 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
819 | |
820 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
821 playlist_load_ins(playlist, filename, pos); | |
822 return TRUE; | |
823 } | |
824 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
825 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
|
826 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
827 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
828 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
829 |
2313 | 830 return FALSE; |
831 } | |
832 | |
833 /* FIXME: The next few functions are specific to Unix | |
834 * filesystems. Either abstract it away, or don't even bother checking | |
835 * at such low level */ | |
836 | |
837 typedef struct { | |
838 dev_t dev; | |
839 ino_t ino; | |
840 } DeviceInode; | |
841 | |
842 static DeviceInode * | |
843 devino_new(dev_t device, | |
844 ino_t inode) | |
845 { | |
846 DeviceInode *devino = g_new0(DeviceInode, 1); | |
847 | |
3635 | 848 if (devino) { |
2313 | 849 devino->dev = device; |
850 devino->ino = inode; | |
851 } | |
852 | |
853 return devino; | |
854 } | |
855 | |
856 static guint | |
857 devino_hash(gconstpointer key) | |
858 { | |
859 const DeviceInode *d = key; | |
860 return d->ino; | |
861 } | |
862 | |
863 static gint | |
864 devino_compare(gconstpointer a, | |
865 gconstpointer b) | |
866 { | |
867 const DeviceInode *da = a, *db = b; | |
868 return (da->dev == db->dev && da->ino == db->ino); | |
869 } | |
870 | |
871 static gboolean | |
872 devino_destroy(gpointer key, | |
873 gpointer value, | |
874 gpointer data) | |
875 { | |
876 g_free(key); | |
877 return TRUE; | |
878 } | |
879 | |
880 static gboolean | |
881 file_is_hidden(const gchar * filename) | |
882 { | |
883 g_return_val_if_fail(filename != NULL, FALSE); | |
2570 | 884 return (g_basename(filename)[0] == '.'); |
2313 | 885 } |
886 | |
887 static GList * | |
888 playlist_dir_find_files(const gchar * path, | |
889 gboolean background, | |
890 GHashTable * htab) | |
891 { | |
892 GDir *dir; | |
893 GList *list = NULL, *ilist; | |
894 const gchar *dir_entry; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
895 ProbeResult *pr = NULL; |
2313 | 896 |
897 struct stat statbuf; | |
898 DeviceInode *devino; | |
899 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
900 if (!path) |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
901 return NULL; |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
902 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
903 if (!vfs_file_test(path, G_FILE_TEST_IS_DIR)) |
2313 | 904 return NULL; |
905 | |
906 stat(path, &statbuf); | |
907 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
908 | |
909 if (g_hash_table_lookup(htab, devino)) { | |
910 g_free(devino); | |
911 return NULL; | |
912 } | |
913 | |
914 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
915 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
916 /* XXX: what the hell is this for? --nenolod */ |
2313 | 917 if ((ilist = input_scan_dir(path))) { |
918 GList *node; | |
919 for (node = ilist; node; node = g_list_next(node)) { | |
920 gchar *name = g_build_filename(path, node->data, NULL); | |
921 list = g_list_prepend(list, name); | |
922 g_free(node->data); | |
923 } | |
924 g_list_free(ilist); | |
925 return list; | |
926 } | |
927 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
928 /* g_dir_open does not handle URI, so path should come here not-urified. --giacomo */ |
2313 | 929 if (!(dir = g_dir_open(path, 0, NULL))) |
930 return NULL; | |
931 | |
932 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
|
933 gchar *filename, *tmp; |
2313 | 934 |
935 if (file_is_hidden(dir_entry)) | |
936 continue; | |
937 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
938 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
|
939 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
|
940 g_free(tmp); |
2313 | 941 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
942 if (vfs_file_test(filename, G_FILE_TEST_IS_DIR)) { |
2313 | 943 GList *sub; |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
944 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
|
945 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
|
946 g_free(dirfilename); |
2313 | 947 g_free(filename); |
948 list = g_list_concat(list, sub); | |
949 } | |
950 else if (cfg.playlist_detect == TRUE) | |
951 list = g_list_prepend(list, filename); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
952 else if ((pr = input_check_file(filename, TRUE)) != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
953 { |
2313 | 954 list = g_list_prepend(list, filename); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
955 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
956 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
957 pr = NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
958 } |
2313 | 959 else |
960 g_free(filename); | |
961 | |
962 while (background && gtk_events_pending()) | |
963 gtk_main_iteration(); | |
964 } | |
965 g_dir_close(dir); | |
966 | |
967 return list; | |
968 } | |
969 | |
970 gboolean | |
971 playlist_add(Playlist * playlist, const gchar * filename) | |
972 { | |
973 return playlist_ins(playlist, filename, -1); | |
974 } | |
975 | |
976 guint | |
977 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
978 { | |
979 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
980 } | |
981 | |
982 guint | |
983 playlist_add_url(Playlist * playlist, const gchar * url) | |
984 { | |
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
|
985 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
|
986 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
|
987 // printf("playlist_add_url: entries = %d\n", entries); |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
988 return entries; |
2313 | 989 } |
990 | |
991 guint | |
992 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
993 gint pos, | |
994 gboolean background) | |
995 { | |
996 guint entries = 0; | |
997 GList *list, *node; | |
998 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
|
999 gchar *path2 = g_filename_from_uri(path, NULL, NULL); |
2313 | 1000 |
2580
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
1001 if (path2 == NULL) |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
1002 path2 = g_strdup(path); |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
1003 |
2313 | 1004 htab = g_hash_table_new(devino_hash, devino_compare); |
1005 | |
2579 | 1006 list = playlist_dir_find_files(path2, background, htab); |
2313 | 1007 list = g_list_sort(list, (GCompareFunc) path_compare); |
1008 | |
1009 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
1010 | |
1011 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
|
1012 playlist_ins(playlist, node->data, pos); |
2313 | 1013 g_free(node->data); |
1014 entries++; | |
1015 if (pos >= 0) | |
1016 pos++; | |
1017 } | |
1018 | |
1019 g_list_free(list); | |
2579 | 1020 g_free(path2); |
2313 | 1021 |
1022 playlist_recalc_total_time(playlist); | |
1023 playlist_generate_shuffle_list(playlist); | |
1024 playlistwin_update_list(playlist); | |
1025 playlist_manager_update(); | |
1026 return entries; | |
1027 } | |
1028 | |
1029 guint | |
1030 playlist_ins_url(Playlist * playlist, const gchar * string, | |
1031 gint pos) | |
1032 { | |
1033 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
|
1034 gint entries = 0; |
2313 | 1035 gchar *decoded = NULL; |
1036 | |
1037 g_return_val_if_fail(playlist != NULL, 0); | |
1038 g_return_val_if_fail(string != NULL, 0); | |
1039 | |
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
|
1040 // playlistwin_update_list(playlist); // is this necessary? --yaz |
2313 | 1041 |
1042 while (*string) { | |
1043 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
|
1044 guint i = 0; |
2313 | 1045 tmp = strchr(string, '\n'); |
1046 if (tmp) { | |
1047 if (*(tmp - 1) == '\r') | |
1048 *(tmp - 1) = '\0'; | |
1049 *tmp = '\0'; | |
1050 } | |
1051 | |
1052 decoded = g_strdup(string); | |
1053 | |
2575 | 1054 if (vfs_file_test(decoded, G_FILE_TEST_IS_DIR)) { |
2313 | 1055 i = playlist_ins_dir(playlist, decoded, pos, FALSE); |
1056 } | |
1057 else { | |
1058 if (is_playlist_name(decoded)) { | |
1059 i = playlist_load_ins(playlist, decoded, pos); | |
1060 } | |
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
|
1061 else if (playlist_ins(playlist, decoded, pos)) { |
2313 | 1062 i = 1; |
1063 } | |
1064 } | |
1065 | |
1066 g_free(decoded); | |
1067 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1068 PLAYLIST_LOCK(playlist); |
2313 | 1069 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
|
1070 PLAYLIST_UNLOCK(playlist); |
2313 | 1071 |
1072 entries += i; | |
1073 | |
1074 if (pos >= 0) | |
1075 pos += i; | |
1076 if (!tmp) | |
1077 break; | |
1078 | |
1079 string = tmp + 1; | |
1080 } | |
1081 | |
1082 playlist_recalc_total_time(playlist); | |
1083 playlist_generate_shuffle_list(playlist); | |
1084 playlistwin_update_list(playlist); | |
1085 | |
1086 playlist_manager_update(); | |
1087 | |
1088 return entries; | |
1089 } | |
1090 | |
1091 void | |
1092 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
1093 gint freq, gint nch) | |
1094 { | |
1095 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
|
1096 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
|
1097 gchar *text; |
2313 | 1098 |
3197
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1099 if(length == -1) { |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1100 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
|
1101 } |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1102 |
2313 | 1103 g_return_if_fail(playlist != NULL); |
1104 | |
1105 if (playlist->position) { | |
1106 g_free(playlist->position->title); | |
1107 playlist->position->title = g_strdup(title); | |
1108 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1109 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1110 // overwrite tuple::title, mainly for streaming. it may incur side effects. --yaz |
3635 | 1111 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
|
1112 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
|
1113 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
|
1114 } |
2313 | 1115 } |
1116 | |
1117 playlist_recalc_total_time(playlist); | |
1118 | |
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
|
1119 /* 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
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 |
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
|
1125 event_queue("playlist info change", msg); |
2460 | 1126 |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1127 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
|
1128 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
|
1129 |
2460 | 1130 if ( playlist->position ) |
1131 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1132 } |
1133 | |
1134 void | |
1135 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1136 gint freq, gint nch) | |
1137 { | |
1138 g_return_if_fail(playlist != NULL); | |
1139 | |
1140 if (playlist->position) { | |
1141 g_free(playlist->position->title); | |
1142 playlist->position->title = g_strdup(title); | |
1143 playlist->position->length = length; | |
1144 } | |
1145 | |
1146 playlist_recalc_total_time(playlist); | |
1147 | |
1148 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1149 |
3635 | 1150 if (playlist->position) |
2460 | 1151 hook_call( "playlist set info" , playlist->position ); |
2313 | 1152 } |
1153 | |
1154 void | |
1155 playlist_check_pos_current(Playlist *playlist) | |
1156 { | |
1157 gint pos, row, bottom; | |
1158 | |
1159 if (!playlist) | |
1160 return; | |
1161 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1162 PLAYLIST_LOCK(playlist); |
2313 | 1163 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
|
1164 PLAYLIST_UNLOCK(playlist); |
2313 | 1165 return; |
1166 } | |
1167 | |
1168 pos = g_list_index(playlist->entries, playlist->position); | |
1169 | |
1170 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
|
1171 PLAYLIST_UNLOCK(playlist); |
2313 | 1172 return; |
1173 } | |
1174 | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1175 bottom = MAX(0, playlist_get_length(playlist) - |
3217 | 1176 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); |
1177 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
|
1178 PLAYLIST_UNLOCK(playlist); |
2313 | 1179 playlistwin_set_toprow(row); |
1180 g_cond_signal(cond_scan); | |
1181 } | |
1182 | |
1183 void | |
1184 playlist_next(Playlist *playlist) | |
1185 { | |
1186 GList *plist_pos_list; | |
1187 gboolean restart_playing = FALSE; | |
3635 | 1188 |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1189 if (!playlist_get_length(playlist)) |
2313 | 1190 return; |
1191 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1192 PLAYLIST_LOCK(playlist); |
2313 | 1193 |
3635 | 1194 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) { |
2313 | 1195 playlist->position = playlist_position_before_jump; |
1196 playlist_position_before_jump = NULL; | |
1197 } | |
1198 | |
1199 plist_pos_list = find_playlist_position_list(playlist); | |
1200 | |
1201 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
|
1202 PLAYLIST_UNLOCK(playlist); |
2313 | 1203 return; |
1204 } | |
1205 | |
1206 if (playback_get_playing()) { | |
1207 /* 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
|
1208 PLAYLIST_UNLOCK(playlist); |
2313 | 1209 ip_data.stop = TRUE; |
1210 playback_stop(); | |
1211 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
|
1212 PLAYLIST_LOCK(playlist); |
2313 | 1213 restart_playing = TRUE; |
1214 } | |
1215 | |
1216 plist_pos_list = find_playlist_position_list(playlist); | |
1217 if (playlist->queue != NULL) | |
1218 play_queued(playlist); | |
1219 else if (g_list_next(plist_pos_list)) | |
1220 playlist->position = g_list_next(plist_pos_list)->data; | |
1221 else if (cfg.repeat) { | |
1222 playlist->position = NULL; | |
1223 playlist_generate_shuffle_list_nolock(playlist); | |
1224 if (cfg.shuffle) | |
1225 playlist->position = playlist->shuffle->data; | |
1226 else | |
1227 playlist->position = playlist->entries->data; | |
1228 } | |
3635 | 1229 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1230 PLAYLIST_UNLOCK(playlist); |
3635 | 1231 |
2313 | 1232 playlist_check_pos_current(playlist); |
1233 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1234 if (restart_playing) |
2313 | 1235 playback_initiate(); |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1236 |
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1237 playlistwin_update_list(playlist); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1238 playlist_manager_update(); |
2313 | 1239 } |
1240 | |
1241 void | |
1242 playlist_prev(Playlist *playlist) | |
1243 { | |
1244 GList *plist_pos_list; | |
1245 gboolean restart_playing = FALSE; | |
1246 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1247 if (!playlist_get_length(playlist)) |
2313 | 1248 return; |
1249 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1250 PLAYLIST_LOCK(playlist); |
2313 | 1251 |
3635 | 1252 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) { |
2313 | 1253 playlist->position = playlist_position_before_jump; |
1254 playlist_position_before_jump = NULL; | |
1255 } | |
1256 | |
1257 plist_pos_list = find_playlist_position_list(playlist); | |
1258 | |
1259 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
|
1260 PLAYLIST_UNLOCK(playlist); |
2313 | 1261 return; |
1262 } | |
1263 | |
1264 if (playback_get_playing()) { | |
1265 /* 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
|
1266 PLAYLIST_UNLOCK(playlist); |
2313 | 1267 ip_data.stop = TRUE; |
1268 playback_stop(); | |
1269 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
|
1270 PLAYLIST_LOCK(playlist); |
2313 | 1271 restart_playing = TRUE; |
1272 } | |
1273 | |
1274 plist_pos_list = find_playlist_position_list(playlist); | |
1275 if (g_list_previous(plist_pos_list)) { | |
1276 playlist->position = g_list_previous(plist_pos_list)->data; | |
1277 } | |
1278 else if (cfg.repeat) { | |
1279 GList *node; | |
1280 playlist->position = NULL; | |
1281 playlist_generate_shuffle_list_nolock(playlist); | |
1282 if (cfg.shuffle) | |
1283 node = g_list_last(playlist->shuffle); | |
1284 else | |
1285 node = g_list_last(playlist->entries); | |
1286 if (node) | |
1287 playlist->position = node->data; | |
1288 } | |
1289 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1290 PLAYLIST_UNLOCK(playlist); |
2313 | 1291 |
1292 playlist_check_pos_current(playlist); | |
1293 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1294 if (restart_playing) |
2313 | 1295 playback_initiate(); |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1296 else |
2313 | 1297 playlistwin_update_list(playlist); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1298 |
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1299 playlist_manager_update(); |
2313 | 1300 } |
1301 | |
1302 void | |
1303 playlist_queue(Playlist *playlist) | |
1304 { | |
1305 GList *list = playlist_get_selected(playlist); | |
1306 GList *it = list; | |
1307 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1308 PLAYLIST_LOCK(playlist); |
2313 | 1309 |
3635 | 1310 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) { |
2313 | 1311 /* Shuffling and this is our first manual jump. */ |
1312 playlist_position_before_jump = playlist->position; | |
1313 } | |
1314 | |
1315 while (it) { | |
1316 GList *next = g_list_next(it); | |
1317 GList *tmp; | |
1318 | |
1319 /* XXX: WTF? --nenolod */ | |
1320 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1321 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1322 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1323 g_list_free_1(tmp); | |
1324 list = g_list_remove_link(list, it); | |
1325 g_list_free_1(it); | |
1326 } | |
1327 | |
1328 it = next; | |
1329 } | |
1330 | |
1331 playlist->queue = g_list_concat(playlist->queue, list); | |
1332 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1333 PLAYLIST_UNLOCK(playlist); |
2313 | 1334 |
1335 playlist_recalc_total_time(playlist); | |
1336 playlistwin_update_list(playlist); | |
1337 } | |
1338 | |
1339 void | |
1340 playlist_queue_position(Playlist *playlist, guint pos) | |
1341 { | |
1342 GList *tmp; | |
1343 PlaylistEntry *entry; | |
1344 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1345 PLAYLIST_LOCK(playlist); |
2313 | 1346 |
1347 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1348 { | |
1349 /* Shuffling and this is our first manual jump. */ | |
1350 playlist_position_before_jump = playlist->position; | |
1351 } | |
1352 | |
1353 entry = g_list_nth_data(playlist->entries, pos); | |
1354 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1355 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1356 g_list_free_1(tmp); | |
1357 } | |
1358 else | |
1359 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
|
1360 PLAYLIST_UNLOCK(playlist); |
2313 | 1361 |
1362 playlist_recalc_total_time(playlist); | |
1363 playlistwin_update_list(playlist); | |
1364 } | |
1365 | |
1366 gboolean | |
1367 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1368 { | |
1369 PlaylistEntry *entry; | |
1370 GList *tmp; | |
1371 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1372 PLAYLIST_LOCK(playlist); |
2313 | 1373 entry = g_list_nth_data(playlist->entries, pos); |
1374 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
|
1375 PLAYLIST_UNLOCK(playlist); |
2313 | 1376 |
1377 return tmp != NULL; | |
1378 } | |
1379 | |
1380 gint | |
1381 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1382 { | |
1383 PlaylistEntry *entry; | |
1384 gint tmp; | |
1385 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1386 PLAYLIST_LOCK(playlist); |
2313 | 1387 entry = g_list_nth_data(playlist->entries, pos); |
1388 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
|
1389 PLAYLIST_UNLOCK(playlist); |
2313 | 1390 |
1391 return tmp; | |
1392 } | |
1393 | |
1394 gint | |
1395 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1396 { | |
1397 PlaylistEntry *entry; | |
1398 gint tmp; | |
1399 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1400 PLAYLIST_LOCK(playlist); |
2313 | 1401 entry = g_list_nth_data(playlist->queue, pos); |
1402 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
|
1403 PLAYLIST_UNLOCK(playlist); |
2313 | 1404 |
1405 return tmp; | |
1406 } | |
1407 | |
1408 void | |
1409 playlist_clear_queue(Playlist *playlist) | |
1410 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1411 PLAYLIST_LOCK(playlist); |
2313 | 1412 g_list_free(playlist->queue); |
1413 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
|
1414 PLAYLIST_UNLOCK(playlist); |
2313 | 1415 |
1416 playlist_recalc_total_time(playlist); | |
1417 playlistwin_update_list(playlist); | |
1418 } | |
1419 | |
1420 void | |
1421 playlist_queue_remove(Playlist *playlist, guint pos) | |
1422 { | |
1423 void *entry; | |
1424 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1425 PLAYLIST_LOCK(playlist); |
2313 | 1426 entry = g_list_nth_data(playlist->entries, pos); |
1427 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
|
1428 PLAYLIST_UNLOCK(playlist); |
2313 | 1429 |
1430 playlistwin_update_list(playlist); | |
1431 } | |
1432 | |
1433 gint | |
1434 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1435 { | |
1436 return g_list_index(playlist->queue, entry); | |
1437 } | |
1438 | |
1439 void | |
1440 playlist_set_position(Playlist *playlist, guint pos) | |
1441 { | |
1442 GList *node; | |
1443 gboolean restart_playing = FALSE; | |
1444 | |
1445 if (!playlist) | |
1446 return; | |
1447 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1448 PLAYLIST_LOCK(playlist); |
2313 | 1449 |
1450 node = g_list_nth(playlist->entries, pos); | |
1451 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
|
1452 PLAYLIST_UNLOCK(playlist); |
2313 | 1453 return; |
1454 } | |
1455 | |
1456 if (playback_get_playing()) { | |
1457 /* 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
|
1458 PLAYLIST_UNLOCK(playlist); |
2313 | 1459 ip_data.stop = TRUE; |
1460 playback_stop(); | |
1461 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
|
1462 PLAYLIST_LOCK(playlist); |
2313 | 1463 restart_playing = TRUE; |
1464 } | |
1465 | |
1466 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1467 { | |
1468 /* Shuffling and this is our first manual jump. */ | |
1469 playlist_position_before_jump = playlist->position; | |
1470 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1471 |
2313 | 1472 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
|
1473 PLAYLIST_UNLOCK(playlist); |
2313 | 1474 playlist_check_pos_current(playlist); |
1475 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1476 if (restart_playing) |
2313 | 1477 playback_initiate(); |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1478 else |
2313 | 1479 playlistwin_update_list(playlist); |
1480 } | |
1481 | |
1482 void | |
1483 playlist_eof_reached(Playlist *playlist) | |
1484 { | |
1485 GList *plist_pos_list; | |
1486 | |
1487 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1488 ip_data.stop = TRUE; | |
1489 playback_stop(); | |
1490 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1491 ip_data.stop = FALSE; | |
1492 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1493 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1494 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1495 PLAYLIST_LOCK(playlist); |
2313 | 1496 |
1497 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1498 { | |
1499 playlist->position = playlist_position_before_jump; | |
1500 playlist_position_before_jump = NULL; | |
1501 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1502 |
2313 | 1503 plist_pos_list = find_playlist_position_list(playlist); |
1504 | |
1505 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
|
1506 PLAYLIST_UNLOCK(playlist); |
2313 | 1507 mainwin_clear_song_info(); |
1508 if (cfg.repeat) | |
1509 playback_initiate(); | |
1510 return; | |
1511 } | |
1512 | |
1513 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
|
1514 PLAYLIST_UNLOCK(playlist); |
2313 | 1515 mainwin_clear_song_info(); |
1516 mainwin_set_stopaftersong(FALSE); | |
1517 return; | |
1518 } | |
1519 | |
1520 if (playlist->queue != NULL) { | |
1521 play_queued(playlist); | |
1522 } | |
1523 else if (!g_list_next(plist_pos_list)) { | |
1524 if (cfg.shuffle) { | |
1525 playlist->position = NULL; | |
1526 playlist_generate_shuffle_list_nolock(playlist); | |
1527 } | |
2380 | 1528 else if (playlist->entries != NULL) |
2313 | 1529 playlist->position = playlist->entries->data; |
1530 | |
1531 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
|
1532 PLAYLIST_UNLOCK(playlist); |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1533 hook_call("playlist end reached", playlist->position); |
2313 | 1534 mainwin_clear_song_info(); |
1535 return; | |
1536 } | |
1537 } | |
1538 else | |
1539 playlist->position = g_list_next(plist_pos_list)->data; | |
1540 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1541 PLAYLIST_UNLOCK(playlist); |
2313 | 1542 |
1543 playlist_check_pos_current(playlist); | |
1544 playback_initiate(); | |
1545 playlistwin_update_list(playlist); | |
1546 } | |
1547 | |
1548 gint | |
1549 playlist_queue_get_length(Playlist *playlist) | |
1550 { | |
1551 gint length; | |
1552 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1553 PLAYLIST_LOCK(playlist); |
2313 | 1554 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
|
1555 PLAYLIST_UNLOCK(playlist); |
2313 | 1556 |
1557 return length; | |
1558 } | |
1559 | |
1560 gint | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1561 playlist_get_length(Playlist *playlist) |
2313 | 1562 { |
1563 return g_list_length(playlist->entries); | |
1564 } | |
1565 | |
1566 gchar * | |
1567 playlist_get_info_text(Playlist *playlist) | |
1568 { | |
1569 gchar *text, *title, *numbers, *length; | |
1570 | |
1571 g_return_val_if_fail(playlist != NULL, NULL); | |
1572 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1573 PLAYLIST_LOCK(playlist); |
2313 | 1574 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
|
1575 PLAYLIST_UNLOCK(playlist); |
2313 | 1576 return NULL; |
1577 } | |
1578 | |
1579 /* FIXME: there should not be a need to do additional conversion, | |
1580 * if playlist is properly maintained */ | |
1581 if (playlist->position->title) { | |
1582 title = str_to_utf8(playlist->position->title); | |
1583 } | |
1584 else { | |
3635 | 1585 gchar *realfn = g_filename_from_uri(playlist->position->filename, NULL, NULL); |
1586 gchar *basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); | |
2313 | 1587 title = filename_to_utf8(basename); |
3635 | 1588 g_free(realfn); |
1589 g_free(basename); | |
2313 | 1590 } |
1591 | |
1592 /* | |
1593 * If the user don't want numbers in the playlist, don't | |
1594 * display them in other parts of XMMS | |
1595 */ | |
1596 | |
1597 if (cfg.show_numbers_in_pl) | |
1598 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1599 else | |
1600 numbers = g_strdup(""); | |
1601 | |
1602 if (playlist->position->length != -1) | |
1603 length = g_strdup_printf(" (%d:%-2.2d)", | |
1604 playlist->position->length / 60000, | |
1605 (playlist->position->length / 1000) % 60); | |
1606 else | |
1607 length = g_strdup(""); | |
1608 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1609 PLAYLIST_UNLOCK(playlist); |
2313 | 1610 |
1611 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1612 | |
1613 g_free(numbers); | |
1614 g_free(title); | |
1615 g_free(length); | |
1616 | |
1617 return text; | |
1618 } | |
1619 | |
1620 gint | |
1621 playlist_get_current_length(Playlist * playlist) | |
1622 { | |
1623 gint len = 0; | |
1624 | |
1625 if (!playlist) | |
1626 return 0; | |
1627 | |
1628 if (playlist->position) | |
1629 len = playlist->position->length; | |
1630 | |
1631 return len; | |
1632 } | |
1633 | |
1634 gboolean | |
1635 playlist_save(Playlist * playlist, const gchar * filename) | |
1636 { | |
1637 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
|
1638 GList *old_iter; |
2313 | 1639 gchar *ext; |
1640 | |
1641 g_return_val_if_fail(playlist != NULL, FALSE); | |
1642 g_return_val_if_fail(filename != NULL, FALSE); | |
1643 | |
1644 ext = strrchr(filename, '.') + 1; | |
1645 | |
1646 if ((plc = playlist_container_find(ext)) == NULL) | |
1647 return FALSE; | |
1648 | |
1649 if (plc->plc_write == NULL) | |
1650 return FALSE; | |
1651 | |
3476
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1652 /* 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
|
1653 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
|
1654 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
|
1655 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
|
1656 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
|
1657 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
|
1658 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
|
1659 } else { |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1660 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
|
1661 } |
2313 | 1662 |
1663 return TRUE; | |
1664 } | |
1665 | |
1666 gboolean | |
1667 playlist_load(Playlist * playlist, const gchar * filename) | |
1668 { | |
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
|
1669 guint ret = 0; |
2313 | 1670 g_return_val_if_fail(playlist != NULL, FALSE); |
1671 | |
1672 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
|
1673 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
|
1674 /* 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
|
1675 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
|
1676 } |
2313 | 1677 ret = playlist_load_ins(playlist, filename, -1); |
1678 playlist->loading_playlist = FALSE; | |
1679 | |
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
|
1680 return ret ? TRUE : FALSE; |
2313 | 1681 } |
1682 | |
1683 void | |
1684 playlist_load_ins_file(Playlist *playlist, | |
1685 const gchar * filename_p, | |
1686 const gchar * playlist_name, gint pos, | |
1687 const gchar * title, gint len) | |
1688 { | |
1689 gchar *filename; | |
1690 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1691 ProbeResult *pr = NULL; |
2313 | 1692 |
1693 g_return_if_fail(filename_p != NULL); | |
1694 g_return_if_fail(playlist != NULL); | |
1695 g_return_if_fail(playlist_name != NULL); | |
1696 | |
1697 filename = g_strchug(g_strdup(filename_p)); | |
1698 | |
3635 | 1699 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
|
1700 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
|
1701 *tmp = '/'; |
2313 | 1702 |
1703 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1704 path = g_strdup(playlist_name); | |
1705 if ((tmp = strrchr(path, '/'))) | |
1706 *tmp = '\0'; | |
1707 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1708 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1709 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1710 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1711 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
|
1712 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1713 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1714 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1715 __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
|
1716 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1717 g_free(pr); |
2313 | 1718 return; |
1719 } | |
1720 tmp = g_build_filename(path, filename, NULL); | |
1721 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1722 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
|
1723 pr = NULL; |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
1724 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
|
1725 !str_has_prefix_nocase(tmp, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1726 pr = input_check_file(tmp, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1727 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
1728 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
2313 | 1729 g_free(tmp); |
1730 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1731 g_free(pr); |
2313 | 1732 } |
1733 else | |
1734 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1735 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1736 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1737 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1738 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1739 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1740 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1741 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1742 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1743 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1744 g_free(pr); |
2313 | 1745 } |
1746 | |
1747 g_free(filename); | |
1748 } | |
1749 | |
1750 void | |
1751 playlist_load_ins_file_tuple(Playlist * playlist, | |
1752 const gchar * filename_p, | |
1753 const gchar * playlist_name, | |
1754 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1755 Tuple *tuple) |
2313 | 1756 { |
1757 gchar *filename; | |
1758 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1759 ProbeResult *pr = NULL; /* for decoder cache */ |
2313 | 1760 |
1761 g_return_if_fail(filename_p != NULL); | |
1762 g_return_if_fail(playlist_name != NULL); | |
1763 g_return_if_fail(playlist != NULL); | |
1764 | |
1765 filename = g_strchug(g_strdup(filename_p)); | |
1766 | |
3635 | 1767 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
|
1768 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
|
1769 *tmp = '/'; |
2313 | 1770 |
1771 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1772 path = g_strdup(playlist_name); | |
1773 if ((tmp = strrchr(path, '/'))) | |
1774 *tmp = '\0'; | |
1775 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1776 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1777 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1778 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1779 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
|
1780 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1781 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1782 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1783 __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
|
1784 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1785 g_free(pr); |
2313 | 1786 return; |
1787 } | |
1788 tmp = g_build_filename(path, filename, NULL); | |
1789 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1790 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1791 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1792 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1793 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
|
1794 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1795 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1796 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1797 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
2313 | 1798 g_free(tmp); |
1799 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1800 g_free(pr); |
2313 | 1801 } |
1802 else | |
1803 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1804 if ((playlist->loading_playlist == TRUE || |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1805 cfg.playlist_detect == TRUE)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1806 pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1807 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
|
1808 !str_has_prefix_nocase(filename, "https://")) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1809 pr = input_check_file(filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1810 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1811 __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
|
1812 g_free(pr); |
2313 | 1813 } |
1814 | |
1815 g_free(filename); | |
1816 } | |
1817 | |
1818 static guint | |
1819 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1820 { | |
1821 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
|
1822 GList *old_iter; |
2313 | 1823 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
|
1824 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
|
1825 |
2313 | 1826 g_return_val_if_fail(playlist != NULL, 0); |
1827 g_return_val_if_fail(filename != NULL, 0); | |
1828 | |
1829 ext = strrchr(filename, '.') + 1; | |
1830 plc = playlist_container_find(ext); | |
1831 | |
1832 g_return_val_if_fail(plc != NULL, 0); | |
1833 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1834 | |
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
|
1835 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
|
1836 /* 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
|
1837 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
|
1838 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
|
1839 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
|
1840 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
|
1841 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
|
1842 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
|
1843 } 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
|
1844 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
|
1845 } |
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
|
1846 new_len = playlist_get_length(playlist); |
2313 | 1847 |
1848 playlist_generate_shuffle_list(playlist); | |
1849 playlistwin_update_list(playlist); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1850 playlist_manager_update(); |
2313 | 1851 |
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
|
1852 return new_len - old_len; |
2313 | 1853 } |
1854 | |
1855 GList * | |
1856 get_playlist_nth(Playlist *playlist, guint nth) | |
1857 { | |
1858 g_warning("deprecated function get_playlist_nth() was called"); | |
1859 REQUIRE_LOCK(playlist->mutex); | |
1860 return g_list_nth(playlist->entries, nth); | |
1861 } | |
1862 | |
1863 gint | |
1864 playlist_get_position_nolock(Playlist *playlist) | |
1865 { | |
1866 if (playlist && playlist->position) | |
1867 return g_list_index(playlist->entries, playlist->position); | |
1868 return 0; | |
1869 } | |
1870 | |
1871 gint | |
1872 playlist_get_position(Playlist *playlist) | |
1873 { | |
1874 gint pos; | |
1875 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1876 PLAYLIST_LOCK(playlist); |
2313 | 1877 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
|
1878 PLAYLIST_UNLOCK(playlist); |
2313 | 1879 |
1880 return pos; | |
1881 } | |
1882 | |
1883 gchar * | |
1884 playlist_get_filename(Playlist *playlist, guint pos) | |
1885 { | |
1886 gchar *filename; | |
1887 PlaylistEntry *entry; | |
1888 GList *node; | |
1889 | |
1890 if (!playlist) | |
1891 return NULL; | |
1892 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1893 PLAYLIST_LOCK(playlist); |
2313 | 1894 node = g_list_nth(playlist->entries, pos); |
1895 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
|
1896 PLAYLIST_UNLOCK(playlist); |
2313 | 1897 return NULL; |
1898 } | |
1899 entry = node->data; | |
1900 | |
1901 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
|
1902 PLAYLIST_UNLOCK(playlist); |
2313 | 1903 |
1904 return filename; | |
1905 } | |
1906 | |
1907 gchar * | |
1908 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1909 { | |
1910 gchar *title = NULL; | |
1911 PlaylistEntry *entry; | |
1912 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1913 time_t mtime; |
2313 | 1914 |
1915 if (!playlist) | |
1916 return NULL; | |
1917 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1918 PLAYLIST_LOCK(playlist); |
2313 | 1919 |
1920 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
|
1921 PLAYLIST_UNLOCK(playlist); |
2313 | 1922 return NULL; |
1923 } | |
1924 | |
1925 entry = node->data; | |
1926 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1927 if (entry->tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
1928 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
|
1929 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1930 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1931 |
2313 | 1932 /* FIXME: simplify this logic */ |
1933 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
|
1934 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1935 { |
1936 if (playlist_entry_get_info(entry)) | |
1937 title = entry->title; | |
1938 } | |
1939 else { | |
1940 title = entry->title; | |
1941 } | |
1942 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1943 PLAYLIST_UNLOCK(playlist); |
2313 | 1944 |
1945 if (!title) { | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1946 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1947 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
|
1948 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
|
1949 g_free(realfn); realfn = NULL; |
2313 | 1950 return str_replace(title, filename_to_utf8(title)); |
1951 } | |
1952 | |
1953 return str_to_utf8(title); | |
1954 } | |
1955 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1956 Tuple * |
2313 | 1957 playlist_get_tuple(Playlist *playlist, guint pos) |
1958 { | |
1959 PlaylistEntry *entry; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1960 Tuple *tuple = NULL; |
2313 | 1961 GList *node; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1962 time_t mtime; |
2313 | 1963 |
1964 if (!playlist) | |
1965 return NULL; | |
1966 | |
1967 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1968 return NULL; | |
1969 } | |
1970 | |
1971 entry = (PlaylistEntry *) node->data; | |
1972 | |
1973 tuple = entry->tuple; | |
1974 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1975 if (tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
1976 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
|
1977 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1978 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1979 |
2313 | 1980 // if no tuple or tuple with old mtime, get new one. |
1981 if (tuple == NULL || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1982 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1983 { |
1984 playlist_entry_get_info(entry); | |
1985 tuple = entry->tuple; | |
1986 } | |
1987 | |
1988 return tuple; | |
1989 } | |
1990 | |
1991 gint | |
1992 playlist_get_songtime(Playlist *playlist, guint pos) | |
1993 { | |
1994 gint song_time = -1; | |
1995 PlaylistEntry *entry; | |
1996 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1997 time_t mtime; |
2313 | 1998 |
1999 if (!playlist) | |
2000 return -1; | |
2001 | |
3635 | 2002 if (!(node = g_list_nth(playlist->entries, pos))) |
2313 | 2003 return -1; |
2004 | |
2005 entry = node->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2006 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2007 if (entry->tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2008 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
|
2009 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2010 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2011 |
2313 | 2012 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
|
2013 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { |
2313 | 2014 |
2015 if (playlist_entry_get_info(entry)) | |
2016 song_time = entry->length; | |
3635 | 2017 } else |
2313 | 2018 song_time = entry->length; |
2019 | |
2020 return song_time; | |
2021 } | |
2022 | |
2023 static gint | |
2024 playlist_compare_track(PlaylistEntry * a, | |
2025 PlaylistEntry * b) | |
2026 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2027 gint tracknumber_a; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2028 gint tracknumber_b; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2029 |
2313 | 2030 g_return_val_if_fail(a != NULL, 0); |
2031 g_return_val_if_fail(b != NULL, 0); | |
2032 | |
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
|
2033 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
|
2034 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
|
2035 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
|
2036 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
|
2037 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2038 if (a->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2039 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2040 if (b->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2041 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2042 |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2043 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
|
2044 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
|
2045 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2046 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
|
2047 tracknumber_a - tracknumber_b : 0); |
2313 | 2048 } |
2049 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2050 static void |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2051 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
|
2052 { |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2053 if (e->title) |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2054 *title = e->title; |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2055 else { |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2056 if (strrchr(e->filename, '/')) |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2057 *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
|
2058 else |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2059 *title = e->filename; |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2060 } |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2061 } |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2062 |
2313 | 2063 static gint |
2064 playlist_compare_playlist(PlaylistEntry * a, | |
2065 PlaylistEntry * b) | |
2066 { | |
2067 const gchar *a_title = NULL, *b_title = NULL; | |
2068 | |
2069 g_return_val_if_fail(a != NULL, 0); | |
2070 g_return_val_if_fail(b != NULL, 0); | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2071 |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2072 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
|
2073 playlist_get_entry_title(b, &b_title); |
2313 | 2074 |
2075 return strcasecmp(a_title, b_title); | |
2076 } | |
2077 | |
2078 static gint | |
2079 playlist_compare_title(PlaylistEntry * a, | |
2080 PlaylistEntry * b) | |
2081 { | |
2082 const gchar *a_title = NULL, *b_title = NULL; | |
2083 | |
2084 g_return_val_if_fail(a != NULL, 0); | |
2085 g_return_val_if_fail(b != NULL, 0); | |
2086 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2087 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
|
2088 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
|
2089 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
|
2090 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
|
2091 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2092 if (a->tuple != NULL) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2093 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
|
2094 if (b->tuple != NULL) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2095 b_title = tuple_get_string(b->tuple, FIELD_TITLE, NULL); |
2313 | 2096 |
2097 if (a_title != NULL && b_title != NULL) | |
2098 return strcasecmp(a_title, b_title); | |
2099 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2100 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
|
2101 playlist_get_entry_title(b, &b_title); |
2313 | 2102 |
2103 return strcasecmp(a_title, b_title); | |
2104 } | |
2105 | |
2106 static gint | |
2107 playlist_compare_artist(PlaylistEntry * a, | |
2108 PlaylistEntry * b) | |
2109 { | |
2110 const gchar *a_artist = NULL, *b_artist = NULL; | |
2111 | |
2112 g_return_val_if_fail(a != NULL, 0); | |
2113 g_return_val_if_fail(b != NULL, 0); | |
2114 | |
2115 if (a->tuple != NULL) | |
2116 playlist_entry_get_info(a); | |
2117 | |
2118 if (b->tuple != NULL) | |
2119 playlist_entry_get_info(b); | |
2120 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2121 if (a->tuple != NULL) { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2122 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
|
2123 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
|
2124 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2125 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2126 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2127 if (b->tuple != NULL) { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2128 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
|
2129 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
|
2130 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2131 } |
2313 | 2132 |
2133 if (a_artist != NULL && b_artist != NULL) | |
2134 return strcasecmp(a_artist, b_artist); | |
2135 | |
2136 return 0; | |
2137 } | |
2138 | |
2139 static gint | |
2140 playlist_compare_filename(PlaylistEntry * a, | |
2141 PlaylistEntry * b) | |
2142 { | |
2143 gchar *a_filename, *b_filename; | |
2144 | |
2145 g_return_val_if_fail(a != NULL, 0); | |
2146 g_return_val_if_fail(b != NULL, 0); | |
2147 | |
2148 if (strrchr(a->filename, '/')) | |
2149 a_filename = strrchr(a->filename, '/') + 1; | |
2150 else | |
2151 a_filename = a->filename; | |
2152 | |
2153 if (strrchr(b->filename, '/')) | |
2154 b_filename = strrchr(b->filename, '/') + 1; | |
2155 else | |
2156 b_filename = b->filename; | |
2157 | |
2158 | |
2159 return strcasecmp(a_filename, b_filename); | |
2160 } | |
2161 | |
2162 static gint | |
2163 path_compare(const gchar * a, const gchar * b) | |
2164 { | |
2165 gchar *posa, *posb; | |
2166 gint len, ret; | |
2167 | |
2168 posa = strrchr(a, '/'); | |
2169 posb = strrchr(b, '/'); | |
2170 | |
2171 /* | |
2172 * Sort directories before files | |
2173 */ | |
2174 if (posa && posb && (posa - a != posb - b)) { | |
2175 if (posa - a > posb - b) { | |
2176 len = posb - b; | |
2177 ret = -1; | |
2178 } | |
2179 else { | |
2180 len = posa - a; | |
2181 ret = 1; | |
2182 } | |
2183 if (!strncasecmp(a, b, len)) | |
2184 return ret; | |
2185 } | |
2186 return strcasecmp(a, b); | |
2187 } | |
2188 | |
2189 static gint | |
2190 playlist_compare_path(PlaylistEntry * a, | |
2191 PlaylistEntry * b) | |
2192 { | |
2193 return path_compare(a->filename, b->filename); | |
2194 } | |
2195 | |
2196 | |
2197 static time_t | |
2198 playlist_get_mtime(const gchar *filename) | |
2199 { | |
2200 struct stat buf; | |
2201 gint rv; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2202 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2203 |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2204 /* 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
|
2205 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
|
2206 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
|
2207 g_free(realfn); realfn = NULL; |
2313 | 2208 |
2209 if (rv == 0) { | |
2210 return buf.st_mtime; | |
2211 } else { | |
2212 return 0; //error | |
2213 } | |
2214 } | |
2215 | |
2216 | |
2217 static gint | |
2218 playlist_compare_date(PlaylistEntry * a, | |
2219 PlaylistEntry * b) | |
2220 { | |
2221 struct stat buf; | |
2222 time_t modtime; | |
2223 | |
2224 gint rv; | |
2225 | |
2226 | |
2227 rv = stat(a->filename, &buf); | |
2228 | |
2229 if (rv == 0) { | |
2230 modtime = buf.st_mtime; | |
2231 rv = stat(b->filename, &buf); | |
2232 | |
2233 if (stat(b->filename, &buf) == 0) { | |
2234 if (buf.st_mtime == modtime) | |
2235 return 0; | |
2236 else | |
2237 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2238 } | |
2239 else | |
2240 return -1; | |
2241 } | |
2242 else if (!lstat(b->filename, &buf)) | |
2243 return 1; | |
2244 else | |
2245 return playlist_compare_filename(a, b); | |
2246 } | |
2247 | |
2248 | |
2249 void | |
2250 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2251 { | |
2252 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
|
2253 PLAYLIST_LOCK(playlist); |
2313 | 2254 playlist->entries = |
2255 g_list_sort(playlist->entries, | |
2256 (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
|
2257 PLAYLIST_UNLOCK(playlist); |
2313 | 2258 } |
2259 | |
2260 static GList * | |
2261 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2262 { | |
2263 GList *list1, *list2; | |
2264 GList *tmp_list = NULL; | |
2265 GList *index_list = NULL; | |
2266 | |
2267 /* | |
2268 * We take all the selected entries out of the playlist, | |
2269 * sorts them, and then put them back in again. | |
2270 */ | |
2271 | |
2272 list1 = g_list_last(list); | |
2273 | |
2274 while (list1) { | |
2275 list2 = g_list_previous(list1); | |
2276 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2277 gpointer idx; | |
2278 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2279 index_list = g_list_prepend(index_list, idx); | |
2280 list = g_list_remove_link(list, list1); | |
2281 tmp_list = g_list_concat(list1, tmp_list); | |
2282 } | |
2283 list1 = list2; | |
2284 } | |
2285 | |
2286 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2287 list1 = tmp_list; | |
2288 list2 = index_list; | |
2289 | |
2290 while (list2) { | |
2291 if (!list1) { | |
2292 g_critical(G_STRLOC ": Error during list sorting. " | |
2293 "Possibly dropped some playlist-entries."); | |
2294 break; | |
2295 } | |
2296 | |
2297 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2298 | |
2299 list2 = g_list_next(list2); | |
2300 list1 = g_list_next(list1); | |
2301 } | |
2302 | |
2303 g_list_free(index_list); | |
2304 g_list_free(tmp_list); | |
2305 | |
2306 return list; | |
2307 } | |
2308 | |
2309 void | |
2310 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2311 { | |
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_LOCK(playlist); |
2313 | 2313 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) |
2314 playlist_compare_func_table | |
2315 [type]); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2316 PLAYLIST_UNLOCK(playlist); |
2313 | 2317 } |
2318 | |
2319 void | |
2320 playlist_reverse(Playlist *playlist) | |
2321 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2322 PLAYLIST_LOCK(playlist); |
2313 | 2323 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
|
2324 PLAYLIST_UNLOCK(playlist); |
2313 | 2325 } |
2326 | |
2327 static GList * | |
2328 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2329 { | |
2330 /* | |
2331 * Note that this doesn't make a copy of the original list. | |
2332 * The pointer to the original list is not valid after this | |
2333 * fuction is run. | |
2334 */ | |
2335 gint len = g_list_length(list); | |
2336 gint i, j; | |
2337 GList *node, **ptrs; | |
2338 | |
2339 if (!playlist) | |
2340 return NULL; | |
2341 | |
2342 REQUIRE_LOCK(playlist->mutex); | |
2343 | |
2344 if (!len) | |
2345 return NULL; | |
2346 | |
2347 ptrs = g_new(GList *, len); | |
2348 | |
2349 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2350 ptrs[i] = node; | |
2351 | |
2352 j = g_random_int_range(0, len); | |
2353 list = ptrs[j]; | |
2354 ptrs[j]->next = NULL; | |
2355 ptrs[j] = ptrs[0]; | |
2356 | |
2357 for (i = 1; i < len; i++) { | |
2358 j = g_random_int_range(0, len - i); | |
2359 list->prev = ptrs[i + j]; | |
2360 ptrs[i + j]->next = list; | |
2361 list = ptrs[i + j]; | |
2362 ptrs[i + j] = ptrs[i]; | |
2363 } | |
2364 list->prev = NULL; | |
2365 | |
2366 g_free(ptrs); | |
2367 | |
2368 return list; | |
2369 } | |
2370 | |
2371 void | |
2372 playlist_random(Playlist *playlist) | |
2373 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2374 PLAYLIST_LOCK(playlist); |
2313 | 2375 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
|
2376 PLAYLIST_UNLOCK(playlist); |
2313 | 2377 } |
2378 | |
2379 GList * | |
2380 playlist_get_selected(Playlist *playlist) | |
2381 { | |
2382 GList *node, *list = NULL; | |
2383 gint i = 0; | |
2384 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2385 PLAYLIST_LOCK(playlist); |
2313 | 2386 for (node = playlist->entries; node; node = g_list_next(node), i++) { |
2387 PlaylistEntry *entry = node->data; | |
2388 if (entry->selected) | |
2389 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2390 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2391 PLAYLIST_UNLOCK(playlist); |
2313 | 2392 return g_list_reverse(list); |
2393 } | |
2394 | |
2395 void | |
2396 playlist_clear_selected(Playlist *playlist) | |
2397 { | |
2398 GList *node = NULL; | |
2399 gint i = 0; | |
2400 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2401 PLAYLIST_LOCK(playlist); |
2313 | 2402 for (node = playlist->entries; node; node = g_list_next(node), i++) { |
2403 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2404 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2405 PLAYLIST_UNLOCK(playlist); |
2313 | 2406 playlist_recalc_total_time(playlist); |
2407 playlist_manager_update(); | |
2408 } | |
2409 | |
2410 gint | |
2411 playlist_get_num_selected(Playlist *playlist) | |
2412 { | |
2413 GList *node; | |
2414 gint num = 0; | |
2415 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2416 PLAYLIST_LOCK(playlist); |
2313 | 2417 for (node = playlist->entries; node; node = g_list_next(node)) { |
2418 PlaylistEntry *entry = node->data; | |
2419 if (entry->selected) | |
2420 num++; | |
2421 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2422 PLAYLIST_UNLOCK(playlist); |
2313 | 2423 return num; |
2424 } | |
2425 | |
2426 | |
2427 static void | |
2428 playlist_generate_shuffle_list(Playlist *playlist) | |
2429 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2430 PLAYLIST_LOCK(playlist); |
2313 | 2431 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
|
2432 PLAYLIST_UNLOCK(playlist); |
2313 | 2433 } |
2434 | |
2435 static void | |
2436 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2437 { | |
2438 GList *node; | |
2439 gint numsongs; | |
2440 | |
2441 if (!cfg.shuffle || !playlist) | |
2442 return; | |
2443 | |
2444 REQUIRE_LOCK(playlist->mutex); | |
2445 | |
2446 if (playlist->shuffle) { | |
2447 g_list_free(playlist->shuffle); | |
2448 playlist->shuffle = NULL; | |
2449 } | |
2450 | |
2451 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2452 numsongs = g_list_length(playlist->shuffle); | |
2453 | |
2454 if (playlist->position) { | |
2455 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2456 node = g_list_nth(playlist->shuffle, i); | |
2457 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2458 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2459 } | |
2460 } | |
2461 | |
2462 void | |
2463 playlist_fileinfo(Playlist *playlist, guint pos) | |
2464 { | |
2465 gchar *path = NULL; | |
2466 GList *node; | |
2467 PlaylistEntry *entry = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2468 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2469 ProbeResult *pr = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2470 time_t mtime; |
2313 | 2471 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2472 PLAYLIST_LOCK(playlist); |
2313 | 2473 |
2474 if ((node = g_list_nth(playlist->entries, pos))) | |
2475 { | |
2476 entry = node->data; | |
2477 tuple = entry->tuple; | |
2478 path = g_strdup(entry->filename); | |
2479 } | |
2480 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2481 PLAYLIST_UNLOCK(playlist); |
2313 | 2482 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2483 if (entry->tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2484 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
|
2485 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2486 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2487 |
2313 | 2488 /* 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
|
2489 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
|
2490 mtime == 0 || mtime != playlist_get_mtime(entry->filename)) |
2313 | 2491 { |
2492 playlist_entry_get_info(entry); | |
2493 tuple = entry->tuple; | |
2494 } | |
2495 | |
2496 if (tuple != NULL) | |
2497 { | |
2498 if (entry->decoder == NULL) | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2499 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2500 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
|
2501 entry->decoder = pr ? pr->ip : NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2502 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2503 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2504 } |
2313 | 2505 |
2506 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2507 fileinfo_show_for_tuple(tuple); | |
2508 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2509 entry->decoder->file_info_box(path); | |
2510 else | |
2511 fileinfo_show_for_path(path); | |
2512 g_free(path); | |
2513 } | |
2514 else if (path != NULL) | |
2515 { | |
2516 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2517 entry->decoder->file_info_box(path); | |
2518 else | |
2519 fileinfo_show_for_path(path); | |
2520 g_free(path); | |
2521 } | |
2522 } | |
2523 | |
2524 void | |
2525 playlist_fileinfo_current(Playlist *playlist) | |
2526 { | |
2527 gchar *path = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2528 Tuple *tuple = NULL; |
2313 | 2529 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2530 PLAYLIST_LOCK(playlist); |
2313 | 2531 |
2532 if (playlist->entries && playlist->position) | |
2533 { | |
2534 path = g_strdup(playlist->position->filename); | |
2535 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2536 playlist_entry_get_info(playlist->position); | |
2537 tuple = playlist->position->tuple; | |
2538 } | |
2539 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2540 PLAYLIST_UNLOCK(playlist); |
2313 | 2541 |
2542 if (tuple != NULL) | |
2543 { | |
2544 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2545 fileinfo_show_for_tuple(tuple); | |
2546 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2547 playlist->position->decoder->file_info_box(path); | |
2548 else | |
2549 fileinfo_show_for_path(path); | |
2550 g_free(path); | |
2551 } | |
2552 else if (path != NULL) | |
2553 { | |
2554 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2555 playlist->position->decoder->file_info_box(path); | |
2556 else | |
2557 fileinfo_show_for_path(path); | |
2558 g_free(path); | |
2559 } | |
2560 } | |
2561 | |
2562 | |
2563 static gboolean | |
2564 playlist_get_info_is_going(void) | |
2565 { | |
2566 gboolean result; | |
2567 | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2568 g_static_rw_lock_reader_lock(&playlist_get_info_rwlock); |
2313 | 2569 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
|
2570 g_static_rw_lock_reader_unlock(&playlist_get_info_rwlock); |
2313 | 2571 |
2572 return result; | |
2573 } | |
2574 | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2575 |
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
|
2576 static gboolean |
3467
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2577 playlist_get_info_scanning(void) |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2578 { |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2579 gboolean result; |
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 g_mutex_lock(mutex_scan); |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2582 result = playlist_get_info_scan_active; |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2583 g_mutex_unlock(mutex_scan); |
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 return result; |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2586 } |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2587 |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2588 |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
2589 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
|
2590 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
|
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 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
|
2593 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
|
2594 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
|
2595 } |
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
|
2596 |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2597 |
2313 | 2598 static gpointer |
2599 playlist_get_info_func(gpointer arg) | |
2600 { | |
2601 GList *node; | |
2602 gboolean update_playlistwin = FALSE; | |
2603 | |
2604 while (playlist_get_info_is_going()) { | |
2605 PlaylistEntry *entry; | |
2606 Playlist *playlist = playlist_get_active(); | |
2607 | |
2608 // on_load | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2609 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
|
2610 playlist_get_info_scanning()) { |
2313 | 2611 |
2612 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2613 entry = node->data; | |
2614 | |
2636 | 2615 if(playlist->attribute & PLAYLIST_STATIC || |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2616 (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
|
2617 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { |
2313 | 2618 update_playlistwin = TRUE; |
2619 continue; | |
2620 } | |
2621 | |
2622 if (!playlist_entry_get_info(entry)) { | |
2623 if (g_list_index(playlist->entries, entry) == -1) | |
2624 /* Entry disappeared while we looked it up. | |
2625 Restart. */ | |
2626 node = playlist->entries; | |
2627 } | |
2628 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2629 update_playlistwin = TRUE; | |
2630 break; | |
2631 } | |
2632 } | |
2633 | |
2634 if (!node) { | |
2635 g_mutex_lock(mutex_scan); | |
2636 playlist_get_info_scan_active = FALSE; | |
2637 g_mutex_unlock(mutex_scan); | |
2638 } | |
2639 } // on_load | |
2640 | |
2641 // on_demand | |
2642 else if (!cfg.get_info_on_load && | |
2643 cfg.get_info_on_demand && | |
2644 cfg.playlist_visible && | |
2645 !cfg.playlist_shaded && | |
2646 cfg.use_pl_metadata) { | |
2647 | |
2648 g_mutex_lock(mutex_scan); | |
2649 playlist_get_info_scan_active = FALSE; | |
2650 g_mutex_unlock(mutex_scan); | |
2651 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2652 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
|
2653 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
|
2654 node = g_list_next(node)) { |
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 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2657 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2658 if(playlist->attribute & PLAYLIST_STATIC || |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2659 (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
|
2660 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
|
2661 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2662 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2663 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2664 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2665 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2666 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
|
2667 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2668 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2669 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2670 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2671 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2672 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2673 update_playlistwin = TRUE; |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
2674 // no need for break here since this iteration is very short. |
2313 | 2675 } |
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 } | |
2958 } | |
2959 | |
2960 static void | |
2961 playlist_recalc_total_time(Playlist *playlist) | |
2962 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2963 PLAYLIST_LOCK(playlist); |
2313 | 2964 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
|
2965 PLAYLIST_UNLOCK(playlist); |
2313 | 2966 } |
2967 | |
2968 gint | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2969 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) |
2313 | 2970 { |
2971 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2972 gboolean is_first_search = TRUE; | |
2973 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
|
2974 const gchar *regex_pattern; |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2975 const gchar *track_name = tuple_get_string( tuple, FIELD_TITLE, NULL ); |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2976 const gchar *album_name = tuple_get_string( tuple, FIELD_ALBUM, NULL ); |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2977 const gchar *performer = tuple_get_string( tuple, FIELD_PERFORMER, NULL ); |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2978 const gchar *file_name = tuple_get_string( tuple, FIELD_FILE_NAME, NULL ); |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2979 |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2980 #if defined(USE_REGEX_ONIGURUMA) |
2313 | 2981 /* set encoding for Oniguruma regex to UTF-8 */ |
2982 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2983 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
|
2984 #endif |
2313 | 2985 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2986 PLAYLIST_LOCK(playlist); |
2313 | 2987 |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2988 if ( (regex_pattern = tuple_get_string(tuple, FIELD_TITLE, NULL)) != NULL ) |
2313 | 2989 { |
2990 /* match by track_name */ | |
2991 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2992 #if defined(USE_REGEX_PCRE) |
2313 | 2993 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
|
2994 #else |
2313 | 2995 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
|
2996 #endif |
2313 | 2997 { |
2998 GList *tfound_list = NULL; | |
2999 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3000 else entry_list = found_list; /* use found_list */ | |
3001 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3002 { | |
3003 PlaylistEntry *entry = entry_list->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3004 if ( ( entry->tuple != NULL ) && ( track_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3005 ( regexec( ®ex , track_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3006 { |
3007 tfound_list = g_list_append( tfound_list , entry ); | |
3008 } | |
3009 } | |
3010 g_list_free( found_list ); /* wipe old found_list */ | |
3011 found_list = tfound_list; /* move tfound_list in found_list */ | |
3012 regfree( ®ex ); | |
3013 } | |
3014 is_first_search = FALSE; | |
3015 } | |
3016 | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3017 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ALBUM, NULL)) != NULL ) |
2313 | 3018 { |
3019 /* match by album_name */ | |
3020 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3021 #if defined(USE_REGEX_PCRE) |
2313 | 3022 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
|
3023 #else |
2313 | 3024 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
|
3025 #endif |
2313 | 3026 { |
3027 GList *tfound_list = NULL; | |
3028 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3029 else entry_list = found_list; /* use found_list */ | |
3030 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3031 { | |
3032 PlaylistEntry *entry = entry_list->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3033 if ( ( entry->tuple != NULL ) && ( album_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3034 ( regexec( ®ex , album_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3035 { |
3036 tfound_list = g_list_append( tfound_list , entry ); | |
3037 } | |
3038 } | |
3039 g_list_free( found_list ); /* wipe old found_list */ | |
3040 found_list = tfound_list; /* move tfound_list in found_list */ | |
3041 regfree( ®ex ); | |
3042 } | |
3043 is_first_search = FALSE; | |
3044 } | |
3045 | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3046 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ARTIST, NULL)) != NULL ) |
2313 | 3047 { |
3048 /* match by performer */ | |
3049 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3050 #if defined(USE_REGEX_PCRE) |
2313 | 3051 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
|
3052 #else |
2313 | 3053 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
|
3054 #endif |
2313 | 3055 { |
3056 GList *tfound_list = NULL; | |
3057 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3058 else entry_list = found_list; /* use found_list */ | |
3059 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3060 { | |
3061 PlaylistEntry *entry = entry_list->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3062 if ( ( entry->tuple != NULL ) && ( performer != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3063 ( regexec( ®ex , performer , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3064 { |
3065 tfound_list = g_list_append( tfound_list , entry ); | |
3066 } | |
3067 } | |
3068 g_list_free( found_list ); /* wipe old found_list */ | |
3069 found_list = tfound_list; /* move tfound_list in found_list */ | |
3070 regfree( ®ex ); | |
3071 } | |
3072 is_first_search = FALSE; | |
3073 } | |
3074 | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3075 if ( (regex_pattern = tuple_get_string(tuple, FIELD_FILE_NAME, NULL)) != NULL ) |
2313 | 3076 { |
3077 /* match by file_name */ | |
3078 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3079 #if defined(USE_REGEX_PCRE) |
2313 | 3080 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
|
3081 #else |
2313 | 3082 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
|
3083 #endif |
2313 | 3084 { |
3085 GList *tfound_list = NULL; | |
3086 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3087 else entry_list = found_list; /* use found_list */ | |
3088 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3089 { | |
3090 PlaylistEntry *entry = entry_list->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3091 if ( ( entry->tuple != NULL ) && ( file_name != NULL ) && |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3092 ( regexec( ®ex , file_name , 0 , NULL , 0 ) == 0 ) ) |
2313 | 3093 { |
3094 tfound_list = g_list_append( tfound_list , entry ); | |
3095 } | |
3096 } | |
3097 g_list_free( found_list ); /* wipe old found_list */ | |
3098 found_list = tfound_list; /* move tfound_list in found_list */ | |
3099 regfree( ®ex ); | |
3100 } | |
3101 is_first_search = FALSE; | |
3102 } | |
3103 | |
3104 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
3105 /* if some entries are still in found_list, those | |
3106 are what the user is searching for; select them */ | |
3107 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
3108 { | |
3109 PlaylistEntry *entry = sel_list->data; | |
3110 entry->selected = TRUE; | |
3111 num_of_entries_found++; | |
3112 } | |
3113 | |
3114 g_list_free( found_list ); | |
3115 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3116 PLAYLIST_UNLOCK(playlist); |
2313 | 3117 playlist_recalc_total_time(playlist); |
3118 | |
3119 return num_of_entries_found; | |
3120 } | |
3121 | |
3122 void | |
3123 playlist_select_all(Playlist *playlist, gboolean set) | |
3124 { | |
3125 GList *list; | |
3126 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3127 PLAYLIST_LOCK(playlist); |
2313 | 3128 |
3129 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3130 PlaylistEntry *entry = list->data; | |
3131 entry->selected = set; | |
3132 } | |
3133 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3134 PLAYLIST_UNLOCK(playlist); |
2313 | 3135 playlist_recalc_total_time(playlist); |
3136 } | |
3137 | |
3138 void | |
3139 playlist_select_invert_all(Playlist *playlist) | |
3140 { | |
3141 GList *list; | |
3142 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3143 PLAYLIST_LOCK(playlist); |
2313 | 3144 |
3145 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3146 PlaylistEntry *entry = list->data; | |
3147 entry->selected = !entry->selected; | |
3148 } | |
3149 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3150 PLAYLIST_UNLOCK(playlist); |
2313 | 3151 playlist_recalc_total_time(playlist); |
3152 } | |
3153 | |
3154 gboolean | |
3155 playlist_select_invert(Playlist *playlist, guint pos) | |
3156 { | |
3157 GList *list; | |
3158 gboolean invert_ok = FALSE; | |
3159 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3160 PLAYLIST_LOCK(playlist); |
2313 | 3161 |
3162 if ((list = g_list_nth(playlist->entries, pos))) { | |
3163 PlaylistEntry *entry = list->data; | |
3164 entry->selected = !entry->selected; | |
3165 invert_ok = TRUE; | |
3166 } | |
3167 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3168 PLAYLIST_UNLOCK(playlist); |
2313 | 3169 playlist_recalc_total_time(playlist); |
3170 | |
3171 return invert_ok; | |
3172 } | |
3173 | |
3174 | |
3175 void | |
3176 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3177 { | |
3178 GList *list; | |
3179 gint i; | |
3180 | |
3181 if (min_pos > max_pos) | |
3182 SWAP(min_pos, max_pos); | |
3183 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3184 PLAYLIST_LOCK(playlist); |
2313 | 3185 |
3186 list = g_list_nth(playlist->entries, min_pos); | |
3187 for (i = min_pos; i <= max_pos && list; i++) { | |
3188 PlaylistEntry *entry = list->data; | |
3189 entry->selected = select; | |
3190 list = g_list_next(list); | |
3191 } | |
3192 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3193 PLAYLIST_UNLOCK(playlist); |
2313 | 3194 |
3195 playlist_recalc_total_time(playlist); | |
3196 } | |
3197 | |
3198 gboolean | |
3199 playlist_read_info_selection(Playlist *playlist) | |
3200 { | |
3201 GList *node; | |
3202 gboolean retval = FALSE; | |
3203 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3204 PLAYLIST_LOCK(playlist); |
2313 | 3205 |
3206 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3207 PlaylistEntry *entry = node->data; | |
3208 if (!entry->selected) | |
3209 continue; | |
3210 | |
3211 retval = TRUE; | |
3212 | |
3213 str_replace_in(&entry->title, NULL); | |
3214 entry->length = -1; | |
3215 | |
3216 /* invalidate mtime to reread */ | |
3217 if (entry->tuple != NULL) | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3218 tuple_associate_int(entry->tuple, FIELD_MTIME, NULL, -1); /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
2313 | 3219 |
3220 if (!playlist_entry_get_info(entry)) { | |
3221 if (g_list_index(playlist->entries, entry) == -1) | |
3222 /* Entry disappeared while we looked it up. Restart. */ | |
3223 node = playlist->entries; | |
3224 } | |
3225 } | |
3226 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3227 PLAYLIST_UNLOCK(playlist); |
2313 | 3228 |
3229 playlistwin_update_list(playlist); | |
3230 playlist_recalc_total_time(playlist); | |
3231 | |
3232 return retval; | |
3233 } | |
3234 | |
3235 void | |
3236 playlist_read_info(Playlist *playlist, guint pos) | |
3237 { | |
3238 GList *node; | |
3239 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3240 PLAYLIST_LOCK(playlist); |
2313 | 3241 |
3242 if ((node = g_list_nth(playlist->entries, pos))) { | |
3243 PlaylistEntry *entry = node->data; | |
3244 str_replace_in(&entry->title, NULL); | |
3245 entry->length = -1; | |
3246 playlist_entry_get_info(entry); | |
3247 } | |
3248 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3249 PLAYLIST_UNLOCK(playlist); |
2313 | 3250 |
3251 playlistwin_update_list(playlist); | |
3252 playlist_recalc_total_time(playlist); | |
3253 } | |
3254 | |
3255 Playlist * | |
3256 playlist_get_active(void) | |
3257 { | |
3258 if (playlists_iter != NULL) | |
3259 return (Playlist *) playlists_iter->data; | |
3260 | |
2736 | 3261 if (playlists) |
3262 return (Playlist *) playlists->data; | |
3263 | |
3264 return NULL; | |
2313 | 3265 } |
3266 | |
3267 void | |
3268 playlist_set_shuffle(gboolean shuffle) | |
3269 { | |
3270 Playlist *playlist = playlist_get_active(); | |
3271 if (!playlist) | |
3272 return; | |
3273 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3274 PLAYLIST_LOCK(playlist); |
2313 | 3275 |
3276 playlist_position_before_jump = NULL; | |
3277 | |
3278 cfg.shuffle = shuffle; | |
3279 playlist_generate_shuffle_list_nolock(playlist); | |
3280 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3281 PLAYLIST_UNLOCK(playlist); |
2313 | 3282 } |
3283 | |
3284 Playlist * | |
3285 playlist_new(void) | |
3286 { | |
3287 Playlist *playlist = g_new0(Playlist, 1); | |
3288 playlist->mutex = g_mutex_new(); | |
3289 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
|
3290 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
|
3291 playlist->filename = NULL; |
2313 | 3292 playlist_clear(playlist); |
3293 | |
3294 return playlist; | |
3295 } | |
3296 | |
3297 void | |
3298 playlist_free(Playlist *playlist) | |
3299 { | |
3467
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3300 if (!playlist) |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3301 return; |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3302 |
2313 | 3303 g_mutex_free( playlist->mutex ); |
3304 g_free( playlist ); | |
3305 } | |
3306 | |
3307 Playlist * | |
3308 playlist_new_from_selected(void) | |
3309 { | |
3310 Playlist *newpl = playlist_new(); | |
3311 Playlist *playlist = playlist_get_active(); | |
3312 GList *list = playlist_get_selected(playlist); | |
3313 | |
3314 playlist_add_playlist( newpl ); | |
3315 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3316 PLAYLIST_LOCK(playlist); |
2313 | 3317 |
3318 while ( list != NULL ) | |
3319 { | |
3320 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3321 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3322 playlist_add( newpl , entry->filename ); | |
3323 list = g_list_next(list); | |
3324 } | |
3325 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3326 PLAYLIST_UNLOCK(playlist); |
2313 | 3327 |
3328 playlist_recalc_total_time(newpl); | |
3329 playlistwin_update_list(playlist); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
3330 playlist_manager_update(); |
2313 | 3331 |
3332 return newpl; | |
3333 } | |
3334 | |
3335 const gchar * | |
3336 playlist_get_filename_to_play(Playlist *playlist) | |
3337 { | |
3338 const gchar *filename = NULL; | |
3339 | |
3340 if (!playlist) | |
3341 return NULL; | |
3342 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3343 PLAYLIST_LOCK(playlist); |
2313 | 3344 |
3345 if (!playlist->position) { | |
3346 if (cfg.shuffle) | |
3347 playlist->position = playlist->shuffle->data; | |
3348 else | |
3349 playlist->position = playlist->entries->data; | |
3350 } | |
3351 | |
3352 filename = playlist->position->filename; | |
3353 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3354 PLAYLIST_UNLOCK(playlist); |
2313 | 3355 |
3356 return filename; | |
3357 } | |
3358 | |
3359 PlaylistEntry * | |
3360 playlist_get_entry_to_play(Playlist *playlist) | |
3361 { | |
3362 if (!playlist) | |
3363 return NULL; | |
3364 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3365 PLAYLIST_LOCK(playlist); |
2313 | 3366 |
3367 if (!playlist->position) { | |
3368 if (cfg.shuffle) | |
3369 playlist->position = playlist->shuffle->data; | |
3370 else | |
3371 playlist->position = playlist->entries->data; | |
3372 } | |
3373 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3374 PLAYLIST_UNLOCK(playlist); |
2313 | 3375 |
3376 return playlist->position; | |
3377 } | |
3474
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3378 |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3379 gboolean |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3380 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
|
3381 { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3382 GList *l1, *l2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3383 PlaylistEntry *e1, *e2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3384 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
|
3385 l1 = p1->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3386 l2 = p2->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3387 do { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3388 if (!l1 && !l2) break; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3389 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
|
3390 e1 = (PlaylistEntry *) l1->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3391 e2 = (PlaylistEntry *) l2->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3392 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
|
3393 l1 = l1->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3394 l2 = l2->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3395 } while(1); |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3396 return TRUE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3397 } |