• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

playlist_container.c

Go to the documentation of this file.
00001 /*
00002  * Audacious: A cross-platform multimedia player
00003  * Copyright (c) 2006-2007 William Pitcock, Tony Vroon, George Averill,
00004  *                         Giacomo Lozito, Derek Pomery and Yoshiki Yazawa.
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; under version 3 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses>.
00017  *
00018  * The Audacious team does not consider modular code linking to
00019  * Audacious or using our public API to be a derived work.
00020  */
00021 
00022 #include <glib.h>
00023 #include <string.h>
00024 
00025 #include "misc.h"
00026 #include "playlist_container.h"
00027 
00028 /*
00029  * PlaylistContainer objects handle the import and export of Playlist
00030  * data. Basically, a PlaylistContainer acts as a filter for a PlaylistEntry.
00031  */
00032 
00033 static GList *registered_plcs = NULL;
00034 
00035 void playlist_container_register(PlaylistContainer *plc)
00036 {
00037         registered_plcs = g_list_append(registered_plcs, plc);
00038 }
00039 
00040 void playlist_container_unregister(PlaylistContainer *plc)
00041 {
00042         registered_plcs = g_list_remove(registered_plcs, plc);
00043 }
00044 
00045 PlaylistContainer *playlist_container_find(gchar *ext)
00046 {
00047         GList *node;
00048         PlaylistContainer *plc;
00049 
00050         /* check ext neither is NULL nor 1 (in a consequence of optimization). */
00051         g_return_val_if_fail(ext != NULL && ext != (void *)1, NULL);
00052 
00053         for (node = registered_plcs; node != NULL; node = g_list_next(node)) {
00054                 plc = node->data;
00055 
00056                 if (!g_ascii_strncasecmp(plc->ext, ext, strlen(plc->ext)))
00057                         return plc;
00058         }
00059 
00060         return NULL;
00061 }
00062 
00063 void playlist_container_read(gchar *filename, gint pos)
00064 {
00065         gchar *ext = strrchr(filename, '.') + 1;        /* optimization: skip past the dot -nenolod */
00066         PlaylistContainer *plc = playlist_container_find(ext);
00067 
00068         if (plc->plc_read == NULL)
00069                 return;
00070 
00071         plc->plc_read(filename, pos);
00072 }
00073 
00074 void playlist_container_write(gchar *filename, gint pos)
00075 {
00076         gchar *ext = strrchr(filename, '.') + 1;        /* optimization: skip past the dot -nenolod */
00077         PlaylistContainer *plc = playlist_container_find(ext);
00078 
00079         if (plc->plc_write == NULL)
00080                 return;
00081 
00082         plc->plc_write(filename, pos);
00083 }

Generated on Wed Apr 6 2011 for Audacious by  doxygen 1.7.1