[epiphany] Add snapshot path to EphyOverviewStore
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add snapshot path to EphyOverviewStore
- Date: Tue, 18 Feb 2014 13:38:40 +0000 (UTC)
commit 77dcdbc0dd4f303381c1b92a2195e56bbf48982c
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Feb 17 14:21:51 2014 +0100
Add snapshot path to EphyOverviewStore
It stores the path were the snapshot has been saved and notifies with a
signal when a new snapshot is saved in the cache.
embed/ephy-web-view.c | 8 +---
lib/ephy-snapshot-service.c | 52 ++++++++++++++++-----
lib/ephy-snapshot-service.h | 4 +-
lib/widgets/ephy-overview-store.c | 87 +++++++++++++++++++++++++++++++-----
lib/widgets/ephy-overview-store.h | 3 +-
tests/ephy-snapshot-service-test.c | 2 +-
6 files changed, 122 insertions(+), 34 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 8c121f5..4397c37 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1520,8 +1520,6 @@ on_snapshot_ready (WebKitWebView *webview,
GtkTreeRowReference *ref)
{
GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeIter iter;
cairo_surface_t *surface;
GError *error = NULL;
@@ -1533,11 +1531,7 @@ on_snapshot_ready (WebKitWebView *webview,
}
model = gtk_tree_row_reference_get_model (ref);
- path = gtk_tree_row_reference_get_path (ref);
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_path_free (path);
-
- ephy_overview_store_set_snapshot (EPHY_OVERVIEW_STORE (model), &iter, surface,
+ ephy_overview_store_set_snapshot (EPHY_OVERVIEW_STORE (model), ref, surface,
webkit_web_view_get_favicon (webview));
cairo_surface_destroy (surface);
}
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 0a4a6f1..3fb7bbe 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -60,6 +60,7 @@ typedef struct {
time_t mtime;
GdkPixbuf *snapshot;
+ char *path;
} SnapshotForURLAsyncData;
static SnapshotForURLAsyncData *
@@ -80,6 +81,7 @@ snapshot_for_url_async_data_free (SnapshotForURLAsyncData *data)
{
g_free (data->url);
g_clear_object (&data->snapshot);
+ g_free (data->path);
g_slice_free (SnapshotForURLAsyncData, data);
}
@@ -90,13 +92,12 @@ get_snapshot_for_url_thread (GSimpleAsyncResult *result,
GCancellable *cancellable)
{
SnapshotForURLAsyncData *data;
- gchar *uri;
GError *error = NULL;
data = (SnapshotForURLAsyncData *)g_simple_async_result_get_op_res_gpointer (result);
- uri = gnome_desktop_thumbnail_factory_lookup (service->priv->factory, data->url, data->mtime);
- if (uri == NULL) {
+ data->path = gnome_desktop_thumbnail_factory_lookup (service->priv->factory, data->url, data->mtime);
+ if (data->path == NULL) {
g_simple_async_result_set_error (result,
EPHY_SNAPSHOT_SERVICE_ERROR,
EPHY_SNAPSHOT_SERVICE_ERROR_NOT_FOUND,
@@ -104,17 +105,15 @@ get_snapshot_for_url_thread (GSimpleAsyncResult *result,
return;
}
- data->snapshot = gdk_pixbuf_new_from_file (uri, &error);
+ data->snapshot = gdk_pixbuf_new_from_file (data->path, &error);
if (data->snapshot == NULL) {
g_simple_async_result_set_error (result,
EPHY_SNAPSHOT_SERVICE_ERROR,
EPHY_SNAPSHOT_SERVICE_ERROR_INVALID,
"Error creating pixbuf for snapshot file \"%s\": %s",
- uri, error->message);
+ data->path, error->message);
g_error_free (error);
}
-
- g_free (uri);
}
typedef struct {
@@ -123,6 +122,7 @@ typedef struct {
GCancellable *cancellable;
GdkPixbuf *snapshot;
+ char *path;
} SnapshotAsyncData;
static SnapshotAsyncData *
@@ -146,6 +146,7 @@ snapshot_async_data_free (SnapshotAsyncData *data)
g_object_unref (data->web_view);
g_clear_object (&data->cancellable);
g_clear_object (&data->snapshot);
+ g_free (data->path);
g_slice_free (SnapshotAsyncData, data);
}
@@ -155,7 +156,10 @@ snapshot_saved (EphySnapshotService *service,
GAsyncResult *result,
GSimpleAsyncResult *simple)
{
- ephy_snapshot_service_save_snapshot_finish (service, result, NULL);
+ SnapshotAsyncData *data;
+
+ data = (SnapshotAsyncData *)g_simple_async_result_get_op_res_gpointer (simple);
+ data->path = ephy_snapshot_service_save_snapshot_finish (service, result, NULL);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
@@ -272,6 +276,7 @@ typedef struct {
GdkPixbuf *snapshot;
char *url;
time_t mtime;
+ char *path;
} SaveSnapshotAsyncData;
static SaveSnapshotAsyncData *
@@ -281,7 +286,7 @@ save_snapshot_async_data_new (GdkPixbuf *snapshot,
{
SaveSnapshotAsyncData *data;
- data = g_slice_new (SaveSnapshotAsyncData);
+ data = g_slice_new0 (SaveSnapshotAsyncData);
data->snapshot = g_object_ref (snapshot);
data->url = g_strdup (url);
data->mtime = mtime;
@@ -294,6 +299,7 @@ save_snapshot_async_data_free (SaveSnapshotAsyncData *data)
{
g_object_unref (data->snapshot);
g_free (data->url);
+ g_free (data->path);
g_slice_free (SaveSnapshotAsyncData, data);
}
@@ -310,6 +316,7 @@ save_snapshot_thread (GSimpleAsyncResult *result,
data->snapshot,
data->url,
data->mtime);
+ data->path = gnome_desktop_thumbnail_path_for_uri (data->url, GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
}
GQuark
@@ -388,6 +395,7 @@ ephy_snapshot_service_get_snapshot_for_url_async (EphySnapshotService *service,
GdkPixbuf *
ephy_snapshot_service_get_snapshot_for_url_finish (EphySnapshotService *service,
GAsyncResult *result,
+ gchar **path,
GError **error)
{
GSimpleAsyncResult *simple;
@@ -406,6 +414,11 @@ ephy_snapshot_service_get_snapshot_for_url_finish (EphySnapshotService *service,
data = (SnapshotForURLAsyncData *)g_simple_async_result_get_op_res_gpointer (simple);
+ if (path) {
+ *path = data->path;
+ data->path = NULL;
+ }
+
return data->snapshot ? g_object_ref (data->snapshot) : NULL;
}
@@ -417,7 +430,7 @@ got_snapshot_for_url (EphySnapshotService *service,
SnapshotAsyncData *data;
data = (SnapshotAsyncData *)g_simple_async_result_get_op_res_gpointer (simple);
- data->snapshot = ephy_snapshot_service_get_snapshot_for_url_finish (service, result, NULL);
+ data->snapshot = ephy_snapshot_service_get_snapshot_for_url_finish (service, result, &data->path, NULL);
if (data->snapshot) {
g_simple_async_result_complete (simple);
g_object_unref (simple);
@@ -488,6 +501,7 @@ ephy_snapshot_service_get_snapshot_async (EphySnapshotService *service,
GdkPixbuf *
ephy_snapshot_service_get_snapshot_finish (EphySnapshotService *service,
GAsyncResult *result,
+ gchar **path,
GError **error)
{
GSimpleAsyncResult *simple;
@@ -505,6 +519,10 @@ ephy_snapshot_service_get_snapshot_finish (EphySnapshotService *service,
return NULL;
data = (SnapshotAsyncData *)g_simple_async_result_get_op_res_gpointer (simple);
+ if (path) {
+ *path = data->path;
+ data->path = NULL;
+ }
return data->snapshot ? g_object_ref (data->snapshot) : NULL;
}
@@ -536,18 +554,28 @@ ephy_snapshot_service_save_snapshot_async (EphySnapshotService *service,
g_object_unref (result);
}
-gboolean
+char *
ephy_snapshot_service_save_snapshot_finish (EphySnapshotService *service,
GAsyncResult *result,
GError **error)
{
+ SaveSnapshotAsyncData *data;
+ char *retval;
+
g_return_val_if_fail (EPHY_IS_SNAPSHOT_SERVICE (service), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result,
G_OBJECT (service),
ephy_snapshot_service_save_snapshot_async),
FALSE);
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
+ return NULL;
+
+ data = (SaveSnapshotAsyncData *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
+ retval = data->path;
+ data->path = NULL;
+
+ return retval;
}
GdkPixbuf *
diff --git a/lib/ephy-snapshot-service.h b/lib/ephy-snapshot-service.h
index 0250ce6..c21282b 100644
--- a/lib/ephy-snapshot-service.h
+++ b/lib/ephy-snapshot-service.h
@@ -78,6 +78,7 @@ void ephy_snapshot_service_get_snapshot_for_url_async (EphySnap
GdkPixbuf *ephy_snapshot_service_get_snapshot_for_url_finish (EphySnapshotService *service,
GAsyncResult *result,
+ gchar **path,
GError **error);
void ephy_snapshot_service_get_snapshot_async (EphySnapshotService *service,
@@ -89,6 +90,7 @@ void ephy_snapshot_service_get_snapshot_async (EphySnap
GdkPixbuf *ephy_snapshot_service_get_snapshot_finish (EphySnapshotService *service,
GAsyncResult *result,
+ gchar **path,
GError **error);
void ephy_snapshot_service_save_snapshot_async (EphySnapshotService *service,
@@ -99,7 +101,7 @@ void ephy_snapshot_service_save_snapshot_async (EphySnap
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean ephy_snapshot_service_save_snapshot_finish (EphySnapshotService *service,
+char *ephy_snapshot_service_save_snapshot_finish (EphySnapshotService *service,
GAsyncResult *result,
GError **error);
diff --git a/lib/widgets/ephy-overview-store.c b/lib/widgets/ephy-overview-store.c
index d570a47..34f88bf 100644
--- a/lib/widgets/ephy-overview-store.c
+++ b/lib/widgets/ephy-overview-store.c
@@ -44,6 +44,14 @@ enum
PROP_ICON_FRAME,
};
+enum {
+ SNAPSHOT_SAVED,
+
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
G_DEFINE_TYPE (EphyOverviewStore, ephy_overview_store, GTK_TYPE_LIST_STORE)
static void
@@ -147,6 +155,16 @@ ephy_overview_store_class_init (EphyOverviewStoreClass *klass)
GDK_TYPE_PIXBUF,
G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ signals[SNAPSHOT_SAVED] =
+ g_signal_new ("snapshot-saved",
+ EPHY_TYPE_OVERVIEW_STORE,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+
g_type_class_add_private (object_class, sizeof(EphyOverviewStorePrivate));
}
@@ -164,6 +182,7 @@ ephy_overview_store_init (EphyOverviewStore *self)
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_INT;
+ types[EPHY_OVERVIEW_STORE_SNAPSHOT_PATH] = G_TYPE_STRING;
gtk_list_store_set_column_types (GTK_LIST_STORE (self),
EPHY_OVERVIEW_STORE_NCOLS, types);
@@ -214,6 +233,7 @@ static void
ephy_overview_store_set_snapshot_internal (EphyOverviewStore *store,
GtkTreeIter *iter,
GdkPixbuf *snapshot,
+ char *path,
int mtime)
{
GdkPixbuf *framed;
@@ -222,13 +242,25 @@ ephy_overview_store_set_snapshot_internal (EphyOverviewStore *store,
gtk_list_store_set (GTK_LIST_STORE (store), iter,
EPHY_OVERVIEW_STORE_SNAPSHOT, framed,
EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME, mtime,
+ EPHY_OVERVIEW_STORE_SNAPSHOT_PATH, path,
-1);
g_object_unref (framed);
+
+ if (path) {
+ char *url;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
+ EPHY_OVERVIEW_STORE_URI, &url,
+ -1);
+ g_signal_emit (store, signals[SNAPSHOT_SAVED], 0, url, path);
+ g_free (url);
+ }
}
typedef struct {
EphyHistoryURL *url;
EphyHistoryService *history_service;
+ GtkTreeRowReference *ref;
} ThumbnailTimeContext;
static void
@@ -236,6 +268,25 @@ on_snapshot_saved_cb (EphySnapshotService *service,
GAsyncResult *res,
ThumbnailTimeContext *ctx)
{
+ char *path;
+ GtkTreeModel *model;
+ GtkTreePath *tree_path;
+ GtkTreeIter iter;
+
+ path = ephy_snapshot_service_save_snapshot_finish (service, res, NULL);
+
+ model = gtk_tree_row_reference_get_model (ctx->ref);
+ tree_path = gtk_tree_row_reference_get_path (ctx->ref);
+ gtk_tree_model_get_iter (model, &iter, tree_path);
+ gtk_tree_path_free (tree_path);
+
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ EPHY_OVERVIEW_STORE_SNAPSHOT_PATH, path,
+ -1);
+ g_signal_emit (model, signals[SNAPSHOT_SAVED], 0, ctx->url->url, path);
+ g_free (path);
+ gtk_tree_row_reference_free (ctx->ref);
+
ephy_history_service_set_url_thumbnail_time (ctx->history_service,
ctx->url->url, ctx->url->thumbnail_time,
NULL, NULL, NULL);
@@ -245,7 +296,7 @@ on_snapshot_saved_cb (EphySnapshotService *service,
void
ephy_overview_store_set_snapshot (EphyOverviewStore *store,
- GtkTreeIter *iter,
+ GtkTreeRowReference *ref,
cairo_surface_t *snapshot,
cairo_surface_t *favicon)
{
@@ -254,11 +305,17 @@ ephy_overview_store_set_snapshot (EphyOverviewStore *store,
ThumbnailTimeContext *ctx;
EphySnapshotService *snapshot_service;
int mtime;
+ 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);
mtime = time (NULL);
pixbuf = ephy_snapshot_service_prepare_snapshot (snapshot, favicon);
- ephy_overview_store_set_snapshot_internal (store, iter, pixbuf, mtime);
- gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
+ ephy_overview_store_set_snapshot_internal (store, &iter, pixbuf, NULL, mtime);
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
EPHY_OVERVIEW_STORE_URI, &url,
-1);
@@ -266,6 +323,7 @@ ephy_overview_store_set_snapshot (EphyOverviewStore *store,
ctx->url = ephy_history_url_new (url, NULL, 0, 0, 0);
ctx->url->thumbnail_time = mtime;
ctx->history_service = store->priv->history_service;
+ ctx->ref = gtk_tree_row_reference_copy (ref);
g_free (url);
snapshot_service = ephy_snapshot_service_get_default ();
@@ -293,18 +351,19 @@ ephy_overview_store_set_default_icon_internal (EphyOverviewStore *store,
static void
set_snapshot (EphyOverviewStore *store,
GdkPixbuf *snapshot,
+ char *path,
GtkTreeRowReference *ref,
time_t timestamp)
{
- GtkTreePath *path;
+ GtkTreePath *tree_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);
+ tree_path = gtk_tree_row_reference_get_path (ref);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, tree_path);
+ gtk_tree_path_free (tree_path);
if (snapshot)
- ephy_overview_store_set_snapshot_internal (store, &iter, snapshot, timestamp);
+ ephy_overview_store_set_snapshot_internal (store, &iter, snapshot, path, timestamp);
else
ephy_overview_store_set_default_icon_internal (store, &iter, store->priv->default_icon);
@@ -319,14 +378,16 @@ on_snapshot_retrieved_cb (GObject *object,
PeekContext *ctx)
{
GdkPixbuf *snapshot;
+ char *path = NULL;
snapshot = ephy_snapshot_service_get_snapshot_finish (EPHY_SNAPSHOT_SERVICE (object),
- res, NULL);
+ res, &path, NULL);
set_snapshot (EPHY_OVERVIEW_STORE (gtk_tree_row_reference_get_model (ctx->ref)),
- snapshot, ctx->ref, ctx->timestamp);
+ snapshot, path, ctx->ref, ctx->timestamp);
if (snapshot)
g_object_unref (snapshot);
+ g_free (path);
peek_context_free (ctx);
}
@@ -337,14 +398,16 @@ on_snapshot_retrieved_for_url_cb (GObject *object,
PeekContext *ctx)
{
GdkPixbuf *snapshot;
+ char *path = NULL;
snapshot = ephy_snapshot_service_get_snapshot_for_url_finish (EPHY_SNAPSHOT_SERVICE (object),
- res, NULL);
+ res, &path, NULL);
set_snapshot (EPHY_OVERVIEW_STORE (gtk_tree_row_reference_get_model (ctx->ref)),
- snapshot, ctx->ref, ctx->timestamp);
+ snapshot, path, ctx->ref, ctx->timestamp);
if (snapshot)
g_object_unref (snapshot);
+ g_free (path);
peek_context_free (ctx);
}
diff --git a/lib/widgets/ephy-overview-store.h b/lib/widgets/ephy-overview-store.h
index 231228b..fb74cb5 100644
--- a/lib/widgets/ephy-overview-store.h
+++ b/lib/widgets/ephy-overview-store.h
@@ -59,6 +59,7 @@ enum {
EPHY_OVERVIEW_STORE_SELECTED,
EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE,
EPHY_OVERVIEW_STORE_SNAPSHOT_MTIME,
+ EPHY_OVERVIEW_STORE_SNAPSHOT_PATH,
EPHY_OVERVIEW_STORE_NCOLS
};
@@ -97,7 +98,7 @@ gboolean ephy_overview_store_find_url (EphyOverviewStore *store,
GtkTreeIter *iter);
void ephy_overview_store_set_snapshot (EphyOverviewStore *store,
- GtkTreeIter *iter,
+ GtkTreeRowReference *ref,
cairo_surface_t *snapshot,
cairo_surface_t *favicon);
diff --git a/tests/ephy-snapshot-service-test.c b/tests/ephy-snapshot-service-test.c
index adb3e7a..609f487 100644
--- a/tests/ephy-snapshot-service-test.c
+++ b/tests/ephy-snapshot-service-test.c
@@ -52,7 +52,7 @@ on_snapshot_ready (GObject *source,
GError *error = NULL;
pixbuf = ephy_snapshot_service_get_snapshot_finish (EPHY_SNAPSHOT_SERVICE (source),
- res, &error);
+ res, NULL, &error);
g_assert (GDK_IS_PIXBUF (pixbuf) || error != NULL);
if (error) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]