svnno****@sourc*****
svnno****@sourc*****
Fri Feb 22 10:41:25 JST 2008
Revision: 3387 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3387 Author: ikezoe Date: 2008-02-22 10:41:24 +0900 (Fri, 22 Feb 2008) Log Message: ----------- * module/embed/webkit-gtk/kz-webkit-gtk.c: Set default settings. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2008-02-22 00:12:43 UTC (rev 3386) +++ kazehakase/trunk/ChangeLog 2008-02-22 01:41:24 UTC (rev 3387) @@ -1,6 +1,7 @@ 2008-02-22 Hiroyuki Ikezoe <poinc****@ikezo*****> * module/embed/webkit-gtk/kz-webkit-gtk.c: more functional. + * module/embed/webkit-gtk/kz-webkit-gtk.c: Set default settings. 2008-02-22 Kouhei Sutou <kou****@cozmi*****> Modified: kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c =================================================================== --- kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c 2008-02-22 00:12:43 UTC (rev 3386) +++ kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c 2008-02-22 01:41:24 UTC (rev 3387) @@ -32,6 +32,7 @@ gchar *location; gchar *title; gboolean lock; + gboolean is_loading; }; #define KZ_WEBKIT_GTK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_WEBKIT_GTK, KzWebKitGtkPrivate)) @@ -84,6 +85,8 @@ WebKitWebFrame* frame, gpointer data); +static void set_default_preferences (KzWebKitGtk *webkit); + void kz_webkit_gtk_register_type (GTypeModule *module) { @@ -247,7 +250,6 @@ kz_webkit_gtk_init (KzWebKitGtk *webkit) { KzWebKitGtkPrivate *priv = KZ_WEBKIT_GTK_GET_PRIVATE(webkit); - WebKitWebSettings *settings; priv->location = NULL; priv->title = NULL; @@ -255,6 +257,7 @@ priv->progress = 0; priv->lock = FALSE; + priv->is_loading = FALSE; g_signal_connect(webkit, "title-changed", G_CALLBACK(cb_title_changed), NULL); @@ -266,11 +269,7 @@ G_CALLBACK(cb_load_started), NULL); g_signal_connect(webkit, "load-finished", G_CALLBACK(cb_load_finished), NULL); - - settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webkit)); - if (!settings) - return; - + set_default_preferences(webkit); } static void @@ -454,7 +453,7 @@ static gboolean is_loading (KzEmbed *kzembed) { - return FALSE; + return KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->is_loading; } static void @@ -500,6 +499,7 @@ WebKitWebFrame* frame, gpointer data) { + KZ_WEBKIT_GTK_GET_PRIVATE(web_view)->is_loading = TRUE; g_signal_emit_by_name(web_view, "kz-net-start"); } @@ -508,6 +508,155 @@ WebKitWebFrame* frame, gpointer data) { + KZ_WEBKIT_GTK_GET_PRIVATE(web_view)->is_loading = FALSE; g_signal_emit_by_name(web_view, "kz-net-stop"); } +static void +set_font_preferences (KzProfile *profile, WebKitWebSettings *settings) +{ + /* font settings */ + GList *list, *node; + gint size_variable = -1, size_fixed = -1; + gint min_size_variable = -1, min_size_fixed = -1; + gchar langs[1024], *lang = NULL; + gchar *serif_font, *sans_font, *mono_font; + double dpi_pixel_ratio = 72.0 / 96.0; + + /* workaround */ + if (kz_profile_get_value(profile, "Language", "accept_languages", + &langs, G_N_ELEMENTS(langs), + KZ_PROFILE_VALUE_TYPE_STRING)) + { + gchar **split_str; + split_str = g_strsplit(langs, ",", 1); + + if (split_str[0]) + { + lang = g_strdup(split_str[0]); + g_strfreev(split_str); + } + } + if (!lang) + lang = g_strdup(""); + + serif_font = g_strdup_printf("name_serif_%s", lang); + sans_font = g_strdup_printf("name_sans-serif_%s", lang); + mono_font = g_strdup_printf("name_monospace_%s", lang); + + list = kz_profile_enum_key(profile, "Font", TRUE); + for (node = list; node; node = g_list_next(node)) + { + const gchar *key = (const gchar*)node->data; + + if (!key || !*key) continue; + if (g_str_has_prefix(key, "size_variable_")) + { + gint value; + kz_profile_get_value(profile, "Font", key, + &value, sizeof(value), + KZ_PROFILE_VALUE_TYPE_INT); + if (value > size_variable) + size_variable = value; + } + else if (g_str_has_prefix(key, "size_fixed_")) + { + gint value; + kz_profile_get_value(profile, "Font", key, + &value, sizeof(value), + KZ_PROFILE_VALUE_TYPE_INT); + if (value > size_fixed) + size_fixed = value; + } + else if (g_str_has_prefix(key, "min-size_variable_")) + { + gint value; + kz_profile_get_value(profile, "Font", key, + &value, sizeof(value), + KZ_PROFILE_VALUE_TYPE_INT); + if (value > min_size_variable) + min_size_variable = value; + } + else if (g_str_has_prefix(key, "min-size_fixed_")) + { + gint value; + kz_profile_get_value(profile, "Font", key, + &value, sizeof(value), + KZ_PROFILE_VALUE_TYPE_INT); + if (value > min_size_fixed) + min_size_fixed = value; + } + else if (!strcmp(key, serif_font)) + { + gchar value[1024]; + kz_profile_get_value(profile, "Font", key, + &value, strlen(value)+1, + KZ_PROFILE_VALUE_TYPE_STRING); + g_object_set(settings, + "serif-font-family", value, + "default-font-family", value, + NULL); + } + else if (!strcmp(key, sans_font)) + { + gchar value[1024]; + kz_profile_get_value(profile, "Font", key, + &value, strlen(value)+1, + KZ_PROFILE_VALUE_TYPE_STRING); + g_object_set(settings, + "sans-serif-font-family", value, + NULL); + } + else if (!strcmp(key, mono_font)) + { + gchar value[1024]; + kz_profile_get_value(profile, "Font", key, + &value, strlen(value)+1, + KZ_PROFILE_VALUE_TYPE_STRING); + g_object_set(settings, + "monospace-serif-font-family", value, + NULL); + } + } + g_list_free(list); + g_free(serif_font); + g_free(sans_font); + g_free(mono_font); + + if (size_variable >= 0) + g_object_set(settings, "default-font-size", (gint)(size_variable * dpi_pixel_ratio), NULL); + if (size_fixed >= 0) + g_object_set(settings, "default-monospace-font-size", (gint)(size_fixed * dpi_pixel_ratio), NULL); + if (min_size_variable >= 0) + g_object_set(settings, "minimum-font-size", (gint)(min_size_variable * dpi_pixel_ratio), NULL); + if (min_size_fixed >= 0) + g_object_set(settings, "minimum-logical-font-size", (gint)(min_size_fixed * dpi_pixel_ratio), NULL); +} + +static void +set_default_preferences (KzWebKitGtk *webkit) +{ + KzProfile *profile = KZ_GET_GLOBAL_PROFILE; + gchar value[1024]; + + WebKitWebSettings *settings; + settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webkit)); + if (!settings) + return; + + if (kz_profile_get_value(profile, "Language", "charset_default", + &value, G_N_ELEMENTS(value), + KZ_PROFILE_VALUE_TYPE_STRING)) + { + g_object_set(settings, "default-encoding", value, NULL); + } + + set_font_preferences (profile, settings); + + g_object_set(settings, + "enable-plugins", TRUE, + "enable-scripts", TRUE, + "auto-load-images", TRUE, + NULL); +} +