diff options
author | Claudio Saavedra <csaavedra@igalia.com> | 2012-08-29 18:43:45 +0800 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2012-09-01 02:34:01 +0800 |
commit | c02832ac1f68cbdcf3fe97348983a64455137d8e (patch) | |
tree | a3527f70e23789e13b8f4485047461c9ae4b5013 | |
parent | 4e9047e324c443b666f07cc356f38a21702c9268 (diff) | |
download | gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.tar gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.tar.gz gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.tar.bz2 gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.tar.lz gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.tar.xz gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.tar.zst gsoc2013-epiphany-c02832ac1f68cbdcf3fe97348983a64455137d8e.zip |
ephy-overview-store: use the age of a thumbnail only to decide when update is needed
Currently, we were not retrieving thumbnails from the service if they
were outdated. This would cause some pages in the overview not to
display a thumbnail at all even if one is available (but old).
Fix this by always retrieving a thumbnail but storing its mtime in the
model, and making ephy_snapshot_store_needs_snapshot() check the age
of snapshots when deciding whether a snapshot update is needed or not.
-rw-r--r-- | lib/widgets/ephy-overview-store.c | 27 | ||||
-rw-r--r-- | lib/widgets/ephy-overview-store.h | 1 |
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/widgets/ephy-overview-store.c b/lib/widgets/ephy-overview-store.c index 6da87d507..a20903da2 100644 --- a/lib/widgets/ephy-overview-store.c +++ b/lib/widgets/ephy-overview-store.c @@ -129,6 +129,7 @@ ephy_overview_store_init (EphyOverviewStore *self) types[EPHY_OVERVIEW_STORE_LAST_VISIT] = G_TYPE_LONG; types[EPHY_OVERVIEW_STORE_SELECTED] = G_TYPE_BOOLEAN; types[EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE] = G_TYPE_CANCELLABLE; + types[EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME] = G_TYPE_LONG; gtk_list_store_set_column_types (GTK_LIST_STORE (self), EPHY_OVERVIEW_STORE_NCOLS, types); @@ -281,13 +282,15 @@ overview_add_frame (GdkPixbuf *pixbuf) { static void ephy_overview_store_set_snapshot_internal (EphyOverviewStore *store, GtkTreeIter *iter, - GdkPixbuf *snapshot) + GdkPixbuf *snapshot, + int mtime) { GdkPixbuf *framed; framed = overview_add_frame (snapshot); gtk_list_store_set (GTK_LIST_STORE (store), iter, EPHY_OVERVIEW_STORE_SNAPSHOT, framed, + EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME, mtime, -1); g_object_unref (framed); } @@ -318,16 +321,18 @@ ephy_overview_store_set_snapshot (EphyOverviewStore *store, char *url; ThumbnailTimeContext *ctx; EphySnapshotService *snapshot_service; + int mtime; + mtime = time (NULL); pixbuf = ephy_snapshot_service_crop_snapshot (snapshot); - ephy_overview_store_set_snapshot_internal (store, iter, pixbuf); + ephy_overview_store_set_snapshot_internal (store, iter, pixbuf, mtime); gtk_tree_model_get (GTK_TREE_MODEL (store), iter, EPHY_OVERVIEW_STORE_URI, &url, -1); ctx = g_slice_new (ThumbnailTimeContext); ctx->url = ephy_history_url_new (url, NULL, 0, 0, 0); - ctx->url->thumbnail_time = time (NULL); + ctx->url->thumbnail_time = mtime; ctx->history_service = store->priv->history_service; g_free (url); @@ -365,7 +370,7 @@ on_snapshot_retrieved_cb (GObject *object, gtk_tree_path_free (path); if (snapshot) { ephy_overview_store_set_snapshot_internal (EPHY_OVERVIEW_STORE (model), - &iter, snapshot); + &iter, snapshot, ctx->timestamp); g_object_unref (snapshot); } @@ -384,15 +389,13 @@ history_service_url_cb (gpointer service, PeekContext *ctx) { EphySnapshotService *snapshot_service; - int timestamp; snapshot_service = ephy_snapshot_service_get_default (); - timestamp = (ctx->timestamp - url->thumbnail_time) > THUMBNAIL_UPDATE_THRESHOLD ? - ctx->timestamp : url->thumbnail_time; + ctx->timestamp = url->thumbnail_time; ephy_snapshot_service_get_snapshot_async (snapshot_service, - ctx->webview, ctx->url, timestamp, ctx->cancellable, + ctx->webview, ctx->url, ctx->timestamp, ctx->cancellable, (GAsyncReadyCallback) on_snapshot_retrieved_cb, ctx); ephy_history_url_free (url); @@ -421,6 +424,7 @@ ephy_overview_store_peek_snapshot (EphyOverviewStore *self, gtk_list_store_set (GTK_LIST_STORE (self), iter, EPHY_OVERVIEW_STORE_SNAPSHOT, self->priv->default_icon, + EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME, 0, -1); if (url == NULL || g_strcmp0 (url, "about:blank") == 0) { @@ -439,7 +443,6 @@ ephy_overview_store_peek_snapshot (EphyOverviewStore *self, path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), iter); ctx->ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path); ctx->url = url; - ctx->timestamp = time (NULL); ctx->webview = webview ? g_object_ref (webview) : NULL; ctx->cancellable = cancellable; ephy_history_service_get_url (self->priv->history_service, @@ -498,18 +501,22 @@ ephy_overview_store_needs_snapshot (EphyOverviewStore *store, GdkPixbuf *icon; GCancellable *cancellable; gboolean needs_snapshot; + int mtime, current_mtime; g_return_val_if_fail (EPHY_IS_OVERVIEW_STORE (store), FALSE); g_return_val_if_fail (iter != NULL, FALSE); + current_mtime = time (NULL); gtk_tree_model_get (GTK_TREE_MODEL (store), iter, EPHY_OVERVIEW_STORE_SNAPSHOT, &icon, + EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME, &mtime, EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE, &cancellable, -1); /* If the thumbnail is the default icon and there is no cancellable in the row, then this row needs a snapshot. */ - needs_snapshot = (icon == store->priv->default_icon && cancellable == NULL); + needs_snapshot = (icon == store->priv->default_icon && cancellable == NULL) || + current_mtime - mtime > THUMBNAIL_UPDATE_THRESHOLD; if (icon) g_object_unref (icon); diff --git a/lib/widgets/ephy-overview-store.h b/lib/widgets/ephy-overview-store.h index b618bb914..a7f99fde9 100644 --- a/lib/widgets/ephy-overview-store.h +++ b/lib/widgets/ephy-overview-store.h @@ -63,6 +63,7 @@ enum { EPHY_OVERVIEW_STORE_LAST_VISIT = GD_MAIN_COLUMN_MTIME, EPHY_OVERVIEW_STORE_SELECTED = GD_MAIN_COLUMN_SELECTED, EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE, + EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME, EPHY_OVERVIEW_STORE_NCOLS }; |