summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2010-07-28 15:22:44 +0000
committerVincent Sanders <vince@netsurf-browser.org>2010-07-28 15:22:44 +0000
commitbda534e12a5071434d700d91750f9c1eaa422812 (patch)
treedf2f256fd55d6e5589e59074aba1ee6edada9848 /gtk
parent4bfd6ea6f0b68202a00f9faa29ad6ff0144af0d9 (diff)
downloadnetsurf-bda534e12a5071434d700d91750f9c1eaa422812.tar.gz
netsurf-bda534e12a5071434d700d91750f9c1eaa422812.tar.bz2
Clean up how GTK frontend finds resources
svn path=/trunk/netsurf/; revision=10668
Diffstat (limited to 'gtk')
-rw-r--r--gtk/dialogs/gtk_options.c47
-rw-r--r--gtk/gtk_download.c16
-rw-r--r--gtk/gtk_download.h2
-rw-r--r--gtk/gtk_gui.c606
-rw-r--r--gtk/gtk_gui.h12
-rw-r--r--gtk/gtk_history.c17
-rw-r--r--gtk/gtk_history.h2
-rw-r--r--gtk/gtk_tabs.c1
8 files changed, 354 insertions, 349 deletions
diff --git a/gtk/dialogs/gtk_options.c b/gtk/dialogs/gtk_options.c
index b883195b4..dae0c8581 100644
--- a/gtk/dialogs/gtk_options.c
+++ b/gtk/dialogs/gtk_options.c
@@ -136,11 +136,9 @@ DECLARE(setDefaultExportOptions);
GtkDialog* nsgtk_options_init(struct browser_window *bw, GtkWindow *parent)
{
- char glade_location[strlen(res_dir_location) + SLEN("options.glade")
- + 1];
- sprintf(glade_location, "%soptions.glade", res_dir_location);
- LOG(("Using '%s' as Glade template file", glade_location));
- gladeFile = glade_xml_new(glade_location, NULL, NULL);
+ gladeFile = glade_xml_new(glade_options_file_location, NULL, NULL);
+ if (gladeFile == NULL)
+ return NULL;
current_browser = bw;
wndPreferences = GTK_DIALOG(glade_xml_get_widget(gladeFile,
@@ -288,7 +286,6 @@ GtkDialog* nsgtk_options_init(struct browser_window *bw, GtkWindow *parent)
void nsgtk_options_load(void)
{
GtkBox *box;
- char languagefile[strlen(res_dir_location) + SLEN("languages") + 1];
const char *default_accept_language =
option_accept_language ? option_accept_language : "en";
int combo_row_count = 0;
@@ -301,33 +298,33 @@ void nsgtk_options_load(void)
box = GTK_BOX(glade_xml_get_widget(gladeFile, "combolanguagevbox"));
comboLanguage = gtk_combo_box_new_text();
- sprintf(languagefile, "%slanguages", res_dir_location);
-
/* Populate combobox from languages file */
- fp = fopen((const char *) languagefile, "r");
- if (fp == NULL) {
- LOG(("Failed opening languages file"));
- warn_user("FileError", (const char *) languagefile);
- return;
- }
+ if ((languages_file_location != NULL) &&
+ ((fp = fopen(languages_file_location, "r")) != NULL)) {
+ LOG(("Used %s for languages", languages_file_location));
+ while (fgets(buf, sizeof(buf), fp)) {
+ /* Ignore blank lines */
+ if (buf[0] == '\0')
+ continue;
- while (fgets(buf, sizeof(buf), fp)) {
- /* Ignore blank lines */
- if (buf[0] == '\0')
- continue;
+ /* Remove trailing \n */
+ buf[strlen(buf) - 1] = '\0';
- /* Remove trailing \n */
- buf[strlen(buf) - 1] = '\0';
+ gtk_combo_box_append_text(GTK_COMBO_BOX(comboLanguage), buf);
- gtk_combo_box_append_text(GTK_COMBO_BOX(comboLanguage), buf);
+ if (strcmp(buf, default_accept_language) == 0)
+ active_language = combo_row_count;
- if (strcmp(buf, default_accept_language) == 0)
- active_language = combo_row_count;
+ combo_row_count++;
+ }
- combo_row_count++;
+ fclose(fp);
+ } else {
+ LOG(("Failed opening languages file"));
+ warn_user("FileError", languages_file_location);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(comboLanguage), "en");
}
- fclose(fp);
gtk_combo_box_set_active(GTK_COMBO_BOX(comboLanguage), active_language);
/** \todo localisation */
diff --git a/gtk/gtk_download.c b/gtk/gtk_download.c
index 6b4e326bf..4d58f389d 100644
--- a/gtk/gtk_download.c
+++ b/gtk/gtk_download.c
@@ -36,7 +36,6 @@
#include "gtk/gtk_compat.h"
#define UPDATE_RATE 500 /* In milliseconds */
-#define GLADE_NAME "downloads.glade"
static GtkWindow *nsgtk_download_window, *nsgtk_download_parent;
static GtkProgressBar *nsgtk_download_progress_bar;
@@ -85,12 +84,14 @@ static gboolean nsgtk_download_handle_error (GError *error);
-void nsgtk_download_init()
+bool nsgtk_download_init()
{
- char glade_location[strlen(res_dir_location) + SLEN(GLADE_NAME) + 1];
- sprintf(glade_location, "%s" GLADE_NAME, res_dir_location);
- GladeXML *gladeFile = glade_xml_new(glade_location, NULL, NULL);
-
+ GladeXML *gladeFile;
+
+ gladeFile = glade_xml_new(glade_downloads_file_location, NULL, NULL);
+ if (gladeFile == NULL)
+ return false;
+
nsgtk_download_buttons =
glade_xml_get_widget_prefix(gladeFile, "button");
nsgtk_download_progress_bar = GTK_PROGRESS_BAR(glade_xml_get_widget(
@@ -150,7 +151,8 @@ void nsgtk_download_init()
nsgtk_download_store_cancel_item);
g_signal_connect(G_OBJECT(nsgtk_download_window), "delete-event",
G_CALLBACK(nsgtk_download_hide), NULL);
-
+
+ return true;
}
void nsgtk_download_destroy ()
diff --git a/gtk/gtk_download.h b/gtk/gtk_download.h
index 7e14600d4..e38c51632 100644
--- a/gtk/gtk_download.h
+++ b/gtk/gtk_download.h
@@ -72,7 +72,7 @@ struct gui_download_window {
typedef void (*nsgtk_download_selection_action)(struct gui_download_window *dl);
-void nsgtk_download_init(void);
+bool nsgtk_download_init(void);
void nsgtk_download_destroy (void);
bool nsgtk_check_for_downloads(GtkWindow *parent);
void nsgtk_download_show(GtkWindow *parent);
diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c
index 6c3916a3a..a9e428b19 100644
--- a/gtk/gtk_gui.c
+++ b/gtk/gtk_gui.c
@@ -65,6 +65,7 @@
#include "gtk/gtk_filetype.h"
#include "gtk/gtk_download.h"
#include "gtk/gtk_schedule.h"
+
#include "render/box.h"
#include "render/form.h"
#include "render/html.h"
@@ -73,35 +74,34 @@
#include "utils/url.h"
#include "utils/utf8.h"
#include "utils/utils.h"
+#include "utils/findresource.h"
char *default_stylesheet_url;
char *quirks_stylesheet_url;
char *adblock_stylesheet_url;
char *options_file_location;
+char *toolbar_indices_file_location;
+char *res_dir_location;
+char *print_options_file_location;
+char *languages_file_location;
+
char *glade_netsurf_file_location;
char *glade_password_file_location;
char *glade_warning_file_location;
char *glade_login_file_location;
char *glade_ssl_file_location;
char *glade_toolbar_file_location;
-char *toolbar_indices_file_location;
-char *res_dir_location;
-char *print_options_file_location;
+char *glade_downloads_file_location;
+char *glade_history_file_location;
+char *glade_options_file_location;
GtkWindow *wndWarning;
-GladeXML *gladeNetsurf;
-GladeXML *gladePassword;
-GladeXML *gladeWarning;
-GladeXML *gladeLogin;
-GladeXML *gladeSsl;
+GtkWidget *widWarning;
static GtkWidget *select_menu;
static struct browser_window *select_menu_bw;
static struct form_control *select_menu_control;
-static void nsgtk_init_glade(void);
-static void nsgtk_check_homedir(void);
-static bool nsgtk_throbber_init(int framec);
static void nsgtk_ssl_accept(GtkButton *w, gpointer data);
static void nsgtk_ssl_reject(GtkButton *w, gpointer data);
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
@@ -113,190 +113,222 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data);
#define THROBBER_FRAMES 9
+#define MAX_RESPATH 128 /* maximum number of elements in the resource vector */
+
+/* expand ${} in a string into environment variables */
static char *
-nsgtk_vsfindfile(char *str, const char *format, va_list ap)
+expand_path(const char *path)
{
- char *realpathname;
- char *pathname;
- int len;
+ char *exp = strdup(path);
+ int explen;
+ int cstart = -1;
+ int cloop = 0;
+ char *envv;
+ int envlen;
+ int replen; /* length of replacement */
+
+ if (exp == NULL)
+ return NULL;
- pathname = malloc(PATH_MAX);
- if (pathname == NULL)
- return NULL; /* unable to allocate memory */
+ explen = strlen(exp) + 1;
+
+ while (exp[cloop] != 0) {
+ if ((exp[cloop] == '$') &&
+ (exp[cloop + 1] == '{')) {
+ cstart = cloop;
+ cloop++;
+ }
+
+ if ((cstart != -1) &&
+ (exp[cloop] == '}')) {
+ replen = cloop - cstart;
+ exp[cloop] = 0;
+ envv = getenv(exp + cstart + 2);
+ if (envv == NULL) {
+ memmove(exp + cstart,
+ exp + cloop + 1,
+ explen - cloop - 1);
+ explen -= replen;
+ } else {
+ envlen = strlen(envv);
+ exp = realloc(exp, explen + envlen - replen);
+ memmove(exp + cstart + envlen,
+ exp + cloop + 1,
+ explen - cloop - 1);
+ memmove(exp + cstart, envv, envlen);
+ explen += envlen - replen;
+ }
+ cloop -= replen;
+ cstart = -1;
+ }
- len = vsnprintf(pathname, PATH_MAX, format, ap);
+ cloop++;
+ }
- if ((len < 0) || (len >= PATH_MAX)) {
- /* error or output exceeded PATH_MAX length so
- * operation is doomed to fail.
- */
- free(pathname);
+ return exp;
+}
+
+/* convert a colon separated list of path elements into a string vector */
+static char **
+path_to_strvec(const char *path)
+{
+ char **strvec;
+ int strc = 0;
+
+ strvec = calloc(MAX_RESPATH, sizeof(char *));
+ if (strvec == NULL)
return NULL;
- }
- realpathname = realpath(pathname, str);
-
- free(pathname);
-
- if (realpathname != NULL) {
- /* sucessfully expanded pathname */
- if (access(realpathname, R_OK) != 0) {
- /* unable to read the file */
- return NULL;
- }
+ strvec[strc] = expand_path(path);
+ if (strvec[strc] == NULL) {
+ free(strvec);
+ return NULL;
}
+ strc++;
- return realpathname;
-}
+ strvec[strc] = strchr(strvec[0], ':');
+ while ((strc < (MAX_RESPATH - 2)) &&
+ (strvec[strc] != NULL)) {
+ /* null terminate previous entry */
+ *strvec[strc] = 0;
+ strvec[strc]++;
-static char *
-nsgtk_sfindfile(char *str, const char *format, ...)
-{
- va_list ap;
- char *ret;
+ /* skip colons */
+ while (*strvec[strc] == ':')
+ strvec[strc]++;
- va_start(ap, format);
- ret = nsgtk_vsfindfile(str, format, ap);
- va_end(ap);
+ if (*strvec[strc] == 0)
+ break; /* string is terminated */
- return ret;
+ strc++;
+
+ strvec[strc] = strchr(strvec[strc - 1], ':');
+ }
+
+ return strvec;
}
-/* create a normalised path
+
+/** Create an array of valid paths to search for resources.
*
- * if the file described by the format exists and is accessible the
- * normalised path is returned or NULL if not.
+ * 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.
*/
-static char *
-nsgtk_findfile(const char *format, ...)
+static char **
+nsgtk_init_resource(const char *resource_path)
{
- char *str;
- char *ret;
- va_list ap;
+ const gchar * const *langv;
+ char **pathv; /* resource path string vector */
+ char **respath; /* resource paths vector */
- str = malloc(PATH_MAX);
- if (str == NULL)
- return NULL; /* unable to allocate memory */
+ pathv = path_to_strvec(resource_path);
- va_start(ap, format);
- ret = nsgtk_vsfindfile(str, format, ap);
- va_end(ap);
+ langv = g_get_language_names();
- if (ret == NULL)
- free(str);
+ respath = findresource_generate(pathv, langv);
- return ret;
-}
+ free(pathv[0]);
+ free(pathv);
+ return respath;
+}
-static char *
-nsgtk_find_messages(void)
+/* This is an ugly hack to just get the new-style throbber going.
+ * It, along with the PNG throbber loader, need making more generic.
+ */
+static bool nsgtk_throbber_init(char **respath, int framec)
{
- int lang_loop = 0;
- char *buf;
- const gchar * const *lang_list;
-
- lang_list = g_get_language_names();
+ char **filenames;
+ char targetname[PATH_MAX];
+ int frame_num;
+ bool ret;
- while (lang_list[lang_loop] != NULL) {
- buf = nsgtk_findfile("%s/%s/Messages", getenv("NETSURFRES"), lang_list[lang_loop]);
+ filenames = calloc(framec, sizeof(char *));
+ if (filenames == NULL)
+ return false;
- if (buf != NULL)
- return buf;
+ for (frame_num = 0; frame_num < framec; frame_num++) {
+ snprintf(targetname, PATH_MAX, "throbber/throbber%d.png", frame_num);
+ filenames[frame_num] = findresource(respath, targetname);
+ }
- buf = nsgtk_findfile("%s/%s/Messages", GTK_RESPATH, lang_list[lang_loop]);
- if (buf != NULL)
- return buf;
+ ret = nsgtk_throbber_initialise_from_png(frame_num, filenames);
- lang_loop++;
+ for (frame_num = 0; frame_num < framec; frame_num++) {
+ free(filenames[frame_num]);
}
+ free(filenames);
- buf = nsgtk_findfile("./gtk/res/en/Messages");
- if (buf != NULL)
- return buf;
-
- buf = strdup("./gtk/res/messages");
+ return ret;
- return buf;
}
-/**
- * Locate a shared resource file by searching known places in order.
- *
- * \param buf buffer to write to. must be at least PATH_MAX chars. May be NULL and routine will allocate string which must be freed by caller.
- * \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 the define
- * GTK_RESPATH.
- */
+#define NEW_GLADE_ERROR_SIZE 128
+
static char *
-nsgtk_find_resource(char *buf, const char *filename, const char *def)
+nsgtk_new_glade(char **respath, const char *name, GladeXML **pglade)
{
- if (buf == NULL) {
- buf = malloc(PATH_MAX);
- if (buf == NULL)
- return NULL;
+ GladeXML *newglade;
+ char *filepath;
+ char errorstr[NEW_GLADE_ERROR_SIZE];
+ char resname[PATH_MAX];
+
+ snprintf(resname, PATH_MAX, "%s.glade", name);
+
+ filepath = findresource(respath, resname);
+ if (filepath == NULL) {
+ snprintf(errorstr, NEW_GLADE_ERROR_SIZE,
+ "Unable to locate %s glade template file.\n", name);
+ die(errorstr);
}
- if (nsgtk_sfindfile(buf, "%s/.netsurf/%s", getenv("HOME"), filename) != NULL)
- return buf;
-
- if (nsgtk_sfindfile(buf, "%s/%s", getenv("NETSURFRES"), filename) != NULL)
- return buf;
+ newglade = glade_xml_new(filepath, NULL, NULL);
+ if (newglade == NULL) {
+ snprintf(errorstr, NEW_GLADE_ERROR_SIZE,
+ "Unable to load glade %s window definitions.\n", name);
- if (nsgtk_sfindfile(buf, "%s/%s", GTK_RESPATH, filename) != NULL)
- return buf;
+ die(errorstr);
+ }
+ glade_xml_signal_autoconnect(newglade);
+ LOG(("Using '%s' as %s glade template file", filepath, name));
- if (def[0] == '~') {
- char t[PATH_MAX];
- 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);
- }
+ if (pglade != NULL) {
+ *pglade = newglade;
}
- return buf;
+ return filepath;
}
-
/**
- * Initialize GTK interface.
+ * Load definitions from glade files.
*/
-static void gui_init(int argc, char** argv)
+static void
+nsgtk_init_glade(char **respath)
{
- char buf[PATH_MAX];
- struct browser_window *bw;
- const char *addr = NETSURF_HOMEPAGE;
+ GladeXML *gladeWarning;
- nsgtk_check_homedir();
-
- nsgtk_find_resource(buf, "netsurf.glade", "./gtk/res/netsurf.glade");
- buf[strlen(buf) - 13] = 0;
- LOG(("Using '%s' as Resources directory", buf));
- res_dir_location = strdup(buf);
-
- nsgtk_init_glade();
-
- nsgtk_find_resource(buf, "Aliases", "./gtk/res/Aliases");
- LOG(("Using '%s' as Aliases file", buf));
- if (hubbub_initialise(buf, ns_realloc, NULL) != HUBBUB_OK)
- die("Unable to initialise HTML parsing library.\n");
+ glade_init();
- nsgtk_find_resource(buf, "netsurf.xpm", "./gtk/res/netsurf.xpm");
- gtk_window_set_default_icon_from_file(buf, NULL);
+ glade_netsurf_file_location = nsgtk_new_glade(respath, "netsurf", NULL);
+ glade_password_file_location = nsgtk_new_glade(respath, "password", NULL);
+ glade_login_file_location = nsgtk_new_glade(respath, "login", NULL);
+ glade_ssl_file_location = nsgtk_new_glade(respath, "ssl", NULL);
+ glade_toolbar_file_location = nsgtk_new_glade(respath, "toolbar", NULL);
+ glade_downloads_file_location = nsgtk_new_glade(respath, "downloads", NULL);
+ glade_history_file_location = nsgtk_new_glade(respath, "history", NULL);
+ glade_options_file_location = nsgtk_new_glade(respath, "options", NULL);
- nsgtk_completion_init();
+ glade_warning_file_location = nsgtk_new_glade(respath, "warning", &gladeWarning);
+ wndWarning = GTK_WINDOW(glade_xml_get_widget(gladeWarning, "wndWarning"));
+ widWarning = glade_xml_get_widget(gladeWarning, "labelWarning");
+}
- if (nsgtk_throbber_init(THROBBER_FRAMES) == false)
- die("Unable to load throbber image.\n");
+static void check_options(char **respath)
+{
+ char *hdir = getenv("HOME");
+ char buf[PATH_MAX];
option_core_select_menu = true;
@@ -310,23 +342,21 @@ static void gui_init(int argc, char** argv)
option_toolbar_status_width = 6667;
}
- /* check what the font settings are, setting them to a default font
- * if they're not set - stops Pango whinging
- */
-#define SETFONTDEFAULT(x,y) (x) = ((x) != NULL) ? (x) : strdup((y))
- SETFONTDEFAULT(option_font_sans, "Sans");
- SETFONTDEFAULT(option_font_serif, "Serif");
- SETFONTDEFAULT(option_font_mono, "Monospace");
- SETFONTDEFAULT(option_font_cursive, "Serif");
- SETFONTDEFAULT(option_font_fantasy, "Serif");
+ /* user options should be stored in the users home directory */
+ snprintf(buf, PATH_MAX, "%s/.netsurf/Choices", hdir);
+ options_file_location = strdup(buf);
+ /* VRS - I do not beleive these setting should search the
+ * resource path, they should just be set to the default
+ * values!
+ */
if (!option_cookie_file) {
- nsgtk_find_resource(buf, "Cookies", "~/.netsurf/Cookies");
+ sfindresourcedef(respath, buf, "Cookies", "~/.netsurf/");
LOG(("Using '%s' as Cookies file", buf));
option_cookie_file = strdup(buf);
}
if (!option_cookie_jar) {
- nsgtk_find_resource(buf, "Cookies", "~/.netsurf/Cookies");
+ sfindresourcedef(respath, buf, "Cookies", "~/.netsurf/");
LOG(("Using '%s' as Cookie Jar file", buf));
option_cookie_jar = strdup(buf);
}
@@ -334,61 +364,126 @@ static void gui_init(int argc, char** argv)
die("Failed initialising cookie options");
if (!option_url_file) {
- nsgtk_find_resource(buf, "URLs", "~/.netsurf/URLs");
+ sfindresourcedef(respath, buf, "URLs", "~/.netsurf/");
LOG(("Using '%s' as URL file", buf));
option_url_file = strdup(buf);
}
if (!option_ca_path) {
- nsgtk_find_resource(buf, "certs", "/etc/ssl/certs");
+ sfindresourcedef(respath, buf, "certs", "/etc/ssl/");
LOG(("Using '%s' as certificate path", buf));
option_ca_path = strdup(buf);
}
if (!option_downloads_directory) {
- char *home = getenv("HOME");
- LOG(("Using '%s' as download directory", home));
- option_downloads_directory = home;
+ LOG(("Using '%s' as download directory", hdir));
+ option_downloads_directory = hdir;
+ }
+
+ sfindresourcedef(respath, buf, "Print", "~/.netsurf/");
+ LOG(("Using '%s' as Print Settings file", buf));
+ print_options_file_location = strdup(buf);
+
+ /* check what the font settings are, setting them to a default font
+ * if they're not set - stops Pango whinging
+ */
+#define SETFONTDEFAULT(x,y) (x) = ((x) != NULL) ? (x) : strdup((y))
+ SETFONTDEFAULT(option_font_sans, "Sans");
+ SETFONTDEFAULT(option_font_serif, "Serif");
+ SETFONTDEFAULT(option_font_mono, "Monospace");
+ SETFONTDEFAULT(option_font_cursive, "Serif");
+ SETFONTDEFAULT(option_font_fantasy, "Serif");
+
+}
+
+/**
+ * Initialize GTK interface.
+ */
+static void gui_init(int argc, char** argv, char **respath)
+{
+ char buf[PATH_MAX];
+ struct browser_window *bw;
+ const char *addr = NETSURF_HOMEPAGE;
+ char *resource_filename;
+
+ /* check user options */
+ check_options(respath);
+
+ /* Character encoding mapping file *must* be available */
+ resource_filename = findresource(respath, "Aliases");
+ if (resource_filename == NULL)
+ die("Unable to locate file for character encoding mapping\n");
+ LOG(("Using '%s' as Aliases file", resource_filename));
+ if (hubbub_initialise(resource_filename, ns_realloc, NULL) != HUBBUB_OK)
+ die("Unable to initialise HTML parsing library.\n");
+ free(resource_filename);
+
+ /* Obtain resources path location.
+ *
+ * Uses the directory the languages file was found in,
+ * previously the location of the glade files was used,
+ * however these may be translated which breaks things
+ * relying on res_dir_location.
+ */
+ resource_filename = findresource(respath, "languages");
+ resource_filename[strlen(resource_filename) - 9] = 0;
+ res_dir_location = resource_filename;
+
+ /* languages file */
+ languages_file_location = findresource(respath, "languages");
+
+ /* initialise the glade templates */
+ nsgtk_init_glade(respath);
+
+ /* set default icon if its available */
+ resource_filename = findresource(respath, "netsurf.xpm");
+ if (resource_filename != NULL) {
+ gtk_window_set_default_icon_from_file(resource_filename, NULL);
+ free(resource_filename);
}
+ /* Search engine sources */
+ search_engines_file_location = findresource(respath, "SearchEngines");
+ LOG(("Using '%s' as Search Engines file", search_engines_file_location));
- nsgtk_find_resource(buf, "mime.types", "/etc/mime.types");
+ /* Default Icon */
+ search_default_ico_location = findresource(respath, "default.ico");
+ LOG(("Using '%s' as default search ico", search_default_ico_location));
+
+ /* Toolbar inicies file */
+ toolbar_indices_file_location = findresource(respath, "toolbarIndices");
+ LOG(("Using '%s' as custom toolbar settings file", toolbar_indices_file_location));
+
+ /* load throbber images */
+ if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false)
+ die("Unable to load throbber image.\n");
+
+ /* Initialise completions - cannot fail */
+ nsgtk_completion_init();
+
+ sfindresourcedef(respath, buf, "mime.types", "/etc/");
gtk_fetch_filetype_init(buf);
/* set up stylesheet urls */
- nsgtk_find_resource(buf, "gtkdefault.css", "./gtk/res/gtkdefault.css");
+ sfindresourcedef(respath, buf, "gtkdefault.css", "./gtk/res/");
default_stylesheet_url = path_to_url(buf);
LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
- nsgtk_find_resource(buf, "quirks.css", "./gtk/res/quirks.css");
+ sfindresourcedef(respath, buf, "quirks.css", "./gtk/res/");
quirks_stylesheet_url = path_to_url(buf);
- nsgtk_find_resource(buf, "adblock.css", "./gtk/res/adblock.css");
+ sfindresourcedef(respath, buf, "adblock.css", "./gtk/res/");
adblock_stylesheet_url = path_to_url(buf);
LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
- nsgtk_find_resource(buf, "Print", "~/.netsurf/Print");
- LOG(("Using '%s' as Print Settings file", buf));
- print_options_file_location = strdup(buf);
-
- nsgtk_find_resource(buf, "SearchEngines", "./gtk/res/SearchEngines");
- LOG(("Using '%s' as Search Engines file", buf));
- search_engines_file_location = strdup(buf);
-
- nsgtk_find_resource(buf, "default.ico", "./gtk/res/default.ico");
- LOG(("Using '%s' as default search ico", buf));
- search_default_ico_location = strdup(buf);
-
- nsgtk_find_resource(buf, "toolbarIndices", "./gtk/res/toolbarIndices");
- LOG(("Using '%s' as custom toolbar settings file", buf));
- toolbar_indices_file_location = strdup(buf);
-
urldb_load(option_url_file);
urldb_load_cookies(option_cookie_file);
- nsgtk_history_init();
- nsgtk_download_init();
+ if (nsgtk_history_init() == false)
+ die("Unable to initialise history window.\n");
+ if (nsgtk_download_init() == false)
+ die("Unable to initialise download window.\n");
if (option_homepage_url != NULL && option_homepage_url[0] != '\0')
addr = option_homepage_url;
@@ -397,71 +492,33 @@ static void gui_init(int argc, char** argv)
addr = argv[1];
/* Last step of initialization. Opens the main browser window. */
-
bw = browser_window_create(addr, 0, 0, true, false);
-
}
/**
- * Load definitions from glade files.
+ * Check that ~/.netsurf/ exists, and if it doesn't, create it.
*/
-void nsgtk_init_glade(void)
+static void nsgtk_check_homedir(void)
{
+ char *hdir = getenv("HOME");
char buf[PATH_MAX];
- glade_init();
-
- nsgtk_find_resource(buf, "netsurf.glade", "./gtk/res/netsurf.glade");
- LOG(("Using '%s' as Netsurf glade template file", buf));
- glade_netsurf_file_location = strdup(buf);
-
- nsgtk_find_resource(buf, "password.glade", "./gtk/res/password.glade");
- LOG(("Using '%s' as password glade template file", buf));
- glade_password_file_location = strdup(buf);
-
- nsgtk_find_resource(buf, "warning.glade", "./gtk/res/warning.glade");
- LOG(("Using '%s' as warning glade template file", buf));
- glade_warning_file_location = strdup(buf);
-
- nsgtk_find_resource(buf, "login.glade", "./gtk/res/login.glade");
- LOG(("Using '%s' as login glade template file", buf));
- glade_login_file_location = strdup(buf);
-
- nsgtk_find_resource(buf, "ssl.glade", "./gtk/res/ssl.glade");
- LOG(("Using '%s' as ssl glade template file", buf));
- glade_ssl_file_location = strdup(buf);
-
- gladeWarning = glade_xml_new(glade_warning_file_location, NULL, NULL);
- if (gladeWarning == NULL)
- die("Unable to load glade warning window definitions.\n");
- glade_xml_signal_autoconnect(gladeWarning);
-
- gladeNetsurf = glade_xml_new(glade_netsurf_file_location, NULL, NULL);
- if (gladeNetsurf == NULL)
- die("Unable to load glade Netsurf window definitions.\n");
- glade_xml_signal_autoconnect(gladeNetsurf);
-
- gladePassword = glade_xml_new(glade_password_file_location, NULL, NULL);
- if (gladePassword == NULL)
- die("Unable to load glade password window definitions.\n");
- glade_xml_signal_autoconnect(gladePassword);
-
- gladeLogin = glade_xml_new(glade_login_file_location, NULL, NULL);
- if (gladeLogin == NULL)
- die("Unable to load glade login window definitions.\n");
- glade_xml_signal_autoconnect(gladeLogin);
-
- gladeSsl = glade_xml_new(glade_ssl_file_location, NULL, NULL);
- if (gladeSsl == NULL)
- die("Unable to load glade ssl window definitions.\n");
- glade_xml_signal_autoconnect(gladeSsl);
+ if (hdir == NULL) {
+ /* we really can't continue without a home directory. */
+ LOG(("HOME is not set - nowhere to store state!"));
+ die("NetSurf requires HOME to be set in order to run.\n");
- nsgtk_find_resource(buf, "toolbar.glade", "./gtk/res/toolbar.glade");
- LOG(("Using '%s' as glade toolbar file", buf));
- glade_toolbar_file_location = strdup(buf);
+ }
- wndWarning = GTK_WINDOW(glade_xml_get_widget(gladeWarning, "wndWarning"));
+ snprintf(buf, PATH_MAX, "%s/.netsurf", hdir);
+ if (access(buf, F_OK) != 0) {
+ LOG(("You don't have a ~/.netsurf - creating one for you."));
+ if (mkdir(buf, 0777) == -1) {
+ LOG(("Unable to create %s", buf));
+ die("NetSurf requires ~/.netsurf to exist, but it cannot be created.\n");
+ }
+ }
}
/**
@@ -469,8 +526,14 @@ void nsgtk_init_glade(void)
*/
int main(int argc, char** argv)
{
- char options[PATH_MAX];
char *messages;
+ char *options;
+ char **respaths;
+
+ /* check home directory is available */
+ nsgtk_check_homedir();
+
+ respaths = nsgtk_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
/* Some modern distributions can set ALL_PROXY/all_proxy if configured
* to by the user. Due to a bug in many versions of libcurl
@@ -488,21 +551,21 @@ int main(int argc, char** argv)
/* set standard error to be non-buffering */
setbuf(stderr, NULL);
- nsgtk_find_resource(options, "Choices", "~/.netsurf/Choices");
- options_file_location = strdup(options);
+ options = findresource(respaths, "Choices");
- messages = nsgtk_find_messages();
+ messages = findresource(respaths, "Messages");
- /* initialise netsurf */
netsurf_init(&argc, &argv, options, messages);
- gui_init(argc, argv);
+ free(messages);
+ free(options);
+
+ gui_init(argc, argv, respaths);
netsurf_main_loop();
netsurf_exit();
- free(messages);
return 0;
}
@@ -598,64 +661,9 @@ void gui_quit(void)
-/**
- * Check that ~/.netsurf/ exists, and if it doesn't, create it.
- */
-void nsgtk_check_homedir(void)
-{
- char *hdir = getenv("HOME");
- char buf[BUFSIZ];
- if (hdir == NULL) {
- /* we really can't continue without a home directory. */
- LOG(("HOME is not set - nowhere to store state!"));
- die("NetSurf requires HOME to be set in order to run.\n");
- }
- snprintf(buf, BUFSIZ, "%s/.netsurf", hdir);
- if (access(buf, F_OK) != 0) {
- LOG(("You don't have a ~/.netsurf - creating one for you."));
- if (mkdir(buf, 0777) == -1) {
- LOG(("Unable to create %s", buf));
- die("NetSurf requires ~/.netsurf to exist, but it cannot be created.\n");
- }
- }
-}
-
-
-
-/* This is an ugly hack to just get the new-style throbber going.
- * It, along with the PNG throbber loader, need making more generic.
- */
-bool nsgtk_throbber_init(int framec)
-{
- char **filenames;
- char targetname[PATH_MAX];
- char targetdefault[PATH_MAX];
- int frame_num;
- bool ret;
-
- filenames = calloc(framec, sizeof(char *));
- if (filenames == NULL)
- return false;
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- snprintf(targetname, PATH_MAX, "throbber/throbber%d.png", frame_num);
- snprintf(targetdefault, PATH_MAX, "./gtk/res/%s", targetname);
- filenames[frame_num] = nsgtk_find_resource(NULL, targetname, targetdefault);
- }
-
- ret = nsgtk_throbber_initialise_from_png(frame_num, filenames);
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- free(filenames[frame_num]);
- }
- free(filenames);
-
- return ret;
-
-}
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
@@ -726,7 +734,7 @@ void warn_user(const char *warning, const char *detail)
detail ? detail : "");
buf[sizeof(buf) - 1] = 0;
- gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWarning, "labelWarning")), buf);
+ gtk_label_set_text(GTK_LABEL(widWarning), buf);
gtk_widget_show_all(GTK_WIDGET(wndWarning));
}
diff --git a/gtk/gtk_gui.h b/gtk/gtk_gui.h
index 89c72101d..622b6ca55 100644
--- a/gtk/gtk_gui.h
+++ b/gtk/gtk_gui.h
@@ -31,19 +31,19 @@
#include <gtk/gtk.h>
#include <glade/glade.h>
-extern GladeXML *gladeNetsurf;
-extern GladeXML *gladePassword;
-extern GladeXML *gladeWarning;
-extern GladeXML *gladeLogin;
-extern GladeXML *gladeSsl;
extern char *glade_netsurf_file_location;
extern char *glade_password_file_location;
extern char *glade_warning_file_location;
extern char *glade_login_file_location;
extern char *glade_ssl_file_location;
extern char *glade_toolbar_file_location;
+extern char *glade_downloads_file_location;
+extern char *glade_history_file_location;
+extern char *glade_options_file_location;
+
+extern char *languages_file_location;
extern char *toolbar_indices_file_location;
-extern char *options_file_location;
+extern char *options_file_location; /**< location where user options are written */
extern char *res_dir_location;
extern char *print_options_file_location;
diff --git a/gtk/gtk_history.c b/gtk/gtk_history.c
index 9bcb584d6..ed0c912f6 100644
--- a/gtk/gtk_history.c
+++ b/gtk/gtk_history.c
@@ -31,8 +31,6 @@
#include "gtk/gtk_window.h"
#include "gtk/gtk_bitmap.h"
-#define GLADE_NAME "history.glade"
-
enum
{
SITE_TITLE = 0,
@@ -100,20 +98,19 @@ static void nsgtk_history_update_info(GtkTreeSelection *treesel,
gboolean domain);
static void nsgtk_history_scroll_top (GtkScrolledWindow *scrolled_window);
-void nsgtk_history_init(void)
+bool nsgtk_history_init(void)
{
dateToday = messages_get("DateToday");
dateYesterday = messages_get("DateYesterday");
dateAt = messages_get("DateAt");
domainAll = messages_get("DomainAll");
-
- char glade_location[strlen(res_dir_location) + SLEN(GLADE_NAME) + 1];
- sprintf(glade_location, "%s" GLADE_NAME, res_dir_location);
- gladeFile = glade_xml_new(glade_location, NULL, NULL);
+
+ gladeFile = glade_xml_new(glade_history_file_location, NULL, NULL);
+ if (gladeFile == NULL)
+ return false;
glade_xml_signal_autoconnect(gladeFile);
- wndHistory = GTK_WINDOW(glade_xml_get_widget(gladeFile,
- "wndHistory"));
+ wndHistory = GTK_WINDOW(glade_xml_get_widget(gladeFile, "wndHistory"));
nsgtk_history_init_model();
nsgtk_history_init_list();
@@ -122,6 +119,8 @@ void nsgtk_history_init(void)
nsgtk_history_init_treeviews();
nsgtk_history_show_all();
+
+ return true;
}
void nsgtk_history_init_model(void)
diff --git a/gtk/gtk_history.h b/gtk/gtk_history.h
index e5662fe89..02cb7f920 100644
--- a/gtk/gtk_history.h
+++ b/gtk/gtk_history.h
@@ -39,6 +39,6 @@ struct history_model {
GtkTreeSelection *domain_selection;
};
-void nsgtk_history_init(void);
+bool nsgtk_history_init(void);
#endif /* __NSGTK_HISTORY_H__ */
diff --git a/gtk/gtk_tabs.c b/gtk/gtk_tabs.c
index f1451ffb0..f92e72291 100644
--- a/gtk/gtk_tabs.c
+++ b/gtk/gtk_tabs.c
@@ -30,7 +30,6 @@
#include "gtk/gtk_tabs.h"
#define TAB_WIDTH_N_CHARS 15
-#define GET_WIDGET(x) glade_xml_get_widget(gladeNetsurf, (x))
static GtkWidget *nsgtk_tab_label_setup(struct gui_window *window);
static void nsgtk_tab_visibility_update(GtkNotebook *notebook, GtkWidget *child,