Mercurial > audlegacy
annotate src/audacious/playlist.c @ 4275:3e0a2cce15f6
Added HG repo URL to buildsys as a comment.
author | Jonathan Schleifer <js-audacious@webkeks.org> |
---|---|
date | Sun, 10 Feb 2008 21:30:29 +0100 |
parents | 2b7a74fce100 |
children | 3ff4aef1e401 |
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); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2065 if (b->tuple != NULL) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2066 b_title = tuple_get_string(b->tuple, FIELD_TITLE, NULL); |
2313 | 2067 |
2068 if (a_title != NULL && b_title != NULL) | |
2069 return strcasecmp(a_title, b_title); | |
2070 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2071 playlist_get_entry_title(a, &a_title); |
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(b, &b_title); |
2313 | 2073 |
2074 return strcasecmp(a_title, b_title); | |
2075 } | |
2076 | |
2077 static gint | |
2078 playlist_compare_artist(PlaylistEntry * a, | |
2079 PlaylistEntry * b) | |
2080 { | |
2081 const gchar *a_artist = NULL, *b_artist = NULL; | |
2082 | |
2083 g_return_val_if_fail(a != NULL, 0); | |
2084 g_return_val_if_fail(b != NULL, 0); | |
2085 | |
2086 if (a->tuple != NULL) | |
2087 playlist_entry_get_info(a); | |
2088 | |
2089 if (b->tuple != NULL) | |
2090 playlist_entry_get_info(b); | |
2091 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2092 if (a->tuple != NULL) { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2093 a_artist = tuple_get_string(a->tuple, FIELD_ARTIST, NULL); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2094 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
|
2095 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2096 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2097 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2098 if (b->tuple != NULL) { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2099 b_artist = tuple_get_string(b->tuple, FIELD_ARTIST, NULL); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2100 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
|
2101 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2102 } |
2313 | 2103 |
2104 if (a_artist != NULL && b_artist != NULL) | |
2105 return strcasecmp(a_artist, b_artist); | |
2106 | |
2107 return 0; | |
2108 } | |
2109 | |
2110 static gint | |
2111 playlist_compare_filename(PlaylistEntry * a, | |
2112 PlaylistEntry * b) | |
2113 { | |
2114 gchar *a_filename, *b_filename; | |
2115 | |
2116 g_return_val_if_fail(a != NULL, 0); | |
2117 g_return_val_if_fail(b != NULL, 0); | |
2118 | |
2119 if (strrchr(a->filename, '/')) | |
2120 a_filename = strrchr(a->filename, '/') + 1; | |
2121 else | |
2122 a_filename = a->filename; | |
2123 | |
2124 if (strrchr(b->filename, '/')) | |
2125 b_filename = strrchr(b->filename, '/') + 1; | |
2126 else | |
2127 b_filename = b->filename; | |
2128 | |
2129 | |
2130 return strcasecmp(a_filename, b_filename); | |
2131 } | |
2132 | |
2133 static gint | |
2134 path_compare(const gchar * a, const gchar * b) | |
2135 { | |
2136 gchar *posa, *posb; | |
2137 gint len, ret; | |
2138 | |
2139 posa = strrchr(a, '/'); | |
2140 posb = strrchr(b, '/'); | |
2141 | |
2142 /* | |
2143 * Sort directories before files | |
2144 */ | |
2145 if (posa && posb && (posa - a != posb - b)) { | |
2146 if (posa - a > posb - b) { | |
2147 len = posb - b; | |
2148 ret = -1; | |
2149 } | |
2150 else { | |
2151 len = posa - a; | |
2152 ret = 1; | |
2153 } | |
2154 if (!strncasecmp(a, b, len)) | |
2155 return ret; | |
2156 } | |
2157 return strcasecmp(a, b); | |
2158 } | |
2159 | |
2160 static gint | |
2161 playlist_compare_path(PlaylistEntry * a, | |
2162 PlaylistEntry * b) | |
2163 { | |
2164 return path_compare(a->filename, b->filename); | |
2165 } | |
2166 | |
2167 | |
2168 static time_t | |
2169 playlist_get_mtime(const gchar *filename) | |
2170 { | |
2171 struct stat buf; | |
2172 gint rv; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2173 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2174 |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2175 /* 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
|
2176 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
|
2177 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
|
2178 g_free(realfn); realfn = NULL; |
2313 | 2179 |
2180 if (rv == 0) { | |
2181 return buf.st_mtime; | |
2182 } else { | |
2183 return 0; //error | |
2184 } | |
2185 } | |
2186 | |
2187 | |
2188 static gint | |
2189 playlist_compare_date(PlaylistEntry * a, | |
2190 PlaylistEntry * b) | |
2191 { | |
2192 struct stat buf; | |
2193 time_t modtime; | |
2194 | |
2195 gint rv; | |
2196 | |
2197 | |
2198 rv = stat(a->filename, &buf); | |
2199 | |
2200 if (rv == 0) { | |
2201 modtime = buf.st_mtime; | |
2202 rv = stat(b->filename, &buf); | |
2203 | |
2204 if (stat(b->filename, &buf) == 0) { | |
2205 if (buf.st_mtime == modtime) | |
2206 return 0; | |
2207 else | |
2208 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2209 } | |
2210 else | |
2211 return -1; | |
2212 } | |
2213 else if (!lstat(b->filename, &buf)) | |
2214 return 1; | |
2215 else | |
2216 return playlist_compare_filename(a, b); | |
2217 } | |
2218 | |
2219 | |
2220 void | |
2221 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2222 { | |
2223 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
|
2224 PLAYLIST_LOCK(playlist); |
2313 | 2225 playlist->entries = |
2226 g_list_sort(playlist->entries, | |
2227 (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
|
2228 PLAYLIST_UNLOCK(playlist); |
2313 | 2229 } |
2230 | |
2231 static GList * | |
2232 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2233 { | |
2234 GList *list1, *list2; | |
2235 GList *tmp_list = NULL; | |
2236 GList *index_list = NULL; | |
2237 | |
2238 /* | |
2239 * We take all the selected entries out of the playlist, | |
2240 * sorts them, and then put them back in again. | |
2241 */ | |
2242 | |
2243 list1 = g_list_last(list); | |
2244 | |
2245 while (list1) { | |
2246 list2 = g_list_previous(list1); | |
2247 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2248 gpointer idx; | |
2249 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2250 index_list = g_list_prepend(index_list, idx); | |
2251 list = g_list_remove_link(list, list1); | |
2252 tmp_list = g_list_concat(list1, tmp_list); | |
2253 } | |
2254 list1 = list2; | |
2255 } | |
2256 | |
2257 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2258 list1 = tmp_list; | |
2259 list2 = index_list; | |
2260 | |
2261 while (list2) { | |
2262 if (!list1) { | |
2263 g_critical(G_STRLOC ": Error during list sorting. " | |
2264 "Possibly dropped some playlist-entries."); | |
2265 break; | |
2266 } | |
2267 | |
2268 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2269 | |
2270 list2 = g_list_next(list2); | |
2271 list1 = g_list_next(list1); | |
2272 } | |
2273 | |
2274 g_list_free(index_list); | |
2275 g_list_free(tmp_list); | |
2276 | |
2277 return list; | |
2278 } | |
2279 | |
2280 void | |
2281 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2282 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2283 PLAYLIST_LOCK(playlist); |
2313 | 2284 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) |
2285 playlist_compare_func_table | |
2286 [type]); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2287 PLAYLIST_UNLOCK(playlist); |
2313 | 2288 } |
2289 | |
2290 void | |
2291 playlist_reverse(Playlist *playlist) | |
2292 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2293 PLAYLIST_LOCK(playlist); |
2313 | 2294 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
|
2295 PLAYLIST_UNLOCK(playlist); |
2313 | 2296 } |
2297 | |
2298 static GList * | |
2299 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2300 { | |
2301 /* | |
2302 * Note that this doesn't make a copy of the original list. | |
2303 * The pointer to the original list is not valid after this | |
2304 * fuction is run. | |
2305 */ | |
2306 gint len = g_list_length(list); | |
2307 gint i, j; | |
2308 GList *node, **ptrs; | |
2309 | |
2310 if (!playlist) | |
2311 return NULL; | |
2312 | |
2313 REQUIRE_LOCK(playlist->mutex); | |
2314 | |
2315 if (!len) | |
2316 return NULL; | |
2317 | |
2318 ptrs = g_new(GList *, len); | |
2319 | |
2320 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2321 ptrs[i] = node; | |
2322 | |
2323 j = g_random_int_range(0, len); | |
2324 list = ptrs[j]; | |
2325 ptrs[j]->next = NULL; | |
2326 ptrs[j] = ptrs[0]; | |
2327 | |
2328 for (i = 1; i < len; i++) { | |
2329 j = g_random_int_range(0, len - i); | |
2330 list->prev = ptrs[i + j]; | |
2331 ptrs[i + j]->next = list; | |
2332 list = ptrs[i + j]; | |
2333 ptrs[i + j] = ptrs[i]; | |
2334 } | |
2335 list->prev = NULL; | |
2336 | |
2337 g_free(ptrs); | |
2338 | |
2339 return list; | |
2340 } | |
2341 | |
2342 void | |
2343 playlist_random(Playlist *playlist) | |
2344 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2345 PLAYLIST_LOCK(playlist); |
2313 | 2346 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
|
2347 PLAYLIST_UNLOCK(playlist); |
2313 | 2348 } |
2349 | |
2350 GList * | |
2351 playlist_get_selected(Playlist *playlist) | |
2352 { | |
2353 GList *node, *list = NULL; | |
2354 gint i = 0; | |
2355 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2356 PLAYLIST_LOCK(playlist); |
2313 | 2357 for (node = playlist->entries; node; node = g_list_next(node), i++) { |
2358 PlaylistEntry *entry = node->data; | |
2359 if (entry->selected) | |
2360 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2361 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2362 PLAYLIST_UNLOCK(playlist); |
2313 | 2363 return g_list_reverse(list); |
2364 } | |
2365 | |
2366 void | |
2367 playlist_clear_selected(Playlist *playlist) | |
2368 { | |
2369 GList *node = NULL; | |
2370 gint i = 0; | |
2371 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2372 PLAYLIST_LOCK(playlist); |
2313 | 2373 for (node = playlist->entries; node; node = g_list_next(node), i++) { |
2374 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2375 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2376 PLAYLIST_UNLOCK(playlist); |
2313 | 2377 playlist_recalc_total_time(playlist); |
2378 playlist_manager_update(); | |
2379 } | |
2380 | |
2381 gint | |
2382 playlist_get_num_selected(Playlist *playlist) | |
2383 { | |
2384 GList *node; | |
2385 gint num = 0; | |
2386 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2387 PLAYLIST_LOCK(playlist); |
2313 | 2388 for (node = playlist->entries; node; node = g_list_next(node)) { |
2389 PlaylistEntry *entry = node->data; | |
2390 if (entry->selected) | |
2391 num++; | |
2392 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2393 PLAYLIST_UNLOCK(playlist); |
2313 | 2394 return num; |
2395 } | |
2396 | |
2397 | |
2398 static void | |
2399 playlist_generate_shuffle_list(Playlist *playlist) | |
2400 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2401 PLAYLIST_LOCK(playlist); |
2313 | 2402 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
|
2403 PLAYLIST_UNLOCK(playlist); |
2313 | 2404 } |
2405 | |
2406 static void | |
2407 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2408 { | |
2409 GList *node; | |
2410 gint numsongs; | |
2411 | |
2412 if (!cfg.shuffle || !playlist) | |
2413 return; | |
2414 | |
2415 REQUIRE_LOCK(playlist->mutex); | |
2416 | |
2417 if (playlist->shuffle) { | |
2418 g_list_free(playlist->shuffle); | |
2419 playlist->shuffle = NULL; | |
2420 } | |
2421 | |
2422 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2423 numsongs = g_list_length(playlist->shuffle); | |
2424 | |
2425 if (playlist->position) { | |
2426 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2427 node = g_list_nth(playlist->shuffle, i); | |
2428 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2429 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2430 } | |
2431 } | |
2432 | |
2433 void | |
2434 playlist_fileinfo(Playlist *playlist, guint pos) | |
2435 { | |
2436 gchar *path = NULL; | |
2437 GList *node; | |
2438 PlaylistEntry *entry = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2439 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2440 ProbeResult *pr = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2441 time_t mtime; |
2313 | 2442 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2443 PLAYLIST_LOCK(playlist); |
2313 | 2444 |
2445 if ((node = g_list_nth(playlist->entries, pos))) | |
2446 { | |
2447 entry = node->data; | |
2448 tuple = entry->tuple; | |
2449 path = g_strdup(entry->filename); | |
2450 } | |
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_UNLOCK(playlist); |
2313 | 2453 |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2454 if (entry->decoder == NULL) |
2313 | 2455 { |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2456 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
|
2457 entry->decoder = pr ? pr->ip : NULL; |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2458 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2459 g_free(pr); |
2313 | 2460 } |
2461 | |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2462 /* 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
|
2463 /* maybe code cleanup required... */ |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2464 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
|
2465 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
|
2466 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2467 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
|
2468 g_free(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2469 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2470 } else { |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2471 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2472 if (entry->tuple) |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2473 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
|
2474 else |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2475 mtime = 0; |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2476 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2477 /* 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
|
2478 if (entry->tuple == NULL || mtime == -1 || |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2479 mtime == 0 || mtime != playlist_get_mtime(entry->filename)) |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2480 { |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2481 playlist_entry_get_info(entry); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2482 tuple = entry->tuple; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2483 } |
2313 | 2484 |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2485 if (tuple != NULL) |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2486 { |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2487 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
|
2488 fileinfo_show_for_tuple(tuple, FALSE); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2489 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
|
2490 { |
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
4228
diff
changeset
|
2491 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
|
2492 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
|
2493 } |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2494 else |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2495 fileinfo_show_for_path(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2496 g_free(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2497 } |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2498 else if (path != NULL) |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2499 { |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2500 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
|
2501 { |
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
4228
diff
changeset
|
2502 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
|
2503 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
|
2504 } |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2505 else |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2506 fileinfo_show_for_path(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2507 g_free(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2508 } |
2313 | 2509 } |
2510 } | |
2511 | |
2512 void | |
2513 playlist_fileinfo_current(Playlist *playlist) | |
2514 { | |
2515 gchar *path = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2516 Tuple *tuple = NULL; |
2313 | 2517 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2518 PLAYLIST_LOCK(playlist); |
2313 | 2519 |
2520 if (playlist->entries && playlist->position) | |
2521 { | |
2522 path = g_strdup(playlist->position->filename); | |
2523 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2524 playlist_entry_get_info(playlist->position); | |
2525 tuple = playlist->position->tuple; | |
2526 } | |
2527 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2528 PLAYLIST_UNLOCK(playlist); |
2313 | 2529 |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2530 if (playlist->position->decoder != NULL && playlist->position->decoder->update_song_tuple != NULL && |
4062 | 2531 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
|
2532 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2533 fileinfo_show_editor_for_path(path, playlist->position->decoder); |
2313 | 2534 g_free(path); |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2535 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2536 } else { |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2537 |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2538 if (tuple != NULL) |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2539 { |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2540 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
|
2541 fileinfo_show_for_tuple(tuple, FALSE); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2542 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
|
2543 { |
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
4228
diff
changeset
|
2544 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
|
2545 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
|
2546 } |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2547 else |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2548 fileinfo_show_for_path(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2549 g_free(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2550 } |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2551 else if (path != NULL) |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2552 { |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2553 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
|
2554 { |
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
4228
diff
changeset
|
2555 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
|
2556 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
|
2557 } |
4020
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2558 else |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2559 fileinfo_show_for_path(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2560 g_free(path); |
66529edae49d
added tag editing capabilities, maybe raw yet
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3980
diff
changeset
|
2561 } |
2313 | 2562 } |
2563 } | |
2564 | |
2565 | |
2566 static gboolean | |
2567 playlist_get_info_is_going(void) | |
2568 { | |
2569 gboolean result; | |
2570 | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2571 g_static_rw_lock_reader_lock(&playlist_get_info_rwlock); |
2313 | 2572 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
|
2573 g_static_rw_lock_reader_unlock(&playlist_get_info_rwlock); |
2313 | 2574 |
2575 return result; | |
2576 } | |
2577 | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2578 |
2313 | 2579 static gpointer |
2580 playlist_get_info_func(gpointer arg) | |
2581 { | |
2582 GList *node; | |
2583 gboolean update_playlistwin = FALSE; | |
2584 | |
2585 while (playlist_get_info_is_going()) { | |
2586 PlaylistEntry *entry; | |
2587 Playlist *playlist = playlist_get_active(); | |
2588 | |
2589 // on_load | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2590 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
|
2591 playlist_get_info_scan_active) { |
2313 | 2592 |
2593 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2594 entry = node->data; | |
2595 | |
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
|
2596 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
|
2597 (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
|
2598 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1 && entry->title_is_valid)) { |
2313 | 2599 update_playlistwin = TRUE; |
2600 continue; | |
2601 } | |
2602 | |
2603 if (!playlist_entry_get_info(entry)) { | |
2604 if (g_list_index(playlist->entries, entry) == -1) | |
2605 /* Entry disappeared while we looked it up. | |
2606 Restart. */ | |
2607 node = playlist->entries; | |
2608 } | |
3733
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2609 else if ((entry->tuple != NULL || entry->title != NULL) && |
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2610 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
|
2611 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1) { |
2313 | 2612 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
|
2613 break; /* hmmm... --asphyx */ |
2313 | 2614 } |
2615 } | |
2616 | |
2617 if (!node) { | |
2618 g_mutex_lock(mutex_scan); | |
2619 playlist_get_info_scan_active = FALSE; | |
2620 g_mutex_unlock(mutex_scan); | |
2621 } | |
2622 } // on_load | |
2623 | |
2624 // on_demand | |
2625 else if (!cfg.get_info_on_load && | |
2626 cfg.get_info_on_demand && | |
2627 cfg.playlist_visible && | |
2628 !cfg.playlist_shaded && | |
2629 cfg.use_pl_metadata) { | |
2630 | |
2631 g_mutex_lock(mutex_scan); | |
2632 playlist_get_info_scan_active = FALSE; | |
2633 g_mutex_unlock(mutex_scan); | |
2634 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2635 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
|
2636 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
|
2637 node = g_list_next(node)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2638 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2639 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2640 |
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
|
2641 if(playlist->attribute & PLAYLIST_STATIC || |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2642 (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
|
2643 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
|
2644 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2645 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2646 |
4087
776c30747439
avoid unnecessary serial increment.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4086
diff
changeset
|
2647 AUDDBG("len=%d mtime=%d\n", |
776c30747439
avoid unnecessary serial increment.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4086
diff
changeset
|
2648 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL), |
776c30747439
avoid unnecessary serial increment.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4086
diff
changeset
|
2649 tuple_get_int(entry->tuple, FIELD_MTIME, NULL)); |
776c30747439
avoid unnecessary serial increment.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4086
diff
changeset
|
2650 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2651 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2652 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
|
2653 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2654 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2655 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2656 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2657 } |
3733
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2658 else if ((entry->tuple != NULL || entry->title != NULL) && |
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2659 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
|
2660 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
|
2661 update_playlistwin = TRUE; |
3733
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2662 } |
2313 | 2663 } |
2664 } // on_demand | |
4087
776c30747439
avoid unnecessary serial increment.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4086
diff
changeset
|
2665 |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2666 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
|
2667 (!cfg.playlist_visible || cfg.playlist_shaded || !cfg.use_pl_metadata)) |
2313 | 2668 { |
2669 g_mutex_lock(mutex_scan); | |
2670 playlist_get_info_scan_active = FALSE; | |
2671 g_mutex_unlock(mutex_scan); | |
2672 } | |
4087
776c30747439
avoid unnecessary serial increment.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4086
diff
changeset
|
2673 |
2313 | 2674 else /* not on_demand and not on_load... |
2675 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2676 { | |
2677 g_mutex_lock(mutex_scan); | |
2678 playlist_get_info_scan_active = FALSE; | |
2679 g_mutex_unlock(mutex_scan); | |
2680 } | |
2681 | |
2682 if (update_playlistwin) { | |
4086
96d8114f0b89
now jtf follows on-demand metadata loading.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4076
diff
changeset
|
2683 Playlist *playlist = playlist_get_active(); |
96d8114f0b89
now jtf follows on-demand metadata loading.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4076
diff
changeset
|
2684 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
|
2685 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 2686 update_playlistwin = FALSE; |
2687 } | |
2688 | |
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
|
2689 if (playlist_get_info_scan_active) { |
2313 | 2690 continue; |
2691 } | |
2692 | |
2693 g_mutex_lock(mutex_scan); | |
2694 g_cond_wait(cond_scan, mutex_scan); | |
2695 g_mutex_unlock(mutex_scan); | |
2696 | |
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
|
2697 // 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
|
2698 |
2313 | 2699 } // while |
2700 | |
2701 g_thread_exit(NULL); | |
2702 return NULL; | |
2703 } | |
2704 | |
2705 void | |
2706 playlist_start_get_info_thread(void) | |
2707 { | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2708 g_static_rw_lock_writer_lock(&playlist_get_info_rwlock); |
2313 | 2709 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
|
2710 g_static_rw_lock_writer_unlock(&playlist_get_info_rwlock); |
2313 | 2711 |
2712 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2713 NULL, TRUE, NULL); | |
2714 } | |
2715 | |
2716 void | |
2717 playlist_stop_get_info_thread(void) | |
2718 { | |
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_lock(&playlist_get_info_rwlock); |
2313 | 2720 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
|
2721 g_static_rw_lock_writer_unlock(&playlist_get_info_rwlock); |
2313 | 2722 |
2723 g_cond_broadcast(cond_scan); | |
2724 g_thread_join(playlist_get_info_thread); | |
2725 } | |
2726 | |
2727 void | |
2728 playlist_start_get_info_scan(void) | |
2729 { | |
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
|
2730 AUDDBG("waking up scan thread\n"); |
2313 | 2731 g_mutex_lock(mutex_scan); |
2732 playlist_get_info_scan_active = TRUE; | |
2733 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
|
2734 |
2313 | 2735 g_cond_signal(cond_scan); |
2736 } | |
2737 | |
2738 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
|
2739 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
|
2740 { |
206378f34610
update titles when formatter template changes even if tuples is up to date
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4184
diff
changeset
|
2741 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
|
2742 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
|
2743 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
|
2744 |
206378f34610
update titles when formatter template changes even if tuples is up to date
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4184
diff
changeset
|
2745 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
|
2746 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
|
2747 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
|
2748 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
|
2749 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
|
2750 } |
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 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
|
2752 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
|
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 |
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 void |
2313 | 2756 playlist_remove_dead_files(Playlist *playlist) |
2757 { | |
2758 GList *node, *next_node; | |
2759 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2760 PLAYLIST_LOCK(playlist); |
2313 | 2761 |
2762 for (node = playlist->entries; node; node = next_node) { | |
2763 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2764 next_node = g_list_next(node); | |
2765 | |
2766 if (!entry || !entry->filename) { | |
2767 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2768 continue; | |
2769 } | |
2770 | |
4060
21833104ed4c
fixed(URI-fied) "remove unavailable files"
Cristi Magherusan <majeru@atheme-project.org>
parents:
4059
diff
changeset
|
2771 if (!g_str_has_prefix(entry->filename, "file://")) |
2313 | 2772 continue; |
2773 | |
2774 /* FIXME: Should test for readability */ | |
2775 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2776 continue; | |
2777 | |
2778 if (entry == playlist->position) { | |
2779 /* Don't remove the currently playing song */ | |
2780 if (playback_get_playing()) | |
2781 continue; | |
2782 | |
2783 if (next_node) | |
2784 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2785 else | |
2786 playlist->position = NULL; | |
2787 } | |
2788 | |
2789 playlist_entry_free(entry); | |
2790 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2791 } | |
2792 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2793 PLAYLIST_UNLOCK(playlist); |
2313 | 2794 |
2795 playlist_generate_shuffle_list(playlist); | |
2796 playlistwin_update_list(playlist); | |
2797 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
|
2798 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 2799 playlist_manager_update(); |
2800 } | |
2801 | |
2802 | |
2803 static gint | |
2804 playlist_dupscmp_title(PlaylistEntry * a, | |
2805 PlaylistEntry * b) | |
2806 { | |
2807 const gchar *a_title, *b_title; | |
2808 | |
2809 g_return_val_if_fail(a != NULL, 0); | |
2810 g_return_val_if_fail(b != NULL, 0); | |
2811 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2812 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
|
2813 playlist_get_entry_title(b, &b_title); |
2313 | 2814 |
2815 return strcmp(a_title, b_title); | |
2816 } | |
2817 | |
2818 static gint | |
2819 playlist_dupscmp_filename(PlaylistEntry * a, | |
2820 PlaylistEntry * b ) | |
2821 { | |
2822 gchar *a_filename, *b_filename; | |
2823 | |
2824 g_return_val_if_fail(a != NULL, 0); | |
2825 g_return_val_if_fail(b != NULL, 0); | |
2826 | |
2827 if (strrchr(a->filename, '/')) | |
2828 a_filename = strrchr(a->filename, '/') + 1; | |
2829 else | |
2830 a_filename = a->filename; | |
2831 | |
2832 if (strrchr(b->filename, '/')) | |
2833 b_filename = strrchr(b->filename, '/') + 1; | |
2834 else | |
2835 b_filename = b->filename; | |
2836 | |
2837 return strcmp(a_filename, b_filename); | |
2838 } | |
2839 | |
2840 static gint | |
2841 playlist_dupscmp_path(PlaylistEntry * a, | |
2842 PlaylistEntry * b) | |
2843 { | |
2844 /* simply compare the entire filename string */ | |
2845 return strcmp(a->filename, b->filename); | |
2846 } | |
2847 | |
2848 void | |
2849 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2850 { | |
2851 GList *node, *next_node; | |
2852 GList *node_cmp, *next_node_cmp; | |
2853 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2854 | |
2855 switch ( type ) | |
2856 { | |
2857 case PLAYLIST_DUPS_TITLE: | |
2858 dups_compare_func = playlist_dupscmp_title; | |
2859 break; | |
2860 case PLAYLIST_DUPS_PATH: | |
2861 dups_compare_func = playlist_dupscmp_path; | |
2862 break; | |
2863 case PLAYLIST_DUPS_FILENAME: | |
2864 default: | |
2865 dups_compare_func = playlist_dupscmp_filename; | |
2866 break; | |
2867 } | |
2868 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2869 PLAYLIST_LOCK(playlist); |
2313 | 2870 |
2871 for (node = playlist->entries; node; node = next_node) { | |
2872 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2873 next_node = g_list_next(node); | |
2874 | |
2875 if (!entry || !entry->filename) { | |
2876 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2877 continue; | |
2878 } | |
2879 | |
2880 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2881 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2882 next_node_cmp = g_list_next(node_cmp); | |
2883 | |
2884 if (!entry_cmp || !entry_cmp->filename) { | |
2885 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2886 continue; | |
2887 } | |
2888 | |
2889 /* compare using the chosen dups_compare_func */ | |
2890 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2891 | |
2892 if (entry_cmp == playlist->position) { | |
2893 /* Don't remove the currently playing song */ | |
2894 if (playback_get_playing()) | |
2895 continue; | |
2896 | |
2897 if (next_node_cmp) | |
2898 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2899 else | |
2900 playlist->position = NULL; | |
2901 } | |
2902 | |
2903 /* check if this was the next item of the external | |
2904 loop; if true, replace it with the next of the next*/ | |
2905 if ( node_cmp == next_node ) | |
2906 next_node = g_list_next(next_node); | |
2907 | |
2908 playlist_entry_free(entry_cmp); | |
2909 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2910 } | |
2911 } | |
2912 } | |
2913 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2914 PLAYLIST_UNLOCK(playlist); |
2313 | 2915 |
2916 playlistwin_update_list(playlist); | |
2917 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
|
2918 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 2919 |
2920 playlist_manager_update(); | |
2921 } | |
2922 | |
2923 void | |
2924 playlist_get_total_time(Playlist * playlist, | |
2925 gulong * total_time, | |
2926 gulong * selection_time, | |
2927 gboolean * total_more, | |
2928 gboolean * selection_more) | |
2929 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2930 PLAYLIST_LOCK(playlist); |
2313 | 2931 *total_time = playlist->pl_total_time; |
2932 *selection_time = playlist->pl_selection_time; | |
2933 *total_more = playlist->pl_total_more; | |
2934 *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
|
2935 PLAYLIST_UNLOCK(playlist); |
2313 | 2936 } |
2937 | |
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
|
2938 static void |
2313 | 2939 playlist_recalc_total_time_nolock(Playlist *playlist) |
2940 { | |
2941 GList *list; | |
2942 PlaylistEntry *entry; | |
2943 | |
2944 REQUIRE_LOCK(playlist->mutex); | |
2945 | |
2946 playlist->pl_total_time = 0; | |
2947 playlist->pl_selection_time = 0; | |
2948 playlist->pl_total_more = FALSE; | |
2949 playlist->pl_selection_more = FALSE; | |
2950 | |
2951 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2952 entry = list->data; | |
2953 | |
2954 if (entry->length != -1) | |
2955 playlist->pl_total_time += entry->length / 1000; | |
2956 else | |
2957 playlist->pl_total_more = TRUE; | |
2958 | |
2959 if (entry->selected) { | |
2960 if (entry->length != -1) | |
2961 playlist->pl_selection_time += entry->length / 1000; | |
2962 else | |
2963 playlist->pl_selection_more = TRUE; | |
2964 } | |
2965 } | |
2966 } | |
2967 | |
2968 static void | |
2969 playlist_recalc_total_time(Playlist *playlist) | |
2970 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2971 PLAYLIST_LOCK(playlist); |
2313 | 2972 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
|
2973 PLAYLIST_UNLOCK(playlist); |
2313 | 2974 } |
2975 | |
2976 gint | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2977 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) |
2313 | 2978 { |
2979 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2980 gboolean is_first_search = TRUE; | |
2981 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
|
2982 const gchar *regex_pattern; |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
2983 const gchar *track_name; |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
2984 const gchar *album_name; |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
2985 const gchar *performer; |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
2986 const gchar *file_name; |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2987 |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2988 #if defined(USE_REGEX_ONIGURUMA) |
2313 | 2989 /* set encoding for Oniguruma regex to UTF-8 */ |
2990 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2991 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
|
2992 #endif |
2313 | 2993 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2994 PLAYLIST_LOCK(playlist); |
2313 | 2995 |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
2996 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
|
2997 (*regex_pattern != '\0') ) |
2313 | 2998 { |
2999 /* match by track_name */ | |
3000 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3001 #if defined(USE_REGEX_PCRE) |
2313 | 3002 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
|
3003 #else |
2313 | 3004 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
|
3005 #endif |
2313 | 3006 { |
3007 GList *tfound_list = NULL; | |
3008 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3009 else entry_list = found_list; /* use found_list */ | |
3010 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3011 { | |
3012 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3013 if ( entry->tuple != NULL ) |
2313 | 3014 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3015 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
|
3016 if (( track_name != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3017 ( regexec( ®ex , track_name , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3018 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3019 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3020 } |
2313 | 3021 } |
3022 } | |
3023 g_list_free( found_list ); /* wipe old found_list */ | |
3024 found_list = tfound_list; /* move tfound_list in found_list */ | |
3025 regfree( ®ex ); | |
3026 } | |
3027 is_first_search = FALSE; | |
3028 } | |
3029 | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3030 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
|
3031 (*regex_pattern != '\0') ) |
2313 | 3032 { |
3033 /* match by album_name */ | |
3034 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3035 #if defined(USE_REGEX_PCRE) |
2313 | 3036 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
|
3037 #else |
2313 | 3038 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
|
3039 #endif |
2313 | 3040 { |
3041 GList *tfound_list = NULL; | |
3042 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3043 else entry_list = found_list; /* use found_list */ | |
3044 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3045 { | |
3046 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3047 if ( entry->tuple != NULL ) |
2313 | 3048 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3049 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
|
3050 if ( ( album_name != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3051 ( regexec( ®ex , album_name , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3052 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3053 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3054 } |
2313 | 3055 } |
3056 } | |
3057 g_list_free( found_list ); /* wipe old found_list */ | |
3058 found_list = tfound_list; /* move tfound_list in found_list */ | |
3059 regfree( ®ex ); | |
3060 } | |
3061 is_first_search = FALSE; | |
3062 } | |
3063 | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3064 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
|
3065 (*regex_pattern != '\0') ) |
2313 | 3066 { |
3067 /* match by performer */ | |
3068 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3069 #if defined(USE_REGEX_PCRE) |
2313 | 3070 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
|
3071 #else |
2313 | 3072 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
|
3073 #endif |
2313 | 3074 { |
3075 GList *tfound_list = NULL; | |
3076 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3077 else entry_list = found_list; /* use found_list */ | |
3078 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3079 { | |
3080 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3081 if ( entry->tuple != NULL ) |
2313 | 3082 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3083 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
|
3084 if ( ( entry->tuple != NULL ) && ( performer != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3085 ( regexec( ®ex , performer , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3086 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3087 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3088 } |
2313 | 3089 } |
3090 } | |
3091 g_list_free( found_list ); /* wipe old found_list */ | |
3092 found_list = tfound_list; /* move tfound_list in found_list */ | |
3093 regfree( ®ex ); | |
3094 } | |
3095 is_first_search = FALSE; | |
3096 } | |
3097 | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3098 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
|
3099 (*regex_pattern != '\0') ) |
2313 | 3100 { |
3101 /* match by file_name */ | |
3102 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3103 #if defined(USE_REGEX_PCRE) |
2313 | 3104 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
|
3105 #else |
2313 | 3106 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
|
3107 #endif |
2313 | 3108 { |
3109 GList *tfound_list = NULL; | |
3110 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3111 else entry_list = found_list; /* use found_list */ | |
3112 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3113 { | |
3114 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3115 if ( entry->tuple != NULL ) |
2313 | 3116 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3117 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
|
3118 if ( ( file_name != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3119 ( regexec( ®ex , file_name , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3120 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3121 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3122 } |
2313 | 3123 } |
3124 } | |
3125 g_list_free( found_list ); /* wipe old found_list */ | |
3126 found_list = tfound_list; /* move tfound_list in found_list */ | |
3127 regfree( ®ex ); | |
3128 } | |
3129 is_first_search = FALSE; | |
3130 } | |
3131 | |
3132 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
3133 /* if some entries are still in found_list, those | |
3134 are what the user is searching for; select them */ | |
3135 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
3136 { | |
3137 PlaylistEntry *entry = sel_list->data; | |
3138 entry->selected = TRUE; | |
3139 num_of_entries_found++; | |
3140 } | |
3141 | |
3142 g_list_free( found_list ); | |
3143 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3144 PLAYLIST_UNLOCK(playlist); |
2313 | 3145 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
|
3146 // PLAYLIST_INCR_SERIAL(playlist); //unnecessary? --yaz |
2313 | 3147 |
3148 return num_of_entries_found; | |
3149 } | |
3150 | |
3151 void | |
3152 playlist_select_all(Playlist *playlist, gboolean set) | |
3153 { | |
3154 GList *list; | |
3155 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3156 PLAYLIST_LOCK(playlist); |
2313 | 3157 |
3158 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3159 PlaylistEntry *entry = list->data; | |
3160 entry->selected = set; | |
3161 } | |
3162 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3163 PLAYLIST_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
|
3164 playlist_recalc_total_time(playlist); |
2313 | 3165 } |
3166 | |
3167 void | |
3168 playlist_select_invert_all(Playlist *playlist) | |
3169 { | |
3170 GList *list; | |
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_LOCK(playlist); |
2313 | 3173 |
3174 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3175 PlaylistEntry *entry = list->data; | |
3176 entry->selected = !entry->selected; | |
3177 } | |
3178 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3179 PLAYLIST_UNLOCK(playlist); |
2313 | 3180 playlist_recalc_total_time(playlist); |
3181 } | |
3182 | |
3183 gboolean | |
3184 playlist_select_invert(Playlist *playlist, guint pos) | |
3185 { | |
3186 GList *list; | |
3187 gboolean invert_ok = FALSE; | |
3188 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3189 PLAYLIST_LOCK(playlist); |
2313 | 3190 |
3191 if ((list = g_list_nth(playlist->entries, pos))) { | |
3192 PlaylistEntry *entry = list->data; | |
3193 entry->selected = !entry->selected; | |
3194 invert_ok = TRUE; | |
3195 } | |
3196 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3197 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
|
3198 playlist_recalc_total_time(playlist); |
2313 | 3199 |
3200 return invert_ok; | |
3201 } | |
3202 | |
3203 | |
3204 void | |
3205 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3206 { | |
3207 GList *list; | |
3208 gint i; | |
3209 | |
3210 if (min_pos > max_pos) | |
3211 SWAP(min_pos, max_pos); | |
3212 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3213 PLAYLIST_LOCK(playlist); |
2313 | 3214 |
3215 list = g_list_nth(playlist->entries, min_pos); | |
3216 for (i = min_pos; i <= max_pos && list; i++) { | |
3217 PlaylistEntry *entry = list->data; | |
3218 entry->selected = select; | |
3219 list = g_list_next(list); | |
3220 } | |
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_UNLOCK(playlist); |
2313 | 3223 |
3224 playlist_recalc_total_time(playlist); | |
3225 } | |
3226 | |
3227 gboolean | |
3228 playlist_read_info_selection(Playlist *playlist) | |
3229 { | |
3230 GList *node; | |
3231 gboolean retval = FALSE; | |
3232 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3233 PLAYLIST_LOCK(playlist); |
2313 | 3234 |
3235 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3236 PlaylistEntry *entry = node->data; | |
3237 if (!entry->selected) | |
3238 continue; | |
3239 | |
3240 retval = TRUE; | |
3241 | |
3242 str_replace_in(&entry->title, NULL); | |
3243 entry->length = -1; | |
3244 | |
3245 /* invalidate mtime to reread */ | |
3246 if (entry->tuple != NULL) | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3247 tuple_associate_int(entry->tuple, FIELD_MTIME, NULL, -1); /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
2313 | 3248 |
3249 if (!playlist_entry_get_info(entry)) { | |
3250 if (g_list_index(playlist->entries, entry) == -1) | |
3251 /* Entry disappeared while we looked it up. Restart. */ | |
3252 node = playlist->entries; | |
3253 } | |
3254 } | |
3255 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3256 PLAYLIST_UNLOCK(playlist); |
2313 | 3257 |
3258 playlistwin_update_list(playlist); | |
3259 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
|
3260 PLAYLIST_INCR_SERIAL(playlist); //tentative --yaz |
2313 | 3261 |
3262 return retval; | |
3263 } | |
3264 | |
3265 void | |
3266 playlist_read_info(Playlist *playlist, guint pos) | |
3267 { | |
3268 GList *node; | |
3269 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3270 PLAYLIST_LOCK(playlist); |
2313 | 3271 |
3272 if ((node = g_list_nth(playlist->entries, pos))) { | |
3273 PlaylistEntry *entry = node->data; | |
3274 str_replace_in(&entry->title, NULL); | |
3275 entry->length = -1; | |
3276 playlist_entry_get_info(entry); | |
3277 } | |
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_UNLOCK(playlist); |
2313 | 3280 |
3281 playlistwin_update_list(playlist); | |
3282 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
|
3283 PLAYLIST_INCR_SERIAL(playlist); //tentative --yaz |
2313 | 3284 } |
3285 | |
3286 Playlist * | |
3287 playlist_get_active(void) | |
3288 { | |
3289 if (playlists_iter != NULL) | |
3290 return (Playlist *) playlists_iter->data; | |
3291 | |
2736 | 3292 if (playlists) |
3293 return (Playlist *) playlists->data; | |
3294 | |
3295 return NULL; | |
2313 | 3296 } |
3297 | |
3298 void | |
3299 playlist_set_shuffle(gboolean shuffle) | |
3300 { | |
3301 Playlist *playlist = playlist_get_active(); | |
3302 if (!playlist) | |
3303 return; | |
3304 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3305 PLAYLIST_LOCK(playlist); |
2313 | 3306 |
3307 playlist_position_before_jump = NULL; | |
3308 | |
3309 cfg.shuffle = shuffle; | |
3310 playlist_generate_shuffle_list_nolock(playlist); | |
3311 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3312 PLAYLIST_UNLOCK(playlist); |
2313 | 3313 } |
3314 | |
3315 Playlist * | |
3316 playlist_new(void) | |
3317 { | |
3318 Playlist *playlist = g_new0(Playlist, 1); | |
3319 playlist->mutex = g_mutex_new(); | |
3320 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
|
3321 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
|
3322 playlist->filename = NULL; |
2313 | 3323 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
|
3324 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
|
3325 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
|
3326 playlist->serial = 0; |
2313 | 3327 |
3328 return playlist; | |
3329 } | |
3330 | |
3331 void | |
3332 playlist_free(Playlist *playlist) | |
3333 { | |
3467
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3334 if (!playlist) |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3335 return; |
4111
3e63b1bee1e7
Fixes memory leak in usage of playlist_free() function. (Bugzilla #36)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4110
diff
changeset
|
3336 |
3e63b1bee1e7
Fixes memory leak in usage of playlist_free() function. (Bugzilla #36)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4110
diff
changeset
|
3337 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
|
3338 g_free( playlist->filename ); |
2313 | 3339 g_mutex_free( playlist->mutex ); |
3340 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
|
3341 playlist = NULL; //XXX lead to crash? --yaz |
2313 | 3342 } |
3343 | |
3344 Playlist * | |
3345 playlist_new_from_selected(void) | |
3346 { | |
3347 Playlist *newpl = playlist_new(); | |
3348 Playlist *playlist = playlist_get_active(); | |
3349 GList *list = playlist_get_selected(playlist); | |
3350 | |
3351 playlist_add_playlist( newpl ); | |
3352 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3353 PLAYLIST_LOCK(playlist); |
2313 | 3354 |
3355 while ( list != NULL ) | |
3356 { | |
3357 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3358 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3359 playlist_add( newpl , entry->filename ); | |
3360 list = g_list_next(list); | |
3361 } | |
3362 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3363 PLAYLIST_UNLOCK(playlist); |
2313 | 3364 |
3365 playlist_recalc_total_time(newpl); | |
3366 playlistwin_update_list(playlist); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
3367 playlist_manager_update(); |
2313 | 3368 |
3369 return newpl; | |
3370 } | |
3371 | |
3372 const gchar * | |
3373 playlist_get_filename_to_play(Playlist *playlist) | |
3374 { | |
3375 const gchar *filename = NULL; | |
3376 | |
3377 if (!playlist) | |
3378 return NULL; | |
3379 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3380 PLAYLIST_LOCK(playlist); |
2313 | 3381 |
3382 if (!playlist->position) { | |
3383 if (cfg.shuffle) | |
3384 playlist->position = playlist->shuffle->data; | |
3385 else | |
3386 playlist->position = playlist->entries->data; | |
3387 } | |
3388 | |
3389 filename = playlist->position->filename; | |
3390 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3391 PLAYLIST_UNLOCK(playlist); |
2313 | 3392 |
3393 return filename; | |
3394 } | |
3395 | |
3396 PlaylistEntry * | |
3397 playlist_get_entry_to_play(Playlist *playlist) | |
3398 { | |
3399 if (!playlist) | |
3400 return NULL; | |
3401 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3402 PLAYLIST_LOCK(playlist); |
2313 | 3403 |
3404 if (!playlist->position) { | |
3405 if (cfg.shuffle) | |
3406 playlist->position = playlist->shuffle->data; | |
3407 else | |
3408 playlist->position = playlist->entries->data; | |
3409 } | |
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_UNLOCK(playlist); |
2313 | 3412 |
3413 return playlist->position; | |
3414 } | |
3474
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3415 |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3416 gboolean |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3417 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
|
3418 { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3419 GList *l1, *l2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3420 PlaylistEntry *e1, *e2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3421 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
|
3422 l1 = p1->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3423 l2 = p2->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3424 do { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3425 if (!l1 && !l2) break; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3426 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
|
3427 e1 = (PlaylistEntry *) l1->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3428 e2 = (PlaylistEntry *) l2->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3429 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
|
3430 l1 = l1->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3431 l2 = l2->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3432 } while(1); |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3433 return TRUE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3434 } |
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
|
3435 |
3971
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3436 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
|
3437 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
|
3438 { |
3979
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3439 gchar *base, *ext, *lext, *filename, *tmp_uri; |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3440 gchar *tmp; |
3971
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3441 gint rv; |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3442 GList **lhandle, *node; |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3443 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
|
3444 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4063
diff
changeset
|
3445 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
|
3446 |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3447 /* 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
|
3448 tmp_uri = g_strdup(uri); |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3449 tmp = strrchr(tmp_uri, '?'); |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3450 |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3451 if (tmp != NULL && g_ascii_isdigit(*(tmp + 1))) |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3452 *tmp = '\0'; |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3453 |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3454 /* Check for plugins with custom URI:// strings */ |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3455 /* cue:// cdda:// tone:// tact:// */ |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3456 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
|
3457 g_free(tmp_uri); |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3458 return EXT_CUSTOM; |
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 |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3461 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
|
3462 filename = g_strdup(tmp ? tmp : tmp_uri); |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3463 g_free(tmp); tmp = NULL; |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3464 g_free(tmp_uri); tmp_uri = NULL; |
67f01143e613
improve on-demand probing:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3971
diff
changeset
|
3465 |
3947
eb20411bb9e1
fixed bug in extension filtering function
mf0102 <0102@gmx.at>
parents:
3945
diff
changeset
|
3466 |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3467 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
|
3468 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
|
3469 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
|
3470 |
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
|
3471 if(!ext) { |
3947
eb20411bb9e1
fixed bug in extension filtering function
mf0102 <0102@gmx.at>
parents:
3945
diff
changeset
|
3472 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
|
3473 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
|
3474 } |
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
|
3475 |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
3476 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
|
3477 g_free(base); |
3945
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3478 |
3971
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3479 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
|
3480 g_free(lext); |
3971
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3481 |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3482 if(!lhandle) { |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3483 return EXT_FALSE; |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3484 } |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3485 |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3486 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
|
3487 ip = (InputPlugin *)node->data; |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3488 |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3489 if(ip->have_subtune == TRUE) { |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3490 return EXT_HAVE_SUBTUNE; |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3491 } |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3492 else |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3493 rv = EXT_TRUE; |
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 |
3945
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3496 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
|
3497 } |
3971
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3498 |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3499 static gboolean |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3500 is_http(const gchar *uri) |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3501 { |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3502 gboolean rv = FALSE; |
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 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
|
3505 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
|
3506 rv = TRUE; |
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 |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3509 return rv; |
b0ae5dbd2f53
- add subtune support to on demand probing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3967
diff
changeset
|
3510 } |