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