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