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