summaryrefslogtreecommitdiff
path: root/libyelp
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-08-29 14:44:44 +0200
committerDavid King <amigadave@amigadave.com>2015-06-22 10:39:52 +0100
commit65d2f05a31bafad5d4f6147fc16db9fdd9aeadc9 (patch)
tree9a779bf74debe6bb2e444142cfee3c50ce4e3045 /libyelp
parentb9eac3dd0a0896919a027bd5ee03dcf81740e5bd (diff)
downloadyelp-65d2f05a31bafad5d4f6147fc16db9fdd9aeadc9.tar.gz
yelp-document: Make document-uri property a YelpUri
All implementations of YelpDocument except YelpSimpleDocument keep a reference to the YelpUri, so move it to the parent class and add a getter to use the YelpUri from derived classes. This is also useful to get the YelpUri directly from the document, instead of getting the document uri string, create a YelpUri and resolve it.
Diffstat (limited to 'libyelp')
-rw-r--r--libyelp/yelp-docbook-document.c38
-rw-r--r--libyelp/yelp-document.c26
-rw-r--r--libyelp/yelp-document.h2
-rw-r--r--libyelp/yelp-info-document.c29
-rw-r--r--libyelp/yelp-mallard-document.c24
-rw-r--r--libyelp/yelp-man-document.c41
-rw-r--r--libyelp/yelp-simple-document.c6
7 files changed, 59 insertions, 107 deletions
diff --git a/libyelp/yelp-docbook-document.c b/libyelp/yelp-docbook-document.c
index dafd38b4..4ac09a97 100644
--- a/libyelp/yelp-docbook-document.c
+++ b/libyelp/yelp-docbook-document.c
@@ -96,8 +96,6 @@ G_DEFINE_TYPE (YelpDocbookDocument, yelp_docbook_document, YELP_TYPE_DOCUMENT)
typedef struct _YelpDocbookDocumentPrivate YelpDocbookDocumentPrivate;
struct _YelpDocbookDocumentPrivate {
- YelpUri *uri;
-
DocbookState state;
GMutex mutex;
@@ -172,11 +170,6 @@ yelp_docbook_document_dispose (GObject *object)
gint i;
YelpDocbookDocumentPrivate *priv = GET_PRIV (object);
- if (priv->uri) {
- g_object_unref (priv->uri);
- priv->uri = NULL;
- }
-
if (priv->monitors != NULL) {
for (i = 0; priv->monitors[i]; i++) {
g_object_unref (priv->monitors[i]);
@@ -212,21 +205,16 @@ yelp_docbook_document_new (YelpUri *uri)
{
YelpDocbookDocument *docbook;
YelpDocbookDocumentPrivate *priv;
- gchar *doc_uri;
gchar **path;
gint path_i;
g_return_val_if_fail (uri != NULL, NULL);
- doc_uri = yelp_uri_get_document_uri (uri);
docbook = (YelpDocbookDocument *) g_object_new (YELP_TYPE_DOCBOOK_DOCUMENT,
- "document-uri", doc_uri,
+ "document-uri", uri,
NULL);
- g_free (doc_uri);
priv = GET_PRIV (docbook);
- priv->uri = g_object_ref (uri);
-
path = yelp_uri_get_search_path (uri);
priv->monitors = g_new0 (GFileMonitor*, g_strv_length (path) + 1);
for (path_i = 0; path[path_i]; path_i++) {
@@ -241,7 +229,6 @@ yelp_docbook_document_new (YelpUri *uri)
g_object_unref (file);
}
g_strfreev (path);
-
return (YelpDocument *) docbook;
}
@@ -290,7 +277,7 @@ docbook_request_page (YelpDocument *document,
break;
case DOCBOOK_STATE_PARSED:
case DOCBOOK_STATE_STOP:
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri (document));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The page ‘%s’ was not found in the document ‘%s’."),
page_id, docuri);
@@ -327,7 +314,7 @@ docbook_process (YelpDocbookDocument *docbook)
debug_print (DB_FUNCTION, "entering\n");
- file = yelp_uri_get_file (priv->uri);
+ file = yelp_uri_get_file (yelp_document_get_uri (document));
if (file == NULL) {
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The file does not exist."));
@@ -367,7 +354,7 @@ docbook_process (YelpDocbookDocument *docbook)
XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA |
XML_PARSE_NOENT | XML_PARSE_NONET )
< 0) {
- error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING,
+ error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING,
_("The file ‘%s’ could not be parsed because"
" one or more of its included files is not"
" a well-formed XML document."),
@@ -577,7 +564,7 @@ docbook_walk (YelpDocbookDocument *docbook)
}
else {
xmlNewProp (priv->xmlcur, BAD_CAST "id", BAD_CAST autoidstr);
- id = xmlGetProp (priv->xmlcur, BAD_CAST "id");
+ id = xmlGetProp (priv->xmlcur, BAD_CAST "id");
}
}
@@ -836,6 +823,7 @@ transform_finished (YelpTransform *transform,
YelpDocbookDocument *docbook)
{
YelpDocbookDocumentPrivate *priv = GET_PRIV (docbook);
+ YelpDocument *document = YELP_DOCUMENT (docbook);
gchar *docuri;
GError *error;
@@ -857,7 +845,7 @@ transform_finished (YelpTransform *transform,
(GWeakNotify) transform_finalized,
docbook);
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri (document));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The requested page was not found in the document ‘%s’."),
docuri);
@@ -893,7 +881,7 @@ transform_finalized (YelpDocbookDocument *docbook,
gpointer transform)
{
YelpDocbookDocumentPrivate *priv = GET_PRIV (docbook);
-
+
debug_print (DB_FUNCTION, "entering\n");
if (priv->xmldoc)
@@ -954,7 +942,6 @@ docbook_index_chunk (DocbookIndexData *index)
xmlNodePtr child;
gchar *title = NULL;
GSList *chunks = NULL;
- YelpDocbookDocumentPrivate *priv = GET_PRIV (index->docbook);
id = xmlGetProp (index->cur, BAD_CAST "id");
if (id != NULL) {
@@ -978,6 +965,7 @@ docbook_index_chunk (DocbookIndexData *index)
}
if (id != NULL) {
+ YelpDocument *document = YELP_DOCUMENT (index->docbook);
YelpUri *uri;
gchar *full_uri, *tmp, *body;
@@ -985,7 +973,7 @@ docbook_index_chunk (DocbookIndexData *index)
index->str = NULL;
tmp = g_strconcat ("xref:", id, NULL);
- uri = yelp_uri_new_relative (priv->uri, tmp);
+ uri = yelp_uri_new_relative (yelp_document_get_uri (document), tmp);
g_free (tmp);
yelp_uri_resolve_sync (uri);
full_uri = yelp_uri_get_canonical_uri (uri);
@@ -1022,16 +1010,18 @@ docbook_index_threaded (YelpDocbookDocument *docbook)
xmlParserCtxtPtr parserCtxt = NULL;
GFile *file = NULL;
gchar *filename = NULL;
+ YelpUri *uri;
YelpDocbookDocumentPrivate *priv = GET_PRIV (docbook);
- file = yelp_uri_get_file (priv->uri);
+ uri = yelp_document_get_uri (YELP_DOCUMENT (docbook));
+ file = yelp_uri_get_file (uri);
if (file == NULL)
goto done;
filename = g_file_get_path (file);
index = g_new0 (DocbookIndexData, 1);
index->docbook = docbook;
- index->doc_uri = yelp_uri_get_document_uri (priv->uri);
+ index->doc_uri = yelp_uri_get_document_uri (uri);
parserCtxt = xmlNewParserCtxt ();
index->doc = xmlCtxtReadFile (parserCtxt, filename, NULL,
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index 271a8996..aa1d82b4 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -73,7 +73,8 @@ struct _YelpDocumentPriv {
GSList *reqs_search; /* Pending search requests, not in reqs_all */
gboolean indexed;
- gchar *doc_uri;
+ YelpUri *uri;
+ gchar *doc_uri;
/* Real page IDs map to themselves, so this list doubles
* as a list of all valid page IDs.
@@ -273,10 +274,10 @@ yelp_document_class_init (YelpDocumentClass *klass)
g_object_class_install_property (object_class,
PROP_URI,
- g_param_spec_string ("document-uri",
+ g_param_spec_object ("document-uri",
N_("Document URI"),
N_("The URI which identifies the document"),
- NULL,
+ YELP_TYPE_URI,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
@@ -340,6 +341,9 @@ yelp_document_finalize (GObject *object)
{
YelpDocument *document = YELP_DOCUMENT (object);
+ g_clear_object (&document->priv->uri);
+ g_free (document->priv->doc_uri);
+
g_slist_free (document->priv->reqs_pending);
hash_free (document->priv->reqs_by_page_id);
@@ -376,7 +380,7 @@ document_get_property (GObject *object,
g_value_set_boolean (value, document->priv->indexed);
break;
case PROP_URI:
- g_value_set_string (value, document->priv->doc_uri);
+ g_value_set_object (value, document->priv->uri);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -399,9 +403,9 @@ document_set_property (GObject *object,
g_idle_add ((GSourceFunc) document_indexed, document);
break;
case PROP_URI:
- if (document->priv->doc_uri != NULL)
- g_free (document->priv->doc_uri);
- document->priv->doc_uri = g_value_dup_string (value);
+ document->priv->uri = g_value_dup_object (value);
+ if (document->priv->uri)
+ document->priv->doc_uri = yelp_uri_get_document_uri (document->priv->uri);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -411,6 +415,14 @@ document_set_property (GObject *object,
/******************************************************************************/
+YelpUri *
+yelp_document_get_uri (YelpDocument *document)
+{
+ g_assert (document != NULL && YELP_IS_DOCUMENT (document));
+
+ return document->priv->uri;
+}
+
gchar **
yelp_document_list_page_ids (YelpDocument *document)
{
diff --git a/libyelp/yelp-document.h b/libyelp/yelp-document.h
index e5cab519..002bab16 100644
--- a/libyelp/yelp-document.h
+++ b/libyelp/yelp-document.h
@@ -78,6 +78,8 @@ GType yelp_document_get_type (void);
YelpDocument * yelp_document_get_for_uri (YelpUri *uri);
+YelpUri * yelp_document_get_uri (YelpDocument *document);
+
gboolean yelp_document_request_page (YelpDocument *document,
const gchar *page_id,
GCancellable *cancellable,
diff --git a/libyelp/yelp-info-document.c b/libyelp/yelp-info-document.c
index 9b546317..b6f50771 100644
--- a/libyelp/yelp-info-document.c
+++ b/libyelp/yelp-info-document.c
@@ -46,7 +46,6 @@ typedef enum {
typedef struct _YelpInfoDocumentPrivate YelpInfoDocumentPrivate;
struct _YelpInfoDocumentPrivate {
- YelpUri *uri;
InfoState state;
GMutex mutex;
@@ -129,11 +128,6 @@ yelp_info_document_dispose (GObject *object)
{
YelpInfoDocumentPrivate *priv = GET_PRIV (object);
- if (priv->uri) {
- g_object_unref (priv->uri);
- priv->uri = NULL;
- }
-
if (priv->sections) {
g_object_unref (priv->sections);
priv->sections = NULL;
@@ -168,22 +162,11 @@ yelp_info_document_finalize (GObject *object)
YelpDocument *
yelp_info_document_new (YelpUri *uri)
{
- YelpInfoDocument *info;
- YelpInfoDocumentPrivate *priv;
- gchar *doc_uri;
-
g_return_val_if_fail (uri != NULL, NULL);
- doc_uri = yelp_uri_get_document_uri (uri);
- info = (YelpInfoDocument *) g_object_new (YELP_TYPE_INFO_DOCUMENT,
- "document-uri", doc_uri,
- NULL);
- g_free (doc_uri);
- priv = GET_PRIV (info);
-
- priv->uri = g_object_ref (uri);
-
- return (YelpDocument *) info;
+ return (YelpDocument *) g_object_new (YELP_TYPE_INFO_DOCUMENT,
+ "document-uri", uri,
+ NULL);
}
@@ -230,7 +213,7 @@ info_request_page (YelpDocument *document,
break;
case INFO_STATE_PARSED:
case INFO_STATE_STOP:
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri (document));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The page ‘%s’ was not found in the document ‘%s’."),
page_id, docuri);
@@ -310,7 +293,7 @@ transform_finished (YelpTransform *transform,
(GWeakNotify) transform_finalized,
info);
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri ((YelpDocument *) info));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The requested page was not found in the document ‘%s’."),
docuri);
@@ -366,7 +349,7 @@ info_document_process (YelpInfoDocument *info)
gint params_i = 0;
gchar **params = NULL;
- file = yelp_uri_get_file (priv->uri);
+ file = yelp_uri_get_file (yelp_document_get_uri ((YelpDocument *) info));
if (file == NULL) {
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The file does not exist."));
diff --git a/libyelp/yelp-mallard-document.c b/libyelp/yelp-mallard-document.c
index 4c6d2ea3..2ed94d82 100644
--- a/libyelp/yelp-mallard-document.c
+++ b/libyelp/yelp-mallard-document.c
@@ -117,7 +117,6 @@ G_DEFINE_TYPE (YelpMallardDocument, yelp_mallard_document, YELP_TYPE_DOCUMENT)
typedef struct _YelpMallardDocumentPrivate YelpMallardDocumentPrivate;
struct _YelpMallardDocumentPrivate {
- YelpUri *uri;
MallardState state;
GMutex mutex;
@@ -198,7 +197,6 @@ yelp_mallard_document_finalize (GObject *object)
{
YelpMallardDocumentPrivate *priv = GET_PRIV (object);
- g_object_unref (priv->uri);
g_mutex_clear (&priv->mutex);
g_hash_table_destroy (priv->pages_hash);
@@ -216,19 +214,15 @@ yelp_mallard_document_new (YelpUri *uri)
{
YelpMallardDocument *mallard;
YelpMallardDocumentPrivate *priv;
- gchar *doc_uri;
gchar **path;
gint path_i;
g_return_val_if_fail (uri != NULL, NULL);
- doc_uri = yelp_uri_get_document_uri (uri);
mallard = (YelpMallardDocument *) g_object_new (YELP_TYPE_MALLARD_DOCUMENT,
- "document-uri", doc_uri,
+ "document-uri", uri,
NULL);
- g_free (doc_uri);
priv = GET_PRIV (mallard);
- priv->uri = g_object_ref (uri);
yelp_document_set_page_id ((YelpDocument *) mallard, NULL, "index");
yelp_document_set_page_id ((YelpDocument *) mallard, "index", "index");
@@ -299,7 +293,7 @@ mallard_request_page (YelpDocument *document,
break;
case MALLARD_STATE_BLANK:
case MALLARD_STATE_STOP:
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri (document));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The page ‘%s’ was not found in the document ‘%s’."),
page_id, docuri);
@@ -336,7 +330,7 @@ mallard_think (YelpMallardDocument *mallard)
editor_mode = yelp_settings_get_editor_mode (yelp_settings_get_default ());
- path = yelp_uri_get_search_path (priv->uri);
+ path = yelp_uri_get_search_path (yelp_document_get_uri ((YelpDocument *) mallard));
if (!path || path[0] == NULL ||
!g_file_test (path[0], G_FILE_TEST_IS_DIR)) {
/* This basically only happens when someone passes an actual directory
@@ -453,7 +447,7 @@ mallard_try_run (YelpMallardDocument *mallard,
}
if (page_data == NULL) {
- gchar *docuri = yelp_uri_get_document_uri (priv->uri);
+ gchar *docuri = yelp_uri_get_document_uri (yelp_document_get_uri ((YelpDocument *) mallard));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The page ‘%s’ was not found in the document ‘%s’."),
page_id, docuri);
@@ -883,7 +877,7 @@ xml_node_is_ns_name (xmlNodePtr node,
if (node->ns == NULL)
return (ns == NULL);
else if (ns != NULL && node->ns->href != NULL)
- return (xmlStrEqual (ns, node->ns->href) && xmlStrEqual (name, node->name));
+ return (xmlStrEqual (ns, node->ns->href) && xmlStrEqual (name, node->name));
return FALSE;
}
@@ -959,11 +953,13 @@ mallard_index_threaded (YelpMallardDocument *mallard)
gint path_i;
GHashTable *ids;
gchar *doc_uri;
+ YelpUri *document_uri;
YelpMallardDocumentPrivate *priv = GET_PRIV (mallard);
- doc_uri = yelp_uri_get_document_uri (priv->uri);
+ document_uri = yelp_document_get_uri (YELP_DOCUMENT (mallard));
+ doc_uri = yelp_uri_get_document_uri (document_uri);
ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- path = yelp_uri_get_search_path (priv->uri);
+ path = yelp_uri_get_search_path (document_uri);
for (path_i = 0; path[path_i] != NULL; path_i++) {
GFile *gfile;
GFileEnumerator *children;
@@ -1039,7 +1035,7 @@ mallard_index_threaded (YelpMallardDocument *mallard)
mallard_index_node (index);
tmp = g_strconcat ("xref:", id, NULL);
- uri = yelp_uri_new_relative (priv->uri, tmp);
+ uri = yelp_uri_new_relative (document_uri, tmp);
yelp_uri_resolve_sync (uri);
full_uri = yelp_uri_get_canonical_uri (uri);
g_free (tmp);
diff --git a/libyelp/yelp-man-document.c b/libyelp/yelp-man-document.c
index 77e5b51a..77e74143 100644
--- a/libyelp/yelp-man-document.c
+++ b/libyelp/yelp-man-document.c
@@ -44,7 +44,6 @@ typedef enum {
typedef struct _YelpManDocumentPrivate YelpManDocumentPrivate;
struct _YelpManDocumentPrivate {
- YelpUri *uri;
ManState state;
gchar *page_id;
@@ -118,7 +117,6 @@ static const YelpLangEncodings langmap[] = {
{ NULL, NULL },
};
-static void yelp_man_document_dispose (GObject *object);
static void yelp_man_document_finalize (GObject *object);
/* YelpDocument */
@@ -154,7 +152,6 @@ yelp_man_document_class_init (YelpManDocumentClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
YelpDocumentClass *document_class = YELP_DOCUMENT_CLASS (klass);
- object_class->dispose = yelp_man_document_dispose;
object_class->finalize = yelp_man_document_finalize;
document_class->request_page = man_request_page;
@@ -172,19 +169,6 @@ yelp_man_document_init (YelpManDocument *man)
}
static void
-yelp_man_document_dispose (GObject *object)
-{
- YelpManDocumentPrivate *priv = GET_PRIV (object);
-
- if (priv->uri) {
- g_object_unref (priv->uri);
- priv->uri = NULL;
- }
-
- G_OBJECT_CLASS (yelp_man_document_parent_class)->dispose (object);
-}
-
-static void
yelp_man_document_finalize (GObject *object)
{
YelpManDocumentPrivate *priv = GET_PRIV (object);
@@ -203,22 +187,11 @@ yelp_man_document_finalize (GObject *object)
YelpDocument *
yelp_man_document_new (YelpUri *uri)
{
- YelpManDocument *man;
- YelpManDocumentPrivate *priv;
- gchar *doc_uri;
-
g_return_val_if_fail (uri != NULL, NULL);
- doc_uri = yelp_uri_get_document_uri (uri);
- man = (YelpManDocument *) g_object_new (YELP_TYPE_MAN_DOCUMENT,
- "document-uri", doc_uri,
- NULL);
- g_free (doc_uri);
- priv = GET_PRIV (man);
-
- priv->uri = g_object_ref (uri);
-
- return (YelpDocument *) man;
+ return (YelpDocument *) g_object_new (YELP_TYPE_MAN_DOCUMENT,
+ "document-uri", uri,
+ NULL);
}
@@ -237,7 +210,7 @@ man_request_page (YelpDocument *document,
GError *error;
gboolean handled;
- fulluri = yelp_uri_get_canonical_uri (priv->uri);
+ fulluri = yelp_uri_get_canonical_uri (yelp_document_get_uri (document));
if (g_str_has_prefix (fulluri, "man:"))
priv->page_id = g_strdup (fulluri + 4);
else
@@ -274,7 +247,7 @@ man_request_page (YelpDocument *document,
break;
case MAN_STATE_PARSED:
case MAN_STATE_STOP:
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri (document));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The page ‘%s’ was not found in the document ‘%s’."),
page_id, docuri);
@@ -354,7 +327,7 @@ transform_finished (YelpTransform *transform,
(GWeakNotify) transform_finalized,
man);
- docuri = yelp_uri_get_document_uri (priv->uri);
+ docuri = yelp_uri_get_document_uri (yelp_document_get_uri ((YelpDocument *) man));
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The requested page was not found in the document ‘%s’."),
docuri);
@@ -411,7 +384,7 @@ man_document_process (YelpManDocument *man)
YelpManParser *parser;
const gchar *language, *encoding;
- file = yelp_uri_get_file (priv->uri);
+ file = yelp_uri_get_file (yelp_document_get_uri ((YelpDocument *) man));
if (file == NULL) {
error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
_("The file does not exist."));
diff --git a/libyelp/yelp-simple-document.c b/libyelp/yelp-simple-document.c
index 51148b1e..47145621 100644
--- a/libyelp/yelp-simple-document.c
+++ b/libyelp/yelp-simple-document.c
@@ -164,14 +164,10 @@ YelpDocument *
yelp_simple_document_new (YelpUri *uri)
{
YelpSimpleDocument *document;
- gchar *doc_uri;
- doc_uri = yelp_uri_get_document_uri (uri);
document = (YelpSimpleDocument *) g_object_new (YELP_TYPE_SIMPLE_DOCUMENT,
- "document-uri", doc_uri,
+ "document-uri", uri,
NULL);
- g_free (doc_uri);
-
document->priv->file = yelp_uri_get_file (uri);
document->priv->page_id = yelp_uri_get_page_id (uri);