[epiphany] Use created-destination as information for pdf name
- From: Jan-Michael Brummer <jbrummer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Use created-destination as information for pdf name
- Date: Thu, 25 Jun 2020 11:37:30 +0000 (UTC)
commit 5a75e6663d756d0e0f9e37f3067ba866510c5a3f
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Wed Jun 24 10:57:56 2020 +0200
Use created-destination as information for pdf name
Maybe fixes https://gitlab.gnome.org/GNOME/epiphany/-/issues/1235
embed/ephy-pdf-handler.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/embed/ephy-pdf-handler.c b/embed/ephy-pdf-handler.c
index 238842b1d..995b1934d 100644
--- a/embed/ephy-pdf-handler.c
+++ b/embed/ephy-pdf-handler.c
@@ -42,6 +42,7 @@ typedef struct {
WebKitURISchemeRequest *scheme_request;
GCancellable *cancellable;
EphyDownload *download;
+ char *file_name;
} EphyPdfRequest;
static EphyPdfRequest *
@@ -50,7 +51,7 @@ ephy_pdf_request_new (EphyPDFHandler *handler,
{
EphyPdfRequest *pdf_request;
- pdf_request = g_new (EphyPdfRequest, 1);
+ pdf_request = g_new0 (EphyPdfRequest, 1);
pdf_request->source_handler = g_object_ref (handler);
pdf_request->scheme_request = g_object_ref (request);
pdf_request->cancellable = g_cancellable_new ();
@@ -70,6 +71,7 @@ ephy_pdf_request_free (EphyPdfRequest *request)
g_object_unref (request->source_handler);
g_object_unref (request->scheme_request);
+ g_clear_pointer (&request->file_name, g_free);
g_cancellable_cancel (request->cancellable);
g_object_unref (request->cancellable);
@@ -123,7 +125,6 @@ pdf_file_loaded (GObject *source,
g_autoptr (GError) error = NULL;
g_autoptr (GString) html = NULL;
g_autofree gchar *b64 = NULL;
- g_autofree gchar *requested_uri = NULL;
g_autofree char *file_data = NULL;
gsize len = 0;
@@ -139,7 +140,7 @@ pdf_file_loaded (GObject *source,
g_file_delete_async (G_FILE (source), G_PRIORITY_DEFAULT, NULL, pdf_file_deleted, NULL);
html = g_string_new ("");
- g_string_printf (html, g_bytes_get_data (html_file, NULL), b64, g_file_get_basename (G_FILE (source)));
+ g_string_printf (html, g_bytes_get_data (html_file, NULL), b64, self->file_name ? self->file_name : "");
finish_uri_scheme_request (self, g_strdup (html->str), NULL);
}
@@ -191,6 +192,19 @@ download_errored_cb (EphyDownload *download,
g_clear_object (&self->download);
}
+static void
+created_destination_cb (WebKitDownload *download,
+ gchar *destination,
+ gpointer user_data)
+{
+ EphyPdfRequest *request = user_data;
+
+ g_signal_handlers_disconnect_by_data (download, request);
+
+ g_clear_pointer (&request->file_name, g_free);
+ request->file_name = g_path_get_basename (destination);
+}
+
static void
ephy_pdf_request_start (EphyPdfRequest *request)
{
@@ -230,6 +244,7 @@ ephy_pdf_request_start (EphyPdfRequest *request)
g_signal_connect (request->download, "completed", G_CALLBACK (download_completed_cb), request);
g_signal_connect (request->download, "error", G_CALLBACK (download_errored_cb), request);
+ g_signal_connect (ephy_download_get_webkit_download (request->download), "created-destination", G_CALLBACK
(created_destination_cb), request);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]