[epiphany/wip/bookmarks: 261/315] bookmarks: Add favicons



commit 8fd48a2a6bf8224497ad9f4847eb7d3532334e79
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sat Jul 30 18:02:07 2016 +0300

    bookmarks: Add favicons

 src/ephy-bookmark-row.c           |   38 +++++++++++++++++++++++++++++++++++++
 src/ephy-bookmarks-popover.c      |    2 +-
 src/resources/gtk/bookmark-row.ui |    9 ++++++++
 3 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/src/ephy-bookmark-row.c b/src/ephy-bookmark-row.c
index 4fe2c92..0884c37 100644
--- a/src/ephy-bookmark-row.c
+++ b/src/ephy-bookmark-row.c
@@ -19,12 +19,16 @@
 
 #include "ephy-bookmark-properties-grid.h"
 #include "ephy-bookmark-row.h"
+#include "ephy-embed-prefs.h"
+#include "ephy-embed-shell.h"
+#include "ephy-favicon-helpers.h"
 
 struct _EphyBookmarkRow {
   GtkListBoxRow    parent_instance;
 
   EphyBookmark    *bookmark;
 
+  GtkWidget       *favicon_image;
   GtkWidget       *title_label;
   GtkWidget       *properties_button;
 };
@@ -69,6 +73,30 @@ ephy_bookmark_row_button_clicked_cb (EphyBookmarkRow *row,
 }
 
 static void
+ephy_bookmark_row_favicon_loaded_cb (GObject      *source,
+                                     GAsyncResult *result,
+                                     gpointer      user_data)
+{
+  EphyBookmarkRow *self = user_data;
+  WebKitFaviconDatabase *database = (WebKitFaviconDatabase *)source;
+  cairo_surface_t *icon_surface;
+  GdkPixbuf *favicon;
+
+  g_assert (EPHY_IS_BOOKMARK_ROW (self));
+
+  icon_surface = webkit_favicon_database_get_favicon_finish (database, result, NULL);
+  if (icon_surface) {
+    favicon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE, FAVICON_SIZE);
+    cairo_surface_destroy (icon_surface);
+  }
+
+  if (favicon) {
+    gtk_image_set_from_pixbuf (GTK_IMAGE (self->favicon_image), favicon);
+    g_object_unref (favicon);
+  }
+}
+
+static void
 ephy_bookmark_row_set_property (GObject      *object,
                                 guint         prop_id,
                                 const GValue *value,
@@ -118,11 +146,20 @@ static void
 ephy_bookmark_row_constructed (GObject *object)
 {
   EphyBookmarkRow *self = EPHY_BOOKMARK_ROW (object);
+  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+  WebKitFaviconDatabase *database;
 
   g_object_bind_property (self->bookmark, "title",
                           self->title_label, "label",
                           G_BINDING_SYNC_CREATE);
 
+  database = webkit_web_context_get_favicon_database (ephy_embed_shell_get_web_context (shell));
+  webkit_favicon_database_get_favicon (database,
+                                       ephy_bookmark_get_url (self->bookmark),
+                                       NULL,
+                                       (GAsyncReadyCallback)ephy_bookmark_row_favicon_loaded_cb,
+                                       self);
+
   G_OBJECT_CLASS (ephy_bookmark_row_parent_class)->constructed (object);
 }
 
@@ -147,6 +184,7 @@ ephy_bookmark_row_class_init (EphyBookmarkRowClass *klass)
   g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/gtk/bookmark-row.ui");
+  gtk_widget_class_bind_template_child (widget_class, EphyBookmarkRow, favicon_image);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkRow, title_label);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkRow, properties_button);
 }
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index 03124ef..59dbf3c 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -279,7 +279,7 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
                                   G_ACTION_GROUP (group));
   g_object_unref (group);
 
-  dummy_bookmark = ephy_bookmark_new (g_strdup ("https://facebook.com";),
+  dummy_bookmark = ephy_bookmark_new (g_strdup ("https://www.facebook.com/";),
                                       g_strdup ("Facebook"),
                                       g_sequence_new (g_free));
   ephy_bookmarks_manager_add_bookmark (manager, dummy_bookmark);
diff --git a/src/resources/gtk/bookmark-row.ui b/src/resources/gtk/bookmark-row.ui
index d068167..14d5078 100644
--- a/src/resources/gtk/bookmark-row.ui
+++ b/src/resources/gtk/bookmark-row.ui
@@ -9,8 +9,17 @@
     <child>
       <object class="GtkBox">
         <property name="orientation">horizontal</property>
+        <property name="spacing">6</property>
         <property name="visible">true</property>
         <child>
+          <object class="GtkImage" id="favicon_image">
+            <property name="visible">true</property>
+          </object>
+          <packing>
+            <property name="pack-type">start</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkLabel" id="title_label">
             <property name="expand">true</property>
             <property name="halign">start</property>


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