1/* 2 Copyright (C) 2008-2018 Christian Dywan <christian@twotoasts.de> 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 See the file COPYING for the full license text. 10*/ 11 12namespace StatusbarFeatures { 13 public class Frontend : Object, Midori.BrowserActivatable { 14 public Midori.Browser browser { owned get; set; } 15 16 public void add_zoom () { 17 var zoom = new Gtk.ComboBoxText.with_entry (); 18 var entry = zoom.get_child () as Gtk.Entry; 19 zoom.append_text ("50%"); 20 zoom.append_text ("80%"); 21 zoom.append_text ("100%"); 22 zoom.append_text ("120%"); 23 zoom.append_text ("150%"); 24 zoom.append_text ("200%"); 25 entry.set_width_chars (6); 26 entry.set_text ((100 * browser.tab.zoom_level).to_string () + "%"); 27 zoom.show (); 28 zoom.changed.connect(() => { 29 if (zoom.get_active_text() == "50%") { 30 browser.tab.zoom_level = 0.5; 31 } else if (zoom.get_active_text() == "80%") { 32 browser.tab.zoom_level = 0.8; 33 } else if (zoom.get_active_text() == "100%") { 34 browser.tab.zoom_level = 1.0; 35 } else if (zoom.get_active_text() == "120%") { 36 browser.tab.zoom_level = 1.2; 37 } else if (zoom.get_active_text() == "150%") { 38 browser.tab.zoom_level = 1.5; 39 } else if (zoom.get_active_text() == "200%") { 40 browser.tab.zoom_level = 2.0; 41 } 42 if (entry.has_focus == false) { 43 browser.tab.grab_focus (); 44 } 45 }); 46 47 entry.activate.connect(() => { 48 if (double.parse(entry.get_text ()) >= 1) { 49 browser.tab.zoom_level = double.parse(zoom.get_active_text ()) / 100; 50 } 51 entry.set_text ((100 * browser.tab.zoom_level).to_string () + "%"); 52 browser.tab.grab_focus (); 53 }); 54 55 deactivate.connect (() => { 56 zoom.destroy (); 57 }); 58 browser.statusbar.add (zoom); 59 } 60 void add_toggle (string item, string? icon_name=null, string? tooltip=null) { 61 var button = new Gtk.ToggleButton (); 62 if (icon_name != null) { 63 button.add (new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON)); 64 } else { 65 button.label = item; 66 } 67 button.tooltip_text = tooltip; 68 var settings = Midori.CoreSettings.get_default (); 69 if (settings.get_class ().find_property (item) != null) { 70 settings.bind_property (item, button, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); 71 } else { 72 button.sensitive = false; 73 } 74 button.show_all (); 75 deactivate.connect (() => { 76 button.destroy (); 77 }); 78 browser.statusbar.add (button); 79 } 80 81 public void activate () { 82 string items = "auto-load-images;enable-javascript;enable-plugins"; 83 foreach (string item in items.split (";")) { 84 if (item == "enable-javascript") { 85 add_toggle (item, "text-x-script", _("Enable scripts")); 86 } else if (item == "auto-load-images") { 87 add_toggle (item, "image-x-generic", _("Load images automatically")); 88 } else if (item == "enable-plugins") { 89 add_toggle (item, "libpeas-plugin", _("Enable Netscape plugins")); 90 } else { 91 add_toggle (item); 92 } 93 } 94 add_zoom (); 95 } 96 } 97} 98 99[ModuleInit] 100public void peas_register_types(TypeModule module) { 101 ((Peas.ObjectModule)module).register_extension_type ( 102 typeof (Midori.BrowserActivatable), typeof (StatusbarFeatures.Frontend)); 103} 104