diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-09-03 03:21:35 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-09-03 03:26:49 +0800 |
commit | 53268d5516083c47607dbd3acbbd6bafd6d15747 (patch) | |
tree | c2a35758d36f00a2ce51633674c811eb1c5070ba /modules/mail | |
parent | 5cbcdddfe769c0df81122b8d4944507f4739a618 (diff) | |
download | gsoc2013-evolution-53268d5516083c47607dbd3acbbd6bafd6d15747.tar.gz gsoc2013-evolution-53268d5516083c47607dbd3acbbd6bafd6d15747.tar.zst gsoc2013-evolution-53268d5516083c47607dbd3acbbd6bafd6d15747.zip |
Introduce an EShellView::execute-search signal.
This addresses bug #593896 but is also a cleaner design than before.
It introduces an EShellView::execute-search signal and renames the
"search-execute" action to "search-quick" to clarify that it's only
meant for the "quick" search bar in the main window.
Shell view subclasses should implement the execute_search() method to
actually execute a search.
e_shell_view_execute_search() emits the new signal.
Diffstat (limited to 'modules/mail')
-rw-r--r-- | modules/mail/e-mail-shell-view-actions.c | 76 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view-private.c | 244 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view-private.h | 7 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view.c | 267 |
4 files changed, 282 insertions, 312 deletions
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c index a16c752e84..adb288d8fb 100644 --- a/modules/mail/e-mail-shell-view-actions.c +++ b/modules/mail/e-mail-shell-view-actions.c @@ -21,10 +21,6 @@ #include "e-mail-shell-view-private.h" -#define STATE_KEY_SEARCH_FILTER "SearchFilter" -#define STATE_KEY_SEARCH_SCOPE "SearchScope" -#define STATE_KEY_SEARCH_TEXT "SearchText" - static void action_gal_save_custom_view_cb (GtkAction *action, EMailShellView *mail_shell_view) @@ -887,70 +883,22 @@ action_mail_view_cb (GtkRadioAction *action, } static void -action_search_execute_cb (GtkAction *action, - EMailShellView *mail_shell_view) -{ - EShellView *shell_view; - EShellContent *shell_content; - EMailReader *reader; - MessageList *message_list; - GKeyFile *key_file; - const gchar *folder_uri; - - shell_view = E_SHELL_VIEW (mail_shell_view); - shell_content = e_shell_view_get_shell_content (shell_view); - key_file = e_shell_view_get_state_key_file (shell_view); - - /* All shell views respond to the activation of this action, - * which is defined by EShellWindow. But only the currently - * active shell view proceeds with executing the search. */ - if (!e_shell_view_is_active (shell_view)) - return; - - reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content); - message_list = e_mail_reader_get_message_list (reader); - folder_uri = message_list->folder_uri; - - if (folder_uri != NULL) { - const gchar *key; - const gchar *string; - gchar *group_name; - - key = STATE_KEY_SEARCH_TEXT; - string = e_shell_content_get_search_text (shell_content); - group_name = g_strdup_printf ("Folder %s", folder_uri); - - if (string != NULL && *string != '\0') - g_key_file_set_string ( - key_file, group_name, key, string); - else - g_key_file_remove_key ( - key_file, group_name, key, NULL); - e_shell_view_set_state_dirty (shell_view); - - g_free (group_name); - } - - e_mail_shell_view_execute_search (mail_shell_view); -} - -static void action_search_filter_cb (GtkRadioAction *action, GtkRadioAction *current, - EMailShellView *mail_shell_view) + EShellView *shell_view) { - EShellView *shell_view; + EShellContent *shell_content; EShellWindow *shell_window; EMailReader *reader; MessageList *message_list; GKeyFile *key_file; const gchar *folder_uri; - shell_view = E_SHELL_VIEW (mail_shell_view); + shell_content = e_shell_view_get_shell_content (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); key_file = e_shell_view_get_state_key_file (shell_view); - reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content); + reader = E_MAIL_READER (shell_content); message_list = e_mail_reader_get_message_list (reader); folder_uri = message_list->folder_uri; @@ -969,26 +917,26 @@ action_search_filter_cb (GtkRadioAction *action, g_free (group_name); } - gtk_action_activate (ACTION (SEARCH_EXECUTE)); + e_shell_view_execute_search (shell_view); } static void action_search_scope_cb (GtkRadioAction *action, GtkRadioAction *current, - EMailShellView *mail_shell_view) + EShellView *shell_view) { - EShellView *shell_view; + EShellContent *shell_content; EShellWindow *shell_window; EMailReader *reader; MessageList *message_list; GKeyFile *key_file; const gchar *folder_uri; - shell_view = E_SHELL_VIEW (mail_shell_view); + shell_content = e_shell_view_get_shell_content (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); key_file = e_shell_view_get_state_key_file (shell_view); - reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content); + reader = E_MAIL_READER (shell_content); message_list = e_mail_reader_get_message_list (reader); folder_uri = message_list->folder_uri; @@ -1007,7 +955,7 @@ action_search_scope_cb (GtkRadioAction *action, g_free (group_name); } - gtk_action_activate (ACTION (SEARCH_EXECUTE)); + e_shell_view_execute_search (shell_view); } static GtkActionEntry mail_entries[] = { @@ -1600,10 +1548,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_EXECUTE), "activate", - G_CALLBACK (action_search_execute_cb), mail_shell_view); } /* Helper for e_mail_shell_view_update_popup_labels() */ diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c index 067900b5c2..984c3acf27 100644 --- a/modules/mail/e-mail-shell-view-private.c +++ b/modules/mail/e-mail-shell-view-private.c @@ -491,250 +491,6 @@ e_mail_shell_view_restore_state (EMailShellView *mail_shell_view) g_free (group_name); } -void -e_mail_shell_view_execute_search (EMailShellView *mail_shell_view) -{ - EShell *shell; - EShellView *shell_view; - EShellWindow *shell_window; - EShellContent *shell_content; - EShellSettings *shell_settings; - EMFormatHTMLDisplay *html_display; - EMailShellContent *mail_shell_content; - MessageList *message_list; - FilterRule *rule; - EMailReader *reader; - CamelFolder *folder; - GtkAction *action; - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter tree_iter; - GString *string; - GList *iter; - GSList *search_strings = NULL; - const gchar *folder_uri; - const gchar *text; - gboolean valid; - gchar *query; - gchar *temp; - gchar *tag; - gint value; - - g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view)); - - 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); - - shell = e_shell_window_get_shell (shell_window); - shell_settings = e_shell_get_shell_settings (shell); - - mail_shell_content = mail_shell_view->priv->mail_shell_content; - - reader = E_MAIL_READER (shell_content); - html_display = e_mail_reader_get_html_display (reader); - message_list = e_mail_reader_get_message_list (reader); - - folder_uri = message_list->folder_uri; - folder = message_list->folder; - - /* This returns a new object reference. */ - model = e_shell_settings_get_object ( - shell_settings, "mail-label-list-store"); - - text = e_shell_content_get_search_text (shell_content); - if (text == NULL || *text == '\0') { - 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_SENDER_CONTAINS); - value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); - g_return_if_fail (value >= 0 && value < MAIL_NUM_SEARCH_RULES); - rule = mail_shell_view->priv->search_rules[value]; - - for (iter = rule->parts; iter != NULL; iter = iter->next) { - FilterPart *part = iter->data; - FilterElement *element = NULL; - - if (strcmp (part->name, "subject") == 0) - element = filter_part_find_element (part, "subject"); - else if (strcmp (part->name, "body") == 0) - element = filter_part_find_element (part, "word"); - else if (strcmp (part->name, "sender") == 0) - element = filter_part_find_element (part, "sender"); - else if (strcmp (part->name, "to") == 0) - element = filter_part_find_element (part, "recipient"); - - if (strcmp (part->name, "body") == 0) { - struct _camel_search_words *words; - gint ii; - - words = camel_search_words_split ((guchar *) text); - for (ii = 0; ii < words->len; ii++) - search_strings = g_slist_prepend ( - search_strings, g_strdup ( - words->words[ii]->word)); - camel_search_words_free (words); - } - - if (element != NULL) { - FilterInput *input = FILTER_INPUT (element); - filter_input_set_value (input, text); - } - } - - string = g_string_sized_new (1024); - filter_rule_build_code (rule, string); - query = g_string_free (string, FALSE); - -filter: - - /* Apply selected filter. */ - - value = e_shell_content_get_filter_value (shell_content); - switch (value) { - case MAIL_FILTER_ALL_MESSAGES: - break; - - case MAIL_FILTER_UNREAD_MESSAGES: - temp = g_strdup_printf ( - "(and %s (match-all (not " - "(system-flag \"Seen\"))))", query); - g_free (query); - query = temp; - break; - - case MAIL_FILTER_NO_LABEL: - string = g_string_sized_new (1024); - g_string_append_printf ( - string, "(and %s (and ", query); - valid = gtk_tree_model_get_iter_first ( - model, &tree_iter); - while (valid) { - tag = e_mail_label_list_store_get_tag ( - E_MAIL_LABEL_LIST_STORE (model), - &tree_iter); - g_string_append_printf ( - string, " (match-all (not (or " - "(= (user-tag \"label\") \"%s\") " - "(user-flag \"$Label%s\") " - "(user-flag \"%s\"))))", - tag, tag, tag); - g_free (tag); - - valid = gtk_tree_model_iter_next ( - model, &tree_iter); - } - g_string_append_len (string, "))", 2); - g_free (query); - query = g_string_free (string, FALSE); - break; - - case MAIL_FILTER_READ_MESSAGES: - temp = g_strdup_printf ( - "(and %s (match-all " - "(system-flag \"Seen\")))", query); - g_free (query); - query = temp; - break; - - case MAIL_FILTER_RECENT_MESSAGES: - if (em_utils_folder_is_sent (folder, folder_uri)) - temp = g_strdup_printf ( - "(and %s (match-all " - "(> (get-sent-date) " - "(- (get-current-date) 86400))))", - query); - else - temp = g_strdup_printf ( - "(and %s (match-all " - "(> (get-received-date) " - "(- (get-current-date) 86400))))", - query); - g_free (query); - query = temp; - break; - - case MAIL_FILTER_LAST_5_DAYS_MESSAGES: - if (em_utils_folder_is_sent (folder, folder_uri)) - temp = g_strdup_printf ( - "(and %s (match-all " - "(> (get-sent-date) " - "(- (get-current-date) 432000))))", - query); - else - temp = g_strdup_printf ( - "(and %s (match-all " - "(> (get-received-date) " - "(- (get-current-date) 432000))))", - query); - g_free (query); - query = temp; - break; - - case MAIL_FILTER_MESSAGES_WITH_ATTACHMENTS: - temp = g_strdup_printf ( - "(and %s (match-all " - "(system-flag \"Attachments\")))", query); - g_free (query); - query = temp; - break; - - case MAIL_FILTER_IMPORTANT_MESSAGES: - temp = g_strdup_printf ( - "(and %s (match-all " - "(system-flag \"Flagged\")))", query); - g_free (query); - query = temp; - break; - - case MAIL_FILTER_MESSAGES_NOT_JUNK: - temp = g_strdup_printf ( - "(and %s (match-all (not " - "(system-flag \"junk\"))))", query); - g_free (query); - query = temp; - break; - - default: - /* The action value also serves as a path for - * the label list store. That's why we number - * the label actions from zero. */ - path = gtk_tree_path_new_from_indices (value, -1); - gtk_tree_model_get_iter (model, &tree_iter, path); - gtk_tree_path_free (path); - - tag = e_mail_label_list_store_get_tag ( - E_MAIL_LABEL_LIST_STORE (model), &tree_iter); - temp = g_strdup_printf ( - "(and %s (match-all (or " - "(= (user-tag \"label\") \"%s\") " - "(user-flag \"$Label%s\") " - "(user-flag \"%s\"))))", - query, tag, tag, tag); - g_free (tag); - - g_free (query); - query = temp; - break; - } - - message_list_set_search (message_list, query); - - e_mail_shell_content_set_search_strings ( - mail_shell_content, search_strings); - - g_slist_foreach (search_strings, (GFunc) g_free, NULL); - g_slist_free (search_strings); - - g_object_unref (model); - g_free (query); -} - /* Helper for e_mail_shell_view_create_filter_from_selected() */ static void mail_shell_view_create_filter_cb (CamelFolder *folder, diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h index 988d494219..30724b26b5 100644 --- a/modules/mail/e-mail-shell-view-private.h +++ b/modules/mail/e-mail-shell-view-private.h @@ -80,6 +80,11 @@ /* ETable Specifications */ #define ETSPEC_FILENAME "message-list.etspec" +/* State File Keys */ +#define STATE_KEY_SEARCH_FILTER "SearchFilter" +#define STATE_KEY_SEARCH_SCOPE "SearchScope" +#define STATE_KEY_SEARCH_TEXT "SearchText" + G_BEGIN_DECLS /* Filter items are displayed in ascending order. @@ -153,8 +158,6 @@ void e_mail_shell_view_actions_init (EMailShellView *mail_shell_view); void e_mail_shell_view_restore_state (EMailShellView *mail_shell_view); -void e_mail_shell_view_execute_search - (EMailShellView *mail_shell_view); void e_mail_shell_view_create_filter_from_selected (EMailShellView *mail_shell_view, gint filter_type); diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c index fb045905e6..493d761432 100644 --- a/modules/mail/e-mail-shell-view.c +++ b/modules/mail/e-mail-shell-view.c @@ -82,6 +82,272 @@ mail_shell_view_toggled (EShellView *shell_view) } static void +mail_shell_view_execute_search (EShellView *shell_view) +{ + EMailShellViewPrivate *priv; + EShell *shell; + EShellWindow *shell_window; + EShellContent *shell_content; + EShellSettings *shell_settings; + EMFormatHTMLDisplay *html_display; + EMailShellContent *mail_shell_content; + MessageList *message_list; + FilterRule *rule; + EMailReader *reader; + CamelFolder *folder; + GtkAction *action; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter tree_iter; + GString *string; + GList *iter; + GSList *search_strings = NULL; + const gchar *folder_uri; + const gchar *text; + gboolean valid; + gchar *query; + gchar *temp; + gchar *tag; + gint value; + + priv = E_MAIL_SHELL_VIEW_GET_PRIVATE (shell_view); + + shell_window = e_shell_view_get_shell_window (shell_view); + shell_content = e_shell_view_get_shell_content (shell_view); + + shell = e_shell_window_get_shell (shell_window); + shell_settings = e_shell_get_shell_settings (shell); + + mail_shell_content = E_MAIL_SHELL_CONTENT (shell_content); + + reader = E_MAIL_READER (shell_content); + html_display = e_mail_reader_get_html_display (reader); + message_list = e_mail_reader_get_message_list (reader); + + folder_uri = message_list->folder_uri; + folder = message_list->folder; + + if (folder_uri != NULL) { + GKeyFile *key_file; + const gchar *key; + const gchar *string; + gchar *group_name; + + key_file = e_shell_view_get_state_key_file (shell_view); + + key = STATE_KEY_SEARCH_TEXT; + string = e_shell_content_get_search_text (shell_content); + group_name = g_strdup_printf ("Folder %s", folder_uri); + + if (string != NULL && *string != '\0') + g_key_file_set_string ( + key_file, group_name, key, string); + else + g_key_file_remove_key ( + key_file, group_name, key, NULL); + e_shell_view_set_state_dirty (shell_view); + + g_free (group_name); + } + + /* This returns a new object reference. */ + model = e_shell_settings_get_object ( + shell_settings, "mail-label-list-store"); + + text = e_shell_content_get_search_text (shell_content); + if (text == NULL || *text == '\0') { + 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_SENDER_CONTAINS); + 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]; + + for (iter = rule->parts; iter != NULL; iter = iter->next) { + FilterPart *part = iter->data; + FilterElement *element = NULL; + + if (strcmp (part->name, "subject") == 0) + element = filter_part_find_element (part, "subject"); + else if (strcmp (part->name, "body") == 0) + element = filter_part_find_element (part, "word"); + else if (strcmp (part->name, "sender") == 0) + element = filter_part_find_element (part, "sender"); + else if (strcmp (part->name, "to") == 0) + element = filter_part_find_element (part, "recipient"); + + if (strcmp (part->name, "body") == 0) { + struct _camel_search_words *words; + gint ii; + + words = camel_search_words_split ((guchar *) text); + for (ii = 0; ii < words->len; ii++) + search_strings = g_slist_prepend ( + search_strings, g_strdup ( + words->words[ii]->word)); + camel_search_words_free (words); + } + + if (element != NULL) { + FilterInput *input = FILTER_INPUT (element); + filter_input_set_value (input, text); + } + } + + string = g_string_sized_new (1024); + filter_rule_build_code (rule, string); + query = g_string_free (string, FALSE); + +filter: + + /* Apply selected filter. */ + + value = e_shell_content_get_filter_value (shell_content); + switch (value) { + case MAIL_FILTER_ALL_MESSAGES: + break; + + case MAIL_FILTER_UNREAD_MESSAGES: + temp = g_strdup_printf ( + "(and %s (match-all (not " + "(system-flag \"Seen\"))))", query); + g_free (query); + query = temp; + break; + + case MAIL_FILTER_NO_LABEL: + string = g_string_sized_new (1024); + g_string_append_printf ( + string, "(and %s (and ", query); + valid = gtk_tree_model_get_iter_first ( + model, &tree_iter); + while (valid) { + tag = e_mail_label_list_store_get_tag ( + E_MAIL_LABEL_LIST_STORE (model), + &tree_iter); + g_string_append_printf ( + string, " (match-all (not (or " + "(= (user-tag \"label\") \"%s\") " + "(user-flag \"$Label%s\") " + "(user-flag \"%s\"))))", + tag, tag, tag); + g_free (tag); + + valid = gtk_tree_model_iter_next ( + model, &tree_iter); + } + g_string_append_len (string, "))", 2); + g_free (query); + query = g_string_free (string, FALSE); + break; + + case MAIL_FILTER_READ_MESSAGES: + temp = g_strdup_printf ( + "(and %s (match-all " + "(system-flag \"Seen\")))", query); + g_free (query); + query = temp; + break; + + case MAIL_FILTER_RECENT_MESSAGES: + if (em_utils_folder_is_sent (folder, folder_uri)) + temp = g_strdup_printf ( + "(and %s (match-all " + "(> (get-sent-date) " + "(- (get-current-date) 86400))))", + query); + else + temp = g_strdup_printf ( + "(and %s (match-all " + "(> (get-received-date) " + "(- (get-current-date) 86400))))", + query); + g_free (query); + query = temp; + break; + + case MAIL_FILTER_LAST_5_DAYS_MESSAGES: + if (em_utils_folder_is_sent (folder, folder_uri)) + temp = g_strdup_printf ( + "(and %s (match-all " + "(> (get-sent-date) " + "(- (get-current-date) 432000))))", + query); + else + temp = g_strdup_printf ( + "(and %s (match-all " + "(> (get-received-date) " + "(- (get-current-date) 432000))))", + query); + g_free (query); + query = temp; + break; + + case MAIL_FILTER_MESSAGES_WITH_ATTACHMENTS: + temp = g_strdup_printf ( + "(and %s (match-all " + "(system-flag \"Attachments\")))", query); + g_free (query); + query = temp; + break; + + case MAIL_FILTER_IMPORTANT_MESSAGES: + temp = g_strdup_printf ( + "(and %s (match-all " + "(system-flag \"Flagged\")))", query); + g_free (query); + query = temp; + break; + + case MAIL_FILTER_MESSAGES_NOT_JUNK: + temp = g_strdup_printf ( + "(and %s (match-all (not " + "(system-flag \"junk\"))))", query); + g_free (query); + query = temp; + break; + + default: + /* The action value also serves as a path for + * the label list store. That's why we number + * the label actions from zero. */ + path = gtk_tree_path_new_from_indices (value, -1); + gtk_tree_model_get_iter (model, &tree_iter, path); + gtk_tree_path_free (path); + + tag = e_mail_label_list_store_get_tag ( + E_MAIL_LABEL_LIST_STORE (model), &tree_iter); + temp = g_strdup_printf ( + "(and %s (match-all (or " + "(= (user-tag \"label\") \"%s\") " + "(user-flag \"$Label%s\") " + "(user-flag \"%s\"))))", + query, tag, tag, tag); + g_free (tag); + + g_free (query); + query = temp; + break; + } + + message_list_set_search (message_list, query); + + e_mail_shell_content_set_search_strings ( + mail_shell_content, search_strings); + + g_slist_foreach (search_strings, (GFunc) g_free, NULL); + g_slist_free (search_strings); + + g_object_unref (model); + g_free (query); +} + +static void mail_shell_view_update_actions (EShellView *shell_view) { EMailShellView *mail_shell_view; @@ -221,6 +487,7 @@ mail_shell_view_class_init (EMailShellViewClass *class, shell_view_class->new_shell_content = e_mail_shell_content_new; shell_view_class->new_shell_sidebar = e_mail_shell_sidebar_new; shell_view_class->toggled = mail_shell_view_toggled; + shell_view_class->execute_search = mail_shell_view_execute_search; shell_view_class->update_actions = mail_shell_view_update_actions; } |