summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-06-23 11:53:41 +0100
committerVincent Sanders <vince@kyllikki.org>2015-06-23 11:53:41 +0100
commitee74f9ac8cacc89a1f8a94f63feac662bb13cbad (patch)
treeeddc0008404293cc2f4e7b0f70c530a4f1bdd049
parent11dc7304d96a2ac3e2ac346e3cb6236f8e14225b (diff)
downloadnetsurf-ee74f9ac8cacc89a1f8a94f63feac662bb13cbad.tar.gz
netsurf-ee74f9ac8cacc89a1f8a94f63feac662bb13cbad.tar.bz2
Change gtk message and language handling to use resource names
The GTK resource handling can now provide the path to resources rather than having to compute them separately. This reduces run time allocation and allows for the resources to be built in if required. Additionally this tweaks the resource scheme handling to redirect favicon.ico to resource:favicon.png instead of rewriting directly to file scheme path allowing the favicon to be a compiled in resource.
-rw-r--r--!NetSurf/Resources/nl/welcome.html,faf2
-rw-r--r--gtk/fetch.c6
-rw-r--r--gtk/gui.c41
-rw-r--r--gtk/gui.h3
-rw-r--r--gtk/preferences.c10
-rw-r--r--gtk/resources.c26
-rw-r--r--gtk/resources.h12
-rw-r--r--gtk/scaffolding.c1
8 files changed, 62 insertions, 39 deletions
diff --git a/!NetSurf/Resources/nl/welcome.html,faf b/!NetSurf/Resources/nl/welcome.html,faf
index 31b24ad67..f35260b73 100644
--- a/!NetSurf/Resources/nl/welcome.html,faf
+++ b/!NetSurf/Resources/nl/welcome.html,faf
@@ -3,7 +3,7 @@
<head>
<title>Welkom bij NetSurf</title>
<style type="text/css">html,body{margin:0;padding:0;}body{color:#000;background:#fff;font-family:sans-serif;margin:0 auto;}a:link{text-decoration:underline;color:#00f;}a:visited{text-decoration:underline;color:#60a;}a:hover{text-decoration:none;}a:active{text-decoration:underline;color:#f00;}.banner{margin:0;padding:0;background:#94adff;text-align:left;}.banner img{border:none;color:#000;height:86px;width:308px;display:block;}.onlycontent{margin:0 1em;}.nslinks{display:table;width:100%;margin:0;border-spacing:0;padding:0;background:#ccd8ff;font-size:88%;}.nslinks li{display:table-cell;text-align:center;padding:0.2em 0.3em 0.3em;vertical-align:middle;}.nslinks li+li{border-left:2px solid #b1c3ff;}.version{padding:0;margin:1.2em auto 0;width:90%;color:#444;font-size:160%;}.intro{width: 90%;margin:1em auto;color:#666;}.websearch{margin:1.5em auto;padding:1.2em 0.3em;background:#d8e2ff;border:2px solid #c5d3ff;width:80%;text-align:center;}input[type=text]{border:2px solid #b6c7ff;background:#f9faff;color:#000;margin:2px;}input[type=submit]{border:2px outset #cedaff;color:#000;background:#cedaff;margin:2px;}.links{display:table;width:80%;margin:0 auto 3em;font-size:94%;}.links p{display:table-cell;}.links ul{padding-left:0.8em;margin-top:-1em;}.links ul+ul{padding-left:1em;}.footer{font-style:italic;color:#666;text-align:right;}.footer p{margin-top:1.5em;padding-top:0.4em;border-top:2px solid #94adff;}</style>
-<link rel="icon" type="image_png" href="http://www.netsurf-browser.org/webimages/favicon_png">
+<link rel="icon" type="image/png" href="http://www.netsurf-browser.org/webimages/favicon.png">
</head>
<body>
diff --git a/gtk/fetch.c b/gtk/fetch.c
index 10b26bd48..13ffceb86 100644
--- a/gtk/fetch.c
+++ b/gtk/fetch.c
@@ -238,11 +238,11 @@ static nsurl *nsgtk_get_resource_url(const char *path)
/* favicon.ico -> favicon.png */
if (strcmp(path, "favicon.ico") == 0) {
- path = "favicon.png";
+ nsurl_create("resource:favicon.png", &url);
+ } else {
+ netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
}
- netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
-
return url;
}
diff --git a/gtk/gui.c b/gtk/gui.c
index 3a41b605e..28e5c3c90 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -74,7 +74,6 @@ bool nsgtk_complete = false;
char *toolbar_indices_file_location;
char *res_dir_location;
-char *languages_file_location;
char *themelist_file_location;
char *nsgtk_config_home; /* exported global defined in gtk/gui.h */
@@ -237,12 +236,6 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
nsurl *url;
nserror error;
- /* find the languages file */
- languages_file_location = filepath_find(respath, "languages");
- if ((languages_file_location == NULL) ||
- (strlen(languages_file_location) < 10)) {
- die("Unable to find resources.\n");
- }
/* find the theme list file */
themelist_file_location = filepath_find(respath, "themelist");
@@ -252,20 +245,21 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
themelist_file_location = NULL;
}
if (themelist_file_location == NULL) {
- LOG("Unable to find themelist - disabling");
+ LOG("Unable to find themelist - disabling themes");
+ res_dir_location = NULL;
+ } else {
+ /* Obtain resources path location.
+ *
+ * Uses the directory the theme file was found in,
+ * @todo find and slaughter all references to this!
+ */
+ res_dir_location = calloc(1, strlen(themelist_file_location) - 8);
+ memcpy(res_dir_location,
+ themelist_file_location,
+ strlen(themelist_file_location) - 9);
+ LOG("Using '%s' for resource path", res_dir_location);
}
- /* Obtain resources path location.
- *
- * Uses the directory the languages file was found in,
- * @todo find and slaughter all references to this!
- */
- res_dir_location = calloc(1, strlen(languages_file_location) - 8);
- memcpy(res_dir_location,
- languages_file_location,
- strlen(languages_file_location) - 9);
- LOG("Using '%s' for resource path", res_dir_location);
-
error = nsgtk_builder_new_from_resname("warning", &warning_builder);
if (error != NSERROR_OK) {
LOG("Unable to initialise warning dialog");
@@ -1046,7 +1040,7 @@ static struct gui_browser_table nsgtk_browser_table = {
static nserror nsgtk_messages_init(char **respaths)
{
- char *messages;
+ const char *messages;
nserror ret;
const uint8_t *data;
size_t data_size;
@@ -1056,12 +1050,9 @@ static nserror nsgtk_messages_init(char **respaths)
ret = messages_add_from_inline(data, data_size);
} else {
/* Obtain path to messages */
- messages = filepath_find(respaths, "Messages");
- if (messages != NULL) {
+ ret = nsgtk_path_from_resname("Messages", &messages);
+ if (ret == NSERROR_OK) {
ret = messages_add_from_file(messages);
- free(messages);
- } else {
- ret = NSERROR_NOT_FOUND;
}
}
return ret;
diff --git a/gtk/gui.h b/gtk/gui.h
index ce234c4a0..a804261de 100644
--- a/gtk/gui.h
+++ b/gtk/gui.h
@@ -21,9 +21,6 @@
struct nsurl;
-/** language list file path. */
-extern char *languages_file_location;
-
/** toolbar arrangement file path. */
extern char *toolbar_indices_file_location;
diff --git a/gtk/preferences.c b/gtk/preferences.c
index ba58bc905..5b6e332f1 100644
--- a/gtk/preferences.c
+++ b/gtk/preferences.c
@@ -548,19 +548,25 @@ nsgtk_preferences_comboboxLanguage_changed(GtkComboBox *combo,
}
}
+/**
+ * Fill content language list store.
+ */
G_MODULE_EXPORT void
nsgtk_preferences_comboboxLanguage_realize(GtkWidget *widget,
struct ppref *priv)
{
- /* Fill content language list store */
int active_language = 0;
GtkTreeIter iter;
FILE *fp;
char buf[50];
const char *default_accept_language = "en";
+ const char *languages_file_location;
+ nserror ret;
+
+ ret = nsgtk_path_from_resname("languages", &languages_file_location);
if ((priv->content_language != NULL) &&
- (languages_file_location != NULL) &&
+ (ret == NSERROR_OK) &&
((fp = fopen(languages_file_location, "r")) != NULL)) {
int combo_row_count = 0;
diff --git a/gtk/resources.c b/gtk/resources.c
index f5b13f1df..0c8c192f3 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -45,12 +45,12 @@
#ifdef WITH_BUILTIN_PIXBUF
#ifdef __GNUC__
extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
-const guint8 favicon_pixdata[] __attribute__ ((__aligned__ (4)));
-const guint8 netsurf_pixdata[] __attribute__ ((__aligned__ (4)));
+extern const guint8 favicon_pixdata[] __attribute__ ((__aligned__ (4)));
+extern const guint8 netsurf_pixdata[] __attribute__ ((__aligned__ (4)));
#else
extern const guint8 menu_cursor_pixdata[];
-const guint8 favicon_pixdata[];
-const guint8 netsurf_pixdata[];
+extern const guint8 favicon_pixdata[];
+extern const guint8 netsurf_pixdata[];
#endif
#endif
@@ -126,6 +126,7 @@ static struct nsgtk_resource_s direct_resource[] = {
RES_ENTRY("icons/hotlist-add.png"),
RES_ENTRY("icons/hotlist-rmv.png"),
RES_ENTRY("icons/search.png"),
+ RES_ENTRY("languages"),
RES_ENTRY("Messages"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
@@ -560,3 +561,20 @@ nsgtk_data_from_resname(const char *resname,
return NSERROR_OK;
}
+
+/* exported interface documented in gtk/resources.h */
+nserror
+nsgtk_path_from_resname(const char *resname, const char **path_out)
+{
+ struct nsgtk_resource_s *resource;
+
+ resource = find_resource_from_name(resname, &direct_resource[0]);
+ if ((resource->name == NULL) ||
+ (resource->type != NSGTK_RESOURCE_FILE)) {
+ return NSERROR_NOT_FOUND;
+ }
+
+ *path_out = (const char *)resource->path;
+
+ return NSERROR_OK;
+}
diff --git a/gtk/resources.h b/gtk/resources.h
index dd52f54f1..923031af4 100644
--- a/gtk/resources.h
+++ b/gtk/resources.h
@@ -94,4 +94,16 @@ nserror nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_ou
*/
nserror nsgtk_data_from_resname(const char *resname, const uint8_t **data_out, size_t *data_size_out);
+/**
+ * Get path to resource data.
+ *
+ * For a named resource this obtains the on-disc path to that resource.
+ *
+ * The path is read only and remains valid untill program exit.
+ * \param resname The resource name to obtain path for.
+ * \param path_out The resulting data.
+ * \return NSERROR_OK and path_out updated or appropriate error code.
+ */
+nserror nsgtk_path_from_resname(const char *resname, const char **path_out);
+
#endif
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c
index c19624257..a45224c81 100644
--- a/gtk/scaffolding.c
+++ b/gtk/scaffolding.c
@@ -25,7 +25,6 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "utils/filepath.h"
#include "utils/messages.h"
#include "utils/corestrings.h"
#include "utils/log.h"