Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
playlist-files.c
Go to the documentation of this file.
00001 /*
00002  * playlist-files.c
00003  * Copyright 2010 John Lindgren
00004  *
00005  * This file is part of Audacious.
00006  *
00007  * Audacious is free software: you can redistribute it and/or modify it under
00008  * the terms of the GNU General Public License as published by the Free Software
00009  * Foundation, version 2 or version 3 of the License.
00010  *
00011  * Audacious is distributed in the hope that it will be useful, but WITHOUT ANY
00012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00013  * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * Audacious. If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * The Audacious team does not consider modular code linking to Audacious or
00019  * using our public API to be a derived work.
00020  */
00021 
00022 #include "debug.h"
00023 #include "playlist.h"
00024 #include "plugin.h"
00025 #include "plugins.h"
00026 
00027 static const gchar * get_extension (const gchar * filename, gboolean quiet)
00028 {
00029     const gchar * s = strrchr (filename, '/');
00030     if (! s)
00031         goto FAIL;
00032 
00033     const gchar * p = strrchr (s + 1, '.');
00034     if (! p)
00035         goto FAIL;
00036 
00037     return p + 1;
00038 
00039 FAIL:
00040     if (! quiet)
00041         fprintf (stderr, "Failed to parse playlist filename %s.\n", filename);
00042     return NULL;
00043 }
00044 
00045 gboolean filename_is_playlist (const gchar * filename)
00046 {
00047     const gchar * ext = get_extension (filename, TRUE);
00048     if (! ext)
00049         return FALSE;
00050 
00051     return playlist_plugin_for_extension (ext) ? TRUE : FALSE;
00052 }
00053 
00054 static PlaylistPlugin * get_plugin (const gchar * filename)
00055 {
00056     const gchar * ext = get_extension (filename, FALSE);
00057     if (! ext)
00058         return NULL;
00059 
00060     PluginHandle * plugin = playlist_plugin_for_extension (ext);
00061     if (! plugin)
00062     {
00063         fprintf (stderr, "Unrecognized playlist file type \"%s\".\n", ext);
00064         return NULL;
00065     }
00066 
00067     return plugin_get_header (plugin);
00068 }
00069 
00070 gboolean playlist_insert_playlist (gint list, gint at, const gchar * filename)
00071 {
00072     AUDDBG ("Loading playlist %s.\n", filename);
00073     PlaylistPlugin * pp = get_plugin (filename);
00074     g_return_val_if_fail (pp && pp->load, FALSE);
00075     return pp->load (filename, list, at);
00076 }
00077 
00078 gboolean playlist_save (gint list, const gchar * filename)
00079 {
00080     AUDDBG ("Saving playlist %s.\n", filename);
00081     PlaylistPlugin * pp = get_plugin (filename);
00082     g_return_val_if_fail (pp && pp->save, FALSE);
00083     return pp->save (filename, list);
00084 }