2008-11-18 01:08:50 +00:00
|
|
|
/*
|
2011-02-24 21:11:35 +00:00
|
|
|
Copyright (C) 2008-2011 Christian Dywan <christian@twotoasts.de>
|
2008-11-18 01:08:50 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
See the file COPYING for the full license text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <midori/midori.h>
|
|
|
|
|
2011-02-24 21:11:35 +00:00
|
|
|
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 }
|
|
|
|
};
|
|
|
|
|
2009-03-25 01:12:12 +00:00
|
|
|
static void
|
|
|
|
statusbar_features_app_add_browser_cb (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser,
|
|
|
|
MidoriExtension* extension);
|
|
|
|
|
2009-06-01 00:46:10 +00:00
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:11:35 +00:00
|
|
|
static void
|
|
|
|
statusbar_features_browser_notify_tab_cb (MidoriBrowser* browser,
|
|
|
|
GParamSpec* pspec,
|
|
|
|
GtkWidget* combobox)
|
|
|
|
{
|
|
|
|
MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
|
2012-02-25 22:52:45 +00:00
|
|
|
gchar* text;
|
|
|
|
|
|
|
|
if (view == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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))), text);
|
|
|
|
g_free (text);
|
2011-02-24 21:11:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-06 01:26:19 +00:00
|
|
|
static void
|
|
|
|
statusbar_features_deactivate_cb (MidoriExtension* extension,
|
|
|
|
GtkWidget* bbox)
|
|
|
|
{
|
2009-03-25 01:12:12 +00:00
|
|
|
MidoriApp* app = midori_extension_get_app (extension);
|
2009-06-01 00:46:10 +00:00
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (bbox);
|
|
|
|
GtkWidget* toolbar = katze_object_get_object (browser, "navigationbar");
|
2009-03-25 01:12:12 +00:00
|
|
|
|
2009-01-06 01:26:19 +00:00
|
|
|
gtk_widget_destroy (bbox);
|
2009-06-01 00:46:10 +00:00
|
|
|
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);
|
2009-02-28 00:43:20 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
extension, statusbar_features_deactivate_cb, bbox);
|
2009-03-25 01:12:12 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
app, statusbar_features_app_add_browser_cb, extension);
|
2011-02-24 21:11:35 +00:00
|
|
|
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);
|
2009-01-06 01:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
statusbar_features_app_add_browser_cb (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser,
|
|
|
|
MidoriExtension* extension)
|
2008-11-18 01:08:50 +00:00
|
|
|
{
|
|
|
|
GtkWidget* statusbar;
|
|
|
|
GtkWidget* bbox;
|
|
|
|
MidoriWebSettings* settings;
|
2009-06-01 00:46:10 +00:00
|
|
|
GtkWidget* toolbar;
|
2008-11-18 01:08:50 +00:00
|
|
|
GtkWidget* button;
|
2009-04-17 01:16:37 +00:00
|
|
|
GtkWidget* image;
|
2011-02-24 21:11:35 +00:00
|
|
|
gsize i;
|
2008-11-18 01:08:50 +00:00
|
|
|
|
|
|
|
/* FIXME: Monitor each view and modify its settings individually
|
|
|
|
instead of merely replicating the global preferences. */
|
|
|
|
|
|
|
|
statusbar = katze_object_get_object (browser, "statusbar");
|
2008-11-23 00:51:30 +00:00
|
|
|
bbox = gtk_hbox_new (FALSE, 0);
|
2010-11-01 15:47:32 +00:00
|
|
|
settings = midori_browser_get_settings (browser);
|
2009-06-01 00:46:10 +00:00
|
|
|
toolbar = katze_object_get_object (browser, "navigationbar");
|
2009-04-17 01:16:37 +00:00
|
|
|
button = katze_property_proxy (settings, "auto-load-images", "toggle");
|
2009-06-01 00:46:10 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "feature-label", _("Images"));
|
2009-04-17 01:16:37 +00:00
|
|
|
image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU);
|
2009-06-01 00:46:10 +00:00
|
|
|
gtk_button_set_image (GTK_BUTTON (button), image);
|
2008-11-30 01:08:28 +00:00
|
|
|
gtk_widget_set_tooltip_text (button, _("Load images automatically"));
|
2009-06-01 00:46:10 +00:00
|
|
|
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);
|
2008-11-23 00:51:30 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
|
2009-04-17 01:16:37 +00:00
|
|
|
button = katze_property_proxy (settings, "enable-scripts", "toggle");
|
2009-06-01 00:46:10 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "feature-label", _("Scripts"));
|
2009-04-17 01:16:37 +00:00
|
|
|
image = gtk_image_new_from_stock (STOCK_SCRIPTS, GTK_ICON_SIZE_MENU);
|
2009-06-01 00:46:10 +00:00
|
|
|
gtk_button_set_image (GTK_BUTTON (button), image);
|
2008-11-30 01:08:28 +00:00
|
|
|
gtk_widget_set_tooltip_text (button, _("Enable scripts"));
|
2009-06-01 00:46:10 +00:00
|
|
|
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);
|
2008-11-30 01:08:28 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
|
2012-02-25 01:06:46 +00:00
|
|
|
if (midori_web_settings_has_plugin_support ())
|
|
|
|
{
|
|
|
|
button = katze_property_proxy (settings, "enable-plugins", "toggle");
|
|
|
|
g_object_set_data (G_OBJECT (button), "feature-label", _("Netscape plugins"));
|
2009-04-17 01:16:37 +00:00
|
|
|
image = gtk_image_new_from_stock (STOCK_PLUGINS, GTK_ICON_SIZE_MENU);
|
2009-06-01 00:46:10 +00:00
|
|
|
gtk_button_set_image (GTK_BUTTON (button), image);
|
2009-04-25 14:13:23 +00:00
|
|
|
gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins"));
|
2009-06-01 00:46:10 +00:00
|
|
|
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);
|
2008-11-23 00:51:30 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
|
2012-02-25 22:52:45 +00:00
|
|
|
}
|
2011-03-04 22:26:41 +00:00
|
|
|
button = katze_property_proxy (settings, "identify-as", "custom-user-agent");
|
2010-10-31 20:24:34 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
|
2011-10-20 20:47:27 +00:00
|
|
|
button = gtk_combo_box_text_new_with_entry ();
|
2011-02-24 21:11:35 +00:00
|
|
|
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++)
|
2011-10-20 21:36:34 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (button), zoom_levels[i].label);
|
2011-02-24 21:11:35 +00:00
|
|
|
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);
|
2012-02-25 22:52:45 +00:00
|
|
|
statusbar_features_browser_notify_tab_cb (browser, NULL, button);
|
2010-10-31 20:24:34 +00:00
|
|
|
gtk_widget_show_all (bbox);
|
2008-11-18 01:08:50 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
|
2009-06-01 00:46:10 +00:00
|
|
|
g_object_unref (statusbar);
|
2009-01-06 01:26:19 +00:00
|
|
|
|
|
|
|
g_signal_connect (extension, "deactivate",
|
|
|
|
G_CALLBACK (statusbar_features_deactivate_cb), bbox);
|
2008-11-18 01:08:50 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 00:22:25 +00:00
|
|
|
static void
|
|
|
|
statusbar_features_activate_cb (MidoriExtension* extension,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
2009-02-28 00:43:20 +00:00
|
|
|
KatzeArray* browsers;
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
|
|
|
|
browsers = katze_object_get_object (app, "browsers");
|
2010-09-11 21:39:51 +00:00
|
|
|
KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
|
2009-02-28 00:43:20 +00:00
|
|
|
statusbar_features_app_add_browser_cb (app, browser, extension);
|
2008-11-20 00:22:25 +00:00
|
|
|
g_signal_connect (app, "add-browser",
|
2009-01-06 01:26:19 +00:00
|
|
|
G_CALLBACK (statusbar_features_app_add_browser_cb), extension);
|
2009-06-01 00:46:10 +00:00
|
|
|
g_object_unref (browsers);
|
2008-11-20 00:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MidoriExtension*
|
|
|
|
extension_init (void)
|
2008-11-18 01:08:50 +00:00
|
|
|
{
|
|
|
|
MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
|
2009-04-28 21:57:56 +00:00
|
|
|
"name", _("Statusbar Features"),
|
|
|
|
"description", _("Easily toggle features on web pages on and off"),
|
2011-11-08 00:53:53 +00:00
|
|
|
"version", "0.1" MIDORI_VERSION_SUFFIX,
|
2008-11-18 01:08:50 +00:00
|
|
|
"authors", "Christian Dywan <christian@twotoasts.de>",
|
|
|
|
NULL);
|
|
|
|
|
2008-11-20 00:22:25 +00:00
|
|
|
g_signal_connect (extension, "activate",
|
|
|
|
G_CALLBACK (statusbar_features_activate_cb), NULL);
|
2008-11-18 01:08:50 +00:00
|
|
|
|
|
|
|
return extension;
|
|
|
|
}
|