comparison src/audlegacy/playlist_container.c @ 4811:7bf7f83a217e

rename src/audacious src/audlegacy so that both audlegacy and audacious can coexist.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 26 Nov 2008 00:44:56 +0900
parents src/audacious/playlist_container.c@ae3ed045e5aa
children c4698861e8fb
comparison
equal deleted inserted replaced
4810:c10e53092037 4811:7bf7f83a217e
1 /*
2 * Audacious: A cross-platform multimedia player
3 * Copyright (c) 2006-2007 William Pitcock, Tony Vroon, George Averill,
4 * Giacomo Lozito, Derek Pomery and Yoshiki Yazawa.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 3 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses>.
17 *
18 * The Audacious team does not consider modular code linking to
19 * Audacious or using our public API to be a derived work.
20 */
21
22 #include <glib.h>
23 #include <string.h>
24 #include "playlist_container.h"
25
26 /*
27 * PlaylistContainer objects handle the import and export of Playlist
28 * data. Basically, a PlaylistContainer acts as a filter for a PlaylistEntry.
29 */
30
31 static GList *registered_plcs = NULL;
32
33 void playlist_container_register(PlaylistContainer *plc)
34 {
35 registered_plcs = g_list_append(registered_plcs, plc);
36 }
37
38 void playlist_container_unregister(PlaylistContainer *plc)
39 {
40 registered_plcs = g_list_remove(registered_plcs, plc);
41 }
42
43 PlaylistContainer *playlist_container_find(gchar *ext)
44 {
45 GList *node;
46 PlaylistContainer *plc;
47
48 /* check ext neither is NULL nor 1 (in a consequence of optimization). */
49 g_return_val_if_fail(ext != NULL && ext != (void *)1, NULL);
50
51 for (node = registered_plcs; node != NULL; node = g_list_next(node)) {
52 plc = PLAYLIST_CONTAINER(node->data);
53
54 if (!g_ascii_strncasecmp(plc->ext, ext, strlen(ext)))
55 return plc;
56 }
57
58 return NULL;
59 }
60
61 void playlist_container_read(gchar *filename, gint pos)
62 {
63 gchar *ext = strrchr(filename, '.') + 1; /* optimization: skip past the dot -nenolod */
64 PlaylistContainer *plc = playlist_container_find(ext);
65
66 if (plc->plc_read == NULL)
67 return;
68
69 plc->plc_read(filename, pos);
70 }
71
72 void playlist_container_write(gchar *filename, gint pos)
73 {
74 gchar *ext = strrchr(filename, '.') + 1; /* optimization: skip past the dot -nenolod */
75 PlaylistContainer *plc = playlist_container_find(ext);
76
77 if (plc->plc_write == NULL)
78 return;
79
80 plc->plc_write(filename, pos);
81 }
82
83 gboolean is_playlist_name(gchar *filename)
84 {
85 gchar *ext = strrchr(filename, '.') + 1; /* optimization: skip past the dot -nenolod */
86 PlaylistContainer *plc = playlist_container_find(ext);
87
88 if (plc != NULL)
89 return TRUE;
90
91 return FALSE;
92 }