[epiphany] Refactor delayed overview thumbnail update handling
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Refactor delayed overview thumbnail update handling
- Date: Tue, 6 Dec 2016 15:14:18 +0000 (UTC)
commit 19322541e8be8f11ad6a4aee4457b9cc636c5a69
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Dec 4 20:56:00 2016 -0600
Refactor delayed overview thumbnail update handling
Move this logic to EphyEmbedShell. It will be needed there in the next
commit and I don't want to duplicate the code in two different places.
https://bugzilla.gnome.org/show_bug.cgi?id=775612
embed/ephy-about-handler.c | 46 +++++++---------------------------------
embed/ephy-embed-shell.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
embed/ephy-embed-shell.h | 3 ++
3 files changed, 61 insertions(+), 38 deletions(-)
---
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index 12b4b5e..eec76b3 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -406,44 +406,22 @@ ephy_about_handler_handle_applications (EphyAboutHandler *handler,
return TRUE;
}
-typedef struct {
- char *url;
- time_t mtime;
-} GetSnapshotPathAsyncData;
-
-static void
-got_snapshot_path_for_url_cb (EphySnapshotService *service,
- GAsyncResult *result,
- GetSnapshotPathAsyncData *data)
-{
- char *snapshot;
- GError *error = NULL;
-
- snapshot = ephy_snapshot_service_get_snapshot_path_for_url_finish (service, result, &error);
- if (snapshot) {
- ephy_embed_shell_set_thumbnail_path (ephy_embed_shell_get_default (), data->url, data->mtime, snapshot);
- g_free (snapshot);
- } else {
- /* Bad luck, not something to warn about. */
- g_info ("Failed to get snapshot for URL %s: %s", data->url, error->message);
- g_error_free (error);
- }
- g_free (data->url);
- g_free (data);
-}
-
static void
history_service_query_urls_cb (EphyHistoryService *history,
gboolean success,
GList *urls,
WebKitURISchemeRequest *request)
{
- EphySnapshotService *snapshot_service = ephy_snapshot_service_get_default ();
+ EphySnapshotService *snapshot_service;
+ EphyEmbedShell *shell;
GString *data_str;
gsize data_length;
char *lang;
GList *l;
+ snapshot_service = ephy_snapshot_service_get_default ();
+ shell = ephy_embed_shell_get_default ();
+
data_str = g_string_new (NULL);
lang = g_strdup (pango_language_to_string (gtk_get_default_language ()));
@@ -510,18 +488,10 @@ history_service_query_urls_cb (EphyHistoryService *history,
char *thumbnail_style = NULL;
snapshot = ephy_snapshot_service_lookup_cached_snapshot_path (snapshot_service, url->url);
- if (!snapshot) {
- GetSnapshotPathAsyncData *data = g_new (GetSnapshotPathAsyncData, 1);
-
- data->url = g_strdup (url->url);
- data->mtime = url->thumbnail_time;
- ephy_snapshot_service_get_snapshot_path_for_url_async (ephy_snapshot_service_get_default (),
- url->url, url->thumbnail_time, NULL,
-
(GAsyncReadyCallback)got_snapshot_path_for_url_cb,
- data);
- } else {
+ if (snapshot)
thumbnail_style = g_strdup_printf (" style=\"background: url(file://%s) no-repeat;\"", snapshot);
- }
+ else
+ ephy_embed_shell_schedule_thumbnail_update (shell, url);
g_string_append_printf (data_str,
"<a class=\"overview-item\" title=\"%s\" href=\"%s\">"
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 2de5603..135657e 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -433,6 +433,56 @@ ephy_embed_shell_set_thumbnail_path (EphyEmbedShell *shell,
}
}
+typedef struct {
+ char *url;
+ time_t mtime;
+} GetSnapshotPathAsyncData;
+
+static void
+got_snapshot_path_for_url_cb (EphySnapshotService *service,
+ GAsyncResult *result,
+ GetSnapshotPathAsyncData *data)
+{
+ char *snapshot;
+ GError *error = NULL;
+
+ snapshot = ephy_snapshot_service_get_snapshot_path_for_url_finish (service, result, &error);
+ if (snapshot) {
+ ephy_embed_shell_set_thumbnail_path (ephy_embed_shell_get_default (), data->url, data->mtime, snapshot);
+ g_free (snapshot);
+ } else {
+ /* Bad luck, not something to warn about. */
+ g_info ("Failed to get snapshot for URL %s: %s", data->url, error->message);
+ g_error_free (error);
+ }
+ g_free (data->url);
+ g_free (data);
+}
+
+void
+ephy_embed_shell_schedule_thumbnail_update (EphyEmbedShell *shell,
+ EphyHistoryURL *url)
+{
+ EphySnapshotService *service;
+ const char *snapshot;
+
+ service = ephy_snapshot_service_get_default ();
+ snapshot = ephy_snapshot_service_lookup_cached_snapshot_path (service, url->url);
+
+ if (snapshot) {
+ ephy_embed_shell_set_thumbnail_path (shell, url->url, url->thumbnail_time, snapshot);
+ } else {
+ GetSnapshotPathAsyncData *data = g_new (GetSnapshotPathAsyncData, 1);
+
+ data->url = g_strdup (url->url);
+ data->mtime = url->thumbnail_time;
+ ephy_snapshot_service_get_snapshot_path_for_url_async (service,
+ url->url, url->thumbnail_time, NULL,
+ (GAsyncReadyCallback)got_snapshot_path_for_url_cb,
+ data);
+ }
+}
+
/**
* ephy_embed_shell_get_global_history_service:
* @shell: the #EphyEmbedShell
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index b7a5163..e327e7e 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -23,6 +23,7 @@
#include <webkit2/webkit2.h>
#include "ephy-downloads-manager.h"
+#include "ephy-history-service.h"
#include "ephy-hosts-manager.h"
G_BEGIN_DECLS
@@ -73,6 +74,8 @@ void ephy_embed_shell_set_thumbnail_path (EphyEmbedShell
const char *url,
time_t mtime,
const char *path);
+void ephy_embed_shell_schedule_thumbnail_update (EphyEmbedShell *shell,
+ EphyHistoryURL *url);
WebKitUserContentManager *ephy_embed_shell_get_user_content_manager (EphyEmbedShell *shell);
EphyDownloadsManager *ephy_embed_shell_get_downloads_manager (EphyEmbedShell *shell);
EphyHostsManager *ephy_embed_shell_get_hosts_manager (EphyEmbedShell *shell);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]