diff options
author | Shaun McCance <shaunm@gnome.org> | 2011-01-17 16:33:13 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2011-01-17 16:35:56 -0500 |
commit | 3b0c1358cfac5dda0ee24c92f3ed6f971a57a35b (patch) | |
tree | d72424251bea57d8c3d4f16e1463b5f938dbf647 | |
parent | 52a31b8820107f67b334246f5a3498b5f1117669 (diff) | |
download | yelp-3b0c1358cfac5dda0ee24c92f3ed6f971a57a35b.tar.gz |
Mangling man URIs so that bookmarks are somewhat sensible
-rw-r--r-- | libyelp/yelp-document.c | 17 | ||||
-rw-r--r-- | libyelp/yelp-man-document.c | 34 | ||||
-rw-r--r-- | libyelp/yelp-uri.c | 14 |
3 files changed, 42 insertions, 23 deletions
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c index 215586e6..b1d17b8d 100644 --- a/libyelp/yelp-document.c +++ b/libyelp/yelp-document.c @@ -139,7 +139,7 @@ YelpDocument * yelp_document_get_for_uri (YelpUri *uri) { static GHashTable *documents = NULL; - gchar *docuri; + gchar *docuri = NULL; gchar *page_id, *tmp; YelpDocument *document = NULL; @@ -149,10 +149,6 @@ yelp_document_get_for_uri (YelpUri *uri) g_return_val_if_fail (yelp_uri_is_resolved (uri), NULL); - docuri = yelp_uri_get_document_uri (uri); - if (docuri == NULL) - return NULL; - switch (yelp_uri_get_document_type (uri)) { case YELP_URI_DOCUMENT_TYPE_TEXT: case YELP_URI_DOCUMENT_TYPE_HTML: @@ -165,12 +161,21 @@ yelp_document_get_for_uri (YelpUri *uri) page_id = yelp_uri_get_page_id (uri); tmp = g_strconcat (docuri, "/", page_id, NULL); g_free (page_id); - g_free (docuri); docuri = tmp; break; + case YELP_URI_DOCUMENT_TYPE_MAN: + /* The document URI for man pages is just man:, so we use the + * full canonical URI to look these up. + */ + docuri = yelp_uri_get_canonical_uri (uri); + break; default: + docuri = yelp_uri_get_document_uri (uri); break; } + + if (docuri == NULL) + return NULL; document = g_hash_table_lookup (documents, docuri); if (document != NULL) { diff --git a/libyelp/yelp-man-document.c b/libyelp/yelp-man-document.c index 4fac05ac..f3c42a66 100644 --- a/libyelp/yelp-man-document.c +++ b/libyelp/yelp-man-document.c @@ -48,6 +48,7 @@ typedef struct _YelpManDocumentPrivate YelpManDocumentPrivate; struct _YelpManDocumentPrivate { YelpUri *uri; ManState state; + gchar *page_id; GMutex *mutex; GThread *thread; @@ -196,6 +197,7 @@ yelp_man_document_finalize (GObject *object) xmlFreeDoc (priv->xmldoc); g_mutex_free (priv->mutex); + g_free (priv->page_id); G_OBJECT_CLASS (yelp_man_document_parent_class)->finalize (object); } @@ -224,18 +226,22 @@ yelp_man_document_new (YelpUri *uri) static gboolean man_request_page (YelpDocument *document, - const gchar *page_id, - GCancellable *cancellable, - YelpDocumentCallback callback, - gpointer user_data) + const gchar *page_id, + GCancellable *cancellable, + YelpDocumentCallback callback, + gpointer user_data) { YelpManDocumentPrivate *priv = GET_PRIV (document); - gchar *docuri; + gchar *docuri, *fulluri; GError *error; gboolean handled; - if (page_id == NULL) - page_id = "//index"; + fulluri = yelp_uri_get_canonical_uri (priv->uri); + if (g_str_has_prefix (fulluri, "man:")) + priv->page_id = g_strdup (fulluri + 4); + else + priv->page_id = g_strdup ("//index"); + g_free (fulluri); handled = YELP_DOCUMENT_CLASS (yelp_man_document_parent_class)->request_page (document, @@ -254,9 +260,11 @@ man_request_page (YelpDocument *document, priv->state = MAN_STATE_PARSING; priv->process_running = TRUE; g_object_ref (document); - yelp_document_set_page_id (document, NULL, "//index"); - yelp_document_set_page_id (document, "//index", "//index"); - yelp_document_set_root_id (document, "//index", "//index"); + yelp_document_set_page_id (document, page_id, priv->page_id); + yelp_document_set_page_id (document, NULL, priv->page_id); + yelp_document_set_page_id (document, "//index", priv->page_id); + yelp_document_set_page_id (document, priv->page_id, priv->page_id); + yelp_document_set_root_id (document, priv->page_id, priv->page_id); priv->thread = g_thread_create ((GThreadFunc) man_document_process, document, FALSE, NULL); break; @@ -300,16 +308,16 @@ transform_chunk_ready (YelpTransform *transform, content = yelp_transform_take_chunk (transform, chunk_id); yelp_document_give_contents (YELP_DOCUMENT (man), - chunk_id, + priv->page_id, content, "application/xhtml+xml"); yelp_document_signal (YELP_DOCUMENT (man), - chunk_id, + priv->page_id, YELP_DOCUMENT_SIGNAL_INFO, NULL); yelp_document_signal (YELP_DOCUMENT (man), - chunk_id, + priv->page_id, YELP_DOCUMENT_SIGNAL_CONTENTS, NULL); } diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c index aa467d6c..9ef480ed 100644 --- a/libyelp/yelp-uri.c +++ b/libyelp/yelp-uri.c @@ -260,6 +260,7 @@ resolve_start (YelpUri *uri) static void resolve_async (YelpUri *uri) { + gchar *tmp; YelpUriPrivate *priv = GET_PRIV (uri); if (g_str_has_prefix (priv->res_arg, "ghelp:") @@ -296,9 +297,13 @@ resolve_async (YelpUri *uri) case YELP_URI_DOCUMENT_TYPE_INFO: resolve_xref_uri (uri); break; - case YELP_URI_DOCUMENT_TYPE_MAN: - /* FIXME: what do we do? */ + case YELP_URI_DOCUMENT_TYPE_MAN: { + gchar *tmp = g_strconcat ("man:", priv->res_arg + 5, NULL); + g_free (priv->res_arg); + priv->res_arg = tmp; + resolve_man_uri (uri); break; + } case YELP_URI_DOCUMENT_TYPE_TEXT: case YELP_URI_DOCUMENT_TYPE_HTML: case YELP_URI_DOCUMENT_TYPE_XHTML: @@ -929,8 +934,9 @@ resolve_man_uri (YelpUri *uri) } priv->tmptype = YELP_URI_DOCUMENT_TYPE_MAN; priv->gfile = g_file_new_for_path (path); - priv->docuri = g_strconcat ("man:", name, ".", section, NULL); - priv->fulluri = g_strdup (priv->docuri); + priv->docuri = g_strdup ("man:"); + priv->fulluri = g_strconcat ("man:", name, ".", section, NULL); + priv->page_id = g_strconcat (name, ".", section, NULL); resolve_gfile (uri, NULL); if (hash && hash[0] != '\0') |