Ejemplo n.º 1
0
 def __init__(self, items):
     """
         Init menu
         @param items as [WebKit2.BackForwardListItem]
     """
     Gio.Menu.__init__(self)
     for item in items[:10]:
         uri = item.get_uri()
         if uri is None:
             continue
         title = item.get_title()
         if not title:
             title = uri
         encoded = "HISTORY_" + sha256(uri.encode("utf-8")).hexdigest()
         action = El().lookup_action(encoded)
         if action is not None:
             El().remove_action(encoded)
         action = Gio.SimpleAction(name=encoded)
         El().add_action(action)
         action.connect('activate', self.__on_action_clicked, item)
         item = Gio.MenuItem.new(title, "app.%s" % encoded)
         item.set_attribute_value("uri", GLib.Variant("s", uri))
         if uri == "populars://":
             item.set_icon(Gio.ThemedIcon.new("emote-love-symbolic"))
         else:
             # Try to set icon
             filepath = El().art.get_path(uri, "favicon")
             f = Gio.File.new_for_path(filepath)
             if f.query_exists():
                 icon = Gio.FileIcon.new(f)
                 item.set_icon(icon)
             else:
                 item.set_icon(Gio.ThemedIcon.new("applications-internet"))
         self.append_item(item)
Ejemplo n.º 2
0
 def add_attributes(self, attributes, uri):
     """
         Add username to model
         @param attributes as {}
         @param uri as str
     """
     if attributes["userform"] != self.__userform:
         return
     encoded = "FORM_" + sha256(
         attributes["login"].encode("utf-8")).hexdigest()
     action = El().lookup_action(encoded)
     if action is not None:
         El().remove_action(encoded)
     action = Gio.SimpleAction(name=encoded)
     El().add_action(action)
     action.connect('activate', self.__on_action_clicked, attributes)
     label = attributes["login"].replace("_", "__")
     item = Gio.MenuItem.new(label, "app.%s" % encoded)
     self.__section.append_item(item)
Ejemplo n.º 3
0
 def __init__(self, views, window):
     """
         Init menu
         @param views as [view]
         @param window as Window
     """
     self.__window = window
     Gio.Menu.__init__(self)
     for view in views:
         uri = view.webview.get_uri()
         if uri is None:
             continue
         title = view.webview.get_title()
         if not title:
             title = uri
         encoded = "SITE_" + sha256(uri.encode("utf-8")).hexdigest()
         action = El().lookup_action(encoded)
         if action is not None:
             El().remove_action(encoded)
         action = Gio.SimpleAction(name=encoded)
         El().add_action(action)
         action.connect('activate', self.__on_action_clicked, view)
         item = Gio.MenuItem.new(title, "app.%s" % encoded)
         item.set_attribute_value("uri", GLib.Variant("s", uri))
         self.append_item(item)
     bottom_section = Gio.Menu()
     self.append_section(None, bottom_section)
     action = Gio.SimpleAction.new("user_agent")
     self.__window.add_action(action)
     # Modify UA
     if El().settings.get_value("developer-extras"):
         item = Gio.MenuItem.new(_("Modify user agent"), "win.user_agent")
         bottom_section.append_item(item)
         action.connect("activate", self.__on_modify_ua_activate, views)
     # Close site
     action = Gio.SimpleAction.new("close_site")
     self.__window.add_action(action)
     item = Gio.MenuItem.new(_("Close site"), "win.close_site")
     bottom_section.append_item(item)
     action.connect("activate", self.__on_close_activate, views)