[epiphany/wip/favicons: 2/3] bookmarks: Add favicons
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/favicons: 2/3] bookmarks: Add favicons
- Date: Sun, 31 Jul 2016 17:29:21 +0000 (UTC)
commit 1e4d6c4f338b996e88d99063192164b477341af1
Author: Iulian Radu <iulian radu67 gmail com>
Date: Sat Jul 30 18:02:07 2016 +0300
bookmarks: Add favicons
src/ephy-bookmark-row.c | 60 +++++++++++++++++++++++++++++++++++++
src/ephy-completion-model.c | 2 +
src/resources/gtk/bookmark-row.ui | 9 +++++
3 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/src/ephy-bookmark-row.c b/src/ephy-bookmark-row.c
index 4fe2c92..9d82e7c 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,47 @@ 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 = NULL;
+ GError *error = NULL;
+
+ g_assert (EPHY_IS_BOOKMARK_ROW (self));
+
+ icon_surface = webkit_favicon_database_get_favicon_finish (database, result, &error);
+ 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_favicon_changed_cb (EphyBookmarkRow *self,
+ char *page_uri,
+ char *favicon_uri,
+ WebKitFaviconDatabase *database)
+{
+ g_assert (EPHY_IS_BOOKMARK_ROW (self));
+
+ printf("Changed\n");
+ webkit_favicon_database_get_favicon (database,
+ ephy_bookmark_get_url (self->bookmark),
+ NULL,
+ (GAsyncReadyCallback)ephy_bookmark_row_favicon_loaded_cb,
+ self);
+}
+
+static void
ephy_bookmark_row_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -118,11 +163,25 @@ 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));
+ printf("%s\n", ephy_bookmark_get_url (self->bookmark));
+ webkit_favicon_database_get_favicon (database,
+ ephy_bookmark_get_url (self->bookmark),
+ NULL,
+ (GAsyncReadyCallback)ephy_bookmark_row_favicon_loaded_cb,
+ self);
+ g_signal_connect_swapped (database,
+ "favicon-changed",
+ G_CALLBACK (ephy_bookmark_row_favicon_changed_cb),
+ self);
+
G_OBJECT_CLASS (ephy_bookmark_row_parent_class)->constructed (object);
}
@@ -147,6 +206,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-completion-model.c b/src/ephy-completion-model.c
index 8c4e69d..970a129 100644
--- a/src/ephy-completion-model.c
+++ b/src/ephy-completion-model.c
@@ -217,6 +217,7 @@ icon_loaded_cb (GObject *source, GAsyncResult *result, gpointer user_data)
GdkPixbuf *favicon = NULL;
cairo_surface_t *icon_surface = webkit_favicon_database_get_favicon_finish (database, result, NULL);
+ printf("Loaded\n");
if (icon_surface) {
favicon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE, FAVICON_SIZE);
cairo_surface_destroy (icon_surface);
@@ -264,6 +265,7 @@ set_row_in_model (EphyCompletionModel *model, int position, PotentialRow *row)
data->row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), path);
gtk_tree_path_free (path);
+ printf("row %s\n", row->location);
webkit_favicon_database_get_favicon (database, row->location,
NULL, icon_loaded_cb, data);
}
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]