1 /* pls.c
2 * Copyright (C) 2005 Sylvain Cresto <scresto@gmail.com>
3 *
4 * This file is part of graveman!
5 *
6 * graveman! 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, or
9 * (at your option) any later version.
10 *
11 * graveman! 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 GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with program; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 *
21 * URL: http://www.nongnu.org/graveman/
22 *
23 */
24
25 #include "graveman.h"
26
27 #define PLS_FILE "File"
28 #define HTTP "http://"
29
30 /* import d'un fichier */
pls_import(gchar * Afilename,Tgrave * Ag,gboolean Anew,GError ** Aerror)31 gboolean pls_import(gchar *Afilename, Tgrave *Ag, gboolean Anew, GError **Aerror)
32 {
33 FILE *Lfic;
34 gchar *s;
35 gchar Lbuf[_BUF_SIZE];
36 gchar Ltmp[MAXPATHLEN];
37 gchar *Lrepertoire;
38 GtkTreeModel *Ltreemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(sc_grave_get_widget(Ag, "LISTEAUDIO")));
39
40 if (!(Lfic = fopen(Afilename, "r"))) {
41 s = g_strdup_printf(_("Cannot import %s: %s"), Afilename, g_strerror(errno));
42 g_set_error(Aerror, G_FILE_ERROR, g_file_error_from_errno(errno), s, g_strerror(errno));
43 g_free(s);
44 return FALSE;
45 }
46
47 if (Anew) clear_list_audio(Ag);
48
49 Lrepertoire = g_path_get_dirname(Afilename);
50
51 while (fgets(Lbuf, _BUF_SIZE-1, Lfic)) {
52 Lbuf[_BUF_SIZE-1] = 0;
53
54 sc_chomp(Lbuf);
55
56 if (g_ascii_strncasecmp(Lbuf, PLS_FILE, strlen(PLS_FILE))) continue;
57
58 for (s=Lbuf+strlen(PLS_FILE); isdigit(*s); s++) ;
59 if (*(s++)!='=') continue;
60
61 /* fichier chemin local ou non */
62 if (!strncmp(s, HTTP, strlen(HTTP)))
63 continue; /* on ignore les http pour le moment .. */
64
65 if (strchr(s, '/')) {
66 g_strlcpy(Ltmp, s, MAXPATHLEN-1);
67 } else {
68 g_snprintf(Ltmp, MAXPATHLEN-1, "%s/%s", Lrepertoire, s);
69 }
70 if (g_file_test(Lbuf, G_FILE_TEST_EXISTS)) {
71 _add_a_piste(Lbuf, GTK_LIST_STORE(Ltreemodel), Ag);
72 }
73 }
74
75 fclose(Lfic);
76
77 g_free(Lrepertoire);
78
79 return TRUE;
80 }
81 /*
82 * vim:et:ts=8:sts=2:sw=2
83 */
84