Mercurial > audlegacy
comparison audacious/playlist.c @ 852:bcff46a2558d trunk
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
author | giacomo |
---|---|
date | Sat, 18 Mar 2006 14:31:38 -0800 |
parents | ffc5ab7b4b2c |
children | 74576869a506 |
comparison
equal
deleted
inserted
replaced
851:c9d70a699f80 | 852:bcff46a2558d |
---|---|
104 static gint playlist_compare_path(const PlaylistEntry * a, const PlaylistEntry * b); | 104 static gint playlist_compare_path(const PlaylistEntry * a, const PlaylistEntry * b); |
105 static gint playlist_compare_filename(const PlaylistEntry * a, const PlaylistEntry * b); | 105 static gint playlist_compare_filename(const PlaylistEntry * a, const PlaylistEntry * b); |
106 static gint playlist_compare_title(const PlaylistEntry * a, const PlaylistEntry * b); | 106 static gint playlist_compare_title(const PlaylistEntry * a, const PlaylistEntry * b); |
107 static gint playlist_compare_date(const PlaylistEntry * a, const PlaylistEntry * b); | 107 static gint playlist_compare_date(const PlaylistEntry * a, const PlaylistEntry * b); |
108 | 108 |
109 static gint playlist_dupscmp_path( const PlaylistEntry * a, const PlaylistEntry * b); | |
110 static gint playlist_dupscmp_filename( const PlaylistEntry * a, const PlaylistEntry * b); | |
111 static gint playlist_dupscmp_title( const PlaylistEntry * a, const PlaylistEntry * b); | |
112 | |
109 static PlaylistCompareFunc playlist_compare_func_table[] = { | 113 static PlaylistCompareFunc playlist_compare_func_table[] = { |
110 playlist_compare_path, | 114 playlist_compare_path, |
111 playlist_compare_filename, | 115 playlist_compare_filename, |
112 playlist_compare_title, | 116 playlist_compare_title, |
113 playlist_compare_date | 117 playlist_compare_date |
2204 playlist_generate_shuffle_list(); | 2208 playlist_generate_shuffle_list(); |
2205 playlistwin_update_list(); | 2209 playlistwin_update_list(); |
2206 playlist_recalc_total_time(); | 2210 playlist_recalc_total_time(); |
2207 } | 2211 } |
2208 | 2212 |
2209 void | 2213 |
2210 playlist_remove_duplicates(void) | 2214 static gint |
2215 playlist_dupscmp_title( const PlaylistEntry * a , const PlaylistEntry * b ) | |
2216 { | |
2217 const gchar *a_title, *b_title; | |
2218 | |
2219 g_return_val_if_fail(a != NULL, 0); | |
2220 g_return_val_if_fail(b != NULL, 0); | |
2221 | |
2222 if (a->title) | |
2223 a_title = a->title; | |
2224 else { | |
2225 if (strrchr(a->filename, '/')) | |
2226 a_title = strrchr(a->filename, '/') + 1; | |
2227 else | |
2228 a_title = a->filename; | |
2229 } | |
2230 | |
2231 if (b->title) | |
2232 b_title = b->title; | |
2233 else { | |
2234 if (strrchr(a->filename, '/')) | |
2235 b_title = strrchr(b->filename, '/') + 1; | |
2236 else | |
2237 b_title = b->filename; | |
2238 } | |
2239 | |
2240 return strcmp(a_title, b_title); | |
2241 } | |
2242 | |
2243 static gint | |
2244 playlist_dupscmp_filename( const PlaylistEntry * a , const PlaylistEntry * b ) | |
2245 { | |
2246 gchar *a_filename, *b_filename; | |
2247 | |
2248 g_return_val_if_fail(a != NULL, 0); | |
2249 g_return_val_if_fail(b != NULL, 0); | |
2250 | |
2251 if (strrchr(a->filename, '/')) | |
2252 a_filename = strrchr(a->filename, '/') + 1; | |
2253 else | |
2254 a_filename = a->filename; | |
2255 | |
2256 if (strrchr(b->filename, '/')) | |
2257 b_filename = strrchr(b->filename, '/') + 1; | |
2258 else | |
2259 b_filename = b->filename; | |
2260 | |
2261 return strcmp(a_filename, b_filename); | |
2262 } | |
2263 | |
2264 static gint | |
2265 playlist_dupscmp_path( const PlaylistEntry * a , const PlaylistEntry * b ) | |
2266 { | |
2267 gchar *a_filename = a->filename, *b_filename = b->filename; | |
2268 gchar *posa, *posb; | |
2269 gint len, ret; | |
2270 | |
2271 posa = strrchr(a_filename, '/'); | |
2272 posb = strrchr(b_filename, '/'); | |
2273 | |
2274 /* sort directories before files */ | |
2275 if (posa && posb && (posa - a_filename != posb - b_filename)) { | |
2276 if (posa -a_filename > posb - b_filename) { | |
2277 len = posb - b_filename; | |
2278 ret = -1; | |
2279 } | |
2280 else { | |
2281 len = posa - a_filename; | |
2282 ret = 1; | |
2283 } | |
2284 if (!strncmp(a_filename, b_filename, len)) | |
2285 return ret; | |
2286 } | |
2287 return strcmp(a_filename, b_filename); | |
2288 } | |
2289 | |
2290 void | |
2291 playlist_remove_duplicates( PlaylistDupsType type ) | |
2211 { | 2292 { |
2212 GList *node, *next_node; | 2293 GList *node, *next_node; |
2213 GList *node_cmp, *next_node_cmp; | 2294 GList *node_cmp, *next_node_cmp; |
2295 gint (*dups_compare_func)( const PlaylistEntry * , const PlaylistEntry * ); | |
2296 | |
2297 switch ( type ) | |
2298 { | |
2299 case PLAYLIST_DUPS_TITLE: | |
2300 dups_compare_func = playlist_dupscmp_title; | |
2301 break; | |
2302 case PLAYLIST_DUPS_PATH: | |
2303 dups_compare_func = playlist_dupscmp_path; | |
2304 break; | |
2305 case PLAYLIST_DUPS_FILENAME: | |
2306 default: | |
2307 dups_compare_func = playlist_dupscmp_filename; | |
2308 break; | |
2309 } | |
2214 | 2310 |
2215 PLAYLIST_LOCK(); | 2311 PLAYLIST_LOCK(); |
2216 | 2312 |
2217 for (node = playlist; node; node = next_node) { | 2313 for (node = playlist; node; node = next_node) { |
2218 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | 2314 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); |
2230 if (!entry_cmp || !entry_cmp->filename) { | 2326 if (!entry_cmp || !entry_cmp->filename) { |
2231 g_message(G_STRLOC ": Playlist entry is invalid!"); | 2327 g_message(G_STRLOC ": Playlist entry is invalid!"); |
2232 continue; | 2328 continue; |
2233 } | 2329 } |
2234 | 2330 |
2235 /* compare path+filenames, this can/should be optimized */ | 2331 /* compare using the chosen dups_compare_func */ |
2236 if ( !strcmp( entry->filename , entry_cmp->filename ) ) { | 2332 if ( !dups_compare_func( entry , entry_cmp ) ) { |
2237 | 2333 |
2238 if (entry_cmp == playlist_position) { | 2334 if (entry_cmp == playlist_position) { |
2239 /* Don't remove the currently playing song */ | 2335 /* Don't remove the currently playing song */ |
2240 if (bmp_playback_get_playing()) | 2336 if (bmp_playback_get_playing()) |
2241 continue; | 2337 continue; |