From 215a5c1ca24c6662d5e5b1a72000f4d013cf2816 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 24 Feb 2011 22:11:35 +0100 Subject: [PATCH] Add a zoom level combobox to Statusbar Features Fixes: https://bugs.launchpad.net/midori/+bug/718155 --- extensions/statusbar-features.c | 55 ++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/extensions/statusbar-features.c b/extensions/statusbar-features.c index eca46138..6d45788e 100644 --- a/extensions/statusbar-features.c +++ b/extensions/statusbar-features.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2008-2010 Christian Dywan + Copyright (C) 2008-2011 Christian Dywan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -12,6 +12,23 @@ #include #include +typedef struct +{ + const gchar* label; + gdouble level; +} ZoomLevel; + +const ZoomLevel zoom_levels[] = +{ + { "200%", 2.0 }, + { "175%", 1.75 }, + { "150%", 1.5 }, + { "125%", 1.25 }, + { "100%", 1.0 }, + { "50%" , 0.5 }, + { "25%" , 0.25 } +}; + static void statusbar_features_app_add_browser_cb (MidoriApp* app, MidoriBrowser* browser, @@ -44,6 +61,19 @@ statusbar_features_toolbar_notify_toolbar_style_cb (GtkWidget* toolbar, } } +static void +statusbar_features_browser_notify_tab_cb (MidoriBrowser* browser, + GParamSpec* pspec, + GtkWidget* combobox) +{ + MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser)); + gchar* zoom_level_text = g_strdup_printf ("%d%%", + (gint)(midori_view_get_zoom_level (view) * 100)); + gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combobox))), + zoom_level_text); + g_free (zoom_level_text); +} + static void statusbar_features_deactivate_cb (MidoriExtension* extension, GtkWidget* bbox) @@ -60,6 +90,19 @@ statusbar_features_deactivate_cb (MidoriExtension* extension, extension, statusbar_features_deactivate_cb, bbox); g_signal_handlers_disconnect_by_func ( app, statusbar_features_app_add_browser_cb, extension); + g_signal_handlers_disconnect_matched (browser, G_SIGNAL_MATCH_FUNC, + 0, -1, NULL, statusbar_features_browser_notify_tab_cb, NULL); +} + +static void +statusbar_features_zoom_level_changed_cb (GtkWidget* combobox, + MidoriBrowser* browser) +{ + MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser)); + GtkWidget* entry = gtk_bin_get_child (GTK_BIN (combobox)); + const gchar* zoom_level_text = gtk_entry_get_text (GTK_ENTRY (entry)); + gdouble zoom_level = g_ascii_strtod (zoom_level_text, NULL); + midori_view_set_zoom_level (view, zoom_level / 100.0); } static void @@ -73,6 +116,7 @@ statusbar_features_app_add_browser_cb (MidoriApp* app, GtkWidget* toolbar; GtkWidget* button; GtkWidget* image; + gsize i; /* FIXME: Monitor each view and modify its settings individually instead of merely replicating the global preferences. */ @@ -110,6 +154,15 @@ statusbar_features_app_add_browser_cb (MidoriApp* app, gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2); button = katze_property_proxy (settings, "identify-as", NULL); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2); + button = gtk_combo_box_entry_new_text (); + gtk_entry_set_width_chars (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (button))), 4); + for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) + gtk_combo_box_append_text (GTK_COMBO_BOX (button), zoom_levels[i].label); + gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2); + g_signal_connect (button, "changed", + G_CALLBACK (statusbar_features_zoom_level_changed_cb), browser); + g_signal_connect (browser, "notify::tab", + G_CALLBACK (statusbar_features_browser_notify_tab_cb), button); gtk_widget_show_all (bbox); gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3); g_object_unref (statusbar);