Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | 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
	}
94
 
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));
102
	return respath;
103
}
104
 
105
nsurl *gui_get_resource_url(const char *path)
106
{
107
	char buf[PATH_MAX];
108
	char *raw;
109
	nsurl *url = NULL;
110
 
111
	if (strcmp(path, "favicon.ico") == 0)
112
		path = "favicon.png";
113
 
114
	raw = path_to_url(filepath_sfind(respaths, buf, path));
115
 
116
	LOG(("Findfile gui: %s", raw));
117
	if (raw != NULL) {
118
		nsurl_create(raw, &url);
119
		free(raw);
120
	}
121
 
122
	return url;
123
}
124
 
125
/*
126
 * Local Variables:
127
 * c-basic-offset: 8
128
 * End:
129
 */
130