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