From 645b837f4d3fd5f81e78676b87e1f905024bac69 Mon Sep 17 00:00:00 2001 From: Jon Trowbridge Date: Sat, 11 Aug 2001 02:01:25 +0000 Subject: Properly handle "Category is" queries by checking the search bar 2001-08-10 Jon Trowbridge * gui/component/addressbook.c (addressbook_query_changed): Properly handle "Category is" queries by checking the search bar suboption. (addressbook_factory_new_control): Attach subitems corresponding to all wombat categories to the "Category is" ESearchBarItem. svn path=/trunk/; revision=11908 --- addressbook/gui/component/addressbook.c | 46 ++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'addressbook/gui/component') diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index c04a3218a1..03744c266e 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -21,6 +21,7 @@ #include #include +#include "e-util/e-categories-master-list-wombat.h" #include "select-names/e-select-names.h" #include "select-names/e-select-names-manager.h" @@ -637,16 +638,27 @@ static ESearchBarItem addressbook_search_option_items[] = { { N_("Any field contains"), ESB_ANY, NULL }, { N_("Name contains"), ESB_FULL_NAME, NULL }, { N_("Email contains"), ESB_EMAIL, NULL }, - { N_("Category contains"), ESB_CATEGORY, NULL }, + { N_("Category is"), ESB_CATEGORY, NULL }, /* We attach subitems below */ { N_("Advanced..."), ESB_ADVANCED, NULL }, { NULL, -1, NULL } }; +static ECategoriesMasterList *category_list = NULL; + +static ECategoriesMasterList * +get_master_list (void) +{ + if (category_list == NULL) + category_list = e_categories_master_list_wombat_new (); + return category_list; +} + static void addressbook_query_changed (ESearchBar *esb, AddressbookView *view) { - char *search_word, *search_query; - int search_type; + ECategoriesMasterList *master_list; + char *search_word, *search_query, *category_name; + int search_type, subopt; gtk_object_get(GTK_OBJECT(esb), "text", &search_word, @@ -657,7 +669,7 @@ addressbook_query_changed (ESearchBar *esb, AddressbookView *view) gtk_widget_show(e_addressbook_search_dialog_new(view->view)); } else { - if (search_word && strlen (search_word)) { + if ((search_word && strlen (search_word)) || search_type == ESB_CATEGORY) { switch (search_type) { case ESB_ANY: search_query = g_strdup_printf ("(contains \"x-evolution-any-field\" \"%s\")", @@ -672,8 +684,10 @@ addressbook_query_changed (ESearchBar *esb, AddressbookView *view) search_word); break; case ESB_CATEGORY: - search_query = g_strdup_printf ("(contains \"category\" \"%s\")", - search_word); + subopt = e_search_bar_get_suboption_choice (esb); + master_list = get_master_list (); + category_name = e_categories_master_list_nth (master_list, subopt); + search_query = g_strdup_printf ("(contains \"category\" \"%s\")", category_name); break; default: search_query = g_strdup ("(contains \"full_name\" \"\")"); @@ -771,6 +785,26 @@ addressbook_factory_new_control (void) /* Create the control. */ view->control = bonobo_control_new (view->vbox); + /* We attach subitems to the "Category is" item, so that we get an option menu of categories. */ + if (addressbook_search_option_items[ESB_CATEGORY].subitems == NULL) { + ESearchBarSubitem *subitems; + ECategoriesMasterList *master_list; + gint i, N; + + g_assert (addressbook_search_option_items[ESB_CATEGORY].id == ESB_CATEGORY); /* sanity check */ + + master_list = get_master_list (); + N = e_categories_master_list_count (master_list); + addressbook_search_option_items[ESB_CATEGORY].subitems = subitems = g_new (ESearchBarSubitem, N+1); + + for (i=0; isearch = E_SEARCH_BAR(e_search_bar_new(addressbook_search_menu_items, addressbook_search_option_items)); gtk_box_pack_start (GTK_BOX (view->vbox), GTK_WIDGET (view->search), -- cgit v1.2.3