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