mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-19 02:32:44 +03:00
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.
This commit is contained in:
parent
11dc7304d9
commit
ee74f9ac8c
@ -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>
|
||||
|
@ -238,10 +238,10 @@ 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);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
31
gtk/gui.c
31
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,19 +245,20 @@ 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 languages file was found in,
|
||||
* Uses the directory the theme file was found in,
|
||||
* @todo find and slaughter all references to this!
|
||||
*/
|
||||
res_dir_location = calloc(1, strlen(languages_file_location) - 8);
|
||||
res_dir_location = calloc(1, strlen(themelist_file_location) - 8);
|
||||
memcpy(res_dir_location,
|
||||
languages_file_location,
|
||||
strlen(languages_file_location) - 9);
|
||||
themelist_file_location,
|
||||
strlen(themelist_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) {
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user