From b70fe20a489b0a89e4f8779551e87698434485a5 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Tue, 4 Sep 2012 14:48:26 +0200 Subject: ephy-snapshot-service: Split ephy_snapshot_service_get_snapshot_async() ephy_snapshot_service_get_snapshot_async() receives an option web view parameter, that it's only used in case the snapshot is not the in the thumbnails cache. We can split the method into ephy_snapshot_service_get_snapshot_async() to get a snapshot from a web view and ephy_snapshot_service_get_snapshot_for_url_async() to get a snapshot from the cache. The former uses the latter to try first if the web view URI is in the cache. Patch includes other cleanups and fixes: - Add missing ephy_snapshot_service_save_snapshot_finish() - Add EphySnapshotServiceError to handle errors - Use GSimpleAsyncResult API instead of using GIOScheduler directly - Use different async data structs for every async operation https://bugzilla.gnome.org/show_bug.cgi?id=683327 --- lib/widgets/ephy-overview-store.c | 87 +++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 30 deletions(-) (limited to 'lib/widgets/ephy-overview-store.c') diff --git a/lib/widgets/ephy-overview-store.c b/lib/widgets/ephy-overview-store.c index 312a24ffc..99ef2cf45 100644 --- a/lib/widgets/ephy-overview-store.c +++ b/lib/widgets/ephy-overview-store.c @@ -291,40 +291,61 @@ ephy_overview_store_set_default_icon_internal (EphyOverviewStore *store, -1); } +static void +set_snapshot (EphyOverviewStore *store, + GdkPixbuf *snapshot, + GtkTreeRowReference *ref, + time_t timestamp) +{ + GtkTreePath *path; + GtkTreeIter iter; + + path = gtk_tree_row_reference_get_path (ref); + gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); + gtk_tree_path_free (path); + + if (snapshot) + ephy_overview_store_set_snapshot_internal (store, &iter, snapshot, timestamp); + else + ephy_overview_store_set_default_icon_internal (store, &iter, store->priv->default_icon); + + gtk_list_store_set (GTK_LIST_STORE (store), &iter, + EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE, NULL, + -1); +} + static void on_snapshot_retrieved_cb (GObject *object, GAsyncResult *res, PeekContext *ctx) { - EphyOverviewStore *store; - GtkTreePath *path; - GtkTreeIter iter; GdkPixbuf *snapshot; - GError *error = NULL; snapshot = ephy_snapshot_service_get_snapshot_finish (EPHY_SNAPSHOT_SERVICE (object), - res, &error); - - if (error) { - g_error_free (error); - error = NULL; - } else { - store = EPHY_OVERVIEW_STORE (gtk_tree_row_reference_get_model (ctx->ref)); - path = gtk_tree_row_reference_get_path (ctx->ref); - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); - gtk_tree_path_free (path); - if (snapshot) { - ephy_overview_store_set_snapshot_internal (store, &iter, snapshot, ctx->timestamp); - g_object_unref (snapshot); - - } else { - ephy_overview_store_set_default_icon_internal (store, &iter, - store->priv->default_icon); - } - gtk_list_store_set (GTK_LIST_STORE (store), &iter, - EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE, NULL, - -1); - } + res, NULL); + + set_snapshot (EPHY_OVERVIEW_STORE (gtk_tree_row_reference_get_model (ctx->ref)), + snapshot, ctx->ref, ctx->timestamp); + if (snapshot) + g_object_unref (snapshot); + + peek_context_free (ctx); +} + +static void +on_snapshot_retrieved_for_url_cb (GObject *object, + GAsyncResult *res, + PeekContext *ctx) +{ + GdkPixbuf *snapshot; + + snapshot = ephy_snapshot_service_get_snapshot_for_url_finish (EPHY_SNAPSHOT_SERVICE (object), + res, NULL); + + set_snapshot (EPHY_OVERVIEW_STORE (gtk_tree_row_reference_get_model (ctx->ref)), + snapshot, ctx->ref, ctx->timestamp); + if (snapshot) + g_object_unref (snapshot); peek_context_free (ctx); } @@ -341,10 +362,16 @@ history_service_url_cb (gpointer service, ctx->timestamp = url->thumbnail_time; - ephy_snapshot_service_get_snapshot_async (snapshot_service, - ctx->webview, ctx->url, ctx->timestamp, ctx->cancellable, - (GAsyncReadyCallback) on_snapshot_retrieved_cb, - ctx); + if (ctx->webview) + ephy_snapshot_service_get_snapshot_async (snapshot_service, + ctx->webview, ctx->timestamp, ctx->cancellable, + (GAsyncReadyCallback) on_snapshot_retrieved_cb, + ctx); + else + ephy_snapshot_service_get_snapshot_for_url_async (snapshot_service, + ctx->url, ctx->timestamp, ctx->cancellable, + (GAsyncReadyCallback) on_snapshot_retrieved_for_url_cb, + ctx); ephy_history_url_free (url); } -- cgit v1.2.3