devhelp r1118 - in trunk: . src



Author: rhult
Date: Fri Oct  3 20:32:21 2008
New Revision: 1118
URL: http://svn.gnome.org/viewvc/devhelp?rev=1118&view=rev

Log:
2008-10-03  Richard Hult  <richard imendio com>

	* src/dh-link.c:
	* src/dh-link.h: Replace the book and page names with pointers to
	their respective DhLinks. This saves quite a bit of memory, but
	breaks searching for pages and books, which will be reimplemented
	soon in a more useful fashion.

	* src/dh-parser.c: (parser_start_node_book),
	(parser_start_node_chapter), (parser_start_node_keyword): Adapt to
	link changes.

	* src/dh-keyword-model.c: (dh_keyword_model_filter): Adapt to the
	link API changes. Also remove (instead of adapt) book/page-only
	searching in the keyword list, it does not belong here.


Modified:
   trunk/ChangeLog
   trunk/src/dh-keyword-model.c
   trunk/src/dh-link.c
   trunk/src/dh-link.h
   trunk/src/dh-parser.c

Modified: trunk/src/dh-keyword-model.c
==============================================================================
--- trunk/src/dh-keyword-model.c	(original)
+++ trunk/src/dh-keyword-model.c	Fri Oct  3 20:32:21 2008
@@ -467,9 +467,10 @@
 
         priv = model->priv;
 
-        /* here we want to change the contents of keyword_words,
-           call update on all rows that is included in the new
-           list and remove on all outside it */
+        /* Here we want to change the contents of keyword_words, call update
+         * on all rows that is included in the new list and remove on all
+         * outside it.
+         */
         old_length = g_list_length (priv->keyword_words);
 
         if (!strcmp ("", string)) {
@@ -482,20 +483,20 @@
                 case_sensitive = FALSE;
                 searchv        = stringv;
 
-                /* Search for any parameters and position search cursor
-                 * to the next element in the search string, also collect
-                 * a search string for exact matches.
+                /* Search for any parameters and position search cursor to
+                 * the next element in the search string, also collect a
+                 * search string for exact matches.
                  */
                 for (i = 0; stringv[i] != NULL; i++) {
 
                         if (stringv[i][0] == '\0')
                                 continue;
 
-                        /* Parse specifications insensitively
-                         */
+                        /* Parse specifications insensitively. */
                         lower = g_ascii_strdown (stringv[i], -1);
 
-                        /* Determine if there was a book or page specification
+                        /* Determine if there was a book or page
+                         * specification.
                          */
                         if (!strncmp (lower, "book:", 5)) {
                                 book_search = g_strdup (stringv[i] + 5);
@@ -505,10 +506,11 @@
                                 searchv++;
                         } else {
 
-                                /* determine wether or not we should search with case
-                                 * sensitivity, searches are case sensitive when upper
-                                 * case is used in the search terms, matching vim
-                                 * smartcase behaviour
+                                /* Determine wether or not we should search
+                                 * with case sensitivity, searches are case
+                                 * sensitive when upper case is used in the
+                                 * search terms, matching vim smartcase
+                                 * behaviour.
                                  */
                                 name = g_ascii_strdown (stringv[i], -1);
                                 if (strcmp (name, stringv[i])) {
@@ -516,8 +518,7 @@
                                 }
                                 g_free (name);
 
-                                /* Accumulate our search string
-                                 */
+                                /* Accumulate our search string. */
                                 if (search == NULL) {
                                         search = g_strdup (stringv[i]);
                                 } else {
@@ -529,95 +530,50 @@
                         g_free (lower);
                 }
 
-                /* Only return book and page matches with empty
-                 * search strings
-                 */
-                if (search == NULL) {
+                /* Now search keywords. */
+                for (node = priv->keys_list;
+                     node && hits < MAX_HITS;
+                     node = node->next) {
 
-                        if (book_search && !page_search) {
-                                /* Search books first */
-                                for (node = priv->book_list;
-                                     node && hits < MAX_HITS;
-                                     node = node->next) {
-
-                                        link = node->data;
-
-                                        if (strcmp (dh_link_get_book (link), book_search))
-                                                continue;
-
-                                        /* Found our book */
-                                        new_list = g_list_prepend (new_list, link);
-                                        hits++;
+                        link = node->data;
+                        found = FALSE;
 
-                                        exact_link = link;
+                        if (book_search &&
+                            strcmp (dh_link_get_book_name (link), book_search) != 0) {
+                                continue;
+                        }
+                        if (page_search &&
+                            strcmp (dh_link_get_page_name (link), page_search) != 0) {
+                                continue;
+                        }
 
-                                }
+                        if (!found) {
+                                found = TRUE;
 
-                                /* Currently, only searches that specify
-                                 * page & book return page indexes.
-                                 */
-                        } else if (book_search && page_search) {
-
-                                /* Now search pages */
-                                for (node = priv->page_list;
-                                     book_search && page_search &&
-                                             node && hits < MAX_HITS; node = node->next) {
-
-                                        link = node->data;
-
-                                        if (strcmp (dh_link_get_book (link), book_search))
-                                                continue;
-                                        if (strcmp (dh_link_get_page (link), page_search))
-                                                continue;
+                                for (i = 0; searchv[i] != NULL; i++) {
+                                        if (!case_sensitive) {
+                                                name = g_ascii_strdown (
+                                                        dh_link_get_name (link), -1);
+                                        } else {
+                                                name = g_strdup (dh_link_get_name (link));
+                                        }
 
-                                        /* Found our page */
-                                        new_list  = g_list_prepend (new_list, link);
-                                        exact_link = link;
-                                        hits++;
-                                }
-                        }
-                } else { /* if (search != NULL) */
-                        /* Now search keywords */
-                        for (node = priv->keys_list;
-                             node && hits < MAX_HITS;
-                             node = node->next) {
-
-                                link = node->data;
-                                found = FALSE;
-
-                                if (book_search && strcmp (dh_link_get_book (link), book_search))
-                                        continue;
-                                if (page_search && strcmp (dh_link_get_page (link), page_search))
-                                        continue;
-
-                                if (!found) {
-                                        found = TRUE;
-
-                                        for (i = 0; searchv[i] != NULL; i++) {
-                                                if (!case_sensitive) {
-                                                        name = g_ascii_strdown (
-                                                                dh_link_get_name (link), -1);
-                                                } else {
-                                                        name = g_strdup (dh_link_get_name (link));
-                                                }
-
-                                                if (!g_strrstr (name, searchv[i])) {
-                                                        found = FALSE;
-                                                        g_free (name);
-                                                        break;
-                                                }
+                                        if (!g_strrstr (name, searchv[i])) {
+                                                found = FALSE;
                                                 g_free (name);
+                                                break;
                                         }
+                                        g_free (name);
                                 }
+                        }
 
-                                if (found) {
-                                        /* Include in the new list */
-                                        new_list = g_list_prepend (new_list, link);
-                                        hits++;
+                        if (found) {
+                                /* Include in the new list */
+                                new_list = g_list_prepend (new_list, link);
+                                hits++;
 
-                                        if (search && strcmp (dh_link_get_name (link), search) == 0) {
-                                                exact_link = link;
-                                        }
+                                if (search && strcmp (dh_link_get_name (link), search) == 0) {
+                                        exact_link = link;
                                 }
                         }
                 }
@@ -642,13 +598,14 @@
 
         if (priv->keyword_words != priv->original_list) {
                 /* Only remove the old list if it's not pointing at the
-                   original list */
+                 * original list.
+                 */
                 g_list_free (priv->keyword_words);
         }
 
         priv->keyword_words = new_list;
 
-        /* Update rows 0 - new_length */
+        /* Update rows 0 - new_length. */
         for (i = 0; i < new_length; ++i) {
                 path = gtk_tree_path_new ();
                 gtk_tree_path_append_index (path, i);

Modified: trunk/src/dh-link.c
==============================================================================
--- trunk/src/dh-link.c	(original)
+++ trunk/src/dh-link.c	Fri Oct  3 20:32:21 2008
@@ -29,8 +29,8 @@
         gchar       *name;
         gchar       *uri;
 
-        gchar       *book;
-        gchar       *page;
+        DhLink      *book;
+        DhLink      *page;
 
         guint        ref_count;
 
@@ -56,8 +56,12 @@
 link_free (DhLink *link)
 {
 	g_free (link->name);
-	g_free (link->book);
-	g_free (link->page);
+        if (link->book) {
+                dh_link_unref (link->book);
+        }
+	if (link->page) {
+                dh_link_unref (link->page);
+        }
 	g_free (link->uri);
 
 	g_slice_free (DhLink, link);
@@ -66,8 +70,8 @@
 DhLink *
 dh_link_new (DhLinkType   type,
 	     const gchar *name,
-	     const gchar *book,
-	     const gchar *page,
+	     DhLink      *book,
+	     DhLink      *page,
 	     const gchar *uri)
 {
 	DhLink *link;
@@ -80,8 +84,12 @@
 	link->type = type;
 
 	link->name = g_strdup (name);
-	link->book = g_strdup (book);
-	link->page = g_strdup (page);
+	if (book) {
+                link->book = dh_link_ref (book);
+        }
+	if (page) {
+                link->page = dh_link_ref (page);
+        }
 	link->uri  = g_strdup (uri);
 
 	link->ref_count = 1;
@@ -93,11 +101,11 @@
 dh_link_compare  (gconstpointer a,
                   gconstpointer b)
 {
-        const DhLink *la = a;
-        const DhLink *lb = b;
-	gint          flags_diff;
-	gint          book_diff;
-	gint          page_diff;
+        DhLink *la = (DhLink *) a;
+        DhLink *lb = (DhLink *) b;
+	gint    flags_diff;
+	gint    book_diff;
+	gint    page_diff;
 
         /* Sort deprecated hits last. */
         flags_diff = (la->flags & DH_LINK_FLAGS_DEPRECATED) - 
@@ -106,15 +114,9 @@
                 return flags_diff;
         }
 
-	book_diff = strcmp (la->book, lb->book);
+	book_diff = strcmp (dh_link_get_book_name (la), dh_link_get_book_name (lb));
 	if (book_diff == 0) {
-		if (la->page == 0 && lb->page == 0) {
-			page_diff = 0;
-		} else {
-			page_diff = (la->page && lb->page) ?
-                                strcmp (la->page, lb->page) : -1;
-		}
-
+                page_diff = strcmp (dh_link_get_page_name (la), dh_link_get_page_name (lb));
 		if (page_diff == 0) {
 			return strcmp (la->name, lb->name);
                 }
@@ -154,15 +156,23 @@
 }
 
 const gchar *
-dh_link_get_book (DhLink *link)
+dh_link_get_book_name (DhLink *link)
 {
-        return link->book;
+        if (link->book) {
+                return link->book->name;
+        }
+
+        return "";
 }
 
 const gchar *
-dh_link_get_page (DhLink *link)
+dh_link_get_page_name (DhLink *link)
 {
-        return link->page;
+        if (link->page) {
+                return link->page->name;
+        }
+
+        return "";
 }
 
 const gchar *

Modified: trunk/src/dh-link.h
==============================================================================
--- trunk/src/dh-link.h	(original)
+++ trunk/src/dh-link.h	Fri Oct  3 20:32:21 2008
@@ -48,8 +48,8 @@
 GType        dh_link_get_type           (void);
 DhLink *     dh_link_new                (DhLinkType     type,
 					 const gchar   *name,
-					 const gchar   *book,
-					 const gchar   *page,
+                                         DhLink        *book,
+                                         DhLink        *page,
 					 const gchar   *uri);
 void         dh_link_free               (DhLink        *link);
 gint         dh_link_compare            (gconstpointer  a,
@@ -57,8 +57,8 @@
 DhLink *     dh_link_ref                (DhLink        *link);
 void         dh_link_unref              (DhLink        *link);
 const gchar *dh_link_get_name           (DhLink        *link);
-const gchar *dh_link_get_book           (DhLink        *link);
-const gchar *dh_link_get_page           (DhLink        *link);
+const gchar *dh_link_get_book_name      (DhLink        *link);
+const gchar *dh_link_get_page_name      (DhLink        *link);
 const gchar *dh_link_get_uri            (DhLink        *link);
 DhLinkFlags  dh_link_get_flags          (DhLink        *link);
 void         dh_link_set_flags          (DhLink        *link,

Modified: trunk/src/dh-parser.c
==============================================================================
--- trunk/src/dh-parser.c	(original)
+++ trunk/src/dh-parser.c	Fri Oct  3 20:32:21 2008
@@ -147,7 +147,7 @@
         }
 
         full_uri = g_strconcat (parser->base, "/", uri, NULL);
-        link = dh_link_new (DH_LINK_TYPE_BOOK, title, name, NULL, full_uri);
+        link = dh_link_new (DH_LINK_TYPE_BOOK, title, NULL, NULL, full_uri);
         g_free (full_uri);
 
         *parser->keywords = g_list_prepend (*parser->keywords, link);
@@ -207,8 +207,8 @@
         full_uri = g_strconcat (parser->base, "/", uri, NULL);
         page = extract_page_name (uri);
         link = dh_link_new (DH_LINK_TYPE_PAGE, name, 
-                            dh_link_get_book (parser->book_node->data),
-                            page, full_uri);
+                            parser->book_node->data,
+                            NULL, full_uri);
         g_free (full_uri);
         g_free (page);
 
@@ -353,8 +353,9 @@
         }
 
         link = dh_link_new (link_type, name, 
-                            dh_link_get_book (parser->book_node->data),
-                            page, full_uri);
+                            parser->book_node->data,
+                            parser->parent->data,
+                            full_uri);
 
         g_free (tmp);
         g_free (full_uri);



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