From 33934e12713f2ba8f5369a27f6abf725862f1a18 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 30 Dec 2012 01:17:17 +0000 Subject: implement the GTK preferances dialog with signals --- gtk/Makefile.target | 2 +- gtk/dialogs/options.c | 1184 --------------------------------------------- gtk/dialogs/options.h | 34 -- gtk/dialogs/preferences.c | 1082 +++++++++++++++++++++++++++++++++++++++++ gtk/dialogs/preferences.h | 32 ++ gtk/gui.c | 13 +- gtk/gui.h | 1 + gtk/res/options.gtk2.ui | 274 ++++++++--- gtk/scaffolding.c | 15 +- gtk/theme.c | 52 +- gtk/theme.h | 2 +- 11 files changed, 1374 insertions(+), 1317 deletions(-) delete mode 100644 gtk/dialogs/options.c delete mode 100644 gtk/dialogs/options.h create mode 100644 gtk/dialogs/preferences.c create mode 100644 gtk/dialogs/preferences.h (limited to 'gtk') diff --git a/gtk/Makefile.target b/gtk/Makefile.target index 2d1eebf50..88f8eccde 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -112,7 +112,7 @@ S_GTK := font_pango.c bitmap.c gui.c schedule.c thumbnail.c plotters.c \ selection.c history.c window.c filetype.c download.c menu.c \ print.c search.c tabs.c theme.c toolbar.c \ compat.c cookies.c hotlist.c system_colour.c \ - $(addprefix dialogs/,options.c about.c source.c) + $(addprefix dialogs/,preferences.c about.c source.c) S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c) # code in utils/container.ch is non-universal it seems diff --git a/gtk/dialogs/options.c b/gtk/dialogs/options.c deleted file mode 100644 index 8bd5665a3..000000000 --- a/gtk/dialogs/options.c +++ /dev/null @@ -1,1184 +0,0 @@ -/* - * Copyright 2006 Rob Kendrick - * Copyright 2008 Mike Lester - * Copyright 2009 Daniel Silverstone - * Copyright 2009 Mark Benjamin - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -#include "desktop/browser_private.h" -#include "desktop/options.h" -#include "desktop/print.h" -#include "desktop/searchweb.h" - -#include "gtk/compat.h" -#include "gtk/gui.h" -#include "gtk/scaffolding.h" -#include "gtk/theme.h" -#include "gtk/dialogs/options.h" -#include "gtk/window.h" -#include "utils/log.h" -#include "utils/utils.h" -#include "utils/messages.h" - -GtkDialog *wndPreferences = NULL; -static GtkBuilder *gladeFile; - -static struct browser_window *current_browser; - -static void dialog_response_handler (GtkDialog *dlg, gint res_id); -static gboolean on_dialog_close (GtkDialog *dlg, gboolean stay_alive); -static void nsgtk_options_theme_combo(void); - -/* Declares both widget and callback */ -#define DECLARE(x) \ - static GtkWidget *x; \ - static gboolean on_##x##_changed(GtkWidget *widget, gpointer data) - -DECLARE(entryHomePageURL); -DECLARE(setCurrentPage); -DECLARE(setDefaultPage); -DECLARE(checkHideAdverts); -DECLARE(checkDisablePopups); -DECLARE(checkDisablePlugins); -DECLARE(spinHistoryAge); -DECLARE(checkHoverURLs); -DECLARE(checkDisplayRecentURLs); -//DECLARE(comboboxLanguage); -static GtkWidget *comboboxLanguage; -static gboolean on_comboboxLanguage_changed(GtkComboBox *combo, gpointer data); -DECLARE(checkSendReferer); -DECLARE(checkSendDNT); - -DECLARE(comboProxyType); -DECLARE(entryProxyHost); -DECLARE(spinProxyPort); -DECLARE(entryProxyUser); -DECLARE(entryProxyPassword); -DECLARE(spinMaxFetchers); -DECLARE(spinFetchesPerHost); -DECLARE(spinCachedConnections); - -DECLARE(checkEnableJavascript); - -DECLARE(checkResampleImages); -DECLARE(spinAnimationSpeed); -DECLARE(checkEnableAnimations); - -//DECLARE(fontSansSerif); -//DECLARE(fontSerif); -//DECLARE(fontMonospace); -//DECLARE(fontCursive); -//DECLARE(fontFantasy); -DECLARE(comboDefault); -DECLARE(spinDefaultSize); -//DECLARE(spinMinimumSize); -DECLARE(fontPreview); - -DECLARE(comboButtonType); - -DECLARE(spinMemoryCacheSize); -DECLARE(spinDiscCacheAge); - -DECLARE(checkClearDownloads); -DECLARE(checkRequestOverwrite); -DECLARE(fileChooserDownloads); -/* Tabs */ -DECLARE(checkShowSingleTab); -DECLARE(checkFocusNew); -DECLARE(checkNewBlank); -DECLARE(comboTabPosition); - -DECLARE(checkUrlSearch); -DECLARE(comboSearch); -DECLARE(combotheme); -DECLARE(buttonaddtheme); -DECLARE(sourceButtonTab); -static GtkWidget *sourceButtonWindow; - -DECLARE(spinMarginTop); -DECLARE(spinMarginBottom); -DECLARE(spinMarginLeft); -DECLARE(spinMarginRight); -DECLARE(spinExportScale); -DECLARE(checkSuppressImages); -DECLARE(checkRemoveBackgrounds); -DECLARE(checkFitPage); -DECLARE(checkCompressPDF); -DECLARE(checkPasswordPDF); -//DECLARE(setDefaultExportOptions); - -/* Used when the feature is not implemented yet */ -#define FIND_WIDGET(wname) \ - do { \ - (wname) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #wname)); \ - if ((wname) == NULL) \ - LOG(("Unable to find widget '%s'!", #wname)); \ - } while (0) - -/* Assigns widget and connects it to its callback function */ -#define CONNECT(wname, event) \ - do { \ - if ((wname) == NULL) \ - LOG(("Unable to find widget '%s'!", #wname)); \ - else \ - g_signal_connect(G_OBJECT(wname), event, \ - G_CALLBACK(on_##wname##_changed), NULL); \ - } while (0) - -/* exported interface documented in gtk/dialogs/options.h */ -GtkDialog* -nsgtk_options_init(struct browser_window *bw, GtkWindow *parent) -{ - GError *error = NULL; - GObject *dlgobject; - //GSList *group; - - gladeFile = gtk_builder_new(); - if (!gtk_builder_add_from_file(gladeFile, glade_file_location->options, &error)) { - g_warning("Couldn't load builder file: %s", error->message); - g_error_free(error); - return NULL; - } - - - dlgobject = gtk_builder_get_object(gladeFile, "dialogPreferences"); - if (dlgobject == NULL) { - LOG(("Unable to get object for preferences dialog")); - return NULL; - } - - current_browser = bw; - wndPreferences = GTK_DIALOG(dlgobject); - gtk_window_set_transient_for(GTK_WINDOW(wndPreferences), parent); - - /* set the widgets to reflect the current options */ - nsgtk_options_load(); - - FIND_WIDGET(sourceButtonTab); - FIND_WIDGET(sourceButtonWindow); - //group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(sourceButtonWindow)); - //gtk_radio_button_set_group(GTK_RADIO_BUTTON(sourceButtonTab), group); - - - /* Connect all widgets to their appropriate callbacks */ - CONNECT(entryHomePageURL, "focus-out-event"); - CONNECT(setCurrentPage, "clicked"); - CONNECT(setDefaultPage, "clicked"); - CONNECT(checkHideAdverts, "toggled"); - - CONNECT(checkDisablePopups, "toggled"); - CONNECT(checkDisablePlugins, "toggled"); - CONNECT(spinHistoryAge, "focus-out-event"); - CONNECT(checkHoverURLs, "toggled"); - - CONNECT(comboboxLanguage, "changed"); - - CONNECT(checkDisplayRecentURLs, "toggled"); - CONNECT(checkSendReferer, "toggled"); - CONNECT(checkSendDNT, "toggled"); - CONNECT(checkShowSingleTab, "toggled"); - - CONNECT(comboProxyType, "changed"); - CONNECT(entryProxyHost, "focus-out-event"); - CONNECT(spinProxyPort, "focus-out-event"); - CONNECT(entryProxyUser, "focus-out-event"); - CONNECT(entryProxyPassword, "focus-out-event"); - CONNECT(spinMaxFetchers, "value-changed"); - CONNECT(spinFetchesPerHost, "value-changed"); - CONNECT(spinCachedConnections, "value-changed"); - - CONNECT(checkEnableJavascript, "toggled"); - - CONNECT(checkResampleImages, "toggled"); - CONNECT(spinAnimationSpeed, "value-changed"); - CONNECT(checkEnableAnimations, "toggled"); - -/* CONNECT(fontSansSerif, "font-set"); - CONNECT(fontSerif, "font-set"); - CONNECT(fontMonospace, "font-set"); - CONNECT(fontCursive, "font-set"); - CONNECT(fontFantasy, "font-set"); - CONNECT(spinMinimumSize, "value-changed"); -*/ - CONNECT(comboDefault, "changed"); - CONNECT(spinDefaultSize, "value-changed"); - CONNECT(fontPreview, "clicked"); - - CONNECT(comboButtonType, "changed"); - - CONNECT(comboTabPosition, "changed"); - - CONNECT(spinMemoryCacheSize, "value-changed"); - CONNECT(spinDiscCacheAge, "value-changed"); - - CONNECT(checkClearDownloads, "toggled"); - CONNECT(checkRequestOverwrite, "toggled"); - CONNECT(fileChooserDownloads, "current-folder-changed"); - - CONNECT(checkFocusNew, "toggled"); - CONNECT(checkNewBlank, "toggled"); - CONNECT(checkUrlSearch, "toggled"); - CONNECT(comboSearch, "changed"); - - CONNECT(combotheme, "changed"); - CONNECT(buttonaddtheme, "clicked"); - CONNECT(sourceButtonTab, "toggled"); - - CONNECT(spinMarginTop, "value-changed"); - CONNECT(spinMarginBottom, "value-changed"); - CONNECT(spinMarginLeft, "value-changed"); - CONNECT(spinMarginRight, "value-changed"); - CONNECT(spinExportScale, "value-changed"); - CONNECT(checkSuppressImages, "toggled"); - CONNECT(checkRemoveBackgrounds, "toggled"); - CONNECT(checkFitPage, "toggled"); - CONNECT(checkCompressPDF, "toggled"); - CONNECT(checkPasswordPDF, "toggled"); -// CONNECT(setDefaultExportOptions, "clicked"); - - g_signal_connect(G_OBJECT(wndPreferences), "response", - G_CALLBACK (dialog_response_handler), NULL); - - g_signal_connect(G_OBJECT(wndPreferences), "delete-event", - G_CALLBACK (on_dialog_close), (gpointer)TRUE); - - g_signal_connect(G_OBJECT(wndPreferences), "destroy", - G_CALLBACK (on_dialog_close), (gpointer)FALSE); - - gtk_widget_show(GTK_WIDGET(wndPreferences)); - - return wndPreferences; -} - -#define SET_ENTRY(widget, value) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - gtk_entry_set_text(GTK_ENTRY((widget)), (value)); \ - } while (0) - -#define SET_SPIN(widget, value) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - gtk_spin_button_set_value(GTK_SPIN_BUTTON((widget)), (value)); \ - } while (0) - -#define SET_CHECK(widget, value) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((widget)), \ - (value)); \ - } while (0) - -#define SET_COMBO(widget, value) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - gtk_combo_box_set_active(GTK_COMBO_BOX((widget)), (value)); \ - } while (0) - -#define SET_FONT(widget, value) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - gtk_font_button_set_font_name(GTK_FONT_BUTTON((widget)), \ - (value)); \ - } while (0) - -#define SET_FILE_CHOOSER(widget, value) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(\ - (widget)), (value)); \ - } while (0) - -#define SET_BUTTON(widget) \ - do { \ - (widget) = GTK_WIDGET(gtk_builder_get_object(gladeFile, #widget)); \ - } while (0) - -static void set_proxy_widgets_sensitivity(int proxyval) -{ - switch (proxyval) { - case 0: /* no proxy */ - gtk_widget_set_sensitive(entryProxyHost, FALSE); - gtk_widget_set_sensitive(spinProxyPort, FALSE); - gtk_widget_set_sensitive(entryProxyUser, FALSE); - gtk_widget_set_sensitive(entryProxyPassword, FALSE); - break; - - case 1: /* proxy with no auth */ - gtk_widget_set_sensitive(entryProxyHost, TRUE); - gtk_widget_set_sensitive(spinProxyPort, TRUE); - gtk_widget_set_sensitive(entryProxyUser, FALSE); - gtk_widget_set_sensitive(entryProxyPassword, FALSE); - break; - - case 2: /* proxy with basic auth */ - gtk_widget_set_sensitive(entryProxyHost, TRUE); - gtk_widget_set_sensitive(spinProxyPort, TRUE); - gtk_widget_set_sensitive(entryProxyUser, TRUE); - gtk_widget_set_sensitive(entryProxyPassword, TRUE); - break; - - case 3: /* proxy with ntlm auth */ - gtk_widget_set_sensitive(entryProxyHost, TRUE); - gtk_widget_set_sensitive(spinProxyPort, TRUE); - gtk_widget_set_sensitive(entryProxyUser, TRUE); - gtk_widget_set_sensitive(entryProxyPassword, TRUE); - break; - - case 4: /* system proxy */ - gtk_widget_set_sensitive(entryProxyHost, FALSE); - gtk_widget_set_sensitive(spinProxyPort, FALSE); - gtk_widget_set_sensitive(entryProxyUser, FALSE); - gtk_widget_set_sensitive(entryProxyPassword, FALSE); - break; - - } -} - -void nsgtk_options_load(void) -{ - const char *default_accept_language = "en"; - const char *default_homepage_url = ""; - const char *default_http_proxy_host; - const char *default_http_proxy_auth_user; - const char *default_http_proxy_auth_pass; - - int active_language = 0; - GtkListStore *liststore; - GtkTreeIter iter; - - int proxytype = 0; - FILE *fp; - char buf[50]; - - /* Network - HTTP Proxy */ - default_http_proxy_host = nsoption_charp(http_proxy_host); - default_http_proxy_auth_user = nsoption_charp(http_proxy_auth_user); - default_http_proxy_auth_pass = nsoption_charp(http_proxy_auth_pass); - - if (nsoption_bool(http_proxy) == true) { - /* proxy type combo box starts with disabled, to allow - * for this the http_proxy option needs combining with - * the http_proxy_auth option - */ - proxytype = nsoption_int(http_proxy_auth) + 1; - if (default_http_proxy_host == NULL) { - /* set to use a proxy without a host, turn proxy off */ - proxytype = 0; - } else if (((proxytype == 2) || - (proxytype == 3)) && - ((default_http_proxy_auth_user == NULL) || - (default_http_proxy_auth_pass == NULL))) { - /* authentication selected with empty credentials, turn proxy off */ - proxytype = 0; - } - } - - if (default_http_proxy_host == NULL) { - default_http_proxy_host = ""; - } - - if (default_http_proxy_auth_user == NULL) { - default_http_proxy_auth_user = ""; - } - - if (default_http_proxy_auth_pass == NULL) { - default_http_proxy_auth_pass = ""; - } - - SET_COMBO(comboProxyType, proxytype); - SET_ENTRY(entryProxyHost, default_http_proxy_host); - SET_SPIN(spinProxyPort, nsoption_int(http_proxy_port)); - SET_ENTRY(entryProxyUser, default_http_proxy_auth_user); - SET_ENTRY(entryProxyPassword, default_http_proxy_auth_pass); - - set_proxy_widgets_sensitivity(proxytype); - - - /* accept language selection */ - if (nsoption_charp(accept_language) != NULL) { - default_accept_language = nsoption_charp(accept_language); - } - - /* Fill content language list store */ - liststore = GTK_LIST_STORE(gtk_builder_get_object(gladeFile, "liststore_content_language")); - if ((liststore != NULL) && - (languages_file_location != NULL) && - ((fp = fopen(languages_file_location, "r")) != NULL)) { - int combo_row_count = 0; - - gtk_list_store_clear(liststore); - active_language = -1; - - LOG(("Used %s for languages", languages_file_location)); - while (fgets(buf, sizeof(buf), fp)) { - /* Ignore blank lines */ - if (buf[0] == '\0') - continue; - - /* Remove trailing \n */ - buf[strlen(buf) - 1] = '\0'; - - gtk_list_store_append(liststore, &iter); - gtk_list_store_set(liststore, &iter, 0, buf, -1 ); - - if (strcmp(buf, default_accept_language) == 0) { - active_language = combo_row_count; - } - - combo_row_count++; - } - - if (active_language == -1) { - /* configured language was not in list, add it */ - gtk_list_store_append(liststore, &iter); - gtk_list_store_set(liststore, &iter, 0, default_accept_language, -1 ); - active_language = combo_row_count; - - } - - fclose(fp); - } else { - LOG(("Failed opening languages file")); - } - - SET_COMBO(comboboxLanguage, active_language); - - - /* Startup */ - if (nsoption_charp(homepage_url) != NULL) { - default_homepage_url = nsoption_charp(homepage_url); - } - - SET_ENTRY(entryHomePageURL, default_homepage_url); - SET_BUTTON(setCurrentPage); - SET_BUTTON(setDefaultPage); - - /* Theme */ - nsgtk_options_theme_combo(); - - SET_CHECK(checkHideAdverts, nsoption_bool(block_ads)); - - SET_CHECK(checkDisablePopups, nsoption_bool(disable_popups)); - SET_CHECK(checkDisablePlugins, nsoption_bool(disable_plugins)); - SET_SPIN(spinHistoryAge, nsoption_int(history_age)); - SET_CHECK(checkHoverURLs, nsoption_bool(hover_urls)); - - SET_CHECK(checkDisplayRecentURLs, nsoption_bool(url_suggestion)); - SET_CHECK(checkSendReferer, nsoption_bool(send_referer)); - SET_CHECK(checkSendDNT, nsoption_bool(do_not_track)); - SET_CHECK(checkShowSingleTab, nsoption_bool(show_single_tab)); - - SET_SPIN(spinMaxFetchers, nsoption_int(max_fetchers)); - SET_SPIN(spinFetchesPerHost, nsoption_int(max_fetchers_per_host)); - SET_SPIN(spinCachedConnections, nsoption_int(max_cached_fetch_handles)); - - SET_CHECK(checkEnableJavascript, nsoption_bool(enable_javascript)); - - SET_CHECK(checkResampleImages, nsoption_bool(render_resample)); - SET_SPIN(spinAnimationSpeed, nsoption_int(minimum_gif_delay) / 100.0); - SET_CHECK(checkEnableAnimations, nsoption_bool(animate_images)); - -/* SET_FONT(fontSansSerif, nsoption_charp(font_sans)); - SET_FONT(fontSerif, nsoption_charp(font_serif)); - SET_FONT(fontMonospace, nsoption_charp(font_mono)); - SET_FONT(fontCursive, nsoption_charp(font_cursive)); - SET_FONT(fontFantasy, nsoption_charp(font_fantasy)); - SET_SPIN(spinMinimumSize, nsoption_bool(font_min_size) / 10); -*/ - SET_COMBO(comboDefault, nsoption_int(font_default)); - SET_SPIN(spinDefaultSize, nsoption_int(font_size) / 10); - SET_BUTTON(fontPreview); - - SET_COMBO(comboButtonType, nsoption_int(button_type) -1); - - SET_COMBO(comboTabPosition, nsoption_int(position_tab)); - - SET_SPIN(spinMemoryCacheSize, nsoption_int(memory_cache_size) >> 20); - SET_SPIN(spinDiscCacheAge, nsoption_int(disc_cache_age)); - - SET_CHECK(checkClearDownloads, nsoption_bool(downloads_clear)); - SET_CHECK(checkRequestOverwrite, nsoption_bool(request_overwrite)); - SET_FILE_CHOOSER(fileChooserDownloads, nsoption_charp(downloads_directory)); - - SET_CHECK(checkFocusNew, nsoption_bool(focus_new)); - SET_CHECK(checkNewBlank, nsoption_bool(new_blank)); - SET_CHECK(checkUrlSearch, nsoption_bool(search_url_bar)); - SET_COMBO(comboSearch, nsoption_int(search_provider)); - - SET_BUTTON(buttonaddtheme); - SET_CHECK(sourceButtonTab, nsoption_bool(source_tab)); - - SET_SPIN(spinMarginTop, nsoption_int(margin_top)); - SET_SPIN(spinMarginBottom, nsoption_int(margin_bottom)); - SET_SPIN(spinMarginLeft, nsoption_int(margin_left)); - SET_SPIN(spinMarginRight, nsoption_int(margin_right)); - SET_SPIN(spinExportScale, nsoption_int(export_scale)); - SET_CHECK(checkSuppressImages, nsoption_bool(suppress_images)); - SET_CHECK(checkRemoveBackgrounds, nsoption_bool(remove_backgrounds)); - SET_CHECK(checkFitPage, nsoption_bool(enable_loosening)); - SET_CHECK(checkCompressPDF, nsoption_bool(enable_PDF_compression)); - SET_CHECK(checkPasswordPDF, nsoption_bool(enable_PDF_password)); -// SET_BUTTON(setDefaultExportOptions); -} - -static void dialog_response_handler(GtkDialog *dlg, gint res_id) -{ - switch (res_id) { - case GTK_RESPONSE_CLOSE: - on_dialog_close(dlg, TRUE); - } -} - -static gboolean on_dialog_close (GtkDialog *dlg, gboolean stay_alive) -{ - LOG(("Writing options to file")); - nsoption_write(options_file_location); - if ((stay_alive) && GTK_IS_WIDGET(dlg)) - gtk_widget_hide(GTK_WIDGET(dlg)); - else { - stay_alive = FALSE; - } - return stay_alive; -} - -static void nsgtk_options_theme_combo(void) { -/* populate theme combo from themelist file */ - GtkBox *box = GTK_BOX(gtk_builder_get_object(gladeFile, "themehbox")); - char buf[50]; - size_t len = SLEN("themelist") + strlen(res_dir_location) + 1; - char themefile[len]; - - combotheme = nsgtk_combo_box_text_new(); - - if ((combotheme == NULL) || (box == NULL)) { - warn_user(messages_get("NoMemory"), 0); - return; - } - snprintf(themefile, len, "%sthemelist", res_dir_location); - FILE *fp = fopen((const char *)themefile, "r"); - if (fp == NULL) { - LOG(("Failed opening themes file")); - warn_user("FileError", (const char *) themefile); - return; - } - while (fgets(buf, sizeof(buf), fp) != NULL) { - /* Ignore blank lines */ - if (buf[0] == '\0') - continue; - - /* Remove trailing \n */ - buf[strlen(buf) - 1] = '\0'; - - nsgtk_combo_box_text_append_text(combotheme, buf); - } - fclose(fp); - gtk_combo_box_set_active(GTK_COMBO_BOX(combotheme), - nsoption_int(current_theme)); - gtk_box_pack_start(box, combotheme, FALSE, TRUE, 0); - gtk_widget_show(combotheme); -} - -bool nsgtk_options_combo_theme_add(const char *themename) -{ - if (wndPreferences == NULL) - return false; - nsgtk_combo_box_text_append_text(combotheme, themename); - return true; -} - - -/* Defines the callback functions for all widgets and specifies - * nsgtk_reflow_all_windows only where necessary */ - -#define ENTRY_CHANGED(widget, option) \ -static gboolean on_##widget##_changed(GtkWidget *widget, gpointer data) \ -{ \ - if (!g_str_equal(gtk_entry_get_text(GTK_ENTRY((widget))), \ - nsoption_charp(option) ? nsoption_charp(option) : "")) { \ - LOG(("Signal emitted on '%s'", #widget)); \ - nsoption_set_charp(option, strdup(gtk_entry_get_text(GTK_ENTRY((widget))))); \ - } \ - return FALSE; \ -} - -#define CHECK_CHANGED(widget, option) \ - static gboolean on_##widget##_changed(GtkWidget *widget, gpointer data) { \ - LOG(("Signal emitted on '%s'", #widget)); \ - nsoption_set_bool(option, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON((widget)))); \ - do - -#define SPIN_CHANGED(widget, option) \ - static gboolean on_##widget##_changed(GtkWidget *widget, gpointer data) { \ - LOG(("Signal emitted on '%s'", #widget)); \ - nsoption_set_int(option, gtk_spin_button_get_value(GTK_SPIN_BUTTON((widget)))); \ - do - -#define COMBO_CHANGED(widget, option) \ - static gboolean on_##widget##_changed(GtkWidget *widget, gpointer data) { \ - LOG(("Signal emitted on '%s'", #widget)); \ - nsoption_set_int(option, gtk_combo_box_get_active(GTK_COMBO_BOX((widget)))); \ - do - -#define FONT_CHANGED(widget, option) \ - static gboolean on_##widget##_changed(GtkWidget *widget, gpointer data) { \ - LOG(("Signal emitted on '%s'", #widget)); \ - nsoption_set_charp(option, strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON((widget))))); \ - do - -#define BUTTON_CLICKED(widget) \ - static gboolean on_##widget##_changed(GtkWidget *widget, gpointer data) { \ - LOG(("Signal emitted on '%s'", #widget)); \ - do - -#define END_HANDLER \ - while (0); \ - return FALSE; \ - } - -static gboolean on_comboboxLanguage_changed(GtkComboBox *combo, gpointer data) -{ - gchar *lang = NULL; - GtkTreeIter iter; - GtkTreeModel *model; - - /* Obtain currently selected item from combo box. - * If nothing is selected, do nothing. - */ - if (gtk_combo_box_get_active_iter(combo, &iter)) { - /* Obtain data model from combo box. */ - model = gtk_combo_box_get_model(combo); - - /* Obtain string from model. */ - gtk_tree_model_get(model, &iter, 0, &lang, -1); - } - - if (lang != NULL) { - nsoption_set_charp(accept_language, strdup(lang)); - g_free(lang); - } - - return FALSE; -} - -ENTRY_CHANGED(entryHomePageURL, homepage_url) - -BUTTON_CLICKED(setCurrentPage) -{ - const gchar *url; - url = nsurl_access(hlcache_handle_get_url(current_browser->current_content)); - gtk_entry_set_text(GTK_ENTRY(entryHomePageURL), url); - nsoption_set_charp(homepage_url, - strdup(gtk_entry_get_text(GTK_ENTRY(entryHomePageURL)))); -} -END_HANDLER - -BUTTON_CLICKED(setDefaultPage) -{ - gtk_entry_set_text(GTK_ENTRY(entryHomePageURL), NETSURF_HOMEPAGE); - nsoption_set_charp(homepage_url, - strdup(gtk_entry_get_text(GTK_ENTRY(entryHomePageURL)))); -} -END_HANDLER - -CHECK_CHANGED(checkHideAdverts, block_ads) -{ -} -END_HANDLER - -CHECK_CHANGED(checkDisplayRecentURLs, url_suggestion) -{ -} -END_HANDLER - -CHECK_CHANGED(checkSendReferer, send_referer) -{ -} -END_HANDLER - -CHECK_CHANGED(checkSendDNT, do_not_track) -{ -} -END_HANDLER - -CHECK_CHANGED(checkShowSingleTab, show_single_tab) -{ - nsgtk_reflow_all_windows(); -} -END_HANDLER - - -COMBO_CHANGED(comboProxyType, http_proxy_auth) -{ - LOG(("proxy auth: %d", nsoption_int(http_proxy_auth))); - - set_proxy_widgets_sensitivity(nsoption_int(http_proxy_auth)); - switch (nsoption_int(http_proxy_auth)) { - case 0: /* no proxy */ - nsoption_set_bool(http_proxy, false); - nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NONE); - break; - - case 1: /* proxy with no auth */ - nsoption_set_bool(http_proxy, true); - nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NONE); - break; - - case 2: /* proxy with basic auth */ - nsoption_set_bool(http_proxy, true); - nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_BASIC); - break; - - case 3: /* proxy with ntlm auth */ - nsoption_set_bool(http_proxy, true); - nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NTLM); - break; - - case 4: /* system proxy */ - nsoption_set_bool(http_proxy, true); - nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NONE); - break; - - } -} -END_HANDLER - -ENTRY_CHANGED(entryProxyHost, http_proxy_host) - -SPIN_CHANGED(spinProxyPort, http_proxy_port) -{ -} -END_HANDLER - -ENTRY_CHANGED(entryProxyUser, http_proxy_auth_user) - -ENTRY_CHANGED(entryProxyPassword, http_proxy_auth_pass) - -SPIN_CHANGED(spinMaxFetchers, max_fetchers) -{ -} -END_HANDLER - -SPIN_CHANGED(spinFetchesPerHost, max_fetchers_per_host) -{ -} -END_HANDLER - -SPIN_CHANGED(spinCachedConnections, max_cached_fetch_handles) -{ -} -END_HANDLER - -CHECK_CHANGED(checkResampleImages, render_resample) -{ -} -END_HANDLER - -static gboolean on_spinAnimationSpeed_changed(GtkWidget *widget, gpointer data) -{ - LOG(("Signal emitted on '%s'", "spinAnimationSpeed")); - nsoption_set_int(minimum_gif_delay, - round(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget)) * 100.0)); - return FALSE; -} - -CHECK_CHANGED(checkEnableAnimations, animate_images) -{ -} -END_HANDLER - -CHECK_CHANGED(checkEnableJavascript, enable_javascript) -{ -} -END_HANDLER - -CHECK_CHANGED(checkDisablePopups, disable_popups) -{ -} -END_HANDLER - -CHECK_CHANGED(checkDisablePlugins, disable_plugins) -{ -} -END_HANDLER - -SPIN_CHANGED(spinHistoryAge, history_age) -{ -} -END_HANDLER - -CHECK_CHANGED(checkHoverURLs, hover_urls) -{ -} -END_HANDLER -/* -FONT_CHANGED(fontSansSerif, font_sans) -{ -} -END_HANDLER - -FONT_CHANGED(fontSerif, font_serif) -{ -} -END_HANDLER - -FONT_CHANGED(fontMonospace, font_mono) -{ -} -END_HANDLER - -FONT_CHANGED(fontCursive, font_cursive) -{ -} -END_HANDLER - -FONT_CHANGED(fontFantasy, font_fantasy) -{ -} -END_HANDLER -*/ -COMBO_CHANGED(comboDefault, font_default) -{ -} -END_HANDLER - -SPIN_CHANGED(spinDefaultSize, font_size) -{ - nsoption_set_int(font_size, nsoption_int(font_size) * 10); -} -END_HANDLER - -/*SPIN_CHANGED(spinMinimumSize, font_min_size) -{ - nsoption_set_int(font_min_size, nsoption_int(font_min_size) * 10); -} -END_HANDLER -*/ -BUTTON_CLICKED(fontPreview) -{ - nsgtk_reflow_all_windows(); -} -END_HANDLER - -COMBO_CHANGED(comboButtonType, button_type) -{ - nsgtk_scaffolding *current = scaf_list; - nsoption_set_int(button_type, nsoption_int(button_type) + 1); - - /* value of 0 is reserved for 'unset' */ - while (current) { - nsgtk_scaffolding_reset_offset(current); - switch(nsoption_int(button_type)) { - case 1: - gtk_toolbar_set_style( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_TOOLBAR_ICONS); - gtk_toolbar_set_icon_size( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_ICON_SIZE_SMALL_TOOLBAR); - break; - case 2: - gtk_toolbar_set_style( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_TOOLBAR_ICONS); - gtk_toolbar_set_icon_size( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_ICON_SIZE_LARGE_TOOLBAR); - break; - case 3: - gtk_toolbar_set_style( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_TOOLBAR_BOTH); - gtk_toolbar_set_icon_size( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_ICON_SIZE_LARGE_TOOLBAR); - break; - case 4: - gtk_toolbar_set_style( - GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), - GTK_TOOLBAR_TEXT); - default: - break; - } - current = nsgtk_scaffolding_iterate(current); - } -} -END_HANDLER - -COMBO_CHANGED(comboTabPosition, position_tab) -{ - nsgtk_scaffolding *current = scaf_list; - nsoption_set_int(button_type, nsoption_int(button_type) + 1); - - /* value of 0 is reserved for 'unset' */ - while (current) { - nsgtk_scaffolding_reset_offset(current); - - nsgtk_reflow_all_windows(); - - current = nsgtk_scaffolding_iterate(current); - } -} -END_HANDLER - -SPIN_CHANGED(spinMemoryCacheSize, memory_cache_size) -{ - nsoption_set_int(memory_cache_size, nsoption_int(memory_cache_size) << 20); -} -END_HANDLER - -SPIN_CHANGED(spinDiscCacheAge, disc_cache_age) -{ -} -END_HANDLER - -CHECK_CHANGED(checkClearDownloads, downloads_clear) -{ -} -END_HANDLER - -CHECK_CHANGED(checkRequestOverwrite, request_overwrite) -{ -} -END_HANDLER - -static gboolean on_fileChooserDownloads_changed(GtkWidget *widget, gpointer data) -{ - gchar *dir; - LOG(("Signal emitted on '%s'", "fileChooserDownloads")); - - dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER((widget))); - nsoption_set_charp(downloads_directory, strdup(dir)); - g_free(dir); - return FALSE; -} - -CHECK_CHANGED(checkFocusNew, focus_new) -{ -} -END_HANDLER - -CHECK_CHANGED(checkNewBlank, new_blank) -{ -} -END_HANDLER - -CHECK_CHANGED(checkUrlSearch, search_url_bar) -{ -} -END_HANDLER - -COMBO_CHANGED(comboSearch, search_provider) -{ - nsgtk_scaffolding *current = scaf_list; - char *name; - - /* refresh web search prefs from file */ - search_web_provider_details(nsoption_charp(search_provider)); - - /* retrieve ico */ - search_web_retrieve_ico(false); - - /* callback may handle changing gui */ - if (search_web_ico() != NULL) - gui_window_set_search_ico(search_web_ico()); - - /* set entry */ - name = search_web_provider_name(); - if (name == NULL) { - warn_user(messages_get("NoMemory"), 0); - continue; - } - char content[strlen(name) + SLEN("Search ") + 1]; - sprintf(content, "Search %s", name); - free(name); - while (current) { - nsgtk_scaffolding_set_websearch(current, content); - current = nsgtk_scaffolding_iterate(current); - } -} -END_HANDLER - -COMBO_CHANGED(combotheme, current_theme) -{ - nsgtk_scaffolding *current = scaf_list; - char *name; - if (nsoption_int(current_theme) != 0) { - if (nsgtk_theme_name() != NULL) - free(nsgtk_theme_name()); - name = nsgtk_combo_box_text_get_active_text(combotheme); - if (name != NULL) { - nsgtk_theme_set_name(name); - nsgtk_theme_prepare(); - /* possible name leak */ - } - } else if (nsgtk_theme_name() != NULL) { - free(nsgtk_theme_name()); - nsgtk_theme_set_name(NULL); - } - - while (current) { - nsgtk_theme_implement(current); - current = nsgtk_scaffolding_iterate(current); - } -} -END_HANDLER - -BUTTON_CLICKED(buttonaddtheme) -{ - char *filename, *directory; - size_t len; - GtkWidget *fc = gtk_file_chooser_dialog_new( - messages_get("gtkAddThemeTitle"), - GTK_WINDOW(wndPreferences), - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - len = SLEN("themes") + strlen(res_dir_location) + 1; - char themesfolder[len]; - snprintf(themesfolder, len, "%sthemes", res_dir_location); - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), - themesfolder); - gint res = gtk_dialog_run(GTK_DIALOG(fc)); - if (res == GTK_RESPONSE_ACCEPT) { - filename = gtk_file_chooser_get_current_folder( - GTK_FILE_CHOOSER(fc)); - if (strcmp(filename, themesfolder) != 0) { - directory = strrchr(filename, '/'); - *directory = '\0'; - if (strcmp(filename, themesfolder) != 0) { - warn_user(messages_get( - "gtkThemeFolderInstructions"), - 0); - gtk_widget_destroy(GTK_WIDGET(fc)); - if (filename != NULL) - g_free(filename); - return FALSE; - } else { - directory++; - } - } else { - if (filename != NULL) - g_free(filename); - filename = gtk_file_chooser_get_filename( - GTK_FILE_CHOOSER(fc)); - if (strcmp(filename, themesfolder) == 0) { - warn_user(messages_get("gtkThemeFolderSub"), - 0); - gtk_widget_destroy(GTK_WIDGET(fc)); - g_free(filename); - return FALSE; - } - directory = strrchr(filename, '/') + 1; - } - gtk_widget_destroy(GTK_WIDGET(fc)); - nsgtk_theme_add(directory); - if (filename != NULL) - g_free(filename); - } -} -END_HANDLER - -CHECK_CHANGED(sourceButtonTab, source_tab) -{ -} -END_HANDLER - -SPIN_CHANGED(spinMarginTop, margin_top) -{ -} -END_HANDLER - -SPIN_CHANGED(spinMarginBottom, margin_bottom) -{ -} -END_HANDLER - -SPIN_CHANGED(spinMarginLeft, margin_left) -{ -} -END_HANDLER - -SPIN_CHANGED(spinMarginRight, margin_right) -{ -} -END_HANDLER - -SPIN_CHANGED(spinExportScale, export_scale) -{ -} -END_HANDLER - -CHECK_CHANGED(checkSuppressImages, suppress_images) -{ -} -END_HANDLER - -CHECK_CHANGED(checkRemoveBackgrounds, remove_backgrounds) -{ -} -END_HANDLER - -CHECK_CHANGED(checkFitPage, enable_loosening) -{ -} -END_HANDLER - -CHECK_CHANGED(checkCompressPDF, enable_PDF_compression) -{ -} -END_HANDLER - -CHECK_CHANGED(checkPasswordPDF, enable_PDF_password) -{ -} -END_HANDLER - -/* -BUTTON_CLICKED(setDefaultExportOptions) -{ - nsoption_set_int(margin_top, DEFAULT_MARGIN_TOP_MM); - nsoption_set_int(margin_bottom, DEFAULT_MARGIN_BOTTOM_MM); - nsoption_set_int(margin_left, DEFAULT_MARGIN_LEFT_MM); - nsoption_set_int(margin_right, DEFAULT_MARGIN_RIGHT_MM); - nsoption_set_int(export_scale, DEFAULT_EXPORT_SCALE * 100); - nsoption_set_bool(suppress_images, false); - nsoption_set_bool(remove_backgrounds, false); - nsoption_set_bool(enable_loosening, true); - nsoption_set_bool(enable_PDF_compression, true); - nsoption_set_bool(enable_PDF_password, false); - - SET_SPIN(spinMarginTop, nsoption_int(margin_top)); - SET_SPIN(spinMarginBottom, nsoption_int(margin_bottom)); - SET_SPIN(spinMarginLeft, nsoption_int(margin_left)); - SET_SPIN(spinMarginRight, nsoption_int(margin_right)); - SET_SPIN(spinExportScale, nsoption_int(export_scale)); - SET_CHECK(checkSuppressImages, nsoption_bool(suppress_images)); - SET_CHECK(checkRemoveBackgrounds, nsoption_bool(remove_backgrounds)); - SET_CHECK(checkCompressPDF, nsoption_bool(enable_PDF_compression)); - SET_CHECK(checkPasswordPDF, nsoption_bool(enable_PDF_password)); - SET_CHECK(checkFitPage, nsoption_bool(enable_loosening)); -} -END_HANDLER -*/ diff --git a/gtk/dialogs/options.h b/gtk/dialogs/options.h deleted file mode 100644 index 9f6602593..000000000 --- a/gtk/dialogs/options.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2006 Rob Kendrick - * Copyright 2009 Mark Benjamin - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef NETSURF_GTK_OPTIONS_H -#define NETSURF_GTK_OPTIONS_H - -#include - -extern GtkDialog *wndPreferences; - -GtkDialog* nsgtk_options_init(struct browser_window *bw, GtkWindow *parent); - /** Init options and load window */ -void nsgtk_options_load(void); /** Load current options into window */ -void nsgtk_options_save(void); /** Save options from window */ -bool nsgtk_options_combo_theme_add(const char *themename); - /** add new theme name to combo */ - -#endif diff --git a/gtk/dialogs/preferences.c b/gtk/dialogs/preferences.c new file mode 100644 index 000000000..2d787e6dc --- /dev/null +++ b/gtk/dialogs/preferences.c @@ -0,0 +1,1082 @@ +/* + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "desktop/browser_private.h" +#include "desktop/options.h" +#include "desktop/searchweb.h" +#include "utils/log.h" +#include "utils/utils.h" +#include "utils/messages.h" + +#include "gtk/compat.h" +#include "gtk/window.h" +#include "gtk/gui.h" +#include "gtk/scaffolding.h" +#include "gtk/theme.h" +#include "gtk/dialogs/preferences.h" + +/* private prefs */ +struct ppref { + /** dialog handle created when window first accessed */ + GObject *dialog; + + struct browser_window *bw; + + /* widgets which are accessed from outside their own signal handlers */ + GtkEntry *entryHomePageURL; + GtkEntry *entryProxyHost; + GtkEntry *entryProxyUser; + GtkEntry *entryProxyPassword; + GtkSpinButton *spinProxyPort; + + /* dynamic list stores */ + GtkListStore *themes; + GtkListStore *content_language; +}; + +static struct ppref ppref; + + +/* Set netsurf option based on toggle button state + * + * This works for any widget which subclasses togglebutton (checkbox, + * radiobutton etc.) + */ +#define TOGGLEBUTTON_SIGNALS(WIDGET, OPTION) \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_toggled(GtkToggleButton *togglebutton, \ + struct ppref *priv); \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_toggled(GtkToggleButton *togglebutton, \ + struct ppref *priv) \ +{ \ + nsoption_set_bool(OPTION, \ + gtk_toggle_button_get_active(togglebutton)); \ +} \ + \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_realize(GtkWidget *widget, \ + struct ppref *priv); \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_realize(GtkWidget *widget, \ + struct ppref *priv) \ +{ \ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), \ + nsoption_bool(OPTION)); \ +} + +#define SPINBUTTON_SIGNALS(WIDGET, OPTION, MULTIPLIER) \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_valuechanged(GtkSpinButton *spinbutton, \ + struct ppref *priv); \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_valuechanged(GtkSpinButton *spinbutton, \ + struct ppref *priv) \ +{ \ + nsoption_set_int(OPTION, \ + round(gtk_spin_button_get_value(spinbutton) * MULTIPLIER)); \ +} \ + \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_realize(GtkWidget *widget, struct ppref *priv); \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_realize(GtkWidget *widget, struct ppref *priv) \ +{ \ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), \ + ((gdouble)nsoption_int(OPTION)) / MULTIPLIER); \ +} + +#define ENTRY_SIGNALS(WIDGET, OPTION) \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_changed(GtkEditable *editable, struct ppref *priv); \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_changed(GtkEditable *editable, struct ppref *priv)\ +{ \ + nsoption_set_charp(OPTION, \ + strdup(gtk_entry_get_text(GTK_ENTRY(editable)))); \ +} \ + \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_realize(GtkWidget *widget, struct ppref *priv); \ +G_MODULE_EXPORT void \ +nsgtk_preferences_##WIDGET##_realize(GtkWidget *widget, struct ppref *priv) \ +{ \ + const char *OPTION; \ + OPTION = nsoption_charp(OPTION); \ + if (OPTION != NULL) { \ + gtk_entry_set_text(GTK_ENTRY(widget), OPTION); \ + } \ +} + +/* GTK module requires these to be exported symbols so these all need + * forward declaring to avoid warnings + */ +G_MODULE_EXPORT void nsgtk_preferences_comboProxyType_changed(GtkComboBox *combo, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboProxyType_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboboxLoadImages_changed(GtkComboBox *combo, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboboxLoadImages_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboDefault_changed(GtkComboBox *combo, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboDefault_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_fontPreview_clicked(GtkButton *button, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboboxLanguage_changed(GtkComboBox *combo, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboboxLanguage_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboTheme_changed(GtkComboBox *combo, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboTheme_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_buttonAddTheme_clicked(GtkButton *button, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_checkShowSingleTab_toggled(GtkToggleButton *togglebutton, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_checkShowSingleTab_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboTabPosition_changed(GtkComboBox *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboTabPosition_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_sourceButtonWindow_toggled(GtkToggleButton *togglebutton, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_sourceButtonWindow_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboButtonType_changed(GtkComboBox *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboButtonType_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_setCurrentPage_clicked(GtkButton *button, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_setDefaultPage_clicked(GtkButton *button, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboSearch_changed(GtkComboBox *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_comboSearch_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_fileChooserDownloads_selectionchanged(GtkFileChooser *chooser, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_fileChooserDownloads_realize(GtkWidget *widget, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_dialogPreferences_response(GtkDialog *dlg, gint resid); +G_MODULE_EXPORT gboolean nsgtk_preferences_dialogPreferences_deleteevent(GtkDialog *dlg, struct ppref *priv); +G_MODULE_EXPORT void nsgtk_preferences_dialogPreferences_destroy(GtkDialog *dlg, struct ppref *priv); + + +/********* PDF **********/ + +/* Appearance */ + +/* no images in output */ +TOGGLEBUTTON_SIGNALS(checkSuppressImages, suppress_images) + +/* no background images */ +TOGGLEBUTTON_SIGNALS(checkRemoveBackgrounds, remove_backgrounds) + +/* scale to fit page */ +TOGGLEBUTTON_SIGNALS(checkFitPage, enable_loosening) + +/* port */ +SPINBUTTON_SIGNALS(spinExportScale, export_scale, 1.0) + +/* Margins */ +SPINBUTTON_SIGNALS(spinMarginTop, margin_top, 1.0) +SPINBUTTON_SIGNALS(spinMarginBottom, margin_bottom, 1.0) +SPINBUTTON_SIGNALS(spinMarginLeft, margin_left, 1.0) +SPINBUTTON_SIGNALS(spinMarginRight, margin_right, 1.0) + + +/* Generation */ + +/* output is compressed */ +TOGGLEBUTTON_SIGNALS(checkCompressPDF, enable_PDF_compression) + +/* output has a password */ +TOGGLEBUTTON_SIGNALS(checkPasswordPDF, enable_PDF_password) + +/********* Network **********/ + +/* HTTP proxy */ +static void set_proxy_widgets_sensitivity(int proxyval, struct ppref *priv) +{ + gboolean host; + gboolean port; + gboolean user; + gboolean pass; + + switch (proxyval) { + case 0: /* no proxy */ + host = FALSE; + port = FALSE; + user = FALSE; + pass = FALSE; + break; + + case 1: /* proxy with no auth */ + host = TRUE; + port = TRUE; + user = FALSE; + pass = FALSE; + break; + + case 2: /* proxy with basic auth */ + host = TRUE; + port = TRUE; + user = TRUE; + pass = TRUE; + break; + + case 3: /* proxy with ntlm auth */ + host = TRUE; + port = TRUE; + user = TRUE; + pass = TRUE; + break; + + case 4: /* system proxy */ + host = FALSE; + port = FALSE; + user = FALSE; + pass = FALSE; + break; + + default: + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(priv->entryProxyHost), host); + gtk_widget_set_sensitive(GTK_WIDGET(priv->spinProxyPort), port); + gtk_widget_set_sensitive(GTK_WIDGET(priv->entryProxyUser), user); + gtk_widget_set_sensitive(GTK_WIDGET(priv->entryProxyPassword), pass); + +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboProxyType_changed(GtkComboBox *combo, struct ppref *priv) +{ + int proxy_sel; + proxy_sel = gtk_combo_box_get_active(combo); + + switch (proxy_sel) { + case 0: /* no proxy */ + nsoption_set_bool(http_proxy, false); + break; + + case 1: /* proxy with no auth */ + nsoption_set_bool(http_proxy, true); + nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NONE); + break; + + case 2: /* proxy with basic auth */ + nsoption_set_bool(http_proxy, true); + nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_BASIC); + break; + + case 3: /* proxy with ntlm auth */ + nsoption_set_bool(http_proxy, true); + nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NTLM); + break; + + case 4: /* system proxy */ + nsoption_set_bool(http_proxy, true); + nsoption_set_int(http_proxy_auth, OPTION_HTTP_PROXY_AUTH_NONE); + break; + } + + set_proxy_widgets_sensitivity(proxy_sel, priv); +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboProxyType_realize(GtkWidget *widget, struct ppref *priv) +{ + int proxytype = 0; /* no proxy by default */ + + if (nsoption_bool(http_proxy) == true) { + /* proxy type combo box starts with disabled, to allow + * for this the http_proxy option needs combining with + * the http_proxy_auth option + */ + proxytype = nsoption_int(http_proxy_auth) + 1; + if (nsoption_charp(http_proxy_host) == NULL) { + /* set to use a proxy without a host, turn proxy off */ + proxytype = 0; + } else if (((proxytype == 2) || + (proxytype == 3)) && + ((nsoption_charp(http_proxy_auth_user) == NULL) || + (nsoption_charp(http_proxy_auth_pass) == NULL))) { + /* authentication selected with empty credentials, turn proxy off */ + proxytype = 0; + } + } + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), proxytype); + + set_proxy_widgets_sensitivity(proxytype, priv); +} + +/* host */ +ENTRY_SIGNALS(entryProxyHost, http_proxy_host) + +/* port */ +SPINBUTTON_SIGNALS(spinProxyPort, http_proxy_port, 1.0) + +/* user */ +ENTRY_SIGNALS(entryProxyUser, http_proxy_auth_user) + +/* password */ +ENTRY_SIGNALS(entryProxyPassword, http_proxy_auth_pass) + +/* Fetching */ + +/* maximum fetchers */ +SPINBUTTON_SIGNALS(spinMaxFetchers, max_fetchers, 1.0) + +/* fetches per host */ +SPINBUTTON_SIGNALS(spinFetchesPerHost, max_fetchers_per_host, 1.0) + +/* cached connections */ +SPINBUTTON_SIGNALS(spinCachedConnections, max_cached_fetch_handles, 1.0) + + +/********* Privacy **********/ + +/* General */ + +/* enable referral submission */ +TOGGLEBUTTON_SIGNALS(checkSendReferer, send_referer) + +/* send do not track */ +TOGGLEBUTTON_SIGNALS(checkSendDNT, do_not_track) + +/* History */ + +/* local history shows url tooltips */ +TOGGLEBUTTON_SIGNALS(checkHoverURLs, hover_urls) + +/* remember browsing history */ +SPINBUTTON_SIGNALS(spinHistoryAge, history_age, 1.0) + +/* Cache */ + +/* memory cache size */ +SPINBUTTON_SIGNALS(spinMemoryCacheSize, memory_cache_size, (1024*1024)) + +/* disc cache size */ +SPINBUTTON_SIGNALS(spinDiscCacheSize, disc_cache_size, (1024*1024)) + + +/* disc cache age */ +SPINBUTTON_SIGNALS(spinDiscCacheAge, disc_cache_age, 1.0) + + +/********* Content **********/ + +/* Control */ + + +/* prevent popups */ +TOGGLEBUTTON_SIGNALS(checkDisablePopups, disable_popups) + +/* hide adverts */ +TOGGLEBUTTON_SIGNALS(checkHideAdverts, block_ads) + +/* enable javascript */ +TOGGLEBUTTON_SIGNALS(checkEnableJavascript, enable_javascript) + +/* disable plugins */ +TOGGLEBUTTON_SIGNALS(checkDisablePlugins, disable_plugins) + +/* high quality image scaling */ +TOGGLEBUTTON_SIGNALS(checkResampleImages, render_resample) + +/* load and display of images */ +G_MODULE_EXPORT void +nsgtk_preferences_comboboxLoadImages_changed(GtkComboBox *combo, + struct ppref *priv) +{ + int img_sel; + /* get the row number for the selection */ + img_sel = gtk_combo_box_get_active(combo); + switch (img_sel) { + case 0: + /* background and foreground */ + nsoption_set_bool(foreground_images, true); + nsoption_set_bool(background_images, true); + break; + + case 1: + /* foreground only */ + nsoption_set_bool(foreground_images, true); + nsoption_set_bool(background_images, false); + break; + + case 2: + /* background only */ + nsoption_set_bool(foreground_images, false); + nsoption_set_bool(background_images, true); + break; + + case 3: + /* no images */ + nsoption_set_bool(foreground_images, false); + nsoption_set_bool(background_images, false); + break; + } +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboboxLoadImages_realize(GtkWidget *widget, + struct ppref *priv) +{ + if (nsoption_bool(foreground_images)) { + if (nsoption_bool(background_images)) { + /* background and foreground */ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0); + } else { + /* foreground only */ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 1); + } + } else { + if (nsoption_bool(background_images)) { + /* background only */ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 2); + } else { + /* no images */ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 3); + } + } +} + +/* Animation */ + +/* enable animation */ +TOGGLEBUTTON_SIGNALS(checkEnableAnimations, animate_images) + +/* frame time */ +SPINBUTTON_SIGNALS(spinAnimationSpeed, minimum_gif_delay, 100.0) + +/* Fonts */ + +/* default font */ +G_MODULE_EXPORT void +nsgtk_preferences_comboDefault_changed(GtkComboBox *combo, struct ppref *priv) +{ + int font_sel; + /* get the row number for the selection */ + font_sel = gtk_combo_box_get_active(combo); + if ((font_sel >= 0) && (font_sel <= 4)) { + nsoption_set_int(font_default, font_sel); + } +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboDefault_realize(GtkWidget *widget, struct ppref *priv) +{ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), + nsoption_int(font_default)); +} + +/* default font size */ +SPINBUTTON_SIGNALS(spinDefaultSize, font_size, 10.0) + +/* preview - actually reflow all views */ +G_MODULE_EXPORT void +nsgtk_preferences_fontPreview_clicked(GtkButton *button, struct ppref *priv) +{ + nsgtk_reflow_all_windows(); +} + + +/* Language */ + +/* accept language */ +G_MODULE_EXPORT void +nsgtk_preferences_comboboxLanguage_changed(GtkComboBox *combo, + struct ppref *priv) +{ + gchar *lang = NULL; + GtkTreeIter iter; + GtkTreeModel *model; + + /* Obtain currently selected item from combo box. + * If nothing is selected, do nothing. + */ + if (gtk_combo_box_get_active_iter(combo, &iter)) { + /* Obtain data model from combo box. */ + model = gtk_combo_box_get_model(combo); + + /* Obtain string from model. */ + gtk_tree_model_get(model, &iter, 0, &lang, -1); + } + + if (lang != NULL) { + nsoption_set_charp(accept_language, strdup(lang)); + g_free(lang); + } +} + +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"; + + if ((priv->content_language != NULL) && + (languages_file_location != NULL) && + ((fp = fopen(languages_file_location, "r")) != NULL)) { + int combo_row_count = 0; + + gtk_list_store_clear(priv->content_language); + active_language = -1; + + LOG(("Used %s for languages", languages_file_location)); + while (fgets(buf, sizeof(buf), fp)) { + /* Ignore blank lines */ + if (buf[0] == '\0') + continue; + + /* Remove trailing \n */ + buf[strlen(buf) - 1] = '\0'; + + gtk_list_store_append(priv->content_language, &iter); + gtk_list_store_set(priv->content_language, + &iter, 0, buf, -1 ); + + if (strcmp(buf, default_accept_language) == 0) { + active_language = combo_row_count; + } + + combo_row_count++; + } + + if (active_language == -1) { + /* configured language was not in list, add it */ + gtk_list_store_append(priv->content_language, &iter); + gtk_list_store_set(priv->content_language, + &iter, + 0, default_accept_language, -1 ); + active_language = combo_row_count; + } + + fclose(fp); + } else { + LOG(("Failed opening languages file")); + } + + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), active_language); +} + + +/********* Apperance **********/ + +/* Themes */ + +/* select theme */ +G_MODULE_EXPORT void +nsgtk_preferences_comboTheme_changed(GtkComboBox *combo, struct ppref *priv) +{ + nsgtk_scaffolding *current = scaf_list; + int theme = 0; + gchar *name; + GtkTreeIter iter; + GtkTreeModel *model; + + /* Obtain currently selected item from combo box. + * If nothing is selected, do nothing. + */ + if (gtk_combo_box_get_active_iter(combo, &iter)) { + /* get the row number for the config */ + theme = gtk_combo_box_get_active(combo); + + nsoption_set_int(current_theme, theme); + + /* retrive the theme name if it is not the default */ + if (theme != 0) { + /* Obtain data model from combo box. */ + model = gtk_combo_box_get_model(combo); + + /* Obtain string from model. */ + gtk_tree_model_get(model, &iter, 0, &name, -1); + } else { + name = NULL; + } + + nsgtk_theme_set_name(name); + + if (name != NULL) { + g_free(name); + } + + while (current) { + nsgtk_theme_implement(current); + current = nsgtk_scaffolding_iterate(current); + } + } +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboTheme_realize(GtkWidget *widget, struct ppref *priv) +{ + /* Fill theme list store */ + FILE *fp; + GtkTreeIter iter; + char buf[50]; + int combo_row_count = 0; + int selected_theme = 0; + + if ((priv->themes != NULL) && + (themelist_file_location != NULL) && + ((fp = fopen(themelist_file_location, "r")) != NULL)) { + gtk_list_store_clear(priv->themes); + + LOG(("Used %s for themelist", themelist_file_location)); + + while (fgets(buf, sizeof(buf), fp)) { + /* Ignore blank lines */ + if (buf[0] == '\0') + continue; + + /* Remove trailing \n */ + buf[strlen(buf) - 1] = '\0'; + + gtk_list_store_append(priv->themes, &iter); + gtk_list_store_set(priv->themes, &iter, 0, buf, -1); + + combo_row_count++; + } + + fclose(fp); + } else { + LOG(("Failed opening themes file")); + } + + /* get configured theme and sanity check value */ + selected_theme = nsoption_int(current_theme); + if (selected_theme > combo_row_count) { + selected_theme = combo_row_count; + } + if (selected_theme < 0) { + selected_theme = 0; + } + + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), selected_theme); +} + +/* add theme */ +G_MODULE_EXPORT void +nsgtk_preferences_buttonAddTheme_clicked(GtkButton *button, struct ppref *priv) +{ + char *filename, *directory; + size_t len; + GtkWidget *fc = gtk_file_chooser_dialog_new( + messages_get("gtkAddThemeTitle"), + GTK_WINDOW(priv->dialog), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + len = SLEN("themes") + strlen(res_dir_location) + 1; + char themesfolder[len]; + snprintf(themesfolder, len, "%sthemes", res_dir_location); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), + themesfolder); + gint res = gtk_dialog_run(GTK_DIALOG(fc)); + if (res == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_current_folder( + GTK_FILE_CHOOSER(fc)); + if (strcmp(filename, themesfolder) != 0) { + directory = strrchr(filename, '/'); + *directory = '\0'; + if (strcmp(filename, themesfolder) != 0) { + warn_user(messages_get( + "gtkThemeFolderInstructions"), + 0); + gtk_widget_destroy(GTK_WIDGET(fc)); + if (filename != NULL) + g_free(filename); + return; + } else { + directory++; + } + } else { + if (filename != NULL) + g_free(filename); + filename = gtk_file_chooser_get_filename( + GTK_FILE_CHOOSER(fc)); + if (strcmp(filename, themesfolder) == 0) { + warn_user(messages_get("gtkThemeFolderSub"), + 0); + gtk_widget_destroy(GTK_WIDGET(fc)); + g_free(filename); + return; + } + directory = strrchr(filename, '/') + 1; + } + gtk_widget_destroy(GTK_WIDGET(fc)); + nsgtk_theme_add(directory); + if (filename != NULL) + g_free(filename); + } +} + +/* Tabs */ + +/* always show tab bar */ +G_MODULE_EXPORT void +nsgtk_preferences_checkShowSingleTab_toggled(GtkToggleButton *togglebutton, + struct ppref *priv) +{ + nsoption_set_bool(show_single_tab, + gtk_toggle_button_get_active(togglebutton)); + nsgtk_reflow_all_windows(); +} + +G_MODULE_EXPORT void +nsgtk_preferences_checkShowSingleTab_realize(GtkWidget *widget, + struct ppref *priv) +{ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), + nsoption_bool(show_single_tab)); +} + +/* switch to newly opened tabs immediately */ +TOGGLEBUTTON_SIGNALS(checkFocusNew, focus_new) + +/* newly opened tabs are blank */ +TOGGLEBUTTON_SIGNALS(checkNewBlank, new_blank) + +/* tab position */ +G_MODULE_EXPORT void +nsgtk_preferences_comboTabPosition_changed(GtkComboBox *widget, + struct ppref *priv) +{ + nsgtk_scaffolding *current = scaf_list; + + /* set the option */ + nsoption_set_int(position_tab, gtk_combo_box_get_active(widget)); + + /* update all notebooks in all scaffolds */ + while (current) { + nsgtk_scaffolding_reset_offset(current); + + nsgtk_reflow_all_windows(); + + current = nsgtk_scaffolding_iterate(current); + } +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboTabPosition_realize(GtkWidget *widget, + struct ppref *priv) +{ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), + nsoption_int(position_tab)); +} + +/* Source */ + +/* source view opening */ +TOGGLEBUTTON_SIGNALS(sourceButtonTab, source_tab) + +G_MODULE_EXPORT void +nsgtk_preferences_sourceButtonWindow_toggled(GtkToggleButton *togglebutton, + struct ppref *priv) +{ + nsoption_set_bool(source_tab, + !gtk_toggle_button_get_active(togglebutton)); +} + +G_MODULE_EXPORT void +nsgtk_preferences_sourceButtonWindow_realize(GtkWidget *widget, + struct ppref *priv) +{ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), + !nsoption_bool(source_tab)); +} + + +/* URLbar */ + +/* show recently visited urls as you type */ +TOGGLEBUTTON_SIGNALS(checkDisplayRecentURLs, url_suggestion) + +/* Toolbar */ + +/* button position */ +G_MODULE_EXPORT void +nsgtk_preferences_comboButtonType_changed(GtkComboBox *widget, + struct ppref *priv) +{ + nsgtk_scaffolding *current = scaf_list; + nsoption_set_int(button_type, gtk_combo_box_get_active(widget) + 1); + + /* value of 0 is reserved for 'unset' */ + while (current) { + nsgtk_scaffolding_reset_offset(current); + switch(nsoption_int(button_type)) { + case 1: + gtk_toolbar_set_style( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_TOOLBAR_ICONS); + gtk_toolbar_set_icon_size( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_ICON_SIZE_SMALL_TOOLBAR); + break; + case 2: + gtk_toolbar_set_style( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_TOOLBAR_ICONS); + gtk_toolbar_set_icon_size( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_ICON_SIZE_LARGE_TOOLBAR); + break; + case 3: + gtk_toolbar_set_style( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_TOOLBAR_BOTH); + gtk_toolbar_set_icon_size( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_ICON_SIZE_LARGE_TOOLBAR); + break; + case 4: + gtk_toolbar_set_style( + GTK_TOOLBAR(nsgtk_scaffolding_toolbar(current)), + GTK_TOOLBAR_TEXT); + default: + break; + } + current = nsgtk_scaffolding_iterate(current); + } +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboButtonType_realize(GtkWidget *widget, + struct ppref *priv) +{ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), + nsoption_int(button_type) - 1); +} + + + +/************ Main ************/ + +/* Startup */ + +/* entry HomePageURL widget */ +ENTRY_SIGNALS(entryHomePageURL, homepage_url) + +/* put current page into homepage url */ +G_MODULE_EXPORT void +nsgtk_preferences_setCurrentPage_clicked(GtkButton *button, struct ppref *priv) +{ + const gchar *url; + + if (priv->bw != NULL) { + url = nsurl_access(hlcache_handle_get_url(priv->bw->current_content)); + } else { + url = "about:blank"; + } + + if (priv->entryHomePageURL != NULL) { + gtk_entry_set_text(GTK_ENTRY(priv->entryHomePageURL), url); + nsoption_set_charp(homepage_url, strdup(url)); + } +} + +/* put default page into homepage */ +G_MODULE_EXPORT void +nsgtk_preferences_setDefaultPage_clicked(GtkButton *button, struct ppref *priv) +{ + const gchar *url = NETSURF_HOMEPAGE; + + if (priv->entryHomePageURL != NULL) { + gtk_entry_set_text(GTK_ENTRY(priv->entryHomePageURL), url); + nsoption_set_charp(homepage_url, strdup(url)); + } +} + +/* Search */ + +/* Url Search widget */ +TOGGLEBUTTON_SIGNALS(checkUrlSearch, search_url_bar) + +/* provider combo */ +G_MODULE_EXPORT void +nsgtk_preferences_comboSearch_changed(GtkComboBox *widget, struct ppref *priv) +{ + nsgtk_scaffolding *current = scaf_list; + char *name; + int provider; + + provider = gtk_combo_box_get_active(widget); + + /* set the option */ + nsoption_set_int(search_provider, provider); + + /* refresh web search prefs from file */ + search_web_provider_details(provider); + + /* retrieve ico */ + search_web_retrieve_ico(false); + + /* callback may handle changing gui */ + if (search_web_ico() != NULL) { + gui_window_set_search_ico(search_web_ico()); + } + + /* set entry */ + name = search_web_provider_name(); + if (name != NULL) { + char content[strlen(name) + SLEN("Search ") + 1]; + + sprintf(content, "Search %s", name); + free(name); + while (current) { + nsgtk_scaffolding_set_websearch(current, content); + current = nsgtk_scaffolding_iterate(current); + } + } +} + +G_MODULE_EXPORT void +nsgtk_preferences_comboSearch_realize(GtkWidget *widget, struct ppref *priv) +{ + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), + nsoption_int(search_provider)); +} + + +/* Downloads */ + +/* clear downloads */ +TOGGLEBUTTON_SIGNALS(checkClearDownloads, downloads_clear) + +/* request overwite */ +TOGGLEBUTTON_SIGNALS(checkRequestOverwrite, request_overwrite) + +/* download location + * + * note selection-changed is used instead of file-set as the returned + * filename when that signal are used is incorrect. Though this signal + * does update frequently often with the same data. + */ +G_MODULE_EXPORT void +nsgtk_preferences_fileChooserDownloads_selectionchanged(GtkFileChooser *chooser, + struct ppref *priv) +{ + gchar *dir; + dir = gtk_file_chooser_get_filename(chooser); + nsoption_set_charp(downloads_directory, strdup(dir)); + g_free(dir); +} + +G_MODULE_EXPORT void +nsgtk_preferences_fileChooserDownloads_realize(GtkWidget *widget, + struct ppref *priv) +{ + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(widget), + nsoption_charp(downloads_directory)); +} + + +/************* Dialog window ***********/ + +/* dialog close and destroy events */ +G_MODULE_EXPORT void +nsgtk_preferences_dialogPreferences_response(GtkDialog *dlg, gint resid) +{ + if (resid == GTK_RESPONSE_CLOSE) { + nsoption_write(options_file_location); + gtk_widget_hide(GTK_WIDGET(dlg)); + } +} + +G_MODULE_EXPORT gboolean +nsgtk_preferences_dialogPreferences_deleteevent(GtkDialog *dlg, + struct ppref *priv) +{ + nsoption_write(options_file_location); + gtk_widget_hide(GTK_WIDGET(dlg)); + + /* delt with it by hiding window, no need to destory widget by + * default */ + return TRUE; +} + +G_MODULE_EXPORT void +nsgtk_preferences_dialogPreferences_destroy(GtkDialog *dlg, struct ppref *priv) +{ + nsoption_write(options_file_location); +} + + +/* exported interface documented in gtk/dialogs/preferences.h */ +GtkWidget* nsgtk_preferences(struct browser_window *bw, GtkWindow *parent) +{ + GError *error = NULL; + GtkBuilder *preferences_builder; + struct ppref *priv = &ppref; + + priv->bw = bw; /* for setting "current" page */ + + /* memoised dialog creation */ + if (priv->dialog != NULL) { + gtk_window_set_transient_for(GTK_WINDOW(priv->dialog), parent); + return GTK_WIDGET(priv->dialog); + } + + /* populate builder object */ + preferences_builder = gtk_builder_new(); + if (!gtk_builder_add_from_file(preferences_builder, + glade_file_location->options, + &error)) { + g_warning("Couldn't load builder file: %s", error->message); + g_error_free(error); + return NULL; + } + + + priv->dialog = gtk_builder_get_object(preferences_builder, + "dialogPreferences"); + if (priv->dialog == NULL) { + LOG(("Unable to get object for preferences dialog")); + /* release builder as were done with it */ + g_object_unref(G_OBJECT(preferences_builder)); + return NULL; + } + + /* need to explicitly obtain handles for some widgets enabling + * updates by other widget events + */ +#define GB(TYPE, NAME) GTK_##TYPE(gtk_builder_get_object(preferences_builder, #NAME)) + priv->entryHomePageURL = GB(ENTRY, entryHomePageURL); + priv->themes = GB(LIST_STORE, liststore_themes); + priv->content_language = GB(LIST_STORE, liststore_content_language); + priv->entryProxyHost = GB(ENTRY, entryProxyHost); + priv->spinProxyPort = GB(SPIN_BUTTON, spinProxyPort); + priv->entryProxyUser = GB(ENTRY, entryProxyUser); + priv->entryProxyPassword = GB(ENTRY, entryProxyPassword); +#undef GB + + /* connect all signals ready to use */ + gtk_builder_connect_signals(preferences_builder, priv); + + /* release builder as were done with it */ + g_object_unref(G_OBJECT(preferences_builder)); + + /* mark dialog as transient on parent */ + gtk_window_set_transient_for(GTK_WINDOW(priv->dialog), parent); + + return GTK_WIDGET(priv->dialog); +} + +/* exported interface documented in gtk/dialogs/preferences.h */ +void nsgtk_preferences_theme_add(const char *themename) +{ + struct ppref *priv = &ppref; + GtkTreeIter iter; + + gtk_list_store_append(priv->themes, &iter); + gtk_list_store_set(priv->themes, &iter, 0, themename, -1 ); +} diff --git a/gtk/dialogs/preferences.h b/gtk/dialogs/preferences.h new file mode 100644 index 000000000..3ef33ca30 --- /dev/null +++ b/gtk/dialogs/preferences.h @@ -0,0 +1,32 @@ +/* + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NETSURF_GTK_PREFERENCES_H +#define NETSURF_GTK_PREFERENCES_H + +#include + +/** Initialise prefernces window + */ +GtkWidget* nsgtk_preferences(struct browser_window *bw, GtkWindow *parent); + +/** Theme added + */ +void nsgtk_preferences_theme_add(const char *themename); + +#endif diff --git a/gtk/gui.c b/gtk/gui.c index 1d15ef743..a120fdfb6 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -59,7 +59,6 @@ #include "desktop/tree.h" #include "css/utils.h" #include "gtk/compat.h" -#include "gtk/dialogs/options.h" #include "gtk/completion.h" #include "gtk/cookies.h" #include "gtk/download.h" @@ -85,6 +84,7 @@ char *toolbar_indices_file_location; char *res_dir_location; char *print_options_file_location; char *languages_file_location; +char *themelist_file_location; GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */ @@ -364,6 +364,17 @@ static void gui_init(int argc, char** argv, char **respath) die("Unable to find resources.\n"); } + /* find the theme list file */ + themelist_file_location = filepath_find(respath, "themelist"); + if ((themelist_file_location != NULL) && + (strlen(themelist_file_location) < 10)) { + free(themelist_file_location); + themelist_file_location = NULL; + } + if (themelist_file_location == NULL) { + LOG(("Unable to find themelist - disabling")); + } + /* Obtain resources path location. * * Uses the directory the languages file was found in, diff --git a/gtk/gui.h b/gtk/gui.h index b53de256a..72794b231 100644 --- a/gtk/gui.h +++ b/gtk/gui.h @@ -54,6 +54,7 @@ extern char *toolbar_indices_file_location; extern char *options_file_location; /**< location where user options are written */ extern char *res_dir_location; extern char *print_options_file_location; +extern char *themelist_file_location; extern GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */ diff --git a/gtk/res/options.gtk2.ui b/gtk/res/options.gtk2.ui index 5dd793062..85db837b8 100644 --- a/gtk/res/options.gtk2.ui +++ b/gtk/res/options.gtk2.ui @@ -9,6 +9,9 @@ True dialog False + + + True @@ -59,6 +62,8 @@ True True + + end @@ -83,11 +88,13 @@ True True True + False False - 1 + end + 2 @@ -96,17 +103,18 @@ True True True + False False - 2 + end + 1 False - end 1 @@ -151,6 +159,8 @@ True False True + + 0 @@ -175,6 +185,8 @@ True liststore_search_provider + + @@ -232,6 +244,8 @@ True False True + + False @@ -245,6 +259,8 @@ True False True + + False @@ -269,6 +285,8 @@ True select-folder + + 1 @@ -330,14 +348,29 @@ True 12 - + + True + liststore_themes + + + + + + 0 + + + + + 0 + - + Add Theme... True True True + False @@ -386,6 +419,8 @@ True False True + + 0 @@ -398,6 +433,8 @@ True False True + + 1 @@ -410,6 +447,8 @@ True False True + + 2 @@ -434,6 +473,8 @@ True liststore_tab_position + + @@ -503,10 +544,11 @@ True True False - 0.54000002145767212 True True sourceButtonTab + + 0 @@ -520,6 +562,8 @@ False True True + + 1 @@ -571,6 +615,8 @@ True False True + + 0 @@ -628,6 +674,8 @@ True liststore_toolbar_buttontype + + @@ -705,6 +753,8 @@ True False True + + False @@ -719,6 +769,8 @@ True False True + + False @@ -733,6 +785,8 @@ True False True + + False @@ -747,6 +801,8 @@ True False True + + False @@ -761,6 +817,8 @@ True False True + + 4 @@ -784,6 +842,8 @@ True liststore_image_loading + + @@ -841,6 +901,8 @@ True False True + + 0 @@ -872,6 +934,8 @@ 1 True if-valid + + False @@ -934,6 +998,8 @@ True liststore_defaultfont + + @@ -970,12 +1036,15 @@ True True The base-line font size to use. - 3 + 4 - 3 + 4 adjustment_font_default_size 1 + 1 True + + False @@ -996,6 +1065,7 @@ True image1 True + False @@ -1055,6 +1125,8 @@ True set preferred language for web pages liststore_content_language + + 0 @@ -1118,6 +1190,68 @@ True vertical 6 + + + True + 0 + none + + + True + 6 + 12 + 12 + + + True + vertical + 6 + + + Enable referral submission + True + True + False + True + + + + + 0 + + + + + Enable sending "Do Not Track" request + True + True + False + True + + + + + 1 + + + + + + + + + True + <b>General</b> + True + + + + + False + 6 + 0 + + True @@ -1141,6 +1275,8 @@ True False True + + 0 @@ -1170,6 +1306,9 @@ adjustment_history_age 1 True + if-valid + + False @@ -1206,7 +1345,7 @@ False 6 - 0 + 1 @@ -1275,6 +1414,8 @@ adjustment_cache_memory_size 1 True + + 1 @@ -1291,6 +1432,8 @@ adjustment_cache_disc_size 1 True + + 1 @@ -1309,6 +1452,8 @@ adjustment_disc_cache_age 1 True + + 1 @@ -1401,63 +1546,6 @@ False 6 - 1 - - - - - True - 0 - none - - - True - 6 - 12 - 12 - - - True - vertical - 6 - - - Enable referral submission - True - True - False - True - - - 0 - - - - - Enable sending "Do Not Track" request - True - True - False - True - - - 1 - - - - - - - - - True - <b>General</b> - True - - - - - False 2 @@ -1551,6 +1639,8 @@ True The type of HTTP proxy server. liststore_proxy_type + + @@ -1574,6 +1664,8 @@ True Host name of your proxy server. + + 0 @@ -1602,6 +1694,8 @@ 1 True if-valid + + False @@ -1623,6 +1717,8 @@ True Username to access the proxy + + 1 @@ -1637,7 +1733,10 @@ True True Password to access the proxy + False + + 1 @@ -1727,6 +1826,8 @@ adjustment_fetching_max 1 True + + 1 @@ -1745,6 +1846,8 @@ adjustment_fetching_perhost 1 True + + 1 @@ -1765,6 +1868,8 @@ adjustment_fetching_cached 1 True + + 1 @@ -1835,6 +1940,8 @@ True False True + + 0 @@ -1847,6 +1954,8 @@ True False True + + 1 @@ -1859,6 +1968,8 @@ True False True + + 2 @@ -1889,6 +2000,8 @@ adjustment_pdf_scale 1 True + + False @@ -1995,6 +2108,8 @@ 1 1 True + + False @@ -2034,6 +2149,8 @@ 1 1 True + + False @@ -2072,6 +2189,8 @@ 1 1 True + + False @@ -2112,6 +2231,8 @@ 1 1 True + + False @@ -2188,6 +2309,8 @@ True False True + + 0 @@ -2200,6 +2323,8 @@ True False True + + 1 @@ -2481,9 +2606,9 @@ 16 1 - 100 - 1 - 10 + 99.900000000000006 + 0.10000000000000001 + 2 28 @@ -2562,4 +2687,15 @@ + + + + + + + + Default + + + diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 91288a22e..8b9b8f3b1 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -53,7 +53,7 @@ #include "desktop/tree.h" #include "gtk/cookies.h" #include "gtk/completion.h" -#include "gtk/dialogs/options.h" +#include "gtk/dialogs/preferences.h" #include "gtk/dialogs/about.h" #include "gtk/dialogs/source.h" #include "gtk/bitmap.h" @@ -138,7 +138,6 @@ struct gtk_scaffolding { GtkBuilder *xml; struct gtk_history_window *history_window; - GtkDialog *preferences_dialog; int throb_frame; struct gui_window *top_level; @@ -1027,10 +1026,12 @@ MULTIHANDLER(find) MULTIHANDLER(preferences) { struct browser_window *bw = nsgtk_get_browser_window(g->top_level); - if (g->preferences_dialog == NULL) - g->preferences_dialog = nsgtk_options_init(bw, g->window); - else - gtk_widget_show(GTK_WIDGET(g->preferences_dialog)); + GtkWidget* wndpreferences; + + wndpreferences = nsgtk_preferences(bw, g->window); + if (wndpreferences != NULL) { + gtk_widget_show(GTK_WIDGET(wndpreferences)); + } return TRUE; } @@ -1769,8 +1770,6 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) g->menu_bar = nsgtk_menu_bar_create(GTK_MENU_SHELL(gtk_builder_get_object(g->xml, "menubar")), group); - g->preferences_dialog = NULL; - /* set this window's size and position to what's in the options, or * or some sensible default if they're not set yet. */ diff --git a/gtk/theme.c b/gtk/theme.c index f16bd2d11..402433c32 100644 --- a/gtk/theme.c +++ b/gtk/theme.c @@ -32,7 +32,7 @@ #include "gtk/theme.h" #include "gtk/window.h" #include "desktop/options.h" -#include "gtk/dialogs/options.h" +#include "gtk/dialogs/preferences.h" #include "utils/container.h" #include "utils/log.h" #include "utils/messages.h" @@ -157,28 +157,32 @@ static bool nsgtk_theme_verify(const char *themename) void nsgtk_theme_init(void) { - size_t len; - if (nsoption_int(current_theme) == 0) { + int theme; + nsgtk_scaffolding *list = scaf_list; + FILE *fp; + char buf[50]; + int row_count = 0; + + theme = nsoption_int(current_theme); + + /* check if default theme is selected */ + if (theme == 0) { return; } - len = SLEN("themelist") + strlen(res_dir_location) + 1; - char themefile[len]; - snprintf(themefile, len, "%s%s", res_dir_location, "themelist"); - nsgtk_scaffolding *list = scaf_list; nsgtk_theme_verify(NULL); - FILE *fp = fopen(themefile, "r"); + fp = fopen(themelist_file_location, "r"); if (fp == NULL) return; - char buf[50]; - int row_count = 0; + while (fgets(buf, sizeof(buf), fp) != NULL) { if (buf[0] == '\0') continue; - if (row_count++ == nsoption_int(current_theme)) { - if (current_theme_name != NULL) + if (row_count++ == theme) { + if (current_theme_name != NULL) { free(current_theme_name); + } /* clear the '\n' ["\n\0"->"\0\0"] */ buf[strlen(buf) - 1] = '\0'; current_theme_name = strdup(buf); @@ -204,13 +208,25 @@ char *nsgtk_theme_name(void) } /** - * set static global current_theme_name from param; caller is responsible - * for the integrity of the global reference + * set static global current_theme_name from param */ -void nsgtk_theme_set_name(char *name) +void nsgtk_theme_set_name(const char *name) { - current_theme_name = name; + if ((name == NULL) && (current_theme_name == NULL)) { + return; /* setting it to the same thing */ + } else if ((name == NULL) && (current_theme_name != NULL)) { + free(current_theme_name); + current_theme_name = NULL; + } else if ((name != NULL) && (current_theme_name == NULL)) { + current_theme_name = strdup(name); + nsgtk_theme_prepare(); + } else if (strcmp(name, current_theme_name) != 0) { + /* disimilar new name */ + free(current_theme_name); + current_theme_name = strdup(name); + nsgtk_theme_prepare(); + } } /** @@ -260,9 +276,7 @@ void nsgtk_theme_add(const char *themename) gtk_widget_show_all(notification); /* update combo */ - if (wndPreferences != NULL) { - nsgtk_options_combo_theme_add(themename); - } + nsgtk_preferences_theme_add(themename); } diff --git a/gtk/theme.h b/gtk/theme.h index 117207037..4aedad23f 100644 --- a/gtk/theme.h +++ b/gtk/theme.h @@ -41,6 +41,6 @@ void nsgtk_theme_init(void); void nsgtk_theme_prepare(void); void nsgtk_theme_implement(struct gtk_scaffolding *g); char *nsgtk_theme_name(void); -void nsgtk_theme_set_name(char *name); +void nsgtk_theme_set_name(const char *name); #endif -- cgit v1.2.3