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