Subversion Repositories Kolibri OS

Rev

Rev 4364 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * Copyright 2008 Daniel Silverstone 
3
 *
4
 * This file is part of NetSurf, http://www.netsurf-browser.org/
5
 *
6
 * NetSurf 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; version 2 of the License.
9
 *
10
 * NetSurf 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
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see .
17
 */
18
 
19
#include 
20
#include 
21
#include 
22
#include 
23
#include 
24
#include 
25
 
26
#include 
27
 
28
#include "utils/filepath.h"
29
#include "utils/log.h"
30
#include "utils/url.h"
31
#include "desktop/gui.h"
32
 
33
#include "framebuffer/findfile.h"
34
 
35
char **respaths; /** resource search path vector */
36
 
37
/** Create an array of valid paths to search for resources.
38
 *
39
 * The idea is that all the complex path computation to find resources
40
 * is performed here, once, rather than every time a resource is
41
 * searched for.
42
 */
43
char **
44
fb_init_resource(const char *resource_path)
45
{
46
	char **pathv; /* resource path string vector */
47
	char **respath; /* resource paths vector */
48
	const char *lang = NULL;
49
 
50
	LOG(("Findfile: %s", resource_path));
51
	pathv = filepath_path_to_strvec(resource_path);
52
 
53
	LOG(("Findfile2: %s", pathv));
54
	respath = filepath_generate(pathv, &lang);
55
 
56
	filepath_free_strvec(pathv);
57
 
58
	return respath;
59
}
60
 
61
 
62
char *path_to_url(const char *path)
63
{
64
	int urllen;
65
	char *url;
66
 
67
	if (path == NULL)
68
		return NULL;
69
 
70
	urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
71
	url = malloc(urllen);
72
 
73
	if (*path == '/') {
74
		path++; /* file: paths are already absolute */
75
	}
76
 
77
	snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
78
 
79
	LOG(("Findfile path2url: %s", url));
80
	return url;
81
}
82
 
83
 
84
char *url_to_path(const char *url)
85
{
86
	char *path;
87
	char *respath;
88
	url_func_result res; /* result from url routines */
89
 
90
	res = url_path(url, &path);
91
	if (res != URL_FUNC_OK) {
92
		return NULL;
93
	}
5043 ashmew2 94
	__menuet__debug_out("Calling url_unescape from findfile.c");
3584 sourcerer 95
	res = url_unescape(path, &respath);
96
	free(path);
97
	if (res != URL_FUNC_OK) {
98
		return NULL;
99
	}
100
 
101
LOG(("Findfile url2path: %s", respath));
5043 ashmew2 102
 __menuet__debug_out("returning from url_to_path in findfile.c\n");
3584 sourcerer 103
	return respath;
104
}
105
 
106
nsurl *gui_get_resource_url(const char *path)
107
{
108
	char buf[PATH_MAX];
109
	char *raw;
110
	nsurl *url = NULL;
111
 
112
	if (strcmp(path, "favicon.ico") == 0)
113
		path = "favicon.png";
114
 
115
	raw = path_to_url(filepath_sfind(respaths, buf, path));
116
 
5043 ashmew2 117
	LOG(("Findfile gui: path is %s, raw is %s", path, raw));
3584 sourcerer 118
	if (raw != NULL) {
119
		nsurl_create(raw, &url);
120
		free(raw);
121
	}
122
 
123
	return url;
124
}
125
 
126
/*
127
 * Local Variables:
128
 * c-basic-offset: 8
129
 * End:
130
 */
131