1# Copyright (c) 2017-2021 Cedric Bellegarde <cedric.bellegarde@adishatz.org> 2# This program is free software: you can redistribute it and/or modify 3# it under the terms of the GNU General Public License as published by 4# the Free Software Foundation, either version 3 of the License, or 5# (at your option) any later version. 6# This program is distributed in the hope that it will be useful, 7# but WITHOUT ANY WARRANTY; without even the implied warranty of 8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9# GNU General Public License for more details. 10# You should have received a copy of the GNU General Public License 11# along with this program. If not, see <http://www.gnu.org/licenses/>. 12 13from gi.repository import Gtk 14 15from gettext import gettext as _ 16 17from eolie.define import App, Indicator 18 19 20class GeolocationPopover(Gtk.Popover): 21 """ 22 Show JavaScript message 23 @warning: will block current execution 24 """ 25 26 def __init__(self, uri, request, window): 27 """ 28 Init popover 29 @param uri as str 30 @param request as WebKit2.PermissionRequest 31 @param window as window 32 """ 33 Gtk.Popover.__init__(self) 34 self.set_modal(False) 35 window.register(self) 36 self.__uri = uri 37 self.__request = request 38 self.__window = window 39 builder = Gtk.Builder() 40 builder.add_from_resource("/org/gnome/Eolie/PopoverGeolocation.ui") 41 builder.connect_signals(self) 42 self.__switch = builder.get_object("switch") 43 widget = builder.get_object("widget") 44 label = builder.get_object("label") 45 label.set_text(_("Grant this page access to your location?")) 46 self.add(widget) 47 48####################### 49# PROTECTED # 50####################### 51 def _on_ok_button_clicked(self, button): 52 """ 53 Pass ok to js 54 @param button as Gtk.Button 55 """ 56 self.__request.allow() 57 self.hide() 58 if self.__switch.get_active(): 59 App().websettings.set("geolocation", self.__uri, True) 60 self.__window.toolbar.title.show_indicator(Indicator.GEOLOCATION) 61 62 def _on_cancel_button_clicked(self, button): 63 """ 64 Pass ok to js 65 @param button as Gtk.Button 66 """ 67 self.__request.deny() 68 self.hide() 69 70####################### 71# PRIVATE # 72####################### 73