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