aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Sanchez Prada <msanchez@gnome.org>2012-12-04 20:32:02 +0800
committerMario Sanchez Prada <msanchez@gnome.org>2012-12-04 20:05:05 +0800
commit7fbf27f3685dab40270b9ed697c6c15b6b120fe4 (patch)
tree4860b249a71d286e14669c916464836e12d0d60b
parentf32e3b06d7ee05d6673950793dab5315b9878161 (diff)
downloadgsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.tar
gsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.tar.gz
gsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.tar.bz2
gsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.tar.lz
gsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.tar.xz
gsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.tar.zst
gsoc2013-epiphany-7fbf27f3685dab40270b9ed697c6c15b6b120fe4.zip
Port EphyHostsStore to WebKit2GTK+ favicons API.
-rw-r--r--lib/widgets/ephy-hosts-store.c175
1 files changed, 108 insertions, 67 deletions
diff --git a/lib/widgets/ephy-hosts-store.c b/lib/widgets/ephy-hosts-store.c
index 126d31387..3173f1bcf 100644
--- a/lib/widgets/ephy-hosts-store.c
+++ b/lib/widgets/ephy-hosts-store.c
@@ -22,22 +22,72 @@
#include "config.h"
#include "ephy-embed-prefs.h"
+#include "ephy-favicon-helpers.h"
#include "ephy-hosts-store.h"
#include <glib/gi18n.h>
+#ifdef HAVE_WEBKIT2
+#include <libsoup/soup.h>
+#endif
G_DEFINE_TYPE (EphyHostsStore, ephy_hosts_store, GTK_TYPE_LIST_STORE)
+typedef struct {
+ GtkListStore *model;
+ GtkTreeRowReference *row_reference;
+} IconLoadData;
+
+static void
+async_update_favicon_icon (GObject *source, GAsyncResult *result, gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ IconLoadData *data = (IconLoadData *)user_data;
+ WebKitFaviconDatabase *database;
+ GdkPixbuf *favicon = NULL;
+#ifdef HAVE_WEBKIT2
+ cairo_surface_t *icon_surface;
+#endif
+
+ database = WEBKIT_FAVICON_DATABASE (source);
+
#ifdef HAVE_WEBKIT2
-/* TODO: Favicons */
+ 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);
+ }
#else
+ favicon = webkit_favicon_database_get_favicon_pixbuf_finish (database, result, NULL);
+#endif
+
+ if (favicon) {
+ /* The completion model might have changed its contents */
+ if (gtk_tree_row_reference_valid (data->row_reference)) {
+ path = gtk_tree_row_reference_get_path (data->row_reference);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (data->model), &iter, path);
+ gtk_tree_path_free (path);
+ gtk_list_store_set (data->model, &iter,
+ EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon, -1);
+ }
+ g_object_unref (favicon);
+ }
+
+ g_object_unref (data->model);
+ gtk_tree_row_reference_free (data->row_reference);
+ g_slice_free (IconLoadData, data);
+}
+
static void
-icon_loaded_cb (WebKitFaviconDatabase *database,
- const char *address,
- GtkTreeModel *model)
+icon_changed_cb (WebKitFaviconDatabase *database,
+ const char *page_uri,
+#ifdef HAVE_WEBKIT2
+ const char *favicon_uri,
+#endif
+ GtkTreeModel *model)
{
GtkTreeIter iter;
- GdkPixbuf *favicon;
int cmp;
char *host_address;
gboolean done, valid;
@@ -45,29 +95,47 @@ icon_loaded_cb (WebKitFaviconDatabase *database,
valid = gtk_tree_model_get_iter_first (model, &iter);
- /* If the address has a path, this icon is not for a host, so it can
- be skipped. */
- uri = soup_uri_new (address);
+ /* If the page_uri has a path, this icon is not for a host, so it
+ can be skipped. */
+ uri = soup_uri_new (page_uri);
done = strcmp (soup_uri_get_path (uri), "/") != 0;
soup_uri_free (uri);
while (valid && !done) {
gtk_tree_model_get (model, &iter,
EPHY_HOSTS_STORE_COLUMN_ADDRESS, &host_address, -1);
- cmp = g_strcmp0 (host_address, address);
+ cmp = g_strcmp0 (host_address, page_uri);
g_free (host_address);
if (cmp == 0) {
- favicon = webkit_favicon_database_try_get_favicon_pixbuf (database,
- address,
- FAVICON_SIZE,
- FAVICON_SIZE);
+#ifdef HAVE_WEBKIT2
+ IconLoadData *data;
+ GtkTreePath *path;
+
+ data = g_slice_new (IconLoadData);
+ data->model = GTK_LIST_STORE (g_object_ref (model));
+ path = gtk_tree_model_get_path (model, &iter);
+ data->row_reference = gtk_tree_row_reference_new (model, path);
+ gtk_tree_path_free (path);
+
+ webkit_favicon_database_get_favicon (database,
+ page_uri,
+ 0,
+ async_update_favicon_icon,
+ data);
+#else
+ GdkPixbuf *favicon = webkit_favicon_database_try_get_favicon_pixbuf (database,
+ page_uri,
+ FAVICON_SIZE,
+ FAVICON_SIZE);
if (favicon) {
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon,
-1);
g_object_unref (favicon);
}
+
+#endif
}
valid = gtk_tree_model_iter_next (model, &iter);
@@ -77,20 +145,21 @@ icon_loaded_cb (WebKitFaviconDatabase *database,
done = cmp >= 0;
}
}
-#endif
static void
ephy_hosts_store_finalize (GObject *object)
{
EphyHostsStore *store = EPHY_HOSTS_STORE (object);
+ WebKitFaviconDatabase *database;
#ifdef HAVE_WEBKIT2
- /* TODO: Favicons */
+ database = webkit_web_context_get_favicon_database (webkit_web_context_get_default ());
#else
- g_signal_handlers_disconnect_by_func (webkit_get_favicon_database (),
- icon_loaded_cb, store);
+ database = webkit_get_favicon_database ();
#endif
+ g_signal_handlers_disconnect_by_func (database, icon_changed_cb, store);
+
G_OBJECT_CLASS (ephy_hosts_store_parent_class)->finalize (object);
}
@@ -121,10 +190,11 @@ ephy_hosts_store_init (EphyHostsStore *self)
GTK_SORT_ASCENDING);
#ifdef HAVE_WEBKIT2
- /* TODO: Favicons */
+ g_signal_connect (webkit_web_context_get_favicon_database (webkit_web_context_get_default ()),
+ "favicon-changed", G_CALLBACK (icon_changed_cb), self);
#else
g_signal_connect (webkit_get_favicon_database (), "icon-loaded",
- G_CALLBACK (icon_loaded_cb), self);
+ G_CALLBACK (icon_changed_cb), self);
#endif
}
@@ -135,41 +205,6 @@ ephy_hosts_store_new (void)
NULL);
}
-#ifdef HAVE_WEBKIT2
-/* TODO: Favicons */
-#else
-typedef struct {
- GtkListStore *model;
- GtkTreeRowReference *row_reference;
-} IconLoadData;
-
-static void
-async_get_favicon_cb (GObject *source, GAsyncResult *result, gpointer user_data)
-{
- GtkTreeIter iter;
- GtkTreePath *path;
- IconLoadData *data = (IconLoadData *) user_data;
- GdkPixbuf *favicon = webkit_favicon_database_get_favicon_pixbuf_finish (webkit_get_favicon_database (),
- result, NULL);
-
- if (favicon) {
- /* The completion model might have changed its contents */
- if (gtk_tree_row_reference_valid (data->row_reference)) {
- path = gtk_tree_row_reference_get_path (data->row_reference);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (data->model), &iter, path);
- gtk_tree_path_free (path);
- gtk_list_store_set (data->model, &iter,
- EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon, -1);
- }
- g_object_unref (favicon);
- }
-
- g_object_unref (data->model);
- gtk_tree_row_reference_free (data->row_reference);
- g_slice_free (IconLoadData, data);
-}
-#endif
-
void
ephy_hosts_store_add_hosts (EphyHostsStore *store,
GList *hosts)
@@ -178,37 +213,36 @@ ephy_hosts_store_add_hosts (EphyHostsStore *store,
GtkTreeIter treeiter;
GtkTreePath *path;
GList *iter;
-#ifdef HAVE_WEBKIT2
- /* TODO: Favicons */
-#else
GdkPixbuf *favicon;
IconLoadData *data;
- WebKitFaviconDatabase *database = webkit_get_favicon_database ();
+ WebKitFaviconDatabase *database;
+
+#ifdef HAVE_WEBKIT2
+ database = webkit_web_context_get_favicon_database (webkit_web_context_get_default ());
+#else
+ database = webkit_get_favicon_database ();
#endif
for (iter = hosts; iter != NULL; iter = iter->next) {
host = (EphyHistoryHost *)iter->data;
#ifdef HAVE_WEBKIT2
- /* TODO: Favicons */
+ /* Flag favicon to NULL to reuse some code later on */
+ favicon = NULL;
#else
favicon = webkit_favicon_database_try_get_favicon_pixbuf (database, host->url,
FAVICON_SIZE, FAVICON_SIZE);
#endif
+
gtk_list_store_insert_with_values (GTK_LIST_STORE (store),
&treeiter, G_MAXINT,
EPHY_HOSTS_STORE_COLUMN_ID, host->id,
EPHY_HOSTS_STORE_COLUMN_TITLE, host->title,
EPHY_HOSTS_STORE_COLUMN_ADDRESS, host->url,
EPHY_HOSTS_STORE_COLUMN_VISIT_COUNT, host->visit_count,
-#ifdef HAVE_WEBKIT2
- /* TODO: Favicons */
-#else
+#ifndef HAVE_WEBKIT2
EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon,
#endif
-1);
-#ifdef HAVE_WEBKIT2
- /* TODO: Favicons */
-#else
if (favicon)
g_object_unref (favicon);
else {
@@ -218,11 +252,18 @@ ephy_hosts_store_add_hosts (EphyHostsStore *store,
data->row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
gtk_tree_path_free (path);
+#ifdef HAVE_WEBKIT2
+ webkit_favicon_database_get_favicon (database,
+ host->url,
+ NULL,
+ async_update_favicon_icon,
+ data);
+#else
webkit_favicon_database_get_favicon_pixbuf (database, host->url,
FAVICON_SIZE, FAVICON_SIZE, NULL,
- async_get_favicon_cb, data);
- }
+ async_update_favicon_icon, data);
#endif
+ }
}
}