diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2012-09-04 20:48:26 +0800 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2012-09-06 16:25:09 +0800 |
commit | b70fe20a489b0a89e4f8779551e87698434485a5 (patch) | |
tree | 08d63f5fce54bd741bea3279fab00ebd7ba65295 /lib/widgets | |
parent | 8712d1d951319e69dabae819d80700023cd920b8 (diff) | |
download | gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.tar gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.tar.gz gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.tar.bz2 gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.tar.lz gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.tar.xz gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.tar.zst gsoc2013-epiphany-b70fe20a489b0a89e4f8779551e87698434485a5.zip |
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
Diffstat (limited to 'lib/widgets')
-rw-r--r-- | lib/widgets/ephy-overview-store.c | 87 |
1 files changed, 57 insertions, 30 deletions
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 @@ -292,39 +292,60 @@ ephy_overview_store_set_default_icon_internal (EphyOverviewStore *store, } 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); } |