1548
|
1 /*
|
|
2 * Audacious: A cross-platform multimedia player
|
|
3 * Copyright (c) 2006 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; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
19 */
|
|
20
|
|
21 #include <glib.h>
|
1549
|
22 #include <string.h>
|
1548
|
23 #include "playlist_container.h"
|
|
24
|
|
25 /*
|
|
26 * PlaylistContainer objects handle the import and export of Playlist
|
|
27 * data. Basically, a PlaylistContainer acts as a filter for a PlaylistEntry.
|
|
28 */
|
|
29
|
|
30 static GList *registered_plcs = NULL;
|
|
31
|
|
32 void playlist_container_register(PlaylistContainer *plc)
|
|
33 {
|
|
34 registered_plcs = g_list_append(registered_plcs, plc);
|
|
35 }
|
|
36
|
|
37 void playlist_container_unregister(PlaylistContainer *plc)
|
|
38 {
|
|
39 registered_plcs = g_list_remove(registered_plcs, plc);
|
|
40 }
|
1549
|
41
|
|
42 PlaylistContainer *playlist_container_find(char *ext)
|
|
43 {
|
|
44 GList *node;
|
|
45 PlaylistContainer *plc;
|
|
46
|
|
47 g_return_val_if_fail(ext != NULL, 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
|
1550
|
59 void playlist_container_read(char *filename, gint pos)
|
1549
|
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)
|
1550
|
65 return;
|
1549
|
66
|
1551
|
67 plc->plc_read(filename, pos);
|
1549
|
68 }
|
|
69
|
1550
|
70 void playlist_container_write(char *filename, gint pos)
|
1549
|
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
|
1550
|
78 plc->plc_write(filename, pos);
|
1549
|
79 }
|
1550
|
80
|
1552
|
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 }
|