diff options
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 4 | ||||
-rw-r--r-- | embed/mozilla/mozilla-notifiers.cpp | 996 | ||||
-rw-r--r-- | embed/mozilla/mozilla-notifiers.h | 33 |
3 files changed, 496 insertions, 537 deletions
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 24c9cf32e..68c44d670 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -506,7 +506,7 @@ init_services (MozillaEmbedSingle *single) mozilla_setup_colors (single); START_PROFILER ("Mozilla prefs notifiers") - mozilla_notifiers_init (EPHY_EMBED_SINGLE (single)); + mozilla_notifiers_init (); STOP_PROFILER ("Mozilla prefs notifiers") mozilla_register_components (); @@ -569,7 +569,7 @@ mozilla_embed_single_finalize (GObject *object) * services depend on xpcom */ G_OBJECT_CLASS (parent_class)->finalize (object); - mozilla_notifiers_free (); + mozilla_notifiers_shutdown (); gtk_moz_embed_pop_startup (); diff --git a/embed/mozilla/mozilla-notifiers.cpp b/embed/mozilla/mozilla-notifiers.cpp index 83a028ffb..4af0c55b6 100644 --- a/embed/mozilla/mozilla-notifiers.cpp +++ b/embed/mozilla/mozilla-notifiers.cpp @@ -1,287 +1,224 @@ /* - * Copyright (C) 2000 Nate Case - * Copyright (C) 2003 Marco Pesenti Gritti - * - * This program 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; either version 2, OR (AT YOUR OPTION) - * any later version. - * - * This program 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ +* Copyright (C) 2000 Nate Case +* Copyright (C) 2000-2004 Marco Pesenti Gritti +* Copyright (C) 2003, 2004 Christian Persch +* +* This program 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; either version 2, OR (AT YOUR OPTION) +* any later version. +* +* This program 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, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* $Id$ +*/ #include "mozilla-config.h" #include "config.h" -#include "ephy-embed-single.h" -#include "ephy-embed-shell.h" #include "mozilla-notifiers.h" + #include "eel-gconf-extensions.h" -#include "MozRegisterComponents.h" #include "ephy-prefs.h" #include "ephy-embed-prefs.h" #include "ephy-langs.h" #include "ephy-debug.h" #include <glib/gi18n.h> +#include <gdk/gdkx.h> +#include <gtk/gtksettings.h> #include <stdio.h> #include <string.h> -#include <locale.h> #include <stdlib.h> -#include <gdk/gdkx.h> -#include <gtk/gtksettings.h> -#include <nsCOMPtr.h> #define MOZILLA_STRICT_API #include <nsEmbedString.h> #undef MOZILLA_STRICT_API -#include <nsIPrefService.h> +#include <nsCOMPtr.h> #include <nsIServiceManager.h> +#include <nsIPrefService.h> -#ifdef ALLOW_PRIVATE_API -#include <nsIProtocolProxyService.h> -#endif - -#define MOZILLA_PREF_NO_PROXIES "network.proxy.no_proxies_on" +/* define to migrate epiphany 1.0 font preferences */ #define MIGRATE_PIXEL_SIZE -static void -mozilla_cache_size_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - char *pref); -static void -mozilla_own_colors_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); -static void -mozilla_own_fonts_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); - -static void -generic_mozilla_string_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - const char *pref_name); -static void -generic_mozilla_int_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - const char *pref_name); -static void -generic_mozilla_bool_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - const char *pref_name); -static void -mozilla_allow_popups_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); - -static void -mozilla_language_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); - -static void -mozilla_proxy_mode_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); -static void -mozilla_proxy_mode_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); -static void -mozilla_cookies_accept_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - char *pref); -static void -mozilla_proxy_ignore_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); - /* Keeps the list of the notifiers we installed for mozilla prefs */ /* to be able to remove them when exiting */ -GList *mozilla_notifiers = NULL; -GList *font_infos = NULL; - -enum -{ - BOOL_PREF, - INT_PREF, - STRING_PREF -}; +GList *notifiers = NULL; -static const struct +typedef struct { char *gconf_key; - guint pref_type; - const char *mozilla_key; -} -conversion_table [] = -{ - { CONF_SECURITY_JAVA_ENABLED, BOOL_PREF, "security.enable_java" }, - { CONF_SECURITY_JAVASCRIPT_ENABLED, BOOL_PREF, "javascript.enabled" }, - { CONF_NETWORK_PROXY_AUTO_URL, STRING_PREF, "network.proxy.autoconfig_url" }, - { CONF_NETWORK_HTTP_PROXY, STRING_PREF, "network.proxy.http" }, - { CONF_NETWORK_FTP_PROXY, STRING_PREF, "network.proxy.ftp" }, - { CONF_NETWORK_SSL_PROXY, STRING_PREF, "network.proxy.ssl" }, - { CONF_NETWORK_SOCKS_PROXY, STRING_PREF, "network.proxy.socks" }, - { CONF_NETWORK_HTTP_PROXY_PORT, INT_PREF, "network.proxy.http_port" }, - { CONF_NETWORK_FTP_PROXY_PORT, INT_PREF, "network.proxy.ftp_port" }, - { CONF_NETWORK_SSL_PROXY_PORT, INT_PREF, "network.proxy.ssl_port" }, - { CONF_NETWORK_SOCKS_PROXY_PORT, INT_PREF, "network.proxy.socks_port" }, - { CONF_LANGUAGE_DEFAULT_ENCODING, STRING_PREF, "intl.charset.default" }, - { CONF_LANGUAGE_AUTODETECT_ENCODING, STRING_PREF, "intl.charset.detector" }, - { CONF_BROWSE_WITH_CARET, BOOL_PREF, "accessibility.browsewithcaret" }, - - { NULL, 0, NULL } -}; - -static const struct + char *mozilla_pref; + PrefValueTransformFunc func; + guint cnxn_id; +} PrefData; + +static void +free_pref_data (PrefData *data) { - const char *gconf_key; - GConfClientNotifyFunc func; + g_free (data->gconf_key); + g_free (data->mozilla_pref); + g_free (data); } -custom_notifiers [] = -{ - { CONF_RENDERING_USE_OWN_COLORS, - (GConfClientNotifyFunc) mozilla_own_colors_notifier }, - { CONF_RENDERING_USE_OWN_FONTS, - (GConfClientNotifyFunc) mozilla_own_fonts_notifier }, - { CONF_SECURITY_ALLOW_POPUPS, - (GConfClientNotifyFunc) mozilla_allow_popups_notifier }, - { CONF_RENDERING_LANGUAGE, - (GConfClientNotifyFunc) mozilla_language_notifier }, - { CONF_NETWORK_PROXY_MODE, - (GConfClientNotifyFunc) mozilla_proxy_mode_notifier }, - { CONF_NETWORK_CACHE_SIZE, - (GConfClientNotifyFunc) mozilla_cache_size_notifier }, - { CONF_SECURITY_COOKIES_ACCEPT, - (GConfClientNotifyFunc) mozilla_cookies_accept_notifier }, - { CONF_NETWORK_PROXY_IGNORE_HOSTS, - (GConfClientNotifyFunc) mozilla_proxy_ignore_notifier }, - - { NULL, NULL } -}; static gboolean -mozilla_prefs_set_string(const char *preference_name, const char *new_value) +transform_accept_languages_list (GConfValue *gcvalue, + GValue *value) { - g_return_val_if_fail (preference_name != NULL, FALSE); - g_return_val_if_fail (new_value != NULL, FALSE); - nsCOMPtr<nsIPrefService> prefService = - do_GetService (NS_PREFSERVICE_CONTRACTID); - nsCOMPtr<nsIPrefBranch> pref; - prefService->GetBranch ("", getter_AddRefs(pref)); - - if (pref) - { - nsresult rv = pref->SetCharPref (preference_name, new_value); - return NS_SUCCEEDED (rv) ? TRUE : FALSE; - } - - return FALSE; + GArray *array; + GSList *languages, *l; + char **langs; + + if (gcvalue->type != GCONF_VALUE_LIST || + gconf_value_get_list_type (gcvalue) != GCONF_VALUE_STRING) return FALSE; + + languages = gconf_value_get_list (gcvalue); + + array = g_array_new (TRUE, FALSE, sizeof (char *)); + + for (l = languages; l != NULL; l = l->next) + { + const char *lang; + + lang = gconf_value_get_string ((GConfValue *) l->data); + + if (lang != NULL && strcmp (lang, "system") == 0) + { + ephy_langs_append_languages (array); + } + else if (lang != NULL && lang[0] != '\0') + { + char *str; + str = g_strdup (lang); + g_array_append_val (array, str); + } + } + + ephy_langs_sanitise (array); + + langs = (char **) g_array_free (array, FALSE); + + g_value_init (value, G_TYPE_STRING); + g_value_take_string (value, g_strjoinv (",", langs)); + + g_strfreev (langs); + + return TRUE; } static gboolean -mozilla_prefs_set_boolean (const char *preference_name, - gboolean new_boolean_value) +transform_cache_size (GConfValue *gcvalue, + GValue *value) { - g_return_val_if_fail (preference_name != NULL, FALSE); - - nsCOMPtr<nsIPrefService> prefService = - do_GetService (NS_PREFSERVICE_CONTRACTID); - nsCOMPtr<nsIPrefBranch> pref; - prefService->GetBranch ("", getter_AddRefs(pref)); - - if (pref) - { - nsresult rv = pref->SetBoolPref (preference_name, - new_boolean_value ? PR_TRUE : PR_FALSE); - return NS_SUCCEEDED (rv) ? TRUE : FALSE; - } - return FALSE; + if (gcvalue->type != GCONF_VALUE_INT) return FALSE; + + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, gconf_value_get_int (gcvalue) * 1024); + + return TRUE; } static gboolean -mozilla_prefs_set_int (const char *preference_name, int new_int_value) +transform_cookies_accept_mode (GConfValue *gcvalue, + GValue *value) { - g_return_val_if_fail (preference_name != NULL, FALSE); + const char *mode; + int mozilla_mode = 0; + + if (gcvalue->type != GCONF_VALUE_STRING) return FALSE; - nsCOMPtr<nsIPrefService> prefService = - do_GetService (NS_PREFSERVICE_CONTRACTID); - nsCOMPtr<nsIPrefBranch> pref; - prefService->GetBranch ("", getter_AddRefs(pref)); + mode = gconf_value_get_string (gcvalue); + if (mode == NULL) return FALSE; - if (pref) - { - nsresult rv = pref->SetIntPref (preference_name, new_int_value); - return NS_SUCCEEDED (rv) ? TRUE : FALSE; - } + if (strcmp (mode, "anywhere") == 0) + { + mozilla_mode = 0; + } + else if (strcmp (mode, "current site") == 0) + { + mozilla_mode = 1; + } + else if (strcmp (mode, "nowhere") == 0) + { + mozilla_mode = 2; + } - return FALSE; + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, mozilla_mode); + + return TRUE; } -static void -mozilla_cache_size_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - char *pref) +static gboolean +transform_font_size (GConfValue *gcvalue, + GValue *value) { - int cache_size; + if (gcvalue->type != GCONF_VALUE_INT) return FALSE; - cache_size = eel_gconf_get_integer (entry->key) * 1024; + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, MAX (1, gconf_value_get_int (gcvalue))); - mozilla_prefs_set_int ("browser.cache.disk.capacity", cache_size); + return TRUE; } -static void -mozilla_font_size_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - char *pref) +static gboolean +transform_proxy_ignore_list (GConfValue *gcvalue, + GValue *value) { - char key[255]; - - if (entry->value == NULL) return; + GArray *array; + GSList *hosts, *l; + char **strings; + + if (gcvalue->type != GCONF_VALUE_LIST || + gconf_value_get_list_type (gcvalue) != GCONF_VALUE_STRING) return FALSE; + + hosts = gconf_value_get_list (gcvalue); + + array = g_array_new (TRUE, FALSE, sizeof (char *)); + + for (l = hosts; l != NULL; l = l->next) + { + const char *host; + + host = gconf_value_get_string ((GConfValue *) l->data); - sprintf (key, "font.%s", pref); + if (host != NULL && host[0] != '\0') + { + g_array_append_val (array, host); + } + } + + strings = (char **) g_array_free (array, FALSE); + + g_value_init (value, G_TYPE_STRING); + g_value_take_string (value, g_strjoinv (",", strings)); - mozilla_prefs_set_int (key, MAX (eel_gconf_get_integer (entry->key), 1)); + /* individual strings are const */ + g_free (strings); + + return TRUE; } -static void -mozilla_proxy_mode_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) +static gboolean +transform_proxy_mode (GConfValue *gcvalue, + GValue *value) { - char *mode; + const char *mode; int mozilla_mode = 0; - - mode = eel_gconf_get_string (entry->key); - if (mode == NULL) return; - + + if (gcvalue->type != GCONF_VALUE_STRING) return FALSE; + + mode = gconf_value_get_string (gcvalue); + if (mode == NULL) return FALSE; + if (strcmp (mode, "manual") == 0) { mozilla_mode = 1; @@ -291,85 +228,284 @@ mozilla_proxy_mode_notifier (GConfClient *client, mozilla_mode = 2; } - mozilla_prefs_set_int ("network.proxy.type", mozilla_mode); + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, mozilla_mode); - g_free (mode); + return TRUE; } -static void -mozilla_cookies_accept_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - char *pref) +static gboolean +transform_use_own_fonts (GConfValue *gcvalue, + GValue *value) { - char *mode; - int mozilla_mode = 0; - - mode = eel_gconf_get_string (entry->key); - if (mode == NULL) return; - - if (strcmp (mode, "anywhere") == 0) - { - mozilla_mode = 0; - } - else if (strcmp (mode, "current site") == 0) - { - mozilla_mode = 1; - } - else if (strcmp (mode, "nowhere") == 0) + if (gcvalue->type != GCONF_VALUE_BOOL) return FALSE; + + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, gconf_value_get_bool (gcvalue) ? 0 : 1); + + return TRUE; +} + +extern "C" gboolean +mozilla_notifier_transform_bool (GConfValue *gcvalue, + GValue *value) +{ + if (gcvalue->type != GCONF_VALUE_BOOL) return FALSE; + + g_value_init (value, G_TYPE_BOOLEAN); + g_value_set_boolean (value, gconf_value_get_bool (gcvalue)); + + return TRUE; +} + +extern "C" gboolean +mozilla_notifier_transform_bool_invert (GConfValue *gcvalue, + GValue *value) +{ + if (gcvalue->type != GCONF_VALUE_BOOL) return FALSE; + + g_value_init (value, G_TYPE_BOOLEAN); + g_value_set_boolean (value, !gconf_value_get_bool (gcvalue)); + + return TRUE; +} + +extern "C" gboolean +mozilla_notifier_transform_int (GConfValue *gcvalue, + GValue *value) +{ + if (gcvalue->type != GCONF_VALUE_INT) return FALSE; + + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, gconf_value_get_int (gcvalue)); + + return TRUE; +} + +extern "C" gboolean +mozilla_notifier_transform_string (GConfValue *gcvalue, + GValue *value) +{ + const char *str; + + if (gcvalue->type != GCONF_VALUE_STRING) return FALSE; + + str = gconf_value_get_string (gcvalue); + if (str == NULL) return FALSE; + + g_value_init (value, G_TYPE_STRING); + g_value_set_string (value, str); + + return TRUE; +} + +static const PrefData notifier_entries[] = +{ + { CONF_BROWSE_WITH_CARET, + "accessibility.browsewithcaret", + mozilla_notifier_transform_bool }, + { CONF_NETWORK_CACHE_SIZE, + "browser.cache.disk.capacity", + transform_cache_size }, + { CONF_RENDERING_USE_OWN_COLORS, + "browser.display.use_document_colors", + mozilla_notifier_transform_bool_invert }, + { CONF_RENDERING_USE_OWN_FONTS, + "browser.display.use_document_fonts", + transform_use_own_fonts }, + { CONF_SECURITY_ALLOW_POPUPS, + "dom.disable_open_during_load", + mozilla_notifier_transform_bool_invert }, + { CONF_RENDERING_LANGUAGE, + "intl.accept_languages", + transform_accept_languages_list }, + { CONF_LANGUAGE_DEFAULT_ENCODING, + "intl.charset.default", + mozilla_notifier_transform_string }, + { CONF_LANGUAGE_AUTODETECT_ENCODING, + "intl.charset.detector", + mozilla_notifier_transform_string }, + { CONF_SECURITY_JAVA_ENABLED, + "security.enable_java", + mozilla_notifier_transform_bool }, + { CONF_SECURITY_JAVASCRIPT_ENABLED, + "javascript.enabled", + mozilla_notifier_transform_bool }, + { CONF_NETWORK_PROXY_AUTO_URL, + "network.proxy.autoconfig_url", + mozilla_notifier_transform_string }, + { CONF_NETWORK_HTTP_PROXY, + "network.proxy.http", + mozilla_notifier_transform_string }, + { CONF_NETWORK_HTTP_PROXY_PORT, + "network.proxy.http_port", + mozilla_notifier_transform_int }, + { CONF_NETWORK_FTP_PROXY, + "network.proxy.ftp", + mozilla_notifier_transform_string }, + { CONF_NETWORK_FTP_PROXY_PORT, + "network.proxy.ftp_port", + mozilla_notifier_transform_int }, + { CONF_NETWORK_SSL_PROXY, + "network.proxy.ssl", + mozilla_notifier_transform_string }, + { CONF_NETWORK_SSL_PROXY_PORT, + "network.proxy.ssl_port", + mozilla_notifier_transform_int }, + { CONF_NETWORK_SOCKS_PROXY, + "network.proxy.socks", + mozilla_notifier_transform_string }, + { CONF_NETWORK_SOCKS_PROXY_PORT, + "network.proxy.socks_port", + mozilla_notifier_transform_int }, + { CONF_NETWORK_PROXY_IGNORE_HOSTS, + "network.proxy.no_proxies_on", + transform_proxy_ignore_list }, + { CONF_NETWORK_PROXY_MODE, + "network.proxy.type", + transform_proxy_mode }, + { CONF_SECURITY_COOKIES_ACCEPT, + "network.cookie.cookieBehavior", + transform_cookies_accept_mode }, +}; + +static gboolean +mozilla_set_pref (const char *pref, + const GValue *value) +{ + g_return_val_if_fail (pref != NULL, FALSE); + g_return_val_if_fail (value != NULL, FALSE); + + nsCOMPtr<nsIPrefService> prefService + (do_GetService (NS_PREFSERVICE_CONTRACTID)); + NS_ENSURE_TRUE (prefService, FALSE); + + nsCOMPtr<nsIPrefBranch> prefBranch; + prefService->GetBranch ("", getter_AddRefs (prefBranch)); + NS_ENSURE_TRUE (prefBranch, FALSE); + + nsresult rv; + switch (G_VALUE_TYPE (value)) { - mozilla_mode = 2; + case G_TYPE_INT: + rv = prefBranch->SetIntPref (pref, g_value_get_int (value)); + break; + case G_TYPE_BOOLEAN: + rv = prefBranch->SetBoolPref (pref, g_value_get_boolean (value)); + break; + case G_TYPE_STRING: + rv = prefBranch->SetCharPref (pref, g_value_get_string (value)); + break; + default: + g_return_val_if_reached (FALSE); + rv = NS_ERROR_FAILURE; + break; } - mozilla_prefs_set_int ("network.cookie.cookieBehavior", mozilla_mode); - - g_free (mode); + return NS_SUCCEEDED (rv) != PR_FALSE; } static void -mozilla_font_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - char *pref) +notify_cb (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + PrefData *data) { - char key[255]; - char *name; + GConfValue *gcvalue; + GValue value = { 0, }; - if (entry->value == NULL) return; - - sprintf (key, "font.name.%s", pref); + g_return_if_fail (entry != NULL); + g_return_if_fail (data != NULL); - name = eel_gconf_get_string (entry->key); - if (name) + gcvalue = gconf_entry_get_value (entry); + /* happens on initial notify if the key doesn't exist */ + if (gcvalue == NULL) return; + + if (data->func (gcvalue, &value)) { - mozilla_prefs_set_string (key, name); - g_free (name); + mozilla_set_pref (data->mozilla_pref, &value); + g_value_unset (&value); } } -static void -add_notification_and_notify (GConfClient *client, - const char *key, - GConfClientNotifyFunc func, - gpointer user_data) +extern "C" void +mozilla_notifier_add (const char *gconf_key, + const char *mozilla_pref, + PrefValueTransformFunc func) { + GConfClient *client; + PrefData *data; GError *error = NULL; guint cnxn_id; - cnxn_id = gconf_client_notify_add (client, key, func, user_data, NULL, &error); + g_return_if_fail (gconf_key != NULL); + g_return_if_fail (mozilla_pref != NULL); + g_return_if_fail (func); + + client = eel_gconf_client_get_global (); + g_return_if_fail (client != NULL); + + data = g_new (PrefData, 1); + data->gconf_key = g_strdup (gconf_key); + data->mozilla_pref = g_strdup (mozilla_pref); + data->func = func; + + cnxn_id = gconf_client_notify_add (client, gconf_key, + (GConfClientNotifyFunc) notify_cb, + data, (GFreeFunc) free_pref_data, + &error); if (eel_gconf_handle_error (&error)) { if (cnxn_id != EEL_GCONF_UNDEFINED_CONNECTION) { gconf_client_notify_remove (client, cnxn_id); } + return; } - mozilla_notifiers = g_list_append (mozilla_notifiers, - GUINT_TO_POINTER (cnxn_id)); + data->cnxn_id = cnxn_id; + notifiers = g_list_prepend (notifiers, data); - gconf_client_notify (client, key); + gconf_client_notify (client, gconf_key); +} + +static int +find_data (const PrefData *a, + const PrefData *b) +{ + return strcmp (a->gconf_key, b->gconf_key) != 0 || + strcmp (a->mozilla_pref, b->mozilla_pref) != 0 || + a->func != b->func; +} + +extern "C" void +mozilla_notifier_remove (const char *gconf_key, + const char *mozilla_pref, + PrefValueTransformFunc func) +{ + PrefData sdata, *data; + GList *l; + + g_return_if_fail (gconf_key != NULL); + g_return_if_fail (mozilla_pref != NULL); + g_return_if_fail (func); + + sdata.gconf_key = (char *) gconf_key; + sdata.mozilla_pref = (char *) mozilla_pref; + sdata.func = func; + + l = g_list_find_custom (notifiers, &sdata, (GCompareFunc) find_data); + g_return_if_fail (l != NULL); + + data = (PrefData *) l->data; + + g_return_if_fail (strcmp (data->gconf_key, gconf_key) == 0); + g_return_if_fail (strcmp (data->mozilla_pref, mozilla_pref) == 0); + g_return_if_fail (data->func == func); + + notifiers = g_list_delete_link (notifiers, l); + eel_gconf_notification_remove (data->cnxn_id); } #ifdef MIGRATE_PIXEL_SIZE @@ -377,15 +513,15 @@ add_notification_and_notify (GConfClient *client, #define INT_ROUND(a) gint((a) + 0.5f) /** - * This function gets the dpi in the same way that mozilla gets the dpi, - * this allows us to convert from pixels to points easily - */ +* This function gets the dpi in the same way that mozilla gets the dpi, +* this allows us to convert from pixels to points easily +*/ static gint mozilla_get_dpi () { GtkSettings* settings = gtk_settings_get_default (); gint dpi = 0; - + /* Use the gdk-xft-dpi setting if it is set */ if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (settings)), "gtk-xft-dpi")) @@ -402,14 +538,15 @@ mozilla_get_dpi () double d = strtod(val, &e); if (e != val) return INT_ROUND (d); } - + /* Fall back to calculating manually from the gdk screen settings */ float screenWidthIn = float (gdk_screen_width_mm()) / 25.4f; return INT_ROUND (gdk_screen_width() / screenWidthIn); } static void -mozilla_migrate_font_gconf_key (const char *pixel_key, const char *point_key) +migrate_font_gconf_key (const char *pixel_key, + const char *point_key) { int size; @@ -418,8 +555,8 @@ mozilla_migrate_font_gconf_key (const char *pixel_key, const char *point_key) if (size > 0) { /* Use doubles to get more accurate arithmetic */ - double dpi = (double)mozilla_get_dpi (); - double value = (double)eel_gconf_get_integer (pixel_key); + double dpi = (double) mozilla_get_dpi (); + double value = (double) eel_gconf_get_integer (pixel_key); gint point = INT_ROUND ((value * 72) / dpi); eel_gconf_set_integer (point_key, point); @@ -428,13 +565,11 @@ mozilla_migrate_font_gconf_key (const char *pixel_key, const char *point_key) #endif -void -mozilla_notifiers_init (EphyEmbedSingle *single) +extern "C" void +mozilla_notifiers_init (void) { - GConfClient *client = eel_gconf_client_get_global (); - guint i; const EphyFontsLanguageInfo *font_languages; - guint n_font_languages; + guint n_font_languages, i; eel_gconf_monitor_add ("/apps/epiphany/web"); eel_gconf_monitor_add ("/system/proxy"); @@ -451,39 +586,11 @@ mozilla_notifiers_init (EphyEmbedSingle *single) } #endif - for (i = 0; conversion_table[i].gconf_key != NULL; i++) - { - GConfClientNotifyFunc func = NULL; - - switch (conversion_table[i].pref_type) - { - case INT_PREF: - func = (GConfClientNotifyFunc) generic_mozilla_int_notifier; - break; - case BOOL_PREF: - func = (GConfClientNotifyFunc) generic_mozilla_bool_notifier; - break; - case STRING_PREF: - func = (GConfClientNotifyFunc) generic_mozilla_string_notifier; - break; - } - - g_assert (func != NULL); - - add_notification_and_notify - (client, - conversion_table[i].gconf_key, - func, - (gpointer)conversion_table[i].mozilla_key); - } - - for (i = 0; custom_notifiers[i].gconf_key != NULL; i++) + for (i = 0; i < G_N_ELEMENTS (notifier_entries); i++) { - add_notification_and_notify - (client, - custom_notifiers[i].gconf_key, - custom_notifiers[i].func, - (gpointer)single); + mozilla_notifier_add (notifier_entries[i].gconf_key, + notifier_entries[i].mozilla_pref, + notifier_entries[i].func); } /* fonts notifiers */ @@ -495,27 +602,25 @@ mozilla_notifiers_init (EphyEmbedSingle *single) const char *code = font_languages[i].code; guint k; char *types [] = { "variable", "monospace" }; - char key[255]; - char *info; + char key[255], pref[255]; #ifdef MIGRATE_PIXEL_SIZE char old_key[255]; #endif - + for (k = 0; k < G_N_ELEMENTS (types); k++) { - info = g_strconcat (types[k], ".", code, NULL); - - g_snprintf (key, 255, "%s_%s_%s", CONF_RENDERING_FONT, - types[k], code); - add_notification_and_notify (client, key, - (GConfClientNotifyFunc)mozilla_font_notifier, - info); - font_infos = g_list_prepend (font_infos, info); + g_snprintf (key, sizeof (key), "%s_%s_%s", + CONF_RENDERING_FONT, types[k], code); + g_snprintf (pref, sizeof (pref), "font.name.%s.%s", + types[k], code); + + mozilla_notifier_add (key, pref, + mozilla_notifier_transform_string); } #ifdef MIGRATE_PIXEL_SIZE - if (migrate_size) - { + if (migrate_size) + { char *type; type = eel_gconf_get_string (CONF_RENDERING_FONT_TYPE_OLD); @@ -524,9 +629,9 @@ mozilla_notifiers_init (EphyEmbedSingle *single) { char *family; - g_snprintf (old_key, 255, "%s_%s_%s", + g_snprintf (old_key, sizeof (old_key), "%s_%s_%s", CONF_RENDERING_FONT, type, code); - g_snprintf (key, 255, "%s_%s_%s", + g_snprintf (key, sizeof (key), "%s_%s_%s", CONF_RENDERING_FONT, "variable", code); family = eel_gconf_get_string (old_key); @@ -541,235 +646,64 @@ mozilla_notifiers_init (EphyEmbedSingle *single) } #endif - g_snprintf (key, 255, "%s_%s", CONF_RENDERING_FONT_MIN_SIZE, code); - info = g_strconcat ("minimum-size", ".", code, NULL); - add_notification_and_notify (client, key, - (GConfClientNotifyFunc)mozilla_font_size_notifier, - info); - font_infos = g_list_prepend (font_infos, info); + /* FIXME is it "minimum-size" or "min-size" !!? */ + g_snprintf (key, sizeof (key), "%s_%s", + CONF_RENDERING_FONT_MIN_SIZE, code); + g_snprintf (pref, sizeof (pref), "font.minimum-size.%s", code); + mozilla_notifier_add (key, pref, transform_font_size); #ifdef MIGRATE_PIXEL_SIZE if (migrate_size) { - g_snprintf (old_key, 255, "%s_%s", + g_snprintf (old_key, sizeof (key), "%s_%s", CONF_RENDERING_FONT_MIN_SIZE_OLD, code); - mozilla_migrate_font_gconf_key (old_key, key); + migrate_font_gconf_key (old_key, key); } #endif - g_snprintf (key, 255, "%s_%s", CONF_RENDERING_FONT_FIXED_SIZE, code); - info = g_strconcat ("size.fixed", ".", code, NULL); - add_notification_and_notify (client, key, - (GConfClientNotifyFunc)mozilla_font_size_notifier, - info); - font_infos = g_list_prepend (font_infos, info); + g_snprintf (key, sizeof (key), "%s_%s", + CONF_RENDERING_FONT_FIXED_SIZE, code); + g_snprintf (pref, sizeof (pref), "font.size.fixed.%s", code); + mozilla_notifier_add (key, pref, transform_font_size); #ifdef MIGRATE_PIXEL_SIZE if (migrate_size) { - g_snprintf (old_key, 255, "%s_%s", + g_snprintf (old_key, sizeof (old_key), "%s_%s", CONF_RENDERING_FONT_FIXED_SIZE_OLD, code); - mozilla_migrate_font_gconf_key (old_key, key); + migrate_font_gconf_key (old_key, key); } #endif - g_snprintf (key, 255, "%s_%s", CONF_RENDERING_FONT_VAR_SIZE, code); - info = g_strconcat ("size.variable", ".", code, NULL); - add_notification_and_notify (client, key, - (GConfClientNotifyFunc)mozilla_font_size_notifier, - info); - font_infos = g_list_prepend (font_infos, info); + g_snprintf (key, sizeof (key), "%s_%s", + CONF_RENDERING_FONT_VAR_SIZE, code); + g_snprintf (pref, sizeof (pref), "font.size.variable.%s", code); + mozilla_notifier_add (key, pref, transform_font_size); #ifdef MIGRATE_PIXEL_SIZE if (migrate_size) { - g_snprintf (old_key, 255, "%s_%s", + g_snprintf (old_key, sizeof (old_key), "%s_%s", CONF_RENDERING_FONT_VAR_SIZE_OLD, code); - mozilla_migrate_font_gconf_key (old_key, key); + migrate_font_gconf_key (old_key, key); } #endif } } -void -mozilla_notifiers_free (void) -{ - eel_gconf_monitor_remove ("/apps/epiphany/web"); - eel_gconf_monitor_remove ("/system/proxy"); - eel_gconf_monitor_remove ("/system/http_proxy"); - - g_list_foreach (mozilla_notifiers, - (GFunc)eel_gconf_notification_remove, - NULL); - g_list_free(mozilla_notifiers); - - g_list_foreach (font_infos, (GFunc) g_free, NULL); - g_list_free (font_infos); -} - -/** - * generic_mozilla_string_notify: update mozilla pref to match epiphany prefs. - * user_data should match the mozilla key - */ static void -generic_mozilla_string_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - const char *pref_name) +remove_notification (PrefData *data) { - char *value; - - value = eel_gconf_get_string (entry->key); - if (value) - { - mozilla_prefs_set_string (pref_name, value); - g_free (value); - } + eel_gconf_notification_remove (data->cnxn_id); } - -/** - * generic_mozilla_int_notify: update mozilla pref to match epiphany prefs. - * user_data should match the mozilla key - */ -static void -generic_mozilla_int_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - const char *pref_name) -{ - int value; - - value = eel_gconf_get_integer (entry->key); - mozilla_prefs_set_int (pref_name, value); -} - - -/** - * generic_mozilla_bool_notify: update mozilla pref to match epiphany prefs. - * user_data should match the mozilla key - */ -static void -generic_mozilla_bool_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - const char *pref_name) -{ - gboolean value; - - value = eel_gconf_get_boolean (entry->key); - mozilla_prefs_set_boolean (pref_name, value); -} - -static void -mozilla_own_colors_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) -{ - gboolean value; - - value = eel_gconf_get_boolean (entry->key); - mozilla_prefs_set_boolean ("browser.display.use_document_colors", !value); -} - -static void -mozilla_own_fonts_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) -{ - int value; - - value = eel_gconf_get_boolean (entry->key) ? 0 : 1; - mozilla_prefs_set_int("browser.display.use_document_fonts", value); -} - -static void -mozilla_allow_popups_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) -{ - gboolean value; - - value = eel_gconf_get_boolean (entry->key); - mozilla_prefs_set_boolean ("dom.disable_open_during_load", !value); -} - -static void -mozilla_language_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) -{ - GArray *array; - GSList *languages, *l; - char **langs; - char *list; - - languages = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE); - - array = g_array_new (TRUE, FALSE, sizeof (char *)); - - for (l = languages; l != NULL; l = l->next) - { - if (strcmp ((char *) l->data, "system") == 0) - { - ephy_langs_append_languages (array); - g_free (l->data); - } - else - { - g_array_append_val (array, l->data); - } - } - - g_slist_free (languages); - - ephy_langs_sanitise (array); - - langs = (char **) g_array_free (array, FALSE); - - list = g_strjoinv (",", langs); - - mozilla_prefs_set_string ("intl.accept_languages", list); - - g_strfreev (langs); - g_free (list); -} - -static void -mozilla_proxy_ignore_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) +extern "C" void +mozilla_notifiers_shutdown (void) { - GSList *hosts, *l; - char **strings, *mozilla_ignore_list; - int i = 0; - - hosts = eel_gconf_get_string_list (entry->key); - - strings = g_new (gchar*, g_slist_length (hosts) + 1); - for (l = hosts; l != NULL; l = l->next) - { - char *item = (char *) l->data; - - if (item && item[0] != '\0') - { - strings[i] = item; - i++; - } - } - strings[i] = NULL; - - mozilla_ignore_list = g_strjoinv (", ", strings); - mozilla_prefs_set_string (MOZILLA_PREF_NO_PROXIES, - mozilla_ignore_list); + eel_gconf_monitor_remove ("/apps/epiphany/web"); + eel_gconf_monitor_remove ("/system/proxy"); + eel_gconf_monitor_remove ("/system/http_proxy"); - g_free (mozilla_ignore_list); - g_free (strings); - g_slist_foreach (hosts, (GFunc) g_free, NULL); - g_slist_free (hosts); + g_list_foreach (notifiers, (GFunc) remove_notification, NULL); + g_list_free (notifiers); } diff --git a/embed/mozilla/mozilla-notifiers.h b/embed/mozilla/mozilla-notifiers.h index b6559a5d2..711031000 100644 --- a/embed/mozilla/mozilla-notifiers.h +++ b/embed/mozilla/mozilla-notifiers.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2000 Nate Case + * Copyright (C) 2000 Nate Case + * Copyright (C) 2000-2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,10 +23,33 @@ #ifndef MOZILLA_NOTIFIERS_H #define MOZILLA_NOTIFIERS_H -#include "ephy-embed-single.h" +#include <glib-object.h> +#include <gconf/gconf.h> -void mozilla_notifiers_init (EphyEmbedSingle *single); +G_BEGIN_DECLS -void mozilla_notifiers_free (void); +typedef gboolean (* PrefValueTransformFunc) (GConfValue *, GValue *); + +gboolean mozilla_notifier_transform_bool (GConfValue *, GValue *); + +gboolean mozilla_notifier_transform_bool_invert (GConfValue *, GValue *); + +gboolean mozilla_notifier_transform_int (GConfValue *, GValue *); + +gboolean mozilla_notifier_transform_string (GConfValue *, GValue *); + +void mozilla_notifier_add (const char *gconf_key, + const char *mozilla_pref, + PrefValueTransformFunc func); + +void mozilla_notifier_remove (const char *gconf_key, + const char *mozilla_pref, + PrefValueTransformFunc func); + +void mozilla_notifiers_init (void); + +void mozilla_notifiers_shutdown (void); + +G_END_DECLS #endif |