summaryrefslogtreecommitdiff
path: root/framebuffer
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-02-23 22:27:55 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-02-23 22:27:55 +0000
commit0231675abf3b467cff49d1976df882931d91019d (patch)
tree08756930c2008871cf5fd5bc0ce345411377cb57 /framebuffer
parentb49669d17e0c9dc70c775623d6cc1154619ff83b (diff)
downloadnetsurf-0231675abf3b467cff49d1976df882931d91019d.tar.gz
netsurf-0231675abf3b467cff49d1976df882931d91019d.tar.bz2
add resource handling
move gtk and framebuffer to use generic resource handling svn path=/trunk/netsurf/; revision=11772
Diffstat (limited to 'framebuffer')
-rw-r--r--framebuffer/Makefile.target1
-rw-r--r--framebuffer/filetype.c2
-rw-r--r--framebuffer/findfile.c97
-rw-r--r--framebuffer/findfile.h10
-rw-r--r--framebuffer/font_freetype.c7
-rw-r--r--framebuffer/gui.c38
6 files changed, 75 insertions, 80 deletions
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index e9dd8a883..98c6427df 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -24,6 +24,7 @@ CFLAGS += -Dnsframebuffer
CFLAGS += '-DNETSURF_FB_RESPATH="$(NETSURF_FB_RESPATH_$(NETSURF_FB_FRONTEND))"'
# compile time font locations
+CFLAGS += '-DNETSURF_FB_FONTPATH="$(NETSURF_FB_FONTPATH)"'
CFLAGS += '-DNETSURF_FB_FONT_SANS_SERIF="$(NETSURF_FB_FONT_SANS_SERIF)"'
CFLAGS += '-DNETSURF_FB_FONT_SANS_SERIF_BOLD="$(NETSURF_FB_FONT_SANS_SERIF_BOLD)"'
CFLAGS += '-DNETSURF_FB_FONT_SANS_SERIF_ITALIC="$(NETSURF_FB_FONT_SANS_SERIF_ITALIC)"'
diff --git a/framebuffer/filetype.c b/framebuffer/filetype.c
index d15890ce4..4b303e5f1 100644
--- a/framebuffer/filetype.c
+++ b/framebuffer/filetype.c
@@ -33,6 +33,8 @@ const char *fetch_filetype(const char *unix_path)
l = strlen(unix_path);
if (2 < l && strcasecmp(unix_path + l - 3, "css") == 0)
return "text/css";
+ if (2 < l && strcasecmp(unix_path + l - 3, "f79") == 0)
+ return "text/css";
if (2 < l && strcasecmp(unix_path + l - 3, "jpg") == 0)
return "image/jpeg";
if (3 < l && strcasecmp(unix_path + l - 4, "jpeg") == 0)
diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c
index caa910005..130804eed 100644
--- a/framebuffer/findfile.c
+++ b/framebuffer/findfile.c
@@ -27,9 +27,45 @@
#include "utils/log.h"
#include "utils/url.h"
+#include "utils/resource.h"
+#include "content/fetchers/resource.h"
#include "framebuffer/findfile.h"
+char **respaths; /** resource search path vector */
+
+/** Create an array of valid paths to search for resources.
+ *
+ * The idea is that all the complex path computation to find resources
+ * is performed here, once, rather than every time a resource is
+ * searched for.
+ */
+char **
+fb_init_resource(const char *resource_path)
+{
+ char **pathv; /* resource path string vector */
+ char **respath; /* resource paths vector */
+ const char *lang = NULL;
+ char *foo;
+ int bar=0;
+ fprintf(stderr, "fb_init_resource:%s\n",resource_path);
+
+ pathv = resource_path_to_strvec(resource_path);
+
+ respath = resource_generate(pathv, &lang);
+
+ resource_free_strvec(pathv);
+
+ foo = respath[bar];
+ while (foo != NULL) {
+ fprintf(stderr, "%s\n",foo);
+ bar++;
+ foo = respath[bar];
+ }
+ return respath;
+}
+
+
char *path_to_url(const char *path)
{
int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
@@ -65,67 +101,12 @@ char *url_to_path(const char *url)
return respath;
}
-/**
- * Locate a shared resource file by searching known places in order.
- *
- * \param buf buffer to write to. must be at least PATH_MAX chars
- * \param filename file to look for
- * \param def default to return if file not found
- * \return buf
- *
- * Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an
- * environment variable), and finally the path specified by NETSURF_FB_RESPATH
- * from the Makefile
- */
-
-char *fb_find_resource(char *buf, const char *filename, const char *def)
+char* gui_find_resource(const char *filename)
{
- char *cdir = getenv("HOME");
- char t[PATH_MAX];
-
- if (cdir != NULL) {
- strcpy(t, cdir);
- strcat(t, "/.netsurf/");
- strcat(t, filename);
- if (realpath(t, buf) != NULL) {
- if (access(buf, R_OK) == 0)
- return buf;
- }
- }
-
- cdir = getenv("NETSURFRES");
-
- if (cdir != NULL) {
- if (realpath(cdir, buf) != NULL) {
- strcat(buf, "/");
- strcat(buf, filename);
- if (access(buf, R_OK) == 0)
- return buf;
- }
- }
-
- strcpy(t, NETSURF_FB_RESPATH);
- strcat(t, filename);
- if (realpath(t, buf) != NULL) {
- if (access(buf, R_OK) == 0)
- return buf;
- }
-
- if (def[0] == '~') {
- snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
- if (realpath(t, buf) == NULL) {
- strcpy(buf, t);
- }
- } else {
- if (realpath(def, buf) == NULL) {
- strcpy(buf, def);
- }
- }
-
- return buf;
+ char buf[PATH_MAX];
+ return path_to_url(resource_sfind(respaths, buf, filename));
}
-
/*
* Local Variables:
* c-basic-offset: 8
diff --git a/framebuffer/findfile.h b/framebuffer/findfile.h
index 85a2f7074..1f3db6eb1 100644
--- a/framebuffer/findfile.h
+++ b/framebuffer/findfile.h
@@ -19,6 +19,14 @@
#ifndef NETSURF_FB_FINDFILE_H
#define NETSURF_FB_FINDFILE_H
-extern char *fb_find_resource(char *buf, const char *filename, const char *def);
+extern char **respaths;
+
+/** Create an array of valid paths to search for resources.
+ *
+ * The idea is that all the complex path computation to find resources
+ * is performed here, once, rather than every time a resource is
+ * searched for.
+ */
+char **fb_init_resource(const char *resource_path);
#endif /* NETSURF_FB_FINDFILE_H */
diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c
index ea183ea4b..44d6701dc 100644
--- a/framebuffer/font_freetype.c
+++ b/framebuffer/font_freetype.c
@@ -27,6 +27,7 @@
#include "render/font.h"
#include "utils/utf8.h"
#include "utils/log.h"
+#include "utils/resource.h"
#include "desktop/options.h"
#include "framebuffer/gui.h"
@@ -112,7 +113,7 @@ static FT_Error ft_face_requester(FTC_FaceID face_id, FT_Library library, FT_Po
/* create new framebuffer face and cause it to be loaded to check its ok */
static fb_faceid_t *
-fb_new_face(const char *option, const char *resname, const char *fontfile)
+fb_new_face(const char *option, const char *resname, const char *fontname)
{
fb_faceid_t *newf;
FT_Error error;
@@ -124,13 +125,13 @@ fb_new_face(const char *option, const char *resname, const char *fontfile)
if (option != NULL) {
newf->fontfile = strdup(option);
} else {
- fb_find_resource(buf, resname, fontfile);
+ resource_sfind(respaths, buf, fontname);
newf->fontfile = strdup(buf);
}
error = FTC_Manager_LookupFace(ft_cmanager, (FTC_FaceID)newf, &aface);
if (error) {
- LOG(("Could not find font face %s (code %d)\n", fontfile, error));
+ LOG(("Could not find font face %s (code %d)\n", fontname, error));
free(newf);
newf = NULL;
}
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 6cec4e7fa..abdb0ed9e 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -37,6 +37,7 @@
#include "desktop/netsurf.h"
#include "desktop/options.h"
#include "desktop/shape.h"
+#include "utils/resource.h"
#include "utils/log.h"
#include "utils/url.h"
#include "utils/messages.h"
@@ -63,7 +64,6 @@
char *default_stylesheet_url;
char *quirks_stylesheet_url;
char *adblock_stylesheet_url;
-char *options_file_location;
fbtk_widget_t *fbtk;
@@ -435,33 +435,31 @@ process_cmdline(int argc, char** argv)
return true;
}
-
static void
gui_init(int argc, char** argv)
{
- char buf[PATH_MAX];
nsfb_t *nsfb;
option_core_select_menu = true;
/* set up stylesheet urls */
- fb_find_resource(buf, "default.css", "./framebuffer/res/default.css");
- default_stylesheet_url = path_to_url(buf);
+ default_stylesheet_url = strdup("resource:default.css");
LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
- fb_find_resource(buf, "quirks.css", "./framebuffer/res/quirks.css");
- quirks_stylesheet_url = path_to_url(buf);
+ quirks_stylesheet_url = strdup("resource:quirks.css");
+ LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url));
+
+ adblock_stylesheet_url = strdup("resource:adblock.css");
+ LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
if (option_cookie_file == NULL) {
- fb_find_resource(buf, "Cookies", "~/.netsurf/Cookies");
- LOG(("Using '%s' as Cookies file", buf));
- option_cookie_file = strdup(buf);
+ option_cookie_file = resource_find(respaths, "Cookies");
+ LOG(("Using '%s' as Cookies file", option_cookie_file));
}
if (option_cookie_jar == NULL) {
- fb_find_resource(buf, "Cookies", "~/.netsurf/Cookies");
- LOG(("Using '%s' as Cookie Jar file", buf));
- option_cookie_jar = strdup(buf);
+ option_cookie_jar = resource_find(respaths, "Cookies");
+ LOG(("Using '%s' as Cookie Jar file", option_cookie_jar));
}
if (option_cookie_file == NULL || option_cookie_jar == NULL)
@@ -496,17 +494,21 @@ int
main(int argc, char** argv)
{
struct browser_window *bw;
- char options[PATH_MAX];
- char messages[PATH_MAX];
+ char *options;
+ char *messages;
setbuf(stderr, NULL);
- fb_find_resource(messages, "messages", "./framebuffer/res/messages");
- fb_find_resource(options, "Choices-fb", "~/.netsurf/Choices-fb");
- options_file_location = strdup(options);
+ respaths = fb_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"NETSURF_FB_RESPATH":./framebuffer/res:"NETSURF_FB_FONTPATH);
+
+ options = resource_find(respaths, "Choices");
+ messages = resource_find(respaths, "messages");
netsurf_init(&argc, &argv, options, messages);
+ free(messages);
+ free(options);
+
gui_init(argc, argv);
LOG(("calling browser_window_create"));