This moves message loading out of netsurf_init into each frontend

The translated message loading is dependant on configuration of
resource location in each frontend, additionally they should have the
ability to deal with errors in this loading in a implementation
specific manner.

This also extends the message loading API to be capable of loading
from an inline memory buffer instead of from a file.
This commit is contained in:
Vincent Sanders 2015-06-19 16:29:42 +01:00
parent 335bbe4f52
commit 67ded2a02a
14 changed files with 90 additions and 31 deletions

View File

@ -5499,7 +5499,9 @@ int main(int argc, char** argv)
return RETURN_FAIL;
}
ret = netsurf_init(messages, current_user_cache);
ret = messages_add_from_file(messages);
ret = netsurf_init(current_user_cache);
if (ret != NSERROR_OK) {
ami_misc_fatal_error("NetSurf failed to initialise");
return RETURN_FAIL;

View File

@ -152,7 +152,7 @@ void ami_theme_init(void)
if(lock)
{
UnLock(lock);
messages_load(themefile);
messages_add_from_file(themefile);
}
}

View File

@ -1169,9 +1169,11 @@ int main(int argc, char** argv)
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
ret = messages_add_from_file(messages);
/* common initialisation */
LOG("Initialising core...");
ret = netsurf_init(messages, store);
ret = netsurf_init(store);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}

View File

@ -1035,7 +1035,9 @@ int main(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
ret = netsurf_init(messages.Path(), NULL);
ret = messages_add_from_file(messages.Path());
ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
@ -1096,7 +1098,9 @@ int gui_init_replicant(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
ret = netsurf_init(messages.Path(), NULL);
ret = messages_add_from_file(messages.Path());
ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
// FIXME: must not die when in replicant!
die("NetSurf failed to initialise");

View File

@ -248,8 +248,10 @@ int main( int argc, char **argv )
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
error = messages_add_from_file(messages);
/* common initialisation */
error = netsurf_init(messages, NULL);
error = netsurf_init(NULL);
if (error != NSERROR_OK) {
die("NetSurf failed to initialise");
}

View File

@ -122,7 +122,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query,
}
/* exported interface documented in desktop/netsurf.h */
nserror netsurf_init(const char *messages, const char *store_path)
nserror netsurf_init(const char *store_path)
{
nserror ret;
struct hlcache_parameters hlcache_parameters = {
@ -151,8 +151,6 @@ nserror netsurf_init(const char *messages, const char *store_path)
signal(SIGPIPE, SIG_IGN);
#endif
messages_load(messages);
/* corestrings init */
ret = corestrings_init();
if (ret != NSERROR_OK)

View File

@ -40,11 +40,10 @@ nserror netsurf_register(struct netsurf_table *table);
/**
* Initialise netsurf core.
*
* @param messages path to translation mesage file.
* @param store_path path to persistant storage.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror netsurf_init(const char *messages, const char *store_path);
nserror netsurf_init(const char *store_path);
/**
* Finalise NetSurf core

View File

@ -2107,9 +2107,12 @@ main(int argc, char** argv)
free(options);
nsoption_commandline(&argc, argv, nsoptions);
/* common initialisation */
/* message init */
messages = filepath_find(respaths, "Messages");
ret = netsurf_init(messages, NULL);
ret = messages_add_from_file(messages);
/* common initialisation */
ret = netsurf_init(NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");

View File

@ -508,7 +508,7 @@ void warn_user(const char *warning, const char *detail)
static GtkWindow *nsgtk_warning_window;
GtkLabel *WarningLabel;
LOG("%s %s", warning, detail ? detail : "");
LOG("%s %s", warning, detail ? detail : "");
fflush(stdout);
nsgtk_warning_window = GTK_WINDOW(gtk_builder_get_object(warning_builder, "wndWarning"));
@ -553,13 +553,13 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data)
if (op[0] == '\0') {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")),
"Owner password must be at least 1 character long:");
"Owner password must be at least 1 character long:");
free(op);
free(up);
} else if (!strcmp(op, up)) {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")),
"User and owner passwords must be different:");
"User and owner passwords must be different:");
free(op);
free(up);
} else if (!strcmp(op, op1) && !strcmp(up, up1)) {
@ -1043,12 +1043,26 @@ static struct gui_browser_table nsgtk_browser_table = {
.pdf_password = nsgtk_pdf_password,
};
static nserror nsgtk_messages_init(char **respaths)
{
char *messages;
nserror ret = NSERROR_NOT_FOUND;
/* Obtain path to messages */
messages = filepath_find(respaths, "Messages");
if (messages != NULL) {
ret = messages_add_from_file(messages);
free(messages);
}
return ret;
}
/**
* Main entry point from OS.
*/
int main(int argc, char** argv)
{
char *messages;
char *cache_home = NULL;
nserror ret;
struct netsurf_table nsgtk_table = {
@ -1110,8 +1124,14 @@ int main(int argc, char** argv)
return 1;
}
/* Obtain path to messages */
messages = filepath_find(respaths, "Messages");
/* Initialise translated messages */
ret = nsgtk_messages_init(respaths);
if (ret != NSERROR_OK) {
fprintf(stderr, "Unable to load translated messages (%s)\n",
messages_get_errorcode(ret));
LOG("Unable to load translated messages");
/** \todo decide if message load faliure should be fatal */
}
/* Locate the correct user cache directory path */
ret = get_cache_home(&cache_home);
@ -1124,8 +1144,7 @@ int main(int argc, char** argv)
}
/* core initialisation */
ret = netsurf_init(messages, cache_home);
free(messages);
ret = netsurf_init(cache_home);
free(cache_home);
if (ret != NSERROR_OK) {
fprintf(stderr, "NetSurf core failed to initialise (%s)\n",

View File

@ -172,9 +172,14 @@ main(int argc, char **argv)
free(options);
nsoption_commandline(&argc, argv, nsoptions);
/* common initialisation */
messages = filepath_find(respaths, "Messages");
ret = netsurf_init(messages, NULL);
ret = messages_add_from_file(messages);
if (ret != NSERROR_OK) {
LOG("Messages failed to load");
}
/* common initialisation */
ret = netsurf_init(NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");

View File

@ -2481,11 +2481,14 @@ int main(int argc, char** argv)
die("Failed to locate Messages resource.");
}
/* initialise messages */
messages_add_from_file(path);
/* obtain cache path */
cachepath = get_cachepath();
/* common initialisation */
ret = netsurf_init(path, cachepath);
ret = netsurf_init(cachepath);
free(cachepath);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise core");
@ -2496,7 +2499,7 @@ int main(int argc, char** argv)
sprite_init();
/* Load some extra RISC OS specific Messages */
messages_load("NetSurf:Resources.LangNames");
messages_add_from_file("NetSurf:Resources.LangNames");
ret = gui_init(argc, argv);
if (ret != NSERROR_OK) {

View File

@ -142,7 +142,7 @@ messages_get_ctx(const char *key, struct hash_table *ctx)
}
/* exported interface documented in messages.h */
nserror messages_load(const char *path)
nserror messages_add_from_file(const char *path)
{
nserror err;
@ -157,6 +157,12 @@ nserror messages_load(const char *path)
return err;
}
/* exported interface documented in messages.h */
nserror messages_add_from_inline(const char *data)
{
return NSERROR_OK;
}
/* exported interface documented in messages.h */
char *messages_get_buff(const char *key, ...)
{

View File

@ -38,13 +38,26 @@
/**
* Read keys and values from messages file into the standard Messages hash.
*
* The messages are merged with any previously loaded messages. Any keys which
* are present already are replaced with the new value.
* The messages are merged with any previously loaded messages. Any
* keys which are present already are replaced with the new value. The
* file may be gzip compressed.
*
* \param path pathname of messages file.
* \return NSERROR_OK on success or error code on faliure.
*/
nserror messages_load(const char *path);
nserror messages_add_from_file(const char *path);
/**
* Read keys and values from inline message data into the standard Messages hash.
*
* The messages are merged with any previously loaded messages. Any
* keys which are present already are replaced with the new value. The
* data may be gzip compressed.
*
* \param data The inline message data.
* \return NSERROR_OK on success or error code on faliure.
*/
nserror messages_add_from_inline(const char *data);
/**
* Fast lookup of a message by key from the standard Messages hash.

View File

@ -183,10 +183,13 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
nsoption_read(options_file_location, NULL);
nsoption_commandline(&argc, argv, NULL);
/* common initialisation */
/* message init */
messages = filepath_find(respaths, "messages");
ret = netsurf_init(messages, NULL);
messages_add_from_file(messages);
free(messages);
/* common initialisation */
ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
free(options_file_location);
LOG("NetSurf failed to initialise");