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