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