1 /*
2    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Bastien Nocera
3    Copyright (C) 2003, 2004 Colin Walters <walters@rhythmbox.org>
4 
5    The Gnome Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    The Gnome Library 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 GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public
16    License along with the Gnome Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301  USA.
19 
20    Author: Bastien Nocera <hadess@hadess.net>
21  */
22 
23 #include "config.h"
24 
25 #include <string.h>
26 #include <glib.h>
27 
28 #ifndef TOTEM_PL_PARSER_MINI
29 
30 #include "totem-pl-parser.h"
31 #include "totem-disc.h"
32 #endif /* !TOTEM_PL_PARSER_MINI */
33 
34 #include "totem-pl-parser-mini.h"
35 #include "totem-pl-parser-misc.h"
36 #include "totem-pl-parser-private.h"
37 
38 #ifndef TOTEM_PL_PARSER_MINI
39 TotemPlParserResult
totem_pl_parser_add_gvp(TotemPlParser * parser,GFile * file,GFile * base_file,TotemPlParseData * parse_data,gpointer data)40 totem_pl_parser_add_gvp (TotemPlParser *parser,
41 			 GFile *file,
42 			 GFile *base_file,
43 			 TotemPlParseData *parse_data,
44 			 gpointer data)
45 {
46 	TotemPlParserResult retval = TOTEM_PL_PARSER_RESULT_UNHANDLED;
47 	char *contents, **lines, *title, *url_link, *version;
48 	gsize size;
49 
50 	if (g_file_load_contents (file, NULL, &contents, &size, NULL, NULL) == FALSE)
51 		return TOTEM_PL_PARSER_RESULT_ERROR;
52 
53 	if (g_str_has_prefix (contents, "#.download.the.free.Google.Video.Player") == FALSE && g_str_has_prefix (contents, "# download the free Google Video Player") == FALSE) {
54 		g_free (contents);
55 		return retval;
56 	}
57 
58 	lines = g_strsplit (contents, "\n", 0);
59 	g_free (contents);
60 
61 	/* We only handle GVP version 1.1 for now */
62 	version = totem_pl_parser_read_ini_line_string_with_sep (lines, "gvp_version", ":");
63 	if (version == NULL || strcmp (version, "1.1") != 0) {
64 		g_free (version);
65 		g_strfreev (lines);
66 		return retval;
67 	}
68 	g_free (version);
69 
70 	url_link = totem_pl_parser_read_ini_line_string_with_sep (lines, "url", ":");
71 	if (url_link == NULL) {
72 		g_strfreev (lines);
73 		return retval;
74 	}
75 
76 	retval = TOTEM_PL_PARSER_RESULT_SUCCESS;
77 
78 	title = totem_pl_parser_read_ini_line_string_with_sep (lines, "title", ":");
79 
80 	totem_pl_parser_add_one_uri (parser, url_link, title);
81 
82 	g_free (url_link);
83 	g_free (title);
84 	g_strfreev (lines);
85 
86 	return retval;
87 }
88 
89 TotemPlParserResult
totem_pl_parser_add_desktop(TotemPlParser * parser,GFile * file,GFile * base_file,TotemPlParseData * parse_data,gpointer data)90 totem_pl_parser_add_desktop (TotemPlParser *parser,
91 			     GFile *file,
92 			     GFile *base_file,
93 			     TotemPlParseData *parse_data,
94 			     gpointer data)
95 {
96 	char *contents, **lines;
97 	const char *path, *display_name, *type;
98 	GFile *target;
99 	gsize size;
100 	TotemPlParserResult res = TOTEM_PL_PARSER_RESULT_ERROR;
101 
102 	if (g_file_load_contents (file, NULL, &contents, &size, NULL, NULL) == FALSE)
103 		return res;
104 
105 	lines = g_strsplit (contents, "\n", 0);
106 	g_free (contents);
107 
108 	type = totem_pl_parser_read_ini_line_string (lines, "Type");
109 	if (type == NULL)
110 		goto bail;
111 
112 	if (g_ascii_strcasecmp (type, "Link") != 0
113 	    && g_ascii_strcasecmp (type, "FSDevice") != 0) {
114 		goto bail;
115 	}
116 
117 	path = totem_pl_parser_read_ini_line_string (lines, "URL");
118 	if (path == NULL)
119 		goto bail;
120 	target = g_file_new_for_uri (path);
121 
122 	display_name = totem_pl_parser_read_ini_line_string (lines, "Name");
123 
124 	if (totem_pl_parser_ignore (parser, path) == FALSE
125 	    && g_ascii_strcasecmp (type, "FSDevice") != 0) {
126 		totem_pl_parser_add_one_file (parser, target, display_name);
127 	} else {
128 		if (totem_pl_parser_parse_internal (parser, target, NULL, parse_data) != TOTEM_PL_PARSER_RESULT_SUCCESS)
129 			totem_pl_parser_add_one_file (parser, target, display_name);
130 	}
131 
132 	res = TOTEM_PL_PARSER_RESULT_SUCCESS;
133 
134 bail:
135 	g_strfreev (lines);
136 
137 	return res;
138 }
139 
140 #endif /* !TOTEM_PL_PARSER_MINI */
141 
142 
143