2313
|
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 2 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, write to the Free Software
|
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18 */
|
|
19
|
|
20 #include <glib.h>
|
|
21 #include <string.h>
|
|
22 #include "playlist_container.h"
|
|
23
|
|
24 /*
|
|
25 * PlaylistContainer objects handle the import and export of Playlist
|
|
26 * data. Basically, a PlaylistContainer acts as a filter for a PlaylistEntry.
|
|
27 */
|
|
28
|
|
29 static GList *registered_plcs = NULL;
|
|
30
|
|
31 void playlist_container_register(PlaylistContainer *plc)
|
|
32 {
|
|
33 registered_plcs = g_list_append(registered_plcs, plc);
|
|
34 }
|
|
35
|
|
36 void playlist_container_unregister(PlaylistContainer *plc)
|
|
37 {
|
|
38 registered_plcs = g_list_remove(registered_plcs, plc);
|
|
39 }
|
|
40
|
|
41 PlaylistContainer *playlist_container_find(char *ext)
|
|
42 {
|
|
43 GList *node;
|
|
44 PlaylistContainer *plc;
|
|
45
|
|
46 /* check ext neither is NULL nor 1 (in a consequence of optimization). */
|
|
47 g_return_val_if_fail(ext != NULL && ext != (void *)1, NULL);
|
|
48
|
|
49 for (node = registered_plcs; node != NULL; node = g_list_next(node)) {
|
|
50 plc = PLAYLIST_CONTAINER(node->data);
|
|
51
|
|
52 if (!g_strcasecmp(plc->ext, ext))
|
|
53 return plc;
|
|
54 }
|
|
55
|
|
56 return NULL;
|
|
57 }
|
|
58
|
|
59 void playlist_container_read(char *filename, gint pos)
|
|
60 {
|
|
61 char *ext = strrchr(filename, '.') + 1; /* optimization: skip past the dot -nenolod */
|
|
62 PlaylistContainer *plc = playlist_container_find(ext);
|
|
63
|
|
64 if (plc->plc_read == NULL)
|
|
65 return;
|
|
66
|
|
67 plc->plc_read(filename, pos);
|
|
68 }
|
|
69
|
|
70 void playlist_container_write(char *filename, gint pos)
|
|
71 {
|
|
72 char *ext = strrchr(filename, '.') + 1; /* optimization: skip past the dot -nenolod */
|
|
73 PlaylistContainer *plc = playlist_container_find(ext);
|
|
74
|
|
75 if (plc->plc_write == NULL)
|
|
76 return;
|
|
77
|
|
78 plc->plc_write(filename, pos);
|
|
79 }
|
|
80
|
|
81 gboolean is_playlist_name(char *filename)
|
|
82 {
|
|
83 char *ext = strrchr(filename, '.') + 1; /* optimization: skip past the dot -nenolod */
|
|
84 PlaylistContainer *plc = playlist_container_find(ext);
|
|
85
|
|
86 if (plc != NULL)
|
|
87 return TRUE;
|
|
88
|
|
89 return FALSE;
|
|
90 }
|