Ejemplo n.º 1
0
 def __set_favicon(self):
     """
         Set favicon
     """
     resized = None
     uri = self.__view.webview.get_uri()
     surface = self.__view.webview.get_favicon()
     artwork = El().art.get_icon_theme_artwork(
         uri, self.__view.webview.ephemeral)
     if artwork is not None:
         self.__close_button.get_image().set_from_icon_name(
             artwork, Gtk.IconSize.INVALID)
     elif surface is not None:
         resized = resize_favicon(surface)
         if not El().art.exists(uri, "favicon"):
             El().art.save_artwork(uri, resized, "favicon")
         self.__set_favicon_related(resized, uri,
                                    self.__view.webview.initial_uri)
         self.__close_button.get_image().set_from_surface(resized)
     else:
         self.__close_button.get_image().set_from_icon_name(
             "applications-internet", Gtk.IconSize.INVALID)
     if resized is not None:
         self.__window.container.sites_manager.set_favicon(
             self.__view, resized)
         del resized
Ejemplo n.º 2
0
    def __set_favicon_result(self, db, result, uri):
        """
            Set favicon db result
            @param db as WebKit2.FaviconDatabase
            @param result as Gio.AsyncResult
            @param uri as str
        """
        try:
            surface = db.get_favicon_finish(result)
            save = True
        except:
            surface = self._view.webview.get_favicon()
            # Getting favicon is not accurate
            # We don't know if it really is for current uri
            # So don't save
            save = False

        if surface is None:
            self._image_close.set_from_icon_name("applications-internet",
                                                 Gtk.IconSize.INVALID)
        else:
            resized = resize_favicon(surface)
            if save:
                El().art.save_artwork(uri, resized, "favicon")
                self.__set_favicon_related(resized, uri,
                                           self._view.webview.related_uri)
            self._image_close.set_from_surface(resized)
            del resized
            del surface
Ejemplo n.º 3
0
    def __set_favicon_from_surface(self, surface, uri, initial_uri):
        """
            Set favicon for surface
            @param favicon_db as WebKit2.FaviconDatabase
            @param result as Gio.AsyncResult
            @param uri as str
            @param initial_uri as str
        """
        resized = None
        # Save webview favicon
        if surface is not None:
            favicon_width = surface.get_width()
            if uri not in self.__favicon_width.keys() or\
                    favicon_width >= self.__favicon_width[uri]:
                if self.__save_favicon_timeout_id is not None:
                    GLib.source_remove(self.__save_favicon_timeout_id)
                    self.__save_favicon_timeout_id = None
                self.__favicon_width[uri] = favicon_width
                resized = resize_favicon(surface)
                favicon_type = "favicon"
        else:
            netloc = remove_www(urlparse(uri).netloc)
            if netloc:
                resized = App().art.get_favicon(uri, self.get_scale_factor())
                if resized is None:
                    resized = get_char_surface(netloc[0])
                favicon_type = "favicon_alt"

        # We wait for a better favicon
        if resized is not None and uri == self.uri:
            self.__save_favicon_timeout_id = GLib.timeout_add(
                500, self.__save_favicon_to_cache, resized, uri, initial_uri,
                favicon_type)
Ejemplo n.º 4
0
 def __set_favicon(self, safe):
     """
         Cache favicon and emit signal
         @param safe as bool
     """
     self.__favicon_id = None
     resized = None
     uri = self.uri
     icon_theme_artwork = El().art.get_icon_theme_artwork(uri,
                                                          self.ephemeral)
     if icon_theme_artwork is not None:
         self.emit("favicon-changed", None, icon_theme_artwork)
     elif uri is not None:
         favicon_type = "favicon"
         parsed = urlparse(uri)
         netloc = remove_www(parsed.netloc)
         if not netloc:
             return
         # Read result
         surface = self.get_favicon()
         # Resize surface and set favicon
         if surface is not None:
             resized = resize_favicon(surface)
         else:
             # Check for already cached favicon
             # We do not want to show a favicon_alt if a favicon is cached
             # so check for favicon too
             for favicon in ["favicon", "favicon_alt"]:
                 resized = El().art.get_artwork(netloc,
                                                favicon,
                                                self.get_scale_factor(),
                                                ArtSize.FAVICON,
                                                ArtSize.FAVICON)
                 if resized is not None:
                     favicon_type = favicon
                     break
             if resized is None:
                 resized = get_char_surface(netloc[0])
                 favicon_type = "favicon_alt"
         self.emit("favicon-changed", resized, None)
         # Save favicon if needed
         if not self.ephemeral:
             (exists, cached) = El().art.exists(uri, favicon_type)
             if not exists or (not cached and safe):
                 El().art.save_artwork(uri, resized, favicon_type)
             (exists, cached) = El().art.exists(netloc, favicon_type)
             if netloc is not None:
                 if not exists or (not cached and safe):
                     El().art.save_artwork(netloc, resized, favicon_type)
             self.__set_initial_uri_favicon(resized,
                                            uri,
                                            favicon_type,
                                            safe)
Ejemplo n.º 5
0
 def __set_favicon_result(self, db, result, favicon):
     """
         Set favicon db result
         @param db as WebKit2.FaviconDatabase
         @param result as Gio.AsyncResult
         @param favicon as Gtk.Image
     """
     try:
         surface = db.get_favicon_finish(result)
     except:
         surface = None
     if surface is None:
         favicon.set_from_icon_name("applications-internet",
                                    Gtk.IconSize.LARGE_TOOLBAR)
     else:
         favicon.set_from_surface(resize_favicon(surface))
         del surface
     favicon.show()
Ejemplo n.º 6
0
 def __set_favicon_result(self, db, result):
     """
         Set favicon db result
         @param db as WebKit2.FaviconDatabase
         @param result as Gio.AsyncResult
     """
     try:
         surface = db.get_favicon_finish(result)
     except:
         surface = None
     if surface is None:
         self.__image_close.set_from_icon_name("applications-internet",
                                               Gtk.IconSize.INVALID)
     else:
         self.__image_close.set_from_surface(resize_favicon(surface))
         del surface
         self.__image_close.get_style_context().remove_class(
             "sidebar-item-close")
         self.__image_close.show()