[epiphany] PDF: Set page title and gracefully handle failures during document loading



commit 272a54c7f307c923c2c5d2510d8ca38ac9cbea8d
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Fri Jan 18 17:54:43 2019 +0100

    PDF: Set page title and gracefully handle failures during document loading

 embed/ephy-embed.c | 29 ++++++++++++++++++++++++++++-
 embed/ephy-embed.h |  2 +-
 2 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 926b1ebcd..7a1d5a66b 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -77,6 +77,7 @@ struct _EphyEmbed {
   GSList *keys;
 
   EphyEmbedMode mode;
+  char *saved_title;
 
   guint seq_context_id;
   guint seq_message_id;
@@ -391,6 +392,7 @@ ephy_embed_dispose (GObject *object)
     embed->fullscreen_message_id = 0;
   }
 
+  g_clear_pointer (&embed->saved_title, g_free);
   g_clear_object (&embed->delayed_request);
   g_clear_pointer (&embed->delayed_state, webkit_web_view_session_state_unref);
 
@@ -1038,6 +1040,11 @@ ephy_embed_set_mode (EphyEmbed *embed, EphyEmbedMode mode)
       embed->document_view = NULL;
     }
     gtk_widget_set_visible (GTK_WIDGET (embed->paned), TRUE);
+
+    if (embed->saved_title) {
+      ephy_embed_set_title (embed, embed->saved_title);
+      g_clear_pointer (&embed->saved_title, g_free);
+    }
     break;
   case EPHY_EMBED_MODE_EVINCE_DOCUMENT:
     gtk_widget_set_visible (GTK_WIDGET (embed->paned), FALSE);
@@ -1059,24 +1066,44 @@ ephy_embed_get_mode (EphyEmbed *embed)
   return embed->mode;
 }
 
+static void
+document_download_failed_cb (WebKitDownload *download,
+                             GError         *error,
+                             EphyEmbed      *embed)
+{
+  /* Error occured: Switch back to web view */
+  ephy_embed_set_mode (embed, EPHY_EMBED_MODE_WEB_VIEW);
+}
+
 static void
 document_download_finished_cb (WebKitDownload *download,
                                EphyEmbed      *embed)
 {
   const char *document_uri = webkit_download_get_destination (download);
 
+  if (!embed->document_view)
+    return;
+
   ephy_evince_document_view_load_uri (EPHY_EVINCE_DOCUMENT_VIEW (embed->document_view),
                                       document_uri);
+
+  embed->saved_title = g_strdup (embed->title);
+  ephy_embed_set_title (embed, g_path_get_basename (document_uri));
 }
 
-void
+gboolean
 ephy_embed_download_started (EphyEmbed    *embed,
                              EphyDownload *ephy_download)
 {
   WebKitDownload *download = ephy_download_get_webkit_download (ephy_download);
+  gboolean ret = FALSE;
 
   if (embed->mode == EPHY_EMBED_MODE_EVINCE_DOCUMENT) {
     ephy_download_enable_evince_document_mode (ephy_download);
+    g_signal_connect (download, "failed", G_CALLBACK (document_download_failed_cb), embed);
     g_signal_connect (download, "finished", G_CALLBACK (document_download_finished_cb), embed);
+    ret = TRUE;
   }
+
+  return ret;
 }
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 8cf658ce7..1eeb39e83 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -62,7 +62,7 @@ void             ephy_embed_detach_notification_container (EphyEmbed *embed);
 void             ephy_embed_set_mode                      (EphyEmbed     *embed,
                                                            EphyEmbedMode  mode);
 EphyEmbedMode    ephy_embed_get_mode                      (EphyEmbed *embed);
-void             ephy_embed_download_started              (EphyEmbed    *embed,
+gboolean         ephy_embed_download_started              (EphyEmbed    *embed,
                                                            EphyDownload *ephy_download);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]