From ecd30f7b95964ec717d5da6873492fab939f2523 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Fri, 5 Jun 2009 19:01:59 +0300 Subject: Fold WebKitEmbedPrefs into EphyEmbedPrefs. --- embed/Makefile.am | 3 +- embed/ephy-embed-prefs.c | 240 ++++++++++++++++++++++++++++++++++++ embed/ephy-embed-prefs.h | 35 ++++++ embed/ephy-embed.c | 5 +- embed/ephy-web-view.c | 1 - embed/webkit-embed-prefs.c | 241 ------------------------------------- embed/webkit-embed-prefs.h | 33 ----- embed/webkit/webkit-embed-single.c | 6 +- 8 files changed, 281 insertions(+), 283 deletions(-) create mode 100644 embed/ephy-embed-prefs.c delete mode 100644 embed/webkit-embed-prefs.c delete mode 100644 embed/webkit-embed-prefs.h diff --git a/embed/Makefile.am b/embed/Makefile.am index 03281c2a3..105efb748 100644 --- a/embed/Makefile.am +++ b/embed/Makefile.am @@ -56,9 +56,8 @@ libephyembed_la_SOURCES = \ ephy-history.c \ ephy-password-manager.c \ ephy-permission-manager.c \ + ephy-embed-prefs.c \ ephy-web-view.c \ - webkit-embed-prefs.c \ - webkit-embed-prefs.h \ $(INST_H_FILES) \ $(NOINST_H_FILES) diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c new file mode 100644 index 000000000..df1c79bef --- /dev/null +++ b/embed/ephy-embed-prefs.c @@ -0,0 +1,240 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* Copyright © 2008 Xan Lopez + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include + +#include +#include + +#include "eel-gconf-extensions.h" +#include "ephy-embed-prefs.h" +#include "ephy-embed-utils.h" +#include "ephy-file-helpers.h" + +typedef struct +{ + char *gconf_key; + char *webkit_pref; + GConfClientNotifyFunc func; + guint cnxn_id; +} PrefData; + +static WebKitWebSettings *settings = NULL; +static guint *connections = NULL; + +static void +webkit_pref_callback_int (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer data) +{ + GConfValue *gcvalue; + gint value = 0; + char *webkit_pref = data; + + gcvalue = gconf_entry_get_value (entry); + + /* happens on initial notify if the key doesn't exist */ + if (gcvalue != NULL && + gcvalue->type == GCONF_VALUE_INT) { + value = gconf_value_get_int (gcvalue); + value = MAX (value, 0); + } + + g_object_set (settings, webkit_pref, value, NULL); +} + +static void +webkit_pref_callback_boolean (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer data) +{ + GConfValue *gcvalue; + gboolean value = FALSE; + char *webkit_pref = data; + + gcvalue = gconf_entry_get_value (entry); + + /* happens on initial notify if the key doesn't exist */ + if (gcvalue != NULL && + gcvalue->type == GCONF_VALUE_BOOL) { + value = gconf_value_get_bool (gcvalue); + } + + g_object_set (settings, webkit_pref, value, NULL); +} + +static void +webkit_pref_callback_string (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer data) +{ + GConfValue *gcvalue; + const char *value = NULL; + char *webkit_pref = data; + + gcvalue = gconf_entry_get_value (entry); + + /* happens on initial notify if the key doesn't exist */ + if (gcvalue != NULL && + gcvalue->type == GCONF_VALUE_STRING) { + value = gconf_value_get_string (gcvalue); + } + + g_object_set (settings, webkit_pref, value, NULL); +} + +static void +webkit_pref_callback_user_stylesheet (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer data) +{ + GConfValue *gcvalue; + gboolean value = FALSE; + char *uri = NULL; + char *webkit_pref = data; + + gcvalue = gconf_entry_get_value (entry); + + /* happens on initial notify if the key doesn't exist */ + if (gcvalue != NULL && + gcvalue->type == GCONF_VALUE_BOOL) { + value = gconf_value_get_bool (gcvalue); + } + + if (value) + /* We need the leading file://, so use g_strconcat instead + * of g_build_filename */ + uri = g_strconcat ("file://", + ephy_dot_dir (), + G_DIR_SEPARATOR_S, + USER_STYLESHEET_FILENAME, + NULL); + g_object_set (settings, webkit_pref, uri, NULL); + g_free (uri); +} + +static void +webkit_pref_callback_font_size (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer data) +{ + GConfValue *gcvalue; + char *webkit_pref = data; + const char *value = NULL; + int size = 9; /* FIXME: What to use here? */ + + gcvalue = gconf_entry_get_value (entry); + + /* happens on initial notify if the key doesn't exist */ + if (gcvalue != NULL && + gcvalue->type == GCONF_VALUE_STRING) { + value = gconf_value_get_string (gcvalue); + } + + if (value) { + PangoFontDescription* desc; + + desc = pango_font_description_from_string (value); + size = pango_font_description_get_size (desc); + if (pango_font_description_get_size_is_absolute (desc) == FALSE) + size /= PANGO_SCALE; + pango_font_description_free (desc); + } + + g_object_set (settings, webkit_pref, size, NULL); +} + +static const PrefData webkit_pref_entries[] = + { + { CONF_RENDERING_FONT_MIN_SIZE, + "minimum-font-size", + webkit_pref_callback_int }, + { CONF_DESKTOP_FONT_VAR_SIZE, + "default-font-size", + webkit_pref_callback_font_size }, + { CONF_DESKTOP_FONT_FIXED_SIZE, + "default-monospace-font-size", + webkit_pref_callback_font_size }, + { CONF_SECURITY_JAVASCRIPT_ENABLED, + "enable-scripts", + webkit_pref_callback_boolean }, + { CONF_LANGUAGE_DEFAULT_ENCODING, + "default-encoding", + webkit_pref_callback_string }, + { CONF_WEB_INSPECTOR_ENABLED, + "enable-developer-extras", + webkit_pref_callback_boolean }, + { CONF_USER_CSS_ENABLED, + "user-stylesheet-uri", + webkit_pref_callback_user_stylesheet }, + { CONF_CARET_BROWSING_ENABLED, + "enable-caret-browsing", + webkit_pref_callback_boolean } + }; + +static void +ephy_embed_prefs_apply (EphyEmbed *embed, WebKitWebSettings *settings) +{ + webkit_web_view_set_settings (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), + settings); +} + +void +ephy_embed_prefs_init (void) +{ + int i; + + eel_gconf_monitor_add ("/apps/epiphany/web"); + + settings = webkit_web_settings_new (); + + connections = g_malloc (sizeof (guint) * G_N_ELEMENTS (webkit_pref_entries)); + + for (i = 0; i < G_N_ELEMENTS (webkit_pref_entries); i++) { + connections[i] = eel_gconf_notification_add (webkit_pref_entries[i].gconf_key, + webkit_pref_entries[i].func, + webkit_pref_entries[i].webkit_pref); + + eel_gconf_notify (webkit_pref_entries[i].gconf_key); + } +} + +void +ephy_embed_prefs_shutdown (void) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (webkit_pref_entries); i++) + eel_gconf_notification_remove (connections[i]); + + g_free (connections); + g_object_unref (settings); +} + +void +ephy_embed_prefs_add_embed (EphyEmbed *embed) +{ + ephy_embed_prefs_apply (embed, settings); +} + diff --git a/embed/ephy-embed-prefs.h b/embed/ephy-embed-prefs.h index 3bfc0342c..680ea8cf2 100644 --- a/embed/ephy-embed-prefs.h +++ b/embed/ephy-embed-prefs.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* Copyright © 2008 Xan Lopez + * Copyright © 2009 Igalia S.L. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef __EPHY_EMBED_PREFS_H__ +#define __EPHY_EMBED_PREFS_H__ + +#include "ephy-embed.h" + #define CONF_NETWORK_CACHE_SIZE "/apps/epiphany/web/cache_size" #define CONF_RENDERING_FONT "/apps/epiphany/web/font" #define CONF_RENDERING_FONT_MIN_SIZE "/apps/epiphany/web/minimum_font_size" @@ -44,3 +69,13 @@ #endif #define USER_STYLESHEET_FILENAME "user-stylesheet.css" + +G_BEGIN_DECLS + +void ephy_embed_prefs_init (void); +void ephy_embed_prefs_shutdown (void); +void ephy_embed_prefs_add_embed (EphyEmbed *embed); + +G_END_DECLS + +#endif /* __EPHY_EMBED_PREFS_H__ */ diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index d3b092396..b32fd49fe 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -48,9 +48,8 @@ #include #include -#include "webkit-embed-prefs.h" +#include "ephy-embed-prefs.h" #include "ephy-embed.h" -#include "ephy-base-embed.h" static void ephy_embed_class_init (EphyEmbedClass *klass); static void ephy_embed_init (EphyEmbed *gs); @@ -804,7 +803,7 @@ ephy_embed_init (EphyEmbed *embed) embed->priv->inspector_window, NULL); - webkit_embed_prefs_add_embed (embed); + ephy_embed_prefs_add_embed (embed); embed->priv->history = EPHY_HISTORY (ephy_embed_shell_get_global_history (ephy_embed_shell_get_default ())); } diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index 3f1c40179..9664ec1d9 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -28,7 +28,6 @@ #include #include "eel-gconf-extensions.h" -#include "ephy-base-embed.h" #include "ephy-debug.h" #include "ephy-embed.h" #include "ephy-embed-container.h" diff --git a/embed/webkit-embed-prefs.c b/embed/webkit-embed-prefs.c deleted file mode 100644 index bcddd9523..000000000 --- a/embed/webkit-embed-prefs.c +++ /dev/null @@ -1,241 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* Copyright © 2008 Xan Lopez - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include - -#include -#include - -#include "webkit-embed-prefs.h" -#include "eel-gconf-extensions.h" -#include "ephy-embed-prefs.h" -#include "ephy-embed-utils.h" -#include "ephy-file-helpers.h" - -typedef struct -{ - char *gconf_key; - char *webkit_pref; - GConfClientNotifyFunc func; - guint cnxn_id; -} PrefData; - -static WebKitWebSettings *settings = NULL; -static guint *connections = NULL; - -static void -webkit_pref_callback_int (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer data) -{ - GConfValue *gcvalue; - gint value = 0; - char *webkit_pref = data; - - gcvalue = gconf_entry_get_value (entry); - - /* happens on initial notify if the key doesn't exist */ - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_INT) { - value = gconf_value_get_int (gcvalue); - value = MAX (value, 0); - } - - g_object_set (settings, webkit_pref, value, NULL); -} - -static void -webkit_pref_callback_boolean (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer data) -{ - GConfValue *gcvalue; - gboolean value = FALSE; - char *webkit_pref = data; - - gcvalue = gconf_entry_get_value (entry); - - /* happens on initial notify if the key doesn't exist */ - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_BOOL) { - value = gconf_value_get_bool (gcvalue); - } - - g_object_set (settings, webkit_pref, value, NULL); -} - -static void -webkit_pref_callback_string (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer data) -{ - GConfValue *gcvalue; - const char *value = NULL; - char *webkit_pref = data; - - gcvalue = gconf_entry_get_value (entry); - - /* happens on initial notify if the key doesn't exist */ - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_STRING) { - value = gconf_value_get_string (gcvalue); - } - - g_object_set (settings, webkit_pref, value, NULL); -} - -static void -webkit_pref_callback_user_stylesheet (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer data) -{ - GConfValue *gcvalue; - gboolean value = FALSE; - char *uri = NULL; - char *webkit_pref = data; - - gcvalue = gconf_entry_get_value (entry); - - /* happens on initial notify if the key doesn't exist */ - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_BOOL) { - value = gconf_value_get_bool (gcvalue); - } - - if (value) - /* We need the leading file://, so use g_strconcat instead - * of g_build_filename */ - uri = g_strconcat ("file://", - ephy_dot_dir (), - G_DIR_SEPARATOR_S, - USER_STYLESHEET_FILENAME, - NULL); - g_object_set (settings, webkit_pref, uri, NULL); - g_free (uri); -} - -static void -webkit_pref_callback_font_size (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer data) -{ - GConfValue *gcvalue; - char *webkit_pref = data; - const char *value = NULL; - int size = 9; /* FIXME: What to use here? */ - - gcvalue = gconf_entry_get_value (entry); - - /* happens on initial notify if the key doesn't exist */ - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_STRING) { - value = gconf_value_get_string (gcvalue); - } - - if (value) { - PangoFontDescription* desc; - - desc = pango_font_description_from_string (value); - size = pango_font_description_get_size (desc); - if (pango_font_description_get_size_is_absolute (desc) == FALSE) - size /= PANGO_SCALE; - pango_font_description_free (desc); - } - - g_object_set (settings, webkit_pref, size, NULL); -} - -static const PrefData webkit_pref_entries[] = - { - { CONF_RENDERING_FONT_MIN_SIZE, - "minimum-font-size", - webkit_pref_callback_int }, - { CONF_DESKTOP_FONT_VAR_SIZE, - "default-font-size", - webkit_pref_callback_font_size }, - { CONF_DESKTOP_FONT_FIXED_SIZE, - "default-monospace-font-size", - webkit_pref_callback_font_size }, - { CONF_SECURITY_JAVASCRIPT_ENABLED, - "enable-scripts", - webkit_pref_callback_boolean }, - { CONF_LANGUAGE_DEFAULT_ENCODING, - "default-encoding", - webkit_pref_callback_string }, - { CONF_WEB_INSPECTOR_ENABLED, - "enable-developer-extras", - webkit_pref_callback_boolean }, - { CONF_USER_CSS_ENABLED, - "user-stylesheet-uri", - webkit_pref_callback_user_stylesheet }, - { CONF_CARET_BROWSING_ENABLED, - "enable-caret-browsing", - webkit_pref_callback_boolean } - }; - -static void -webkit_embed_prefs_apply (EphyEmbed *embed, WebKitWebSettings *settings) -{ - webkit_web_view_set_settings (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), - settings); -} - -void -webkit_embed_prefs_init (void) -{ - int i; - - eel_gconf_monitor_add ("/apps/epiphany/web"); - - settings = webkit_web_settings_new (); - - connections = g_malloc (sizeof (guint) * G_N_ELEMENTS (webkit_pref_entries)); - - for (i = 0; i < G_N_ELEMENTS (webkit_pref_entries); i++) { - connections[i] = eel_gconf_notification_add (webkit_pref_entries[i].gconf_key, - webkit_pref_entries[i].func, - webkit_pref_entries[i].webkit_pref); - - eel_gconf_notify (webkit_pref_entries[i].gconf_key); - } -} - -void -webkit_embed_prefs_shutdown (void) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (webkit_pref_entries); i++) - eel_gconf_notification_remove (connections[i]); - - g_free (connections); - g_object_unref (settings); -} - -void -webkit_embed_prefs_add_embed (EphyEmbed *embed) -{ - webkit_embed_prefs_apply (embed, settings); -} - diff --git a/embed/webkit-embed-prefs.h b/embed/webkit-embed-prefs.h deleted file mode 100644 index 37f109bb3..000000000 --- a/embed/webkit-embed-prefs.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* Copyright © 2008 Xan Lopez - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __WEBKIT_EMBED_PREFS_H__ -#define __WEBKIT_EMBED_PREFS_H__ - -#include "ephy-embed.h" - -G_BEGIN_DECLS - -void webkit_embed_prefs_init (void); -void webkit_embed_prefs_shutdown (void); -void webkit_embed_prefs_add_embed (EphyEmbed *embed); - -G_END_DECLS - -#endif /* __WEBKIT_EMBED_PREFS_H__ */ diff --git a/embed/webkit/webkit-embed-single.c b/embed/webkit/webkit-embed-single.c index 8fcf631ee..af6cbc6e2 100644 --- a/embed/webkit/webkit-embed-single.c +++ b/embed/webkit/webkit-embed-single.c @@ -23,7 +23,7 @@ #include #include "webkit-embed-single.h" -#include "webkit-embed-prefs.h" +#include "ephy-embed-prefs.h" #include "ephy-embed-single.h" #include "ephy-file-helpers.h" #include "ephy-password-manager.h" @@ -89,7 +89,7 @@ webkit_embed_single_init (WebKitEmbedSingle *wes) static void webkit_embed_single_finalize (GObject *object) { - webkit_embed_prefs_shutdown (); + ephy_embed_prefs_shutdown (); G_OBJECT_CLASS (webkit_embed_single_parent_class)->finalize (object); } @@ -188,7 +188,7 @@ impl_init (EphyEmbedSingle *esingle) SoupCookieJar *jar; char *filename; - webkit_embed_prefs_init (); + ephy_embed_prefs_init (); session = webkit_get_default_session (); -- cgit v1.2.3