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