devhelp r1122 - in trunk: . src



Author: rhult
Date: Sat Oct  4 14:02:40 2008
New Revision: 1122
URL: http://svn.gnome.org/viewvc/devhelp?rev=1122&view=rev

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

	* src/dh-keyword-model.[ch]: (keyword_model_finalize),
	(dh_keyword_model_set_words), (dh_keyword_model_filter): Get rid
	of unused copy of the keyword list. Remove support for filtering
	by book id through the search string and add an explicit book id
	instead.

	* src/dh-main.c: (extract_book_id), (search_normal),
	(search_assistant), (message_received_cb), (main): Parse the
	search string here and pass an explicit book id search term to the
	search functionality.

	* src/dh-search.[ch]: Remove the page search UI and replace the
	book search entry with a combo box, and adapt to this throughout
	the rest of the file.

	* src/dh-window.[ch]: (dh_window_search): Add book id parameter
	and pass it on when searching.


Modified:
   trunk/ChangeLog
   trunk/src/dh-keyword-model.c
   trunk/src/dh-keyword-model.h
   trunk/src/dh-main.c
   trunk/src/dh-search.c
   trunk/src/dh-search.h
   trunk/src/dh-window.c
   trunk/src/dh-window.h

Modified: trunk/src/dh-keyword-model.c
==============================================================================
--- trunk/src/dh-keyword-model.c	(original)
+++ trunk/src/dh-keyword-model.c	Sat Oct  4 14:02:40 2008
@@ -28,9 +28,6 @@
 
 struct _DhKeywordModelPriv {
         GList *original_list;
-
-        GList *keys_list;
-
         GList *keyword_words;
 
         gint   stamp;
@@ -166,7 +163,6 @@
         
         g_list_free (priv->keyword_words);
         g_list_free (priv->original_list);
-        g_list_free (priv->keys_list);
 
         g_free (model->priv);
 
@@ -394,42 +390,19 @@
                             GList          *keyword_words)
 {
         DhKeywordModelPriv *priv;
-        DhLink             *link;
-        GList              *list;
 
         g_return_if_fail (DH_IS_KEYWORD_MODEL (model));
 
         priv = model->priv;
 
         g_list_free (priv->original_list);
-        g_list_free (priv->keys_list);
-
         priv->original_list = g_list_copy (keyword_words);
-        priv->keys_list = NULL;
-
-        /* Parse it into usable lists. */
-        for (list = priv->original_list;
-             list; list = list->next) {
-                link = list->data;
-                switch (dh_link_get_link_type (link)) {
-                case DH_LINK_TYPE_KEYWORD:
-                case DH_LINK_TYPE_FUNCTION:
-                case DH_LINK_TYPE_STRUCT:
-                case DH_LINK_TYPE_MACRO:
-                case DH_LINK_TYPE_ENUM:
-                case DH_LINK_TYPE_TYPEDEF:
-                        priv->keys_list =
-                                g_list_prepend (priv->keys_list, link);
-                        break;
-                default:
-                        break;
-                }
-        }
 }
 
 DhLink *
 dh_keyword_model_filter (DhKeywordModel *model,
-                         const gchar    *string)
+                         const gchar    *string,
+                         const gchar    *book_id)
 {
         DhKeywordModelPriv  *priv;
         DhLink              *link;
@@ -445,7 +418,6 @@
         gboolean             case_sensitive;
         gchar               *lower, *name;
         gchar              **stringv, **searchv, *search = NULL;
-        gchar               *book_search;
 
         g_return_val_if_fail (DH_IS_KEYWORD_MODEL (model), NULL);
         g_return_val_if_fail (string != NULL, NULL);
@@ -463,61 +435,54 @@
         } else {
                 stringv = g_strsplit (string, " ", -1);
 
-                book_search    = NULL;
                 case_sensitive = FALSE;
-                searchv        = stringv;
+                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.
                  */
                 for (i = 0; stringv[i] != NULL; i++) {
-
-                        if (stringv[i][0] == '\0')
+                        if (stringv[i][0] == '\0') {
                                 continue;
+                        }
 
                         /* Parse specifications insensitively. */
                         lower = g_ascii_strdown (stringv[i], -1);
 
-                        /* Determine if there was a book. */
-                        if (!strncmp (lower, "book:", 5)) {
-                                book_search = g_strdup (stringv[i] + 5);
-                                searchv++;
+                        /* 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])) {
+                                case_sensitive = TRUE;
+                        }
+                        g_free (name);
+                        
+                        /* Accumulate our search string. */
+                        if (search == NULL) {
+                                search = g_strdup (stringv[i]);
                         } 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.
-                                 */
-                                name = g_ascii_strdown (stringv[i], -1);
-                                if (strcmp (name, stringv[i])) {
-                                        case_sensitive = TRUE;
-                                }
-                                g_free (name);
-
-                                /* Accumulate our search string. */
-                                if (search == NULL) {
-                                        search = g_strdup (stringv[i]);
-                                } else {
-                                        name = g_strdup_printf ("%s %s", search, stringv[i]);
-                                        g_free (search);
-                                        search = name;
-                                }
+                                name = g_strdup_printf ("%s %s", search, stringv[i]);
+                                g_free (search);
+                                search = name;
                         }
+
                         g_free (lower);
                 }
 
                 /* Now search keywords. */
-                for (node = priv->keys_list;
+                for (node = priv->original_list;
                      node && hits < MAX_HITS;
                      node = node->next) {
 
                         link = node->data;
                         found = FALSE;
 
-                        if (book_search &&
-                            strcmp (dh_link_get_book_id (link), book_search) != 0) {
+                        if (book_id &&
+                            strcmp (dh_link_get_book_id (link), book_id) != 0) {
                                 continue;
                         }
 
@@ -556,7 +521,6 @@
                 g_strfreev (stringv);
 
                 g_free (search);
-                g_free (book_search);
         }
 
         new_length = g_list_length (new_list);

Modified: trunk/src/dh-keyword-model.h
==============================================================================
--- trunk/src/dh-keyword-model.h	(original)
+++ trunk/src/dh-keyword-model.h	Sat Oct  4 14:02:40 2008
@@ -55,13 +55,12 @@
         DH_KEYWORD_MODEL_NUM_COLS
 };
 
-GtkType            dh_keyword_model_get_type     (void);
-
-DhKeywordModel *   dh_keyword_model_new          (void);
-void               dh_keyword_model_set_words    (DhKeywordModel  *model,
-                                                  GList           *keywords);
-
-DhLink *           dh_keyword_model_filter       (DhKeywordModel  *model,
-                                                  const gchar     *string);
+GtkType         dh_keyword_model_get_type  (void);
+DhKeywordModel *dh_keyword_model_new       (void);
+void            dh_keyword_model_set_words (DhKeywordModel *model,
+                                            GList          *keywords);
+DhLink *        dh_keyword_model_filter    (DhKeywordModel *model,
+                                            const gchar    *string,
+                                            const gchar    *book_id);
 
 #endif /* __DH_KEYWORD_MODEL_H__ */

Modified: trunk/src/dh-main.c
==============================================================================
--- trunk/src/dh-main.c	(original)
+++ trunk/src/dh-main.c	Sat Oct  4 14:02:40 2008
@@ -39,13 +39,66 @@
 #define COMMAND_RAISE            "raise"
 
 static void
+extract_book_id (const gchar  *str,
+                 gchar       **term,
+                 gchar       **book_id)
+{
+        gchar   **strv;
+        gint      i;
+        GString  *term_string;
+        
+        *term = NULL;
+        *book_id = NULL;
+
+        term_string = g_string_new (NULL);
+
+        strv = g_strsplit (str, " ", 0);
+
+        i = 0;
+        while (strv[i]) {
+                if (!*book_id && g_str_has_prefix (strv[i], "book:")) {
+                        *book_id = g_strdup (strv[i] + 5);
+                } else {
+                        if (i > 0 && term_string->len > 0) {
+                                g_string_append_c (term_string, ' ');
+                        }
+                        g_string_append (term_string, strv[i]);
+                }
+
+                i++;
+        }
+
+        g_strfreev (strv);
+
+        *term = g_string_free (term_string, FALSE);
+}
+
+static void
+search_normal (DhWindow    *window,
+               const gchar *str)
+{
+        gchar *term, *book_id;
+
+        if (str[0] == '\0') {
+                return;
+        }
+
+        extract_book_id (str, &term, &book_id);
+        dh_window_search (window, term, book_id);
+        g_free (term);
+        g_free (book_id);
+}
+
+static gboolean
 search_assistant (DhBase      *base,
                   const gchar *str)
 {
+        return FALSE;
 }
 
 static void
-message_received_cb (const gchar *message, DhBase *base)
+message_received_cb (const gchar *message,
+                     DhBase      *base)
 {
 	GtkWidget *window;
 	guint32    timestamp;
@@ -62,20 +115,10 @@
 		return;
 	}
 
-	/* Note: This is a bit strange. It seems like we need both the
-	 * gtk_window_present() and gtk_window_present_with_time() to make all
-	 * the cases working.
-	 */
-
-	window = dh_base_get_window_on_current_workspace (base);
-	if (!window) {
-		window = dh_base_new_window (base);
-		gtk_window_present (GTK_WINDOW (window));
-	}
-
+	window = dh_base_get_window (base);
 	if (g_str_has_prefix (message, COMMAND_SEARCH)) {
-		dh_window_search (DH_WINDOW (window),
-				  message + strlen (COMMAND_SEARCH) + 1);
+                search_normal (DH_WINDOW (window),
+                               message + strlen (COMMAND_SEARCH) + 1);
 	}
 	else if (strcmp (message, COMMAND_FOCUS_SEARCH) == 0) {
 		dh_window_focus_search (DH_WINDOW (window));
@@ -232,12 +275,14 @@
 		window = dh_base_new_window (base);
 
                 if (option_search) {
-                        dh_window_search (DH_WINDOW (window), option_search);
+                        search_normal (DH_WINDOW (window), option_search);
                 }
 
 		gtk_widget_show (window);
 	} else {
-		search_assistant (base, option_search_assistant);
+		if (!search_assistant (base, option_search_assistant)) {
+                        return 0;
+                }
 	}
 
 	gtk_main ();

Modified: trunk/src/dh-search.c
==============================================================================
--- trunk/src/dh-search.c	(original)
+++ trunk/src/dh-search.c	Sat Oct  4 14:02:40 2008
@@ -35,11 +35,6 @@
 
 #define d(x)
 
-typedef enum {
-        SEARCH_API    = 0,
-        SEARCH_ENTRY
-} DhSearchSource;
-
 typedef struct {
         DhKeywordModel *model;
 
@@ -47,7 +42,7 @@
 
         GtkWidget      *advanced_box;
 
-        GtkWidget      *book;
+        GtkWidget      *book_combo;
         GtkWidget      *entry;
         GtkWidget      *hitlist;
 
@@ -56,14 +51,9 @@
         guint           idle_complete;
         guint           idle_filter;
 
-        gboolean        first;
-
         guint           advanced_options_id;
 
-        GString        *book_str;
         GString        *entry_str;
-
-        DhSearchSource  search_source;
 } DhSearchPriv;
 
 static void         dh_search_init                    (DhSearch         *search);
@@ -81,6 +71,8 @@
 static gboolean     search_entry_key_press_event_cb   (GtkEntry         *entry,
                                                        GdkEventKey      *event,
                                                        DhSearch         *search);
+static void         search_combo_changed_cb           (GtkComboBox      *combo,
+                                                       DhSearch         *search);
 static void         search_entry_changed_cb           (GtkEntry         *entry,
                                                        DhSearch         *search);
 static void         search_entry_activated_cb         (GtkEntry         *entry,
@@ -93,7 +85,6 @@
 static gboolean     search_complete_idle              (DhSearch         *search);
 static gboolean     search_filter_idle                (DhSearch         *search);
 static const gchar *search_complete_func              (DhLink           *link);
-static gchar *      search_get_search_string          (DhSearch         *search);
 
 
 enum {
@@ -116,7 +107,6 @@
 
         priv = GET_PRIVATE (object);
 
-        g_string_free (priv->book_str, TRUE);
         g_string_free (priv->entry_str, TRUE);
 
         g_completion_free (priv->completion);
@@ -152,7 +142,6 @@
 {
         DhSearchPriv *priv = GET_PRIVATE (search);
 
-        priv->book_str = g_string_new ("");
         priv->entry_str = g_string_new ("");
 
         priv->completion = g_completion_new (
@@ -181,16 +170,8 @@
         advanced_options = gconf_client_get_bool (gconf_client,
                                                   GCONF_ADVANCED_OPTIONS,
                                                   NULL);
-        if (advanced_options) {
+        if (1 || advanced_options) {
                 gtk_widget_show (priv->advanced_box);
-
-                g_signal_handlers_block_by_func (priv->book, search_entry_changed_cb, search);
-
-                gtk_entry_set_text (GTK_ENTRY (priv->book),
-                                    priv->book_str->len > 5 ?
-                                    priv->book_str->str + 5 : "");
-
-                g_signal_handlers_unblock_by_func (priv->book, search_entry_changed_cb, search);
         } else {
                 gtk_widget_hide (priv->advanced_box);
         }
@@ -323,55 +304,89 @@
         return FALSE;
 }
 
-static gchar *
-search_get_search_string (DhSearch *search)
+static void
+search_combo_set_active_id (DhSearch    *search,
+                            const gchar *book_id)
 {
-        DhSearchPriv *priv = GET_PRIVATE (search);;
-        GString      *string;
+        DhSearchPriv *priv = GET_PRIVATE (search);
+        GtkTreeIter   iter;
+        GtkTreeModel *model;
+        gboolean      has_next;
 
-        string = g_string_new ("");
+        g_signal_handlers_block_by_func (priv->book_combo,
+                                         search_combo_changed_cb,
+                                         search);
+
+        if (book_id != NULL && GTK_WIDGET_VISIBLE (priv->advanced_box)) {
+                model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->book_combo));
+
+                has_next = gtk_tree_model_get_iter_first (model, &iter);
+                while (has_next) {
+                        gchar *id;
 
-        if (GTK_WIDGET_VISIBLE (priv->advanced_box) ||
-            priv->search_source == SEARCH_API) {
+                        gtk_tree_model_get (model, &iter,
+                                            1, &id,
+                                            -1);
+
+                        if (id && strcmp (book_id, id) == 0) {
+                                g_free (id);
+
+                                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->book_combo),
+                                                               &iter);
+                                break;
+                        }
+
+                        g_free (id);
 
-                if (priv->book_str->len > 0) {
-                        g_string_append (string, priv->book_str->str);
-                        g_string_append (string, " ");
+                        has_next = gtk_tree_model_iter_next (model, &iter);
                 }
+        } else {
+                gtk_combo_box_set_active (GTK_COMBO_BOX (priv->book_combo), 0);
+        }
+        
+        g_signal_handlers_unblock_by_func (priv->book_combo,
+                                           search_combo_changed_cb,
+                                           search);
+}
+
+static gchar *
+search_combo_get_active_id (DhSearch *search)
+{
+        DhSearchPriv *priv = GET_PRIVATE (search);
+        GtkTreeIter   iter;
+        GtkTreeModel *model;
+        gchar        *id;
+
+        if (!GTK_WIDGET_VISIBLE (priv->advanced_box)) {
+                return NULL;
         }
 
-        if (priv->entry_str->len > 0) {
-                g_string_append (string, priv->entry_str->str);
-                g_string_append (string, " ");
+        if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->book_combo),
+                                            &iter)) {
+                return NULL;
         }
 
-        return g_string_free (string, FALSE);
+        model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->book_combo));
+
+        gtk_tree_model_get (model, &iter,
+                            1, &id,
+                            -1);
+        
+        return id;
 }
 
 static void
-search_update_string (DhSearch *search,
-                      GtkEntry *entry)
+search_combo_changed_cb (GtkComboBox *combo,
+                         DhSearch    *search)
 {
-        const gchar  *str = gtk_entry_get_text (entry);
         DhSearchPriv *priv = GET_PRIVATE (search);
+        gchar        *id;
 
-        priv->search_source = SEARCH_ENTRY;
-
-        if (GTK_WIDGET (entry) == priv->book) {
-                if (str && str[0]) {
-                        g_string_printf (priv->book_str, "book:%s", str);
-                } else {
-                        g_string_set_size (priv->book_str, 0);
-                }
-        } else {
-                if (GTK_WIDGET_VISIBLE (priv->advanced_box) == FALSE) {
-                        g_string_set_size (priv->book_str, 0);
-                }
+        id = search_combo_get_active_id (search);
 
-                g_string_set_size (priv->entry_str, 0);
-                if (str && str[0]) {
-                        g_string_append (priv->entry_str, str);
-                }
+        if (!priv->idle_filter) {
+                priv->idle_filter =
+                        g_idle_add ((GSourceFunc) search_filter_idle, search);
         }
 }
 
@@ -383,8 +398,6 @@
 
         d(g_print ("Entry changed\n"));
 
-        search_update_string (search, entry);
-
         if (!priv->idle_filter) {
                 priv->idle_filter =
                         g_idle_add ((GSourceFunc) search_filter_idle, search);
@@ -396,13 +409,18 @@
                            DhSearch *search)
 {
         DhSearchPriv *priv = GET_PRIVATE (search);
+        gchar        *id;
+        const gchar  *str;
         DhLink       *link;
-        gchar        *str;
-
-        str = search_get_search_string (search);
-        link = dh_keyword_model_filter (priv->model, str);
 
-        g_free (str);
+        if (GTK_WIDGET_VISIBLE (priv->advanced_box)) {
+                id = search_combo_get_active_id (search);
+        } else {
+                id = NULL;
+        }
+        str = gtk_entry_get_text (GTK_ENTRY (priv->entry));
+        link = dh_keyword_model_filter (priv->model, str, id);
+        g_free (id);
 }
 
 static void
@@ -425,25 +443,21 @@
 search_complete_idle (DhSearch *search)
 {
         DhSearchPriv *priv = GET_PRIVATE (search);
-        const gchar  *text;
+        const gchar  *str;
         gchar        *completed = NULL;
         GList        *list;
-        gint          text_length;
+        gsize         length;
 
-        text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
-
-        list = g_completion_complete (priv->completion,
-                                      (gchar *)text,
-                                      &completed);
+        str = gtk_entry_get_text (GTK_ENTRY (priv->entry));
 
+        list = g_completion_complete (priv->completion, str, &completed);
         if (completed) {
-                text_length = strlen (text);
+                length = strlen (str);
 
                 gtk_entry_set_text (GTK_ENTRY (priv->entry), completed);
-                gtk_editable_set_position (GTK_EDITABLE (priv->entry),
-                                           text_length);
+                gtk_editable_set_position (GTK_EDITABLE (priv->entry), length);
                 gtk_editable_select_region (GTK_EDITABLE (priv->entry),
-                                            text_length, -1);
+                                            length, -1);
         }
 
         priv->idle_complete = 0;
@@ -455,14 +469,20 @@
 search_filter_idle (DhSearch *search)
 {
         DhSearchPriv *priv = GET_PRIVATE (search);
-        gchar        *str;
+        const gchar  *str;
+        gchar        *id;
         DhLink       *link;
 
         d(g_print ("Filter idle\n"));
 
-        str = search_get_search_string (search);
-        link = dh_keyword_model_filter (priv->model, str);
-        g_free (str);
+        str = gtk_entry_get_text (GTK_ENTRY (priv->entry));
+        if (GTK_WIDGET_VISIBLE (priv->advanced_box)) {
+                id = search_combo_get_active_id (search);
+        } else {
+                id = NULL;
+        }
+        link = dh_keyword_model_filter (priv->model, str, id);
+        g_free (id);
 
         priv->idle_filter = 0;
 
@@ -513,6 +533,54 @@
         g_free (name);
 }
 
+static GtkWidget *
+search_combo_create (DhSearch *search,
+                     GList    *keywords)
+{
+        GtkTreeIter      iter;
+        GtkListStore    *store;
+        GList           *l;
+        GtkWidget       *combo;
+        GtkCellRenderer *cell;
+
+        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+
+        gtk_list_store_append (store, &iter); 
+        gtk_list_store_set (store, &iter,
+                            0, _("All books"),
+                            1, NULL,
+                            -1);
+
+        for (l = keywords; l; l = l->next) {
+                DhLink *link = l->data;
+
+                if (dh_link_get_link_type (link) != DH_LINK_TYPE_BOOK) {
+                        continue;
+                }
+
+                gtk_list_store_append (store, &iter); 
+                gtk_list_store_set (store, &iter,
+                                    0, dh_link_get_name (link),
+                                    1, dh_link_get_book_id (link),
+                                    -1);
+        }
+
+        combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
+        g_object_unref (store);
+
+        cell = gtk_cell_renderer_text_new ();
+        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo),
+                                    cell,
+                                    TRUE);
+        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo),
+                                       cell,
+                                       "text", 0);
+
+        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+
+        return combo;
+}
+
 GtkWidget *
 dh_search_new (GList *keywords)
 {
@@ -532,24 +600,20 @@
 
         gtk_container_set_border_width (GTK_CONTAINER (search), 2);
 
-        /* Setup the book box */
-        priv->book = gtk_entry_new ();
-        g_signal_connect (priv->book, "changed",
-                          G_CALLBACK (search_entry_changed_cb),
-                          search);
-        g_signal_connect (priv->book, "activate",
-                          G_CALLBACK (search_entry_activated_cb),
+        priv->book_combo = search_combo_create (search, keywords);
+        g_signal_connect (priv->book_combo, "changed",
+                          G_CALLBACK (search_combo_changed_cb),
                           search);
 
         book_label = gtk_label_new_with_mnemonic (_("_Book:"));
-        gtk_label_set_mnemonic_widget (GTK_LABEL (book_label), priv->book);
+        gtk_label_set_mnemonic_widget (GTK_LABEL (book_label), priv->book_combo);
 
         priv->advanced_box = gtk_vbox_new (FALSE, 2);
         gtk_box_pack_start (GTK_BOX (search), priv->advanced_box, FALSE, FALSE, 0);
 
         hbox = gtk_hbox_new (FALSE, 6);
         gtk_box_pack_start (GTK_BOX (hbox), book_label, FALSE, FALSE, 0);
-        gtk_box_pack_start (GTK_BOX (hbox), priv->book, TRUE, TRUE, 0);
+        gtk_box_pack_start (GTK_BOX (hbox), priv->book_combo, TRUE, TRUE, 0);
         gtk_box_pack_start (GTK_BOX (priv->advanced_box), hbox, FALSE, FALSE, 0);
 
         gtk_widget_show_all (priv->advanced_box);
@@ -636,83 +700,32 @@
 
 void
 dh_search_set_search_string (DhSearch    *search,
-                             const gchar *str)
+                             const gchar *str,
+                             const gchar *book_id)
 {
-        DhSearchPriv  *priv;
-        gchar        **split, **leftover, *lower;
-        gchar         *string = NULL;
-        gint           i;
+        DhSearchPriv *priv;
 
         g_return_if_fail (DH_IS_SEARCH (search));
 
         priv = GET_PRIVATE (search);
 
-        priv->search_source = SEARCH_API;
-
-        g_string_set_size (priv->book_str, 0);
         g_string_set_size (priv->entry_str, 0);
+        g_string_append (priv->entry_str, str);
 
-        g_signal_handlers_block_by_func (priv->book, search_entry_changed_cb, search);
-        g_signal_handlers_block_by_func (priv->entry, search_entry_changed_cb, search);
-
-        if ((leftover = split = g_strsplit (str, " ", -1)) != NULL) {
+        g_signal_handlers_block_by_func (priv->entry,
+                                         search_entry_changed_cb,
+                                         search);
 
-                for (i = 0; split[i] != NULL; i++) {
-
-                        lower = g_ascii_strdown (split[i], -1);
-
-                        /* Determine if there was a book specification. */
-                        if (!strncmp (lower, "book:", 5)) {
-                                g_string_append (priv->book_str, split[i]);
-                                leftover++;
-                        } else {
-                                /* No more specifications */
-                                break;
-                        }
-
-                        g_free (lower);
-                }
-
-                /* Collect the search string */
-                string = NULL;
-                for (i = 0; leftover[i] != NULL; i++) {
-                        if (string == NULL) {
-                                string = g_strdup (leftover[i]);
-                        } else {
-                                lower = g_strdup_printf ("%s %s", string, leftover[i]);
-                                g_free (string);
-                                string = lower;
-                        }
-                }
-
-                g_strfreev (split);
-
-                if (string) {
-                        g_string_append (priv->entry_str, string);
-                }
-
-                if (string) {
-                        g_free (string);
-                }
-
-        } else if (str) {
-                g_string_append (priv->entry_str, str);
-        }
-
-        gtk_entry_set_text (GTK_ENTRY (priv->entry),
-                            priv->entry_str->str);
-
-        if (GTK_WIDGET_VISIBLE (priv->advanced_box)) {
-                gtk_entry_set_text (GTK_ENTRY (priv->book),
-                                    priv->book_str->len > 5 ?
-                                    priv->book_str->str + 5 : "");
-        }
+        gtk_entry_set_text (GTK_ENTRY (priv->entry), priv->entry_str->str);
 
         gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1);
         gtk_editable_select_region (GTK_EDITABLE (priv->entry), -1, -1);
 
-        g_signal_handlers_unblock_by_func (priv->book, search_entry_changed_cb, search);
-        g_signal_handlers_unblock_by_func (priv->entry, search_entry_changed_cb, search);
+        g_signal_handlers_unblock_by_func (priv->entry,
+                                           search_entry_changed_cb,
+                                           search);
+
+        search_combo_set_active_id (search, book_id);
 
         if (!priv->idle_filter) {
                 priv->idle_filter =

Modified: trunk/src/dh-search.h
==============================================================================
--- trunk/src/dh-search.h	(original)
+++ trunk/src/dh-search.h	Sat Oct  4 14:02:40 2008
@@ -49,7 +49,8 @@
 GType      dh_search_get_type              (void);
 GtkWidget *dh_search_new                   (GList       *keywords);
 void       dh_search_set_search_string     (DhSearch    *search,
-                                            const gchar *str);
+                                            const gchar *str,
+                                            const gchar *book_id);
 void       dh_search_grab_focus            (DhSearch    *search);
 void       dh_search_show_advanced_options (DhSearch    *search,
                                             gboolean     show);

Modified: trunk/src/dh-window.c
==============================================================================
--- trunk/src/dh-window.c	(original)
+++ trunk/src/dh-window.c	Sat Oct  4 14:02:40 2008
@@ -1472,7 +1472,8 @@
 
 void
 dh_window_search (DhWindow    *window,
-                  const gchar *str)
+                  const gchar *str,
+                  const gchar *book_id)
 {
         DhWindowPriv *priv;
 
@@ -1481,8 +1482,7 @@
         priv = window->priv;
 
         gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->control_notebook), 1);
-
-        dh_search_set_search_string (DH_SEARCH (priv->search), str);
+        dh_search_set_search_string (DH_SEARCH (priv->search), str, book_id);
 }
 
 void

Modified: trunk/src/dh-window.h
==============================================================================
--- trunk/src/dh-window.h	(original)
+++ trunk/src/dh-window.h	Sat Oct  4 14:02:40 2008
@@ -49,7 +49,8 @@
 GType      dh_window_get_type     (void) G_GNUC_CONST;
 GtkWidget *dh_window_new          (DhBase      *base);
 void       dh_window_search       (DhWindow    *window,
-                                   const gchar *str);
+                                   const gchar *str,
+                                   const gchar *book_id);
 void       dh_window_focus_search (DhWindow    *window);
 void       _dh_window_display_uri (DhWindow    *window,
                                    const gchar *uri);



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