[epiphany] Add fallback favicon name helper function



commit f14601e2b57b2cf166786aea4b39131dd085a8dc
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Thu Jul 16 17:44:17 2020 +0200

    Add fallback favicon name helper function
    
    Show view-grid-symbolic for overview, web-browser-symbolic for
    about:web, otherwise ephy-missing-favicon-symbolic
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/848

 src/ephy-desktop-utils.c | 14 ++++++++++++++
 src/ephy-desktop-utils.h |  2 ++
 src/ephy-page-row.c      | 11 +++++++----
 src/ephy-tab-label.c     | 30 ++++++++++++++++++++----------
 4 files changed, 43 insertions(+), 14 deletions(-)
---
diff --git a/src/ephy-desktop-utils.c b/src/ephy-desktop-utils.c
index df8620063..9a8839614 100644
--- a/src/ephy-desktop-utils.c
+++ b/src/ephy-desktop-utils.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "ephy-desktop-utils.h"
+#include "ephy-embed-utils.h"
 
 #include <gtk/gtk.h>
 
@@ -42,3 +43,16 @@ get_icon_size (void)
 
   return GTK_ICON_SIZE_BUTTON;
 }
+
+const char *
+ephy_get_fallback_favicon_name (const char *uri)
+{
+  if (uri) {
+    if (g_str_has_prefix (uri, "ephy-about:overview") || g_str_has_prefix (uri, "about:overview"))
+      return "view-grid-symbolic";
+    else if (g_str_has_prefix (uri, "ephy-about:") || g_str_has_prefix (uri, "about:"))
+      return "web-browser-symbolic";
+  }
+
+  return "ephy-missing-favicon-symbolic";
+}
diff --git a/src/ephy-desktop-utils.h b/src/ephy-desktop-utils.h
index 29fcc76ae..fb4532a2a 100644
--- a/src/ephy-desktop-utils.h
+++ b/src/ephy-desktop-utils.h
@@ -29,4 +29,6 @@ gboolean is_desktop_pantheon (void);
 
 GtkIconSize get_icon_size (void);
 
+const char *ephy_get_fallback_favicon_name (const char *title);
+
 G_END_DECLS
diff --git a/src/ephy-page-row.c b/src/ephy-page-row.c
index 594eef119..fb359bd8d 100644
--- a/src/ephy-page-row.c
+++ b/src/ephy-page-row.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include "ephy-desktop-utils.h"
 #include "ephy-embed-utils.h"
 #include "ephy-page-row.h"
 #include "ephy-web-view.h"
@@ -140,11 +141,13 @@ sync_favicon (EphyWebView *view,
   if (ephy_web_view_get_icon (view))
     pixbuf = gdk_pixbuf_copy (ephy_web_view_get_icon (view));
 
-  if (pixbuf)
+  if (pixbuf) {
     gtk_image_set_from_pixbuf (self->icon, pixbuf);
-  else
-    gtk_image_set_from_icon_name (self->icon, "ephy-missing-favicon-symbolic",
-                                  GTK_ICON_SIZE_MENU);
+  } else {
+    const char *favicon_name = ephy_get_fallback_favicon_name (ephy_web_view_get_display_address (view));
+
+    gtk_image_set_from_icon_name (GTK_IMAGE (self->icon), favicon_name, GTK_ICON_SIZE_MENU);
+  }
 }
 
 EphyPageRow *
diff --git a/src/ephy-tab-label.c b/src/ephy-tab-label.c
index 60c06eecf..d3a78f23a 100644
--- a/src/ephy-tab-label.c
+++ b/src/ephy-tab-label.c
@@ -38,6 +38,7 @@ struct _EphyTabLabel {
   GtkWidget *audio_box;
   GtkWidget *audio_image;
 
+  char *uri;
   gboolean is_pinned;
   gboolean is_loading;
   gboolean has_icon;
@@ -81,12 +82,9 @@ static void
 ephy_tab_label_update_icon (EphyTabLabel *self)
 {
   if (!self->has_icon) {
-    if (self->is_pinned)
-      gtk_image_set_from_icon_name (GTK_IMAGE (self->icon),
-                                    "ephy-missing-favicon-symbolic",
-                                    GTK_ICON_SIZE_MENU);
-    else
-      gtk_image_set_from_pixbuf (GTK_IMAGE (self->icon), NULL);
+    const char *favicon_name = ephy_get_fallback_favicon_name (self->uri);
+
+    gtk_image_set_from_icon_name (GTK_IMAGE (self->icon), favicon_name, GTK_ICON_SIZE_MENU);
   }
 }
 
@@ -115,10 +113,11 @@ ephy_tab_label_set_property (GObject      *object,
       }
       break;
     case PROP_LABEL_URI:
-      str = g_value_get_string (value);
-      if (self->is_loading && !ephy_embed_utils_is_no_show_address (str)) {
-        gtk_label_set_text (GTK_LABEL (self->label), str);
-        gtk_widget_set_tooltip_text (GTK_WIDGET (self), str);
+      g_clear_pointer (&self->uri, g_free);
+      self->uri = g_strdup (g_value_get_string (value));
+      if (self->is_loading && !ephy_embed_utils_is_no_show_address (self->uri)) {
+        gtk_label_set_text (GTK_LABEL (self->label), self->uri);
+        gtk_widget_set_tooltip_text (GTK_WIDGET (self), self->uri);
       }
       break;
     case PROP_ICON_BUF:
@@ -304,6 +303,16 @@ style_updated_cb (GtkWidget *widget,
   update_layout (self);
 }
 
+static void
+ephy_tab_label_dispose (GObject *object)
+{
+  EphyTabLabel *self = EPHY_TAB_LABEL (object);
+
+  g_clear_pointer (&self->uri, g_free);
+
+  G_OBJECT_CLASS (ephy_tab_label_parent_class)->dispose (object);
+}
+
 static void
 ephy_tab_label_class_init (EphyTabLabelClass *klass)
 {
@@ -312,6 +321,7 @@ ephy_tab_label_class_init (EphyTabLabelClass *klass)
 
   object_class->set_property = ephy_tab_label_set_property;
   object_class->get_property = ephy_tab_label_get_property;
+  object_class->dispose = ephy_tab_label_dispose;
 
   obj_properties[PROP_LABEL_TEXT] = g_param_spec_string ("label-text",
                                                          "Label Text",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]