[devhelp] DhLink: improve dh_link_get_uri()



commit de310a60f847beefc35d74354c61f4af50ecf000
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 7 15:47:10 2017 +0100

    DhLink: improve dh_link_get_uri()

 src/dh-link.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/dh-link.c b/src/dh-link.c
index 223d86a..2e54d0a 100644
--- a/src/dh-link.c
+++ b/src/dh-link.c
@@ -344,7 +344,11 @@ dh_link_belongs_to_page (DhLink      *link,
  * dh_link_get_uri:
  * @link: a #DhLink.
  *
- * Returns: the @link URI. Free with g_free() when no longer needed.
+ * Gets the @link URI, by concateneting the book base path with the @link
+ * relative URL.
+ *
+ * Returns: (nullable): the @link URI, or %NULL if getting the URI failed. Free
+ * with g_free() when no longer needed.
  */
 gchar *
 dh_link_get_uri (DhLink *link)
@@ -353,6 +357,7 @@ dh_link_get_uri (DhLink *link)
         gchar *filename;
         gchar *uri;
         gchar *anchor;
+        GError *error = NULL;
 
         g_return_val_if_fail (link != NULL, NULL);
 
@@ -369,9 +374,13 @@ dh_link_get_uri (DhLink *link)
                 anchor++;
         }
 
-        uri = g_filename_to_uri (filename, NULL, NULL);
+        uri = g_filename_to_uri (filename, NULL, &error);
+        if (error != NULL) {
+                g_warning ("Failed to get DhLink URI: %s", error->message);
+                g_clear_error (&error);
+        }
 
-        if (anchor != NULL) {
+        if (uri != NULL && anchor != NULL) {
                 gchar *uri_with_anchor;
 
                 uri_with_anchor = g_strconcat (uri, "#", anchor, NULL);


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