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