[yelp/yelp-3-0] Adding yelp_document_get_for_uri factory constructor
- From: Shaun McCance <shaunm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [yelp/yelp-3-0] Adding yelp_document_get_for_uri factory constructor
- Date: Sun, 27 Sep 2009 01:45:14 +0000 (UTC)
commit 5ec9019f7421a677ed7d0a091ce7d2ff1cbabf00
Author: Shaun McCance <shaunm gnome org>
Date: Fri Sep 25 18:47:00 2009 -0500
Adding yelp_document_get_for_uri factory constructor
libyelp/yelp-document.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++
libyelp/yelp-document.h | 4 +++
libyelp/yelp-view.c | 4 +-
3 files changed, 69 insertions(+), 2 deletions(-)
---
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index f4bcb3b..1efcb90 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -110,6 +110,69 @@ static gboolean request_idle_final (YelpDocument *document);
GStaticMutex str_mutex = G_STATIC_MUTEX_INIT;
GHashTable *str_refs = NULL;
+/******************************************************************************/
+
+YelpDocument *
+yelp_document_get_for_uri (YelpUri *uri)
+{
+ static GHashTable *documents = NULL;
+ gchar *base_uri;
+ YelpDocument *document;
+
+ if (documents == NULL)
+ documents = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_object_unref);
+
+ base_uri = yelp_uri_get_base_uri (uri);
+ document = g_hash_table_lookup (documents, base_uri);
+
+ if (document != NULL) {
+ g_free (base_uri);
+ return g_object_ref (document);
+ }
+
+ switch (yelp_uri_get_document_type (uri)) {
+ case YELP_URI_DOCUMENT_TYPE_TEXT:
+ case YELP_URI_DOCUMENT_TYPE_HTML:
+ case YELP_URI_DOCUMENT_TYPE_XHTML:
+ document = yelp_simple_document_new (uri);
+ break;
+ case YELP_URI_DOCUMENT_TYPE_DOCBOOK:
+ /* FIXME */
+ break;
+ case YELP_URI_DOCUMENT_TYPE_MALLARD:
+ /* FIXME */
+ break;
+ case YELP_URI_DOCUMENT_TYPE_MAN:
+ /* FIXME */
+ break;
+ case YELP_URI_DOCUMENT_TYPE_INFO:
+ /* FIXME */
+ break;
+ case YELP_URI_DOCUMENT_TYPE_TOC:
+ /* FIXME */
+ break;
+ case YELP_URI_DOCUMENT_TYPE_SEARCH:
+ /* FIXME */
+ break;
+ case YELP_URI_DOCUMENT_TYPE_UNKNOWN:
+ case YELP_URI_DOCUMENT_TYPE_NOT_FOUND:
+ case YELP_URI_DOCUMENT_TYPE_EXTERNAL:
+ case YELP_URI_DOCUMENT_TYPE_ERROR:
+ break;
+ }
+
+ if (document != NULL) {
+ g_hash_table_insert (documents, base_uri, document);
+ return g_object_ref (document);
+ }
+
+ g_free (base_uri);
+ return NULL;
+}
+
+/******************************************************************************/
+
static void
yelp_document_class_init (YelpDocumentClass *klass)
{
diff --git a/libyelp/yelp-document.h b/libyelp/yelp-document.h
index e86d4f3..64aee49 100644
--- a/libyelp/yelp-document.h
+++ b/libyelp/yelp-document.h
@@ -26,6 +26,8 @@
#include <glib-object.h>
#include <gio/gio.h>
+#include "yelp-uri.h"
+
#define YELP_TYPE_DOCUMENT (yelp_document_get_type ())
#define YELP_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_DOCUMENT, YelpDocument))
#define YELP_DOCUMENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), YELP_TYPE_DOCUMENT, YelpDocumentClass))
@@ -73,6 +75,8 @@ struct _YelpDocumentClass {
GType yelp_document_get_type (void);
+YelpDocument * yelp_document_get_for_uri (YelpUri *uri);
+
gboolean yelp_document_request_page (YelpDocument *document,
const gchar *page_id,
GCancellable *cancellable,
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 7153021..a489263 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -141,8 +141,8 @@ void
yelp_view_load_uri (YelpView *view,
YelpUri *uri)
{
- /* FIXME: want to get from a factory, just for testing */
- YelpDocument *document = yelp_simple_document_new (uri);
+ YelpDocument *document = yelp_document_get_for_uri (uri);
+ /* FIXME: handle document == NULL */
yelp_view_load_document (view, uri, document);
g_object_unref (document);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]