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