Update interface and web featureswith preference changes.

The toolbar style, small toolbar, New Tab, Web Search and
Trash buttons are shown or hidden respectively as
the preference values change.
This is also an attempt at updating the web view's settings
immediately. Although it seems to work, an ugly warning is
emitted to the console on every change.
This commit is contained in:
Christian Dywan 2008-04-22 22:19:24 +02:00
parent 68e0e521f4
commit d9f7abc5c7
3 changed files with 91 additions and 28 deletions

View file

@ -2664,7 +2664,39 @@ midori_browser_finalize (GObject* object)
} }
static void static void
_midori_browser_update_settings (MidoriBrowser* browser) _midori_browser_set_toolbar_style (MidoriBrowser* browser,
MidoriToolbarStyle toolbar_style)
{
MidoriBrowserPrivate* priv = browser->priv;
GtkToolbarStyle gtk_toolbar_style;
GtkSettings* gtk_settings = gtk_widget_get_settings (GTK_WIDGET (browser));
if (toolbar_style == MIDORI_TOOLBAR_DEFAULT && gtk_settings)
g_object_get (gtk_settings, "gtk-toolbar-style", &gtk_toolbar_style, NULL);
else
{
switch (toolbar_style)
{
case MIDORI_TOOLBAR_ICONS:
gtk_toolbar_style = GTK_TOOLBAR_ICONS;
break;
case MIDORI_TOOLBAR_TEXT:
gtk_toolbar_style = GTK_TOOLBAR_TEXT;
break;
case MIDORI_TOOLBAR_BOTH:
gtk_toolbar_style = GTK_TOOLBAR_BOTH;
break;
case MIDORI_TOOLBAR_BOTH_HORIZ:
case MIDORI_TOOLBAR_DEFAULT:
gtk_toolbar_style = GTK_TOOLBAR_BOTH_HORIZ;
}
}
gtk_toolbar_set_style (GTK_TOOLBAR (priv->navigationbar),
gtk_toolbar_style);
}
static void
_midori_browser_update_settings (MidoriBrowser* browser)
{ {
MidoriBrowserPrivate* priv = browser->priv; MidoriBrowserPrivate* priv = browser->priv;
@ -2709,30 +2741,7 @@ _midori_browser_update_settings (MidoriBrowser* browser)
default_width, default_height); default_width, default_height);
} }
GtkToolbarStyle gtk_toolbar_style; _midori_browser_set_toolbar_style (browser, toolbar_style);
GtkSettings* gtk_settings = gtk_widget_get_settings (GTK_WIDGET (browser));
if (toolbar_style == MIDORI_TOOLBAR_DEFAULT && gtk_settings)
g_object_get (gtk_settings, "gtk-toolbar-style", &gtk_toolbar_style, NULL);
else
{
switch (toolbar_style)
{
case MIDORI_TOOLBAR_ICONS:
gtk_toolbar_style = GTK_TOOLBAR_ICONS;
break;
case MIDORI_TOOLBAR_TEXT:
gtk_toolbar_style = GTK_TOOLBAR_TEXT;
break;
case MIDORI_TOOLBAR_BOTH:
gtk_toolbar_style = GTK_TOOLBAR_BOTH;
break;
case MIDORI_TOOLBAR_BOTH_HORIZ:
case MIDORI_TOOLBAR_DEFAULT:
gtk_toolbar_style = GTK_TOOLBAR_BOTH_HORIZ;
}
}
gtk_toolbar_set_style (GTK_TOOLBAR (priv->navigationbar),
gtk_toolbar_style);
gtk_toolbar_set_icon_size (GTK_TOOLBAR (priv->navigationbar), gtk_toolbar_set_icon_size (GTK_TOOLBAR (priv->navigationbar),
small_toolbar ? GTK_ICON_SIZE_SMALL_TOOLBAR small_toolbar ? GTK_ICON_SIZE_SMALL_TOOLBAR
: GTK_ICON_SIZE_LARGE_TOOLBAR); : GTK_ICON_SIZE_LARGE_TOOLBAR);
@ -2756,6 +2765,40 @@ _midori_browser_update_settings (MidoriBrowser* browser)
g_free (last_pageholder_uri); g_free (last_pageholder_uri);
} }
static void
midori_browser_settings_notify (MidoriWebSettings* web_settings,
GParamSpec* pspec,
MidoriBrowser* browser)
{
MidoriBrowserPrivate* priv = browser->priv;
const gchar* name = g_intern_string (pspec->name);
GValue value = {0, };
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (priv->settings), name, &value);
if (name == g_intern_string ("toolbar-style"))
_midori_browser_set_toolbar_style (browser, g_value_get_enum (&value));
else if (name == g_intern_string ("small-toolbar"))
gtk_toolbar_set_icon_size (GTK_TOOLBAR (priv->navigationbar),
g_value_get_boolean (&value) ? GTK_ICON_SIZE_SMALL_TOOLBAR
: GTK_ICON_SIZE_LARGE_TOOLBAR);
else if (name == g_intern_string ("show-new-tab"))
sokoke_widget_set_visible (priv->button_tab_new,
g_value_get_boolean (&value));
else if (name == g_intern_string ("show-web-search"))
sokoke_widget_set_visible (priv->search,
g_value_get_boolean (&value));
else if (name == g_intern_string ("show-trash"))
sokoke_widget_set_visible (priv->button_trash,
g_value_get_boolean (&value));
else if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_settings),
name))
g_warning("Unexpected setting '%s'", name);
g_value_unset (&value);
}
static void static void
midori_browser_set_property (GObject* object, midori_browser_set_property (GObject* object,
guint prop_id, guint prop_id,
@ -2771,9 +2814,15 @@ midori_browser_set_property (GObject* object,
_midori_browser_set_statusbar_text (browser, g_value_get_string (value)); _midori_browser_set_statusbar_text (browser, g_value_get_string (value));
break; break;
case PROP_SETTINGS: case PROP_SETTINGS:
if (priv->settings)
g_signal_handlers_disconnect_by_func (priv->settings,
midori_browser_settings_notify,
browser);
katze_object_assign (priv->settings, g_value_get_object (value)); katze_object_assign (priv->settings, g_value_get_object (value));
g_object_ref (priv->settings); g_object_ref (priv->settings);
_midori_browser_update_settings (browser); _midori_browser_update_settings (browser);
g_signal_connect (priv->settings, "notify",
G_CALLBACK (midori_browser_settings_notify), browser);
gtk_container_foreach (GTK_CONTAINER (priv->notebook), gtk_container_foreach (GTK_CONTAINER (priv->notebook),
(GtkCallback) midori_web_view_set_settings, (GtkCallback) midori_web_view_set_settings,
priv->settings); priv->settings);

View file

@ -225,6 +225,10 @@ midori_web_settings_get_property (GObject* object,
GValue* value, GValue* value,
GParamSpec* pspec); GParamSpec* pspec);
static void
midori_web_settings_notify (GObject* object,
GParamSpec* pspec);
static void static void
midori_web_settings_class_init (MidoriWebSettingsClass* class) midori_web_settings_class_init (MidoriWebSettingsClass* class)
{ {
@ -232,6 +236,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
gobject_class->finalize = midori_web_settings_finalize; gobject_class->finalize = midori_web_settings_finalize;
gobject_class->set_property = midori_web_settings_set_property; gobject_class->set_property = midori_web_settings_set_property;
gobject_class->get_property = midori_web_settings_get_property; gobject_class->get_property = midori_web_settings_get_property;
gobject_class->notify = midori_web_settings_notify;
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
@ -919,6 +924,13 @@ midori_web_settings_get_property (GObject* object,
} }
} }
static void
midori_web_settings_notify (GObject* object,
GParamSpec* pspec)
{
}
/** /**
* midori_web_settings_new: * midori_web_settings_new:
* *

View file

@ -569,9 +569,9 @@ midori_web_view_settings_notify (MidoriWebSettings* web_settings,
else if (name == g_intern_string ("middle-click-opens-selection")) else if (name == g_intern_string ("middle-click-opens-selection"))
priv->middle_click_opens_selection = g_value_get_boolean (&value); priv->middle_click_opens_selection = g_value_get_boolean (&value);
else if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_settings), else if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_settings),
name)) name))
g_warning("Unexpected setting '%s'", name); g_warning("Unexpected setting '%s'", name);
g_value_unset(&value); g_value_unset (&value);
} }
static void static void
@ -585,6 +585,7 @@ midori_web_view_init (MidoriWebView* web_view)
priv->settings = midori_web_settings_new (); priv->settings = midori_web_settings_new ();
_midori_web_view_update_settings (web_view); _midori_web_view_update_settings (web_view);
g_object_set (web_view, "WebKitWebView::settings", priv->settings, NULL);
g_signal_connect (priv->settings, "notify", g_signal_connect (priv->settings, "notify",
G_CALLBACK (midori_web_view_settings_notify), web_view); G_CALLBACK (midori_web_view_settings_notify), web_view);
@ -701,6 +702,7 @@ midori_web_view_set_property (GObject* object,
katze_object_assign (priv->settings, g_value_get_object (value)); katze_object_assign (priv->settings, g_value_get_object (value));
g_object_ref (priv->settings); g_object_ref (priv->settings);
_midori_web_view_update_settings (web_view); _midori_web_view_update_settings (web_view);
g_object_set (object, "WebKitWebView::settings", priv->settings, NULL);
g_signal_connect (priv->settings, "notify", g_signal_connect (priv->settings, "notify",
G_CALLBACK (midori_web_view_settings_notify), web_view); G_CALLBACK (midori_web_view_settings_notify), web_view);
break; break;