diff options
author | Milan Crha <mcrha@redhat.com> | 2009-11-19 22:40:50 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2009-11-19 22:40:50 +0800 |
commit | aa813bd7cadffa0110ddeeecd2b8df9d367db6e1 (patch) | |
tree | 8580dce61f4952b17225fa5262339432db092e4c /modules | |
parent | 72861cffee5a3f9a5434fe0a94c7ec60beec1cc2 (diff) | |
download | gsoc2013-evolution-aa813bd7cadffa0110ddeeecd2b8df9d367db6e1.tar.gz gsoc2013-evolution-aa813bd7cadffa0110ddeeecd2b8df9d367db6e1.tar.zst gsoc2013-evolution-aa813bd7cadffa0110ddeeecd2b8df9d367db6e1.zip |
Bug #579599 - Let the Advanced Search work again
Diffstat (limited to 'modules')
20 files changed, 241 insertions, 298 deletions
diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c index 41b88efbc6..85db9d58e8 100644 --- a/modules/addressbook/e-book-shell-view-actions.c +++ b/modules/addressbook/e-book-shell-view-actions.c @@ -599,29 +599,6 @@ exit: } static void -action_contact_search_cb (GtkRadioAction *action, - GtkRadioAction *current, - EBookShellView *book_shell_view) -{ - EShellView *shell_view; - EShellContent *shell_content; - const gchar *search_hint; - - /* XXX Figure out a way to handle this in EShellContent - * instead of every shell view having to handle it. - * The problem is EShellContent does not know what - * the search option actions are for this view. It - * would have to dig up the popup menu and retrieve - * the action for each menu item. Seems messy. */ - - shell_view = E_SHELL_VIEW (book_shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - - search_hint = gtk_action_get_label (GTK_ACTION (current)); - e_shell_content_set_search_hint (shell_content, search_hint); -} - -static void action_contact_select_all_cb (GtkAction *action, EBookShellView *book_shell_view) { @@ -994,6 +971,13 @@ static GtkRadioActionEntry contact_filter_entries[] = { static GtkRadioActionEntry contact_search_entries[] = { + { "contact-search-advanced-hidden", + NULL, + N_("Advanced search"), + NULL, + NULL, + CONTACT_SEARCH_ADVANCED }, + { "contact-search-any-field-contains", NULL, N_("Any field contains"), @@ -1074,6 +1058,7 @@ e_book_shell_view_actions_init (EBookShellView *book_shell_view) GtkActionGroup *action_group; GConfBridge *bridge; GtkAction *action; + GtkRadioAction *radio_action; GObject *object; const gchar *key; @@ -1101,8 +1086,13 @@ e_book_shell_view_actions_init (EBookShellView *book_shell_view) gtk_action_group_add_radio_actions ( action_group, contact_search_entries, G_N_ELEMENTS (contact_search_entries), - CONTACT_SEARCH_NAME_CONTAINS, - G_CALLBACK (action_contact_search_cb), book_shell_view); + -1, NULL, NULL); + + /* Advanced Search action */ + radio_action = GTK_RADIO_ACTION (ACTION (CONTACT_SEARCH_ADVANCED_HIDDEN)); + e_shell_content_set_search_radio_action (e_shell_view_get_shell_content (shell_view), radio_action); + gtk_action_set_visible (GTK_ACTION (radio_action), FALSE); + gtk_radio_action_set_current_value (radio_action, CONTACT_SEARCH_NAME_CONTAINS); /* Lockdown Printing Actions */ action_group = ACTION_GROUP (LOCKDOWN_PRINTING); diff --git a/modules/addressbook/e-book-shell-view-actions.h b/modules/addressbook/e-book-shell-view-actions.h index e5eea1fb5a..98cd8b6689 100644 --- a/modules/addressbook/e-book-shell-view-actions.h +++ b/modules/addressbook/e-book-shell-view-actions.h @@ -81,6 +81,8 @@ E_SHELL_WINDOW_ACTION ((window), "contact-view-vertical") /* Search Actions */ +#define E_SHELL_WINDOW_ACTION_CONTACT_SEARCH_ADVANCED_HIDDEN(window) \ + E_SHELL_WINDOW_ACTION ((window), "contact-search-advanced-hidden") #define E_SHELL_WINDOW_ACTION_CONTACT_SEARCH_ANY_FIELD_CONTAINS(window) \ E_SHELL_WINDOW_ACTION ((window), "contact-search-any-field-contains") #define E_SHELL_WINDOW_ACTION_CONTACT_SEARCH_EMAIL_BEGINS_WITH(window) \ diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h index c1aa300739..6d513aa273 100644 --- a/modules/addressbook/e-book-shell-view-private.h +++ b/modules/addressbook/e-book-shell-view-private.h @@ -91,6 +91,7 @@ enum { /* List these in the order to be displayed. */ enum { + CONTACT_SEARCH_ADVANCED = -1, CONTACT_SEARCH_NAME_CONTAINS, CONTACT_SEARCH_EMAIL_BEGINS_WITH, CONTACT_SEARCH_ANY_FIELD_CONTAINS diff --git a/modules/addressbook/e-book-shell-view.c b/modules/addressbook/e-book-shell-view.c index e7d26d727d..663f2a109e 100644 --- a/modules/addressbook/e-book-shell-view.c +++ b/modules/addressbook/e-book-shell-view.c @@ -128,11 +128,8 @@ book_shell_view_execute_search (EShellView *shell_view) EShellWindow *shell_window; EShellContent *shell_content; GtkRadioAction *action; - GString *string; EAddressbookView *view; EAddressbookModel *model; - const gchar *format; - const gchar *text; gchar *query; gchar *temp; gint value; @@ -140,40 +137,51 @@ book_shell_view_execute_search (EShellView *shell_view) priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (shell_view); shell_content = e_shell_view_get_shell_content (shell_view); - text = e_shell_content_get_search_text (shell_content); - 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); - if (text == NULL || *text == '\0') { - text = ""; - value = CONTACT_SEARCH_ANY_FIELD_CONTAINS; - } + if (value == CONTACT_SEARCH_ADVANCED) { + query = e_shell_content_get_search_rule_as_string (shell_content); - switch (value) { - case CONTACT_SEARCH_NAME_CONTAINS: - format = "(contains \"full_name\" %s)"; - break; + if (!query) + query = g_strdup (""); + } else { + const gchar *text; + const gchar *format; + GString *string; - case CONTACT_SEARCH_EMAIL_BEGINS_WITH: - format = "(beginswith \"email\" %s)"; - break; + text = e_shell_content_get_search_text (shell_content); - default: + if (text == NULL || *text == '\0') { text = ""; - /* fall through */ + value = CONTACT_SEARCH_ANY_FIELD_CONTAINS; + } - case CONTACT_SEARCH_ANY_FIELD_CONTAINS: - format = "(contains \"x-evolution-any-field\" %s)"; - break; - } + switch (value) { + case CONTACT_SEARCH_NAME_CONTAINS: + format = "(contains \"full_name\" %s)"; + break; + + case CONTACT_SEARCH_EMAIL_BEGINS_WITH: + format = "(beginswith \"email\" %s)"; + break; - /* Build the query. */ - string = g_string_new (""); - e_sexp_encode_string (string, text); - query = g_strdup_printf (format, string->str); - g_string_free (string, TRUE); + default: + text = ""; + /* fall through */ + + case CONTACT_SEARCH_ANY_FIELD_CONTAINS: + format = "(contains \"x-evolution-any-field\" %s)"; + break; + } + + /* Build the query. */ + string = g_string_new (""); + e_sexp_encode_string (string, text); + query = g_strdup_printf (format, string->str); + g_string_free (string, TRUE); + } /* Apply selected filter. */ value = e_shell_content_get_filter_value (shell_content); @@ -207,11 +215,6 @@ book_shell_view_execute_search (EShellView *shell_view) } } - /* XXX This is wrong. We need to programmatically construct an - * EFilterRule, tell it to build code, and pass the resulting - * expression string to EAddressbookModel. */ - e_shell_content_set_search_rule (shell_content, NULL); - /* Submit the query. */ book_shell_content = E_BOOK_SHELL_CONTENT (shell_content); view = e_book_shell_content_get_current_view (book_shell_content); diff --git a/modules/calendar/e-cal-shell-view-actions.c b/modules/calendar/e-cal-shell-view-actions.c index bc0fcc00e5..e88fae7eb9 100644 --- a/modules/calendar/e-cal-shell-view-actions.c +++ b/modules/calendar/e-cal-shell-view-actions.c @@ -363,29 +363,6 @@ action_calendar_rename_cb (GtkAction *action, } static void -action_calendar_search_cb (GtkRadioAction *action, - GtkRadioAction *current, - ECalShellView *cal_shell_view) -{ - EShellView *shell_view; - EShellContent *shell_content; - const gchar *search_hint; - - /* XXX Figure out a way to handle this in EShellContent - * instead of every shell view having to handle it. - * The problem is EShellContent does not know what - * the search option actions are for this view. It - * would have to dig up the popup menu and retrieve - * the action for each menu item. Seems messy. */ - - shell_view = E_SHELL_VIEW (cal_shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - - search_hint = gtk_action_get_label (GTK_ACTION (current)); - e_shell_content_set_search_hint (shell_content, search_hint); -} - -static void action_calendar_select_one_cb (GtkAction *action, ECalShellView *cal_shell_view) { @@ -1588,6 +1565,13 @@ static GtkRadioActionEntry calendar_filter_entries[] = { static GtkRadioActionEntry calendar_search_entries[] = { + { "calendar-search-advanced-hidden", + NULL, + N_("Advanced search"), + NULL, + NULL, + CALENDAR_SEARCH_ADVANCED }, + { "calendar-search-any-field-contains", NULL, N_("Any field contains"), @@ -1648,6 +1632,7 @@ e_cal_shell_view_actions_init (ECalShellView *cal_shell_view) EShellWindow *shell_window; GtkActionGroup *action_group; GtkAction *action; + GtkRadioAction *radio_action; shell_view = E_SHELL_VIEW (cal_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); @@ -1667,8 +1652,13 @@ e_cal_shell_view_actions_init (ECalShellView *cal_shell_view) gtk_action_group_add_radio_actions ( action_group, calendar_search_entries, G_N_ELEMENTS (calendar_search_entries), - CALENDAR_SEARCH_SUMMARY_CONTAINS, - G_CALLBACK (action_calendar_search_cb), cal_shell_view); + -1, NULL, NULL); + + /* Advanced Search action */ + radio_action = GTK_RADIO_ACTION (ACTION (CALENDAR_SEARCH_ADVANCED_HIDDEN)); + e_shell_content_set_search_radio_action (e_shell_view_get_shell_content (shell_view), radio_action); + gtk_action_set_visible (GTK_ACTION (radio_action), FALSE); + gtk_radio_action_set_current_value (radio_action, CALENDAR_SEARCH_SUMMARY_CONTAINS); /* Lockdown Printing Actions */ action_group = ACTION_GROUP (LOCKDOWN_PRINTING); diff --git a/modules/calendar/e-cal-shell-view-actions.h b/modules/calendar/e-cal-shell-view-actions.h index e05649397e..840985b03a 100644 --- a/modules/calendar/e-cal-shell-view-actions.h +++ b/modules/calendar/e-cal-shell-view-actions.h @@ -151,6 +151,8 @@ E_SHELL_WINDOW_ACTION ((window), "calendar-filter-next-7-days-appointments") #define E_SHELL_WINDOW_ACTION_CALENDAR_FILTER_UNMATCHED(window) \ E_SHELL_WINDOW_ACTION ((window), "calendar-filter-unmatched") +#define E_SHELL_WINDOW_ACTION_CALENDAR_SEARCH_ADVANCED_HIDDEN(window) \ + E_SHELL_WINDOW_ACTION ((window), "calendar-search-advanced-hidden") #define E_SHELL_WINDOW_ACTION_CALENDAR_SEARCH_ANY_FIELD_CONTAINS(window) \ E_SHELL_WINDOW_ACTION ((window), "calendar-search-any-field-contains") #define E_SHELL_WINDOW_ACTION_CALENDAR_SEARCH_DESCRIPTION_CONTAINS(window) \ diff --git a/modules/calendar/e-cal-shell-view-private.h b/modules/calendar/e-cal-shell-view-private.h index 1f447bc162..c92fb8cffe 100644 --- a/modules/calendar/e-cal-shell-view-private.h +++ b/modules/calendar/e-cal-shell-view-private.h @@ -95,6 +95,7 @@ enum { /* Search items are displayed in ascending order. */ enum { + CALENDAR_SEARCH_ADVANCED = -1, CALENDAR_SEARCH_SUMMARY_CONTAINS, CALENDAR_SEARCH_DESCRIPTION_CONTAINS, CALENDAR_SEARCH_ANY_FIELD_CONTAINS diff --git a/modules/calendar/e-cal-shell-view.c b/modules/calendar/e-cal-shell-view.c index 44e0883527..f767f92ec6 100644 --- a/modules/calendar/e-cal-shell-view.c +++ b/modules/calendar/e-cal-shell-view.c @@ -62,9 +62,6 @@ cal_shell_view_execute_search (EShellView *shell_view) GnomeCalendar *calendar; ECalendar *date_navigator; GtkRadioAction *action; - GString *string; - const gchar *format; - const gchar *text; time_t start_range; time_t end_range; gboolean range_search; @@ -80,36 +77,47 @@ cal_shell_view_execute_search (EShellView *shell_view) action = GTK_RADIO_ACTION (ACTION (CALENDAR_SEARCH_ANY_FIELD_CONTAINS)); value = gtk_radio_action_get_current_value (action); - text = e_shell_content_get_search_text (shell_content); + if (value == CALENDAR_SEARCH_ADVANCED) { + query = e_shell_content_get_search_rule_as_string (shell_content); - if (text == NULL || *text == '\0') { - text = ""; - value = CALENDAR_SEARCH_SUMMARY_CONTAINS; - } + if (!query) + query = g_strdup (""); + } else { + const gchar *format; + const gchar *text; + GString *string; - switch (value) { - default: + text = e_shell_content_get_search_text (shell_content); + + if (text == NULL || *text == '\0') { text = ""; - /* fall through */ + value = CALENDAR_SEARCH_SUMMARY_CONTAINS; + } - case CALENDAR_SEARCH_SUMMARY_CONTAINS: - format = "(contains? \"summary\" %s)"; - break; + switch (value) { + default: + text = ""; + /* fall through */ - case CALENDAR_SEARCH_DESCRIPTION_CONTAINS: - format = "(contains? \"description\" %s)"; - break; + case CALENDAR_SEARCH_SUMMARY_CONTAINS: + format = "(contains? \"summary\" %s)"; + break; - case CALENDAR_SEARCH_ANY_FIELD_CONTAINS: - format = "(contains? \"any\" %s)"; - break; - } + case CALENDAR_SEARCH_DESCRIPTION_CONTAINS: + format = "(contains? \"description\" %s)"; + break; - /* Build the query. */ - string = g_string_new (""); - e_sexp_encode_string (string, text); - query = g_strdup_printf (format, string->str); - g_string_free (string, TRUE); + case CALENDAR_SEARCH_ANY_FIELD_CONTAINS: + format = "(contains? \"any\" %s)"; + break; + } + + /* Build the query. */ + string = g_string_new (""); + e_sexp_encode_string (string, text); + query = g_strdup_printf (format, string->str); + g_string_free (string, TRUE); + } range_search = FALSE; start_range = end_range = 0; @@ -178,11 +186,6 @@ cal_shell_view_execute_search (EShellView *shell_view) } } - /* XXX This is wrong. We need to programmatically construct an - * EFilterRule, tell it to build code, and pass the resulting - * expressing string to ECalModel. */ - e_shell_content_set_search_rule (shell_content, NULL); - cal_shell_sidebar = E_CAL_SHELL_SIDEBAR (shell_sidebar); date_navigator = e_cal_shell_sidebar_get_date_navigator (cal_shell_sidebar); diff --git a/modules/calendar/e-memo-shell-view-actions.c b/modules/calendar/e-memo-shell-view-actions.c index 80ebca237d..57420cd963 100644 --- a/modules/calendar/e-memo-shell-view-actions.c +++ b/modules/calendar/e-memo-shell-view-actions.c @@ -526,29 +526,6 @@ action_memo_save_as_cb (GtkAction *action, } static void -action_memo_search_cb (GtkRadioAction *action, - GtkRadioAction *current, - EMemoShellView *memo_shell_view) -{ - EShellView *shell_view; - EShellContent *shell_content; - const gchar *search_hint; - - /* XXX Figure out a way to handle this in EShellContent - * instead of every shell view having to handle it. - * The problem is EShellContent does not know what - * the search option actions are for this view. It - * would have to dig up the popup menu and retrieve - * the action for each menu item. Seems messy. */ - - shell_view = E_SHELL_VIEW (memo_shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - - search_hint = gtk_action_get_label (GTK_ACTION (current)); - e_shell_content_set_search_hint (shell_content, search_hint); -} - -static void action_memo_view_cb (GtkRadioAction *action, GtkRadioAction *current, EMemoShellView *memo_shell_view) @@ -800,6 +777,13 @@ static GtkRadioActionEntry memo_filter_entries[] = { static GtkRadioActionEntry memo_search_entries[] = { + { "memo-search-advanced-hidden", + NULL, + N_("Advanced search"), + NULL, + NULL, + MEMO_SEARCH_ADVANCED }, + { "memo-search-any-field-contains", NULL, N_("Any field contains"), @@ -880,6 +864,7 @@ e_memo_shell_view_actions_init (EMemoShellView *memo_shell_view) GtkActionGroup *action_group; GConfBridge *bridge; GtkAction *action; + GtkRadioAction *radio_action; GObject *object; const gchar *key; @@ -907,8 +892,13 @@ e_memo_shell_view_actions_init (EMemoShellView *memo_shell_view) gtk_action_group_add_radio_actions ( action_group, memo_search_entries, G_N_ELEMENTS (memo_search_entries), - MEMO_SEARCH_SUMMARY_CONTAINS, - G_CALLBACK (action_memo_search_cb), memo_shell_view); + -1, NULL, NULL); + + /* Advanced Search action */ + radio_action = GTK_RADIO_ACTION (ACTION (MEMO_SEARCH_ADVANCED_HIDDEN)); + e_shell_content_set_search_radio_action (e_shell_view_get_shell_content (shell_view), radio_action); + gtk_action_set_visible (GTK_ACTION (radio_action), FALSE); + gtk_radio_action_set_current_value (radio_action, MEMO_SEARCH_SUMMARY_CONTAINS); /* Lockdown Printing Actions */ action_group = ACTION_GROUP (LOCKDOWN_PRINTING); diff --git a/modules/calendar/e-memo-shell-view-actions.h b/modules/calendar/e-memo-shell-view-actions.h index d43d0239d9..9fe4d6964d 100644 --- a/modules/calendar/e-memo-shell-view-actions.h +++ b/modules/calendar/e-memo-shell-view-actions.h @@ -75,6 +75,8 @@ E_SHELL_WINDOW_ACTION ((window), "memo-filter-any-category") #define E_SHELL_WINDOW_ACTION_MEMO_FILTER_UNMATCHED(window) \ E_SHELL_WINDOW_ACTION ((window), "memo-filter-unmatched") +#define E_SHELL_WINDOW_ACTION_MEMO_SEARCH_ADVANCED_HIDDEN(window) \ + E_SHELL_WINDOW_ACTION ((window), "memo-search-advanced-hidden") #define E_SHELL_WINDOW_ACTION_MEMO_SEARCH_ANY_FIELD_CONTAINS(window) \ E_SHELL_WINDOW_ACTION ((window), "memo-search-any-field-contains") #define E_SHELL_WINDOW_ACTION_MEMO_SEARCH_DESCRIPTION_CONTAINS(window) \ diff --git a/modules/calendar/e-memo-shell-view-private.h b/modules/calendar/e-memo-shell-view-private.h index 37556943f2..1818ba0808 100644 --- a/modules/calendar/e-memo-shell-view-private.h +++ b/modules/calendar/e-memo-shell-view-private.h @@ -81,6 +81,7 @@ enum { /* Search items are displayed in ascending order. */ enum { + MEMO_SEARCH_ADVANCED = -1, MEMO_SEARCH_SUMMARY_CONTAINS, MEMO_SEARCH_DESCRIPTION_CONTAINS, MEMO_SEARCH_ANY_FIELD_CONTAINS diff --git a/modules/calendar/e-memo-shell-view.c b/modules/calendar/e-memo-shell-view.c index 5cc8e159bb..5d932e1599 100644 --- a/modules/calendar/e-memo-shell-view.c +++ b/modules/calendar/e-memo-shell-view.c @@ -58,51 +58,59 @@ memo_shell_view_execute_search (EShellView *shell_view) EShellWindow *shell_window; EShellContent *shell_content; GtkRadioAction *action; - GString *string; ECalComponentPreview *memo_preview; EMemoTable *memo_table; ECalModel *model; - const gchar *format; - const gchar *text; gchar *query; gchar *temp; gint value; shell_content = e_shell_view_get_shell_content (shell_view); - text = e_shell_content_get_search_text (shell_content); - shell_window = e_shell_view_get_shell_window (shell_view); action = GTK_RADIO_ACTION (ACTION (MEMO_SEARCH_ANY_FIELD_CONTAINS)); value = gtk_radio_action_get_current_value (action); - if (text == NULL || *text == '\0') { - text = ""; - value = MEMO_SEARCH_SUMMARY_CONTAINS; - } + if (value == MEMO_SEARCH_ADVANCED) { + query = e_shell_content_get_search_rule_as_string (shell_content); - switch (value) { - default: + if (!query) + query = g_strdup (""); + } else { + const gchar *format; + const gchar *text; + GString *string; + + text = e_shell_content_get_search_text (shell_content); + + if (text == NULL || *text == '\0') { text = ""; - /* fall through */ + value = MEMO_SEARCH_SUMMARY_CONTAINS; + } - case MEMO_SEARCH_SUMMARY_CONTAINS: - format = "(contains? \"summary\" %s)"; - break; + switch (value) { + default: + text = ""; + /* fall through */ - case MEMO_SEARCH_DESCRIPTION_CONTAINS: - format = "(contains? \"description\" %s)"; - break; + case MEMO_SEARCH_SUMMARY_CONTAINS: + format = "(contains? \"summary\" %s)"; + break; - case MEMO_SEARCH_ANY_FIELD_CONTAINS: - format = "(contains? \"any\" %s)"; - break; - } + case MEMO_SEARCH_DESCRIPTION_CONTAINS: + format = "(contains? \"description\" %s)"; + break; - /* Build the query. */ - string = g_string_new (""); - e_sexp_encode_string (string, text); - query = g_strdup_printf (format, string->str); - g_string_free (string, TRUE); + case MEMO_SEARCH_ANY_FIELD_CONTAINS: + format = "(contains? \"any\" %s)"; + break; + } + + /* Build the query. */ + string = g_string_new (""); + e_sexp_encode_string (string, text); + query = g_strdup_printf (format, string->str); + g_string_free (string, TRUE); + } /* Apply selected filter. */ value = e_shell_content_get_filter_value (shell_content); @@ -134,11 +142,6 @@ memo_shell_view_execute_search (EShellView *shell_view) } } - /* XXX This is wrong. We need to programmatically construct an - * EFilterRule, tell it to build code, and pass the resulting - * expression string to ECalModel. */ - e_shell_content_set_search_rule (shell_content, NULL); - /* Submit the query. */ memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content); memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); diff --git a/modules/calendar/e-task-shell-view-actions.c b/modules/calendar/e-task-shell-view-actions.c index e5063c1d85..0e77efb1d8 100644 --- a/modules/calendar/e-task-shell-view-actions.c +++ b/modules/calendar/e-task-shell-view-actions.c @@ -653,29 +653,6 @@ action_task_save_as_cb (GtkAction *action, } static void -action_task_search_cb (GtkRadioAction *action, - GtkRadioAction *current, - ETaskShellView *task_shell_view) -{ - EShellView *shell_view; - EShellContent *shell_content; - const gchar *search_hint; - - /* XXX Figure out a way to handle this in EShellContent - * instead of every shell view having to handle it. - * The problem is EShellContent does not know what - * the search option actions are for this view. It - * would have to dig up the popup menu and retrieve - * the action for each menu item. Seems messy. */ - - shell_view = E_SHELL_VIEW (task_shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - - search_hint = gtk_action_get_label (GTK_ACTION (current)); - e_shell_content_set_search_hint (shell_content, search_hint); -} - -static void action_task_view_cb (GtkRadioAction *action, GtkRadioAction *current, ETaskShellView *task_shell_view) @@ -1001,6 +978,13 @@ static GtkRadioActionEntry task_filter_entries[] = { static GtkRadioActionEntry task_search_entries[] = { + { "task-search-advanced-hidden", + NULL, + N_("Advanced search"), + NULL, + NULL, + TASK_SEARCH_ADVANCED }, + { "task-search-any-field-contains", NULL, N_("Any field contains"), @@ -1081,6 +1065,7 @@ e_task_shell_view_actions_init (ETaskShellView *task_shell_view) GtkActionGroup *action_group; GConfBridge *bridge; GtkAction *action; + GtkRadioAction *radio_action; GObject *object; const gchar *key; @@ -1108,8 +1093,13 @@ e_task_shell_view_actions_init (ETaskShellView *task_shell_view) gtk_action_group_add_radio_actions ( action_group, task_search_entries, G_N_ELEMENTS (task_search_entries), - TASK_SEARCH_SUMMARY_CONTAINS, - G_CALLBACK (action_task_search_cb), task_shell_view); + -1, NULL, NULL); + + /* Advanced Search action */ + radio_action = GTK_RADIO_ACTION (ACTION (TASK_SEARCH_ADVANCED_HIDDEN)); + e_shell_content_set_search_radio_action (e_shell_view_get_shell_content (shell_view), radio_action); + gtk_action_set_visible (GTK_ACTION (radio_action), FALSE); + gtk_radio_action_set_current_value (radio_action, TASK_SEARCH_SUMMARY_CONTAINS); /* Lockdown Printing Actions */ action_group = ACTION_GROUP (LOCKDOWN_PRINTING); diff --git a/modules/calendar/e-task-shell-view-actions.h b/modules/calendar/e-task-shell-view-actions.h index daa70c36da..6c2d5d51b6 100644 --- a/modules/calendar/e-task-shell-view-actions.h +++ b/modules/calendar/e-task-shell-view-actions.h @@ -93,6 +93,8 @@ E_SHELL_WINDOW_ACTION ((window), "task-filter-tasks-with-attachments") #define E_SHELL_WINDOW_ACTION_TASK_FILTER_UNMATCHED(window) \ E_SHELL_WINDOW_ACTION ((window), "task-filter-unmatched") +#define E_SHELL_WINDOW_ACTION_TASK_SEARCH_ADVANCED_HIDDEN(window) \ + E_SHELL_WINDOW_ACTION ((window), "task-search-advanced-hidden") #define E_SHELL_WINDOW_ACTION_TASK_SEARCH_ANY_FIELD_CONTAINS(window) \ E_SHELL_WINDOW_ACTION ((window), "task-search-any-field-contains") #define E_SHELL_WINDOW_ACTION_TASK_SEARCH_DESCRIPTION_CONTAINS(window) \ diff --git a/modules/calendar/e-task-shell-view-private.h b/modules/calendar/e-task-shell-view-private.h index 38b03ae359..fcbe852898 100644 --- a/modules/calendar/e-task-shell-view-private.h +++ b/modules/calendar/e-task-shell-view-private.h @@ -90,6 +90,7 @@ enum { /* Search items are displayed in ascending order. */ enum { + TASK_SEARCH_ADVANCED = -1, TASK_SEARCH_SUMMARY_CONTAINS, TASK_SEARCH_DESCRIPTION_CONTAINS, TASK_SEARCH_ANY_FIELD_CONTAINS diff --git a/modules/calendar/e-task-shell-view.c b/modules/calendar/e-task-shell-view.c index 1bb2820911..b7c2bc9333 100644 --- a/modules/calendar/e-task-shell-view.c +++ b/modules/calendar/e-task-shell-view.c @@ -97,12 +97,9 @@ task_shell_view_execute_search (EShellView *shell_view) EShellWindow *shell_window; EShellContent *shell_content; GtkRadioAction *action; - GString *string; ECalComponentPreview *task_preview; ECalendarTable *task_table; ECalModel *model; - const gchar *format; - const gchar *text; time_t start_range; time_t end_range; gchar *start, *end; @@ -111,40 +108,51 @@ task_shell_view_execute_search (EShellView *shell_view) gint value; shell_content = e_shell_view_get_shell_content (shell_view); - text = e_shell_content_get_search_text (shell_content); - shell_window = e_shell_view_get_shell_window (shell_view); action = GTK_RADIO_ACTION (ACTION (TASK_SEARCH_ANY_FIELD_CONTAINS)); value = gtk_radio_action_get_current_value (action); - if (text == NULL || *text == '\0') { - text = ""; - value = TASK_SEARCH_SUMMARY_CONTAINS; - } + if (value == TASK_SEARCH_ADVANCED) { + query = e_shell_content_get_search_rule_as_string (shell_content); - switch (value) { - default: + if (!query) + query = g_strdup (""); + } else { + const gchar *format; + const gchar *text; + GString *string; + + text = e_shell_content_get_search_text (shell_content); + + if (text == NULL || *text == '\0') { text = ""; - /* fall through */ + value = TASK_SEARCH_SUMMARY_CONTAINS; + } - case TASK_SEARCH_SUMMARY_CONTAINS: - format = "(contains? \"summary\" %s)"; - break; + switch (value) { + default: + text = ""; + /* fall through */ - case TASK_SEARCH_DESCRIPTION_CONTAINS: - format = "(contains? \"description\" %s)"; - break; + case TASK_SEARCH_SUMMARY_CONTAINS: + format = "(contains? \"summary\" %s)"; + break; - case TASK_SEARCH_ANY_FIELD_CONTAINS: - format = "(contains? \"any\" %s)"; - break; - } + case TASK_SEARCH_DESCRIPTION_CONTAINS: + format = "(contains? \"description\" %s)"; + break; - /* Build the query. */ - string = g_string_new (""); - e_sexp_encode_string (string, text); - query = g_strdup_printf (format, string->str); - g_string_free (string, TRUE); + case TASK_SEARCH_ANY_FIELD_CONTAINS: + format = "(contains? \"any\" %s)"; + break; + } + + /* Build the query. */ + string = g_string_new (""); + e_sexp_encode_string (string, text); + query = g_strdup_printf (format, string->str); + g_string_free (string, TRUE); + } /* Apply selected filter. */ value = e_shell_content_get_filter_value (shell_content); @@ -246,11 +254,6 @@ task_shell_view_execute_search (EShellView *shell_view) query = temp2; } - /* XXX This is wrong. We need to programmatically construct an - * EFilterRule, tell it to build code, and pass the resulting - * expression string to ECalModel. */ - e_shell_content_set_search_rule (shell_content, NULL); - /* Submit the query. */ task_shell_content = E_TASK_SHELL_CONTENT (shell_content); task_table = e_task_shell_content_get_task_table (task_shell_content); diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c index 3473d2a727..4dce2de80b 100644 --- a/modules/mail/e-mail-shell-view-actions.c +++ b/modules/mail/e-mail-shell-view-actions.c @@ -648,29 +648,6 @@ action_mail_label_none_cb (GtkAction *action, } static void -action_mail_search_cb (GtkRadioAction *action, - GtkRadioAction *current, - EMailShellView *mail_shell_view) -{ - EShellView *shell_view; - EShellContent *shell_content; - const gchar *search_hint; - - /* XXX Figure out a way to handle this in EShellContent - * instead of every shell view having to handle it. - * The problem is EShellContent does not know what - * the search option actions are for this view. It - * would have to dig up the popup menu and retrieve - * the action for each menu item. Seems messy. */ - - shell_view = E_SHELL_VIEW (mail_shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - - search_hint = gtk_action_get_label (GTK_ACTION (current)); - e_shell_content_set_search_hint (shell_content, search_hint); -} - -static void action_mail_show_hidden_cb (GtkAction *action, EMailShellView *mail_shell_view) { @@ -963,31 +940,6 @@ action_search_filter_cb (GtkRadioAction *action, } static void -action_search_quick_cb (GtkAction *action, - EMailShellView *mail_shell_view) -{ - EShellView *shell_view; - EShellWindow *shell_window; - EShellContent *shell_content; - EFilterRule *search_rule; - gint value; - - /* Set the search rule in EShellContent so that "Create - * Search Folder from Search" works for quick searches. */ - - shell_view = E_SHELL_VIEW (mail_shell_view); - shell_window = e_shell_view_get_shell_window (shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - - action = ACTION (MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN); - value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); - g_return_if_fail (value >= 0 && value < MAIL_NUM_SEARCH_RULES); - search_rule = mail_shell_view->priv->search_rules[value]; - - e_shell_content_set_search_rule (shell_content, search_rule); -} - -static void action_search_scope_cb (GtkRadioAction *action, GtkRadioAction *current, EShellView *shell_view) @@ -1445,6 +1397,13 @@ static GtkRadioActionEntry mail_filter_entries[] = { static GtkRadioActionEntry mail_search_entries[] = { + { "mail-search-advanced-hidden", + NULL, + N_("Advanced search"), + NULL, + NULL, + MAIL_SEARCH_ADVANCED }, + { "mail-search-body-contains", NULL, N_("Body contains"), @@ -1548,8 +1507,7 @@ e_mail_shell_view_actions_init (EMailShellView *mail_shell_view) gtk_action_group_add_radio_actions ( action_group, mail_search_entries, G_N_ELEMENTS (mail_search_entries), - MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN, - G_CALLBACK (action_mail_search_cb), mail_shell_view); + -1, NULL, NULL); gtk_action_group_add_radio_actions ( action_group, mail_scope_entries, G_N_ELEMENTS (mail_scope_entries), @@ -1560,6 +1518,12 @@ e_mail_shell_view_actions_init (EMailShellView *mail_shell_view) e_shell_content_set_scope_action (shell_content, radio_action); e_shell_content_set_scope_visible (shell_content, TRUE); + /* Advanced Search action */ + radio_action = GTK_RADIO_ACTION (ACTION (MAIL_SEARCH_ADVANCED_HIDDEN)); + e_shell_content_set_search_radio_action (shell_content, radio_action); + gtk_action_set_visible (GTK_ACTION (radio_action), FALSE); + gtk_radio_action_set_current_value (radio_action, MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN); + /* Bind GObject properties for GConf keys. */ bridge = gconf_bridge_get (); @@ -1622,10 +1586,6 @@ e_mail_shell_view_actions_init (EMailShellView *mail_shell_view) g_signal_connect ( ACTION (GAL_SAVE_CUSTOM_VIEW), "activate", G_CALLBACK (action_gal_save_custom_view_cb), mail_shell_view); - - g_signal_connect ( - ACTION (SEARCH_QUICK), "activate", - G_CALLBACK (action_search_quick_cb), mail_shell_view); } /* Helper for e_mail_shell_view_update_popup_labels() */ diff --git a/modules/mail/e-mail-shell-view-actions.h b/modules/mail/e-mail-shell-view-actions.h index 6ae2e24a95..0ddc29488e 100644 --- a/modules/mail/e-mail-shell-view-actions.h +++ b/modules/mail/e-mail-shell-view-actions.h @@ -159,6 +159,8 @@ E_SHELL_WINDOW_ACTION ((window), "mail-reply-list") #define E_SHELL_WINDOW_ACTION_MAIL_REPLY_SENDER(window) \ E_SHELL_WINDOW_ACTION ((window), "mail-reply-sender") +#define E_SHELL_WINDOW_ACTION_MAIL_SEARCH_ADVANCED_HIDDEN(window) \ + E_SHELL_WINDOW_ACTION ((window), "mail-search-advanced-hidden") #define E_SHELL_WINDOW_ACTION_MAIL_SEARCH_FOLDER_FROM_MAILING_LIST(window) \ E_SHELL_WINDOW_ACTION ((window), "mail-search-folder-from-mailing-list") #define E_SHELL_WINDOW_ACTION_MAIL_SEARCH_FOLDER_FROM_RECIPIENTS(window) \ diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h index 6142b6e9d8..3c9ec88630 100644 --- a/modules/mail/e-mail-shell-view-private.h +++ b/modules/mail/e-mail-shell-view-private.h @@ -108,6 +108,7 @@ enum { /* Search items are displayed in ascending order. */ enum { + MAIL_SEARCH_ADVANCED = -1, MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN, MAIL_SEARCH_RECIPIENTS_CONTAIN, MAIL_SEARCH_MESSAGE_CONTAINS, diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c index 1241716340..895bd33903 100644 --- a/modules/mail/e-mail-shell-view.c +++ b/modules/mail/e-mail-shell-view.c @@ -94,7 +94,6 @@ mail_shell_view_execute_search (EShellView *shell_view) EMailShellContent *mail_shell_content; MessageList *message_list; EFilterRule *rule; - EFilterRule *search_rule; EMailReader *reader; CamelFolder *folder; GtkAction *action; @@ -156,20 +155,29 @@ mail_shell_view_execute_search (EShellView *shell_view) model = e_shell_settings_get_object ( shell_settings, "mail-label-list-store"); + action = ACTION (MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN); + value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); + text = e_shell_content_get_search_text (shell_content); - if (text == NULL || *text == '\0') { - query = g_strdup (""); + if (value == MAIL_SEARCH_ADVANCED || text == NULL || *text == '\0') { + query = e_shell_content_get_search_rule_as_string (shell_content); + + if (!query) + query = g_strdup (""); + goto filter; } /* Replace variables in the selected rule with the * current search text and extract a query string. */ - action = ACTION (MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN); - value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); g_return_if_fail (value >= 0 && value < MAIL_NUM_SEARCH_RULES); rule = priv->search_rules[value]; + /* Set the search rule in EShellContent so that "Create + * Search Folder from Search" works for quick searches. */ + e_shell_content_set_search_rule (shell_content, rule); + for (iter = rule->parts; iter != NULL; iter = iter->next) { EFilterPart *part = iter->data; EFilterElement *element = NULL; @@ -337,18 +345,6 @@ filter: break; } - search_rule = e_shell_content_get_search_rule (shell_content); - if (search_rule != NULL) { - string = g_string_sized_new (1024); - e_filter_rule_build_code (search_rule, string); - temp = g_strconcat ("(and", string->str, query, ")", NULL); - - g_free (query); - query = temp; - - g_string_free (string, TRUE); - } - message_list_set_search (message_list, query); e_mail_shell_content_set_search_strings ( |