[yelp] * src/yelp-window.c:



commit 7e8148bb802f147010c6dd18079dac4b7e41276f
Author: Don Scorgie <dscorgie git gnome org>
Date:   Thu Apr 30 19:31:34 2009 +0100

    * src/yelp-window.c:
    * src/yelp-utils.c:
    Fix a crash when requesting bad URIs from the
    command line (and show the main index in the process)
    Fix loading "local" files from the current
    directory - bug #575405 (at least)
---
 ChangeLog         |   11 +++++++++++
 src/yelp-utils.c  |   31 +++++++++++++++++++++++++++++--
 src/yelp-window.c |   20 +++++++++++++++-----
 3 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f6b6fb6..501af5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-04-30  Don Scorgie  <dscorgie src gnome org>
+
+	* src/yelp-window.c: 
+	* src/yelp-utils.c:
+	Fix a crash when requesting bad URIs from the
+	command line (and show the main index in the
+	process)
+	Fix loading "local" files from the current
+	directory - bug #575405 (at least)
+	
+
 2009-04-29  Don Scorgie  <dscorgie src gnome org>
 
 	* src/yelp-window.c: 
diff --git a/src/yelp-utils.c b/src/yelp-utils.c
index cae8663..a0f4e93 100644
--- a/src/yelp-utils.c
+++ b/src/yelp-utils.c
@@ -169,6 +169,7 @@ resolve_full_file (const gchar *path)
     if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
 	return YELP_RRN_TYPE_ERROR;
     }
+
     mime_type = g_content_type_guess (path, NULL, 0, &uncertain);
     if (mime_type == NULL) {
 	return YELP_RRN_TYPE_ERROR;
@@ -431,17 +432,43 @@ yelp_uri_resolve (gchar *uri, gchar **result, gchar **section)
 	*section = g_strdup ("results");
 	ret = YELP_RRN_TYPE_SEARCH;
     } else if (g_file_test (intern_uri, G_FILE_TEST_EXISTS)) {
+	gchar *copy_uri;
 	/* Full path */
+	/* Check to see if the file is in the current directory */
+	if (intern_uri[0] != '/' &&
+	    strstr (intern_uri, ":/") == NULL) {
+	    /* Probably current dir - get the current directory,
+	     * put it on the front and see if it exists */
+	    gchar *current_path = NULL;
+	    gchar *new_uri = NULL;
+
+	    current_path = g_get_current_dir();
+
+	    new_uri = g_strdup_printf ("%s/%s", current_path,
+				       intern_uri);
+	    printf ("new_uri: %s\n", new_uri);
+
+	    if (g_file_test (new_uri, G_FILE_TEST_EXISTS)) {
+		copy_uri = g_strdup (new_uri);
+	    } else {
+		copy_uri = g_strdup (intern_uri);
+	    }
+	    g_free (current_path);
+	    g_free (new_uri);
+	} else {
+		copy_uri = g_strdup (intern_uri);
+	}
+
 	ret = resolve_full_file (intern_uri);
 	if (ret == YELP_RRN_TYPE_EXTERNAL) {
 	    *section = NULL;
-	    *result = g_strdup (uri);
+	    *result = copy_uri;
 	}
 	else if (ret == YELP_RRN_TYPE_ERROR) {
 	    *section = NULL;
 	    *result = NULL;
 	} else {
-	    *result = g_strdup (intern_uri);
+	    *result = copy_uri;
 	    *section = g_strdup (intern_section);
 	}
     } else if (*uri == '/' || g_str_has_suffix (uri, ".xml")) {
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 7b355af..970c7e9 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -1083,11 +1083,11 @@ yelp_window_load (YelpWindow *window, const gchar *uri)
 	case YELP_RRN_TYPE_XHTML:
 	case YELP_RRN_TYPE_TEXT:
  	    {
-		gchar *uri;
+		gchar *call_uri;
 		priv->base_uri = g_strdup ("file:///fakefile");
-		uri = g_filename_to_uri (real_uri, NULL, NULL);
-		window_do_load_html (window, uri, frag_id, type, TRUE);
-		g_free (uri);
+		call_uri = g_filename_to_uri (real_uri, NULL, NULL);
+		window_do_load_html (window, call_uri, frag_id, type, TRUE);
+		g_free (call_uri);
  	    }
 	    break;
 	case YELP_RRN_TYPE_EXTERNAL:
@@ -1109,8 +1109,18 @@ yelp_window_load (YelpWindow *window, const gchar *uri)
 		if (!gtk_show_uri (NULL, trace_uri, gtk_get_current_event_time (), &error)) {
 		    gchar *message = g_strdup_printf (_("The requested URI \"%s\" is invalid"), trace_uri);
 		    window_error (window, _("Unable to load page"), message, FALSE);
-		    g_free (error);
+		    /* todo: Freeing error here causes an immediate 
+		     * seg fault.  Why?  Who knows. For now, we'll
+		     * leak it
+		     */
+		    /* g_free (error); */
 		    error = NULL;
+		    if (!priv->current_document) {
+			/* recurse to load the index if we're not
+			 * already somewhere
+			 */
+			yelp_window_load (window, "x-yelp-toc:");
+		    }
 		    goto Exit;
 		}
 	    }



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