diff options
author | Milan Crha <mcrha@redhat.com> | 2009-12-11 04:12:48 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2009-12-11 04:12:48 +0800 |
commit | 223c2f4a75c5423db244430ca3630717e2735a52 (patch) | |
tree | 962dc68f7636586f2224f131a7ecd306d53b7589 /modules/addressbook | |
parent | 4a9bf4dffd98346f9eee848708df573df56ed1d6 (diff) | |
download | gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.gz gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.bz2 gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.lz gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.xz gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.zst gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.zip |
Bug #602998 - Contacts searches are supposed to be per address book
Diffstat (limited to 'modules/addressbook')
-rw-r--r-- | modules/addressbook/e-book-shell-content.c | 30 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-private.c | 3 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-private.h | 2 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view.c | 54 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view.h | 3 |
5 files changed, 83 insertions, 9 deletions
diff --git a/modules/addressbook/e-book-shell-content.c b/modules/addressbook/e-book-shell-content.c index f5b147bf0d..46d9824f2e 100644 --- a/modules/addressbook/e-book-shell-content.c +++ b/modules/addressbook/e-book-shell-content.c @@ -28,6 +28,7 @@ #include "e-util/gconf-bridge.h" #include "shell/e-shell-utils.h" #include "widgets/misc/e-paned.h" +#include "e-book-shell-view.h" #define E_BOOK_SHELL_CONTENT_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ @@ -519,9 +520,10 @@ void e_book_shell_content_set_current_view (EBookShellContent *book_shell_content, EAddressbookView *addressbook_view) { + EBookShellView *book_shell_view; GtkNotebook *notebook; GtkWidget *child; - gint page_num; + gint page_num, old_page_num; g_return_if_fail (E_IS_BOOK_SHELL_CONTENT (book_shell_content)); g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (addressbook_view)); @@ -531,7 +533,33 @@ e_book_shell_content_set_current_view (EBookShellContent *book_shell_content, page_num = gtk_notebook_page_num (notebook, child); g_return_if_fail (page_num >= 0); + old_page_num = gtk_notebook_get_current_page (notebook); gtk_notebook_set_current_page (notebook, page_num); + + if (old_page_num != page_num) { + EShellContent *shell_content; + gint filter_id = 0, search_id = 0; + gchar *search_text = NULL; + EFilterRule *advanced_search = NULL; + GtkRadioAction *radio_action; + + shell_content = E_SHELL_CONTENT (book_shell_content); + book_shell_view = E_BOOK_SHELL_VIEW (e_shell_content_get_shell_view (shell_content)); + + e_book_shell_view_disable_searching (book_shell_view); + e_addressbook_view_get_search (addressbook_view, &filter_id, &search_id, &search_text, &advanced_search); + if (e_shell_content_get_filter_action (shell_content)) + e_shell_content_set_filter_value (shell_content, filter_id); + radio_action = e_shell_content_get_search_radio_action (shell_content); + gtk_radio_action_set_current_value (radio_action, search_id); + e_shell_content_set_search_text (shell_content, search_text ? search_text : ""); + e_shell_content_set_search_rule (shell_content, advanced_search); + g_free (search_text); + if (advanced_search) + g_object_unref (advanced_search); + e_book_shell_view_enable_searching (book_shell_view); + } + g_object_notify (G_OBJECT (book_shell_content), "current-view"); } diff --git a/modules/addressbook/e-book-shell-view-private.c b/modules/addressbook/e-book-shell-view-private.c index 279cf87cf6..5b71c3c555 100644 --- a/modules/addressbook/e-book-shell-view-private.c +++ b/modules/addressbook/e-book-shell-view-private.c @@ -242,6 +242,9 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, widget = e_addressbook_view_new (shell_view, source); gtk_widget_show (widget); + /* default searching options for a new view */ + e_addressbook_view_set_search (E_ADDRESSBOOK_VIEW (widget), CONTACT_FILTER_ANY_CATEGORY, CONTACT_SEARCH_NAME_CONTAINS, NULL, NULL); + e_book_shell_content_insert_view ( book_shell_content, E_ADDRESSBOOK_VIEW (widget)); diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h index 6d513aa273..f1b23c2cfb 100644 --- a/modules/addressbook/e-book-shell-view-private.h +++ b/modules/addressbook/e-book-shell-view-private.h @@ -108,6 +108,8 @@ struct _EBookShellViewPrivate { GHashTable *uid_to_editor; gint preview_index; + + gint search_locked; /* can track whether search changed while locked, but it is not usable at the moment */ }; void e_book_shell_view_private_init diff --git a/modules/addressbook/e-book-shell-view.c b/modules/addressbook/e-book-shell-view.c index 6c4c4303d1..ebbf3e79d0 100644 --- a/modules/addressbook/e-book-shell-view.c +++ b/modules/addressbook/e-book-shell-view.c @@ -132,20 +132,28 @@ book_shell_view_execute_search (EShellView *shell_view) EAddressbookModel *model; gchar *query; gchar *temp; - gint value; + gint filter_id, search_id; + gchar *search_text = NULL; + EFilterRule *advanced_search = NULL; priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (shell_view); + if (priv->search_locked) + return; + shell_content = e_shell_view_get_shell_content (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); action = GTK_RADIO_ACTION (ACTION (CONTACT_SEARCH_ANY_FIELD_CONTAINS)); - value = gtk_radio_action_get_current_value (action); + search_id = gtk_radio_action_get_current_value (action); - if (value == CONTACT_SEARCH_ADVANCED) { + if (search_id == CONTACT_SEARCH_ADVANCED) { query = e_shell_content_get_search_rule_as_string (shell_content); if (!query) query = g_strdup (""); + + /* internal pointer, no need to free it */ + advanced_search = e_shell_content_get_search_rule (shell_content); } else { const gchar *text; const gchar *format; @@ -155,10 +163,12 @@ book_shell_view_execute_search (EShellView *shell_view) if (text == NULL || *text == '\0') { text = ""; - value = CONTACT_SEARCH_ANY_FIELD_CONTAINS; + search_id = CONTACT_SEARCH_ANY_FIELD_CONTAINS; } - switch (value) { + search_text = text && *text ? g_strdup (text) : NULL; + + switch (search_id) { case CONTACT_SEARCH_NAME_CONTAINS: format = "(contains \"full_name\" %s)"; break; @@ -184,8 +194,8 @@ book_shell_view_execute_search (EShellView *shell_view) } /* Apply selected filter. */ - value = e_shell_content_get_filter_value (shell_content); - switch (value) { + filter_id = e_shell_content_get_filter_value (shell_content); + switch (filter_id) { case CONTACT_FILTER_ANY_CATEGORY: break; @@ -204,7 +214,7 @@ book_shell_view_execute_search (EShellView *shell_view) const gchar *category_name; categories = e_categories_get_list (); - category_name = g_list_nth_data (categories, value); + category_name = g_list_nth_data (categories, filter_id); g_list_free (categories); temp = g_strdup_printf ( @@ -220,7 +230,9 @@ book_shell_view_execute_search (EShellView *shell_view) view = e_book_shell_content_get_current_view (book_shell_content); model = e_addressbook_view_get_model (view); e_addressbook_model_set_query (model, query); + e_addressbook_view_set_search (view, filter_id, search_id, search_text, advanced_search); g_free (query); + g_free (search_text); e_book_shell_content_set_preview_contact (book_shell_content, NULL); priv->preview_index = -1; @@ -441,3 +453,29 @@ e_book_shell_view_register_type (GTypeModule *type_module) type_module, E_TYPE_SHELL_VIEW, "EBookShellView", &type_info, 0); } + +void +e_book_shell_view_disable_searching (EBookShellView *book_shell_view) +{ + EBookShellViewPrivate *priv; + + g_return_if_fail (book_shell_view != NULL); + g_return_if_fail (E_IS_BOOK_SHELL_VIEW (book_shell_view)); + + priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (book_shell_view); + priv->search_locked++; +} + +void +e_book_shell_view_enable_searching (EBookShellView *book_shell_view) +{ + EBookShellViewPrivate *priv; + + g_return_if_fail (book_shell_view != NULL); + g_return_if_fail (E_IS_BOOK_SHELL_VIEW (book_shell_view)); + + priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (book_shell_view); + g_return_if_fail (priv->search_locked > 0); + + priv->search_locked--; +} diff --git a/modules/addressbook/e-book-shell-view.h b/modules/addressbook/e-book-shell-view.h index 33a0c8a75d..a5e726b422 100644 --- a/modules/addressbook/e-book-shell-view.h +++ b/modules/addressbook/e-book-shell-view.h @@ -61,6 +61,9 @@ struct _EBookShellViewClass { GType e_book_shell_view_get_type (void); void e_book_shell_view_register_type (GTypeModule *type_module); +void e_book_shell_view_disable_searching (EBookShellView *book_shell_view); +void e_book_shell_view_enable_searching (EBookShellView *book_shell_view); + G_END_DECLS #endif /* E_BOOK_SHELL_VIEW_H */ |