Show icons/ labels in statusbar features according to toolbar style

This commit is contained in:
Christian Dywan 2009-06-01 02:46:10 +02:00
parent ae945c4269
commit 6296ce147d

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de> Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -16,13 +16,45 @@ statusbar_features_app_add_browser_cb (MidoriApp* app,
MidoriBrowser* browser, MidoriBrowser* browser,
MidoriExtension* extension); MidoriExtension* extension);
static void
statusbar_features_toolbar_notify_toolbar_style_cb (GtkWidget* toolbar,
GParamSpec* pspec,
GtkWidget* button)
{
GtkToolbarStyle style = katze_object_get_enum (toolbar, "toolbar-style");
const gchar* text = g_object_get_data (G_OBJECT (button), "feature-label");
switch (style)
{
case GTK_TOOLBAR_BOTH:
case GTK_TOOLBAR_BOTH_HORIZ:
gtk_button_set_label (GTK_BUTTON (button), text);
gtk_widget_show (gtk_button_get_image (GTK_BUTTON (button)));
break;
case GTK_TOOLBAR_TEXT:
gtk_button_set_label (GTK_BUTTON (button), text);
gtk_widget_hide (gtk_button_get_image (GTK_BUTTON (button)));
break;
case GTK_TOOLBAR_ICONS:
gtk_button_set_label (GTK_BUTTON (button), "");
gtk_widget_show (gtk_button_get_image (GTK_BUTTON (button)));
break;
default:
g_assert_not_reached ();
}
}
static void static void
statusbar_features_deactivate_cb (MidoriExtension* extension, statusbar_features_deactivate_cb (MidoriExtension* extension,
GtkWidget* bbox) GtkWidget* bbox)
{ {
MidoriApp* app = midori_extension_get_app (extension); MidoriApp* app = midori_extension_get_app (extension);
MidoriBrowser* browser = midori_browser_get_for_widget (bbox);
GtkWidget* toolbar = katze_object_get_object (browser, "navigationbar");
gtk_widget_destroy (bbox); gtk_widget_destroy (bbox);
g_signal_handlers_disconnect_matched (toolbar, G_SIGNAL_MATCH_FUNC,
0, -1, NULL, statusbar_features_toolbar_notify_toolbar_style_cb, NULL);
g_object_unref (toolbar);
g_signal_handlers_disconnect_by_func ( g_signal_handlers_disconnect_by_func (
extension, statusbar_features_deactivate_cb, bbox); extension, statusbar_features_deactivate_cb, bbox);
g_signal_handlers_disconnect_by_func ( g_signal_handlers_disconnect_by_func (
@ -37,6 +69,7 @@ statusbar_features_app_add_browser_cb (MidoriApp* app,
GtkWidget* statusbar; GtkWidget* statusbar;
GtkWidget* bbox; GtkWidget* bbox;
MidoriWebSettings* settings; MidoriWebSettings* settings;
GtkWidget* toolbar;
GtkWidget* button; GtkWidget* button;
GtkWidget* image; GtkWidget* image;
@ -46,36 +79,47 @@ statusbar_features_app_add_browser_cb (MidoriApp* app,
statusbar = katze_object_get_object (browser, "statusbar"); statusbar = katze_object_get_object (browser, "statusbar");
bbox = gtk_hbox_new (FALSE, 0); bbox = gtk_hbox_new (FALSE, 0);
settings = katze_object_get_object (browser, "settings"); settings = katze_object_get_object (browser, "settings");
toolbar = katze_object_get_object (browser, "navigationbar");
button = katze_property_proxy (settings, "auto-load-images", "toggle"); button = katze_property_proxy (settings, "auto-load-images", "toggle");
g_object_set_data (G_OBJECT (button), "feature-label", _("Images"));
image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU); image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU);
gtk_widget_show (image); gtk_button_set_image (GTK_BUTTON (button), image);
gtk_container_add (GTK_CONTAINER (button), image);
#if GTK_CHECK_VERSION(2, 12, 0) #if GTK_CHECK_VERSION(2, 12, 0)
gtk_widget_set_tooltip_text (button, _("Load images automatically")); gtk_widget_set_tooltip_text (button, _("Load images automatically"));
#endif #endif
statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
g_signal_connect (toolbar, "notify::toolbar-style",
G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
gtk_widget_show (button); gtk_widget_show (button);
button = katze_property_proxy (settings, "enable-scripts", "toggle"); button = katze_property_proxy (settings, "enable-scripts", "toggle");
g_object_set_data (G_OBJECT (button), "feature-label", _("Scripts"));
image = gtk_image_new_from_stock (STOCK_SCRIPTS, GTK_ICON_SIZE_MENU); image = gtk_image_new_from_stock (STOCK_SCRIPTS, GTK_ICON_SIZE_MENU);
gtk_widget_show (image); gtk_button_set_image (GTK_BUTTON (button), image);
gtk_container_add (GTK_CONTAINER (button), image);
#if GTK_CHECK_VERSION(2, 12, 0) #if GTK_CHECK_VERSION(2, 12, 0)
gtk_widget_set_tooltip_text (button, _("Enable scripts")); gtk_widget_set_tooltip_text (button, _("Enable scripts"));
#endif #endif
statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
g_signal_connect (toolbar, "notify::toolbar-style",
G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
gtk_widget_show (button); gtk_widget_show (button);
button = katze_property_proxy (settings, "enable-plugins", "toggle"); button = katze_property_proxy (settings, "enable-plugins", "toggle");
g_object_set_data (G_OBJECT (button), "feature-label", _("Netscape plugins"));
image = gtk_image_new_from_stock (STOCK_PLUGINS, GTK_ICON_SIZE_MENU); image = gtk_image_new_from_stock (STOCK_PLUGINS, GTK_ICON_SIZE_MENU);
gtk_widget_show (image); gtk_button_set_image (GTK_BUTTON (button), image);
gtk_container_add (GTK_CONTAINER (button), image);
#if GTK_CHECK_VERSION(2, 12, 0) #if GTK_CHECK_VERSION(2, 12, 0)
gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins")); gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins"));
#endif #endif
statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
g_signal_connect (toolbar, "notify::toolbar-style",
G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
gtk_widget_show (button); gtk_widget_show (button);
gtk_widget_show (bbox); gtk_widget_show (bbox);
gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3); gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
g_object_unref (settings); g_object_unref (settings);
g_object_unref (statusbar);
g_signal_connect (extension, "deactivate", g_signal_connect (extension, "deactivate",
G_CALLBACK (statusbar_features_deactivate_cb), bbox); G_CALLBACK (statusbar_features_deactivate_cb), bbox);
@ -95,6 +139,7 @@ statusbar_features_activate_cb (MidoriExtension* extension,
statusbar_features_app_add_browser_cb (app, browser, extension); statusbar_features_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (statusbar_features_app_add_browser_cb), extension); G_CALLBACK (statusbar_features_app_add_browser_cb), extension);
g_object_unref (browsers);
} }
MidoriExtension* MidoriExtension*