diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-12-08 10:47:44 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-12-08 10:47:44 +0000 |
commit | 238c849d9e18136563bb96f8ac1e9c6d42d7ed8b (patch) | |
tree | 95048c3a97e1c68db0a0e50320934ecacbdd8a9d | |
parent | a01b936f8ccfe93f6cd057f6f64e20df58621f78 (diff) |
made more prefs_filter functions public.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@811 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ChangeLog.ja | 5 | ||||
-rw-r--r-- | src/prefs_filter.c | 5 | ||||
-rw-r--r-- | src/prefs_filter.h | 1 | ||||
-rw-r--r-- | src/prefs_filter_edit.c | 374 | ||||
-rw-r--r-- | src/prefs_filter_edit.h | 6 |
6 files changed, 213 insertions, 183 deletions
@@ -1,5 +1,10 @@ 2005-12-08 + * src/prefs_filter_edit.[ch] + src/prefs_filter.[ch]: made more functions public. + +2005-12-08 + * src/prefs_filter_edit.[ch]: generalized the condition edit. 2005-12-08 diff --git a/ChangeLog.ja b/ChangeLog.ja index a0c68fc3..44ebb4cb 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,5 +1,10 @@ 2005-12-08 + * src/prefs_filter_edit.[ch] + src/prefs_filter.[ch]: 関数をさらに公開。 + +2005-12-08 + * src/prefs_filter_edit.[ch]: 条件の編集を一般化した。 2005-12-08 diff --git a/src/prefs_filter.c b/src/prefs_filter.c index 6e737d21..893fc024 100644 --- a/src/prefs_filter.c +++ b/src/prefs_filter.c @@ -86,8 +86,6 @@ static void prefs_filter_set_list_row (GtkTreeIter *iter, FilterRule *rule, gboolean move_view); -static void prefs_filter_set_header_list (MsgInfo *msginfo); - static void prefs_filter_write_user_header_list (void); static void prefs_filter_set_list (void); @@ -528,7 +526,7 @@ void prefs_filter_set_msg_header_list(MsgInfo *msginfo) } } -static void prefs_filter_set_header_list(MsgInfo *msginfo) +void prefs_filter_set_header_list(MsgInfo *msginfo) { GSList *list = NULL; gchar *path; @@ -563,7 +561,6 @@ static void prefs_filter_set_header_list(MsgInfo *msginfo) g_free(path); prefs_filter_set_user_header_list(list); - prefs_filter_set_msg_header_list(msginfo); } diff --git a/src/prefs_filter.h b/src/prefs_filter.h index 85a1c5f6..08efb43c 100644 --- a/src/prefs_filter.h +++ b/src/prefs_filter.h @@ -36,6 +36,7 @@ GSList *prefs_filter_get_user_header_list (void); gchar *prefs_filter_get_msg_header_field (const gchar *header_name); +void prefs_filter_set_header_list (MsgInfo *msginfo); void prefs_filter_set_user_header_list (GSList *list); void prefs_filter_set_msg_header_list (MsgInfo *msginfo); diff --git a/src/prefs_filter_edit.c b/src/prefs_filter_edit.c index 1b1e12b9..f5a80496 100644 --- a/src/prefs_filter_edit.c +++ b/src/prefs_filter_edit.c @@ -82,8 +82,6 @@ static struct FilterEditHeaderListDialog { static void prefs_filter_edit_create (void); static void prefs_filter_edit_clear (void); static void prefs_filter_edit_rule_to_dialog (FilterRule *rule); -static void prefs_filter_edit_set_header_list (FilterCondEdit *cond_list, - FilterRule *rule); static void prefs_filter_edit_update_header_list(FilterCondEdit *cond_list); static void prefs_filter_edit_set_action_hbox_menu_sensitive @@ -402,8 +400,8 @@ static void prefs_filter_edit_rule_to_dialog(FilterRule *rule) prefs_filter_edit_add_rule_action(rule); } -static void prefs_filter_edit_set_header_list(FilterCondEdit *cond_edit, - FilterRule *rule) +void prefs_filter_edit_set_header_list(FilterCondEdit *cond_edit, + FilterRule *rule) { GSList *list; GSList *rule_hdr_list = NULL; @@ -1580,6 +1578,194 @@ static void prefs_filter_edit_edit_header_list(FilterCondEdit *cond_edit) edit_header_list_dialog.ok = FALSE; } +FilterCond *prefs_filter_edit_cond_hbox_to_cond(CondHBox *hbox, + gchar **error_msg) +{ + FilterCond *cond = NULL; + GtkWidget *cond_type_menuitem; + CondMenuType cond_menu_type; + MatchMenuType match_menu_type; + const gchar *header_name; + const gchar *key_str; + gint int_value; + FilterMatchType match_type = FLT_CONTAIN; + FilterMatchFlag match_flag = 0; + SizeMatchType size_type; + AgeMatchType age_type; + gchar *error_msg_ = NULL; + + cond_type_menuitem = gtk_menu_get_active + (GTK_MENU(gtk_option_menu_get_menu + (GTK_OPTION_MENU(hbox->cond_type_optmenu)))); + cond_menu_type = GPOINTER_TO_INT + (g_object_get_data(G_OBJECT(cond_type_menuitem), MENU_VAL_ID)); + + match_menu_type = menu_get_option_menu_active_index + (GTK_OPTION_MENU(hbox->match_type_optmenu)); + + key_str = gtk_entry_get_text(GTK_ENTRY(hbox->key_entry)); + + switch (match_menu_type) { + case PF_MATCH_CONTAIN: + match_type = FLT_CONTAIN; + break; + case PF_MATCH_NOT_CONTAIN: + match_type = FLT_CONTAIN; + match_flag |= FLT_NOT_MATCH; + break; + case PF_MATCH_EQUAL: + match_type = FLT_EQUAL; + break; + case PF_MATCH_NOT_EQUAL: + match_type = FLT_EQUAL; + match_flag |= FLT_NOT_MATCH; + break; + case PF_MATCH_REGEX: + match_type = FLT_REGEX; + break; + case PF_MATCH_NOT_REGEX: + match_type = FLT_REGEX; + match_flag |= FLT_NOT_MATCH; + break; + default: + break; + } + + switch (cond_menu_type) { + case PF_COND_HEADER: + header_name = g_object_get_data + (G_OBJECT(cond_type_menuitem), "header_str"); + cond = filter_cond_new(FLT_COND_HEADER, + match_type, match_flag, + header_name, key_str); + break; + case PF_COND_TO_OR_CC: + cond = filter_cond_new(FLT_COND_TO_OR_CC, match_type, + match_flag, NULL, key_str); + break; + case PF_COND_ANY_HEADER: + cond = filter_cond_new(FLT_COND_ANY_HEADER, match_type, + match_flag, NULL, key_str); + break; + case PF_COND_BODY: + cond = filter_cond_new(FLT_COND_BODY, match_type, + match_flag, NULL, key_str); + break; + case PF_COND_CMD_TEST: + if (key_str && *key_str) + cond = filter_cond_new(FLT_COND_CMD_TEST, + 0, 0, NULL, key_str); + else + error_msg_ = _("Command is not specified."); + break; + case PF_COND_SIZE: + size_type = menu_get_option_menu_active_index + (GTK_OPTION_MENU(hbox->size_match_optmenu)); + match_flag = size_type == PF_SIZE_LARGER ? 0 : FLT_NOT_MATCH; + int_value = gtk_spin_button_get_value_as_int + (GTK_SPIN_BUTTON(hbox->spin_btn)); + cond = filter_cond_new(FLT_COND_SIZE_GREATER, + 0, match_flag, NULL, itos(int_value)); + break; + case PF_COND_AGE: + age_type = menu_get_option_menu_active_index + (GTK_OPTION_MENU(hbox->age_match_optmenu)); + match_flag = age_type == PF_AGE_LONGER ? 0 : FLT_NOT_MATCH; + int_value = gtk_spin_button_get_value_as_int + (GTK_SPIN_BUTTON(hbox->spin_btn)); + cond = filter_cond_new(FLT_COND_AGE_GREATER, + 0, match_flag, NULL, itos(int_value)); + break; + case PF_COND_ACCOUNT: + case PF_COND_EDIT_HEADER: + default: + break; + } + + if (error_msg) + *error_msg = error_msg_; + + return cond; +} + +FilterAction *prefs_filter_edit_action_hbox_to_action(ActionHBox *hbox, + gchar **error_msg) +{ + FilterAction *action = NULL; + ActionMenuType action_menu_type; + const gchar *str; + guint color; + gchar *error_msg_ = NULL; + + action_menu_type = prefs_filter_edit_get_action_hbox_type(hbox); + + switch (action_menu_type) { + case PF_ACTION_MOVE: + str = gtk_entry_get_text(GTK_ENTRY(hbox->folder_entry)); + if (str && *str) + action = filter_action_new(FLT_ACTION_MOVE, + str); + else + error_msg_ = _("Destination folder is not specified."); + break; + case PF_ACTION_COPY: + str = gtk_entry_get_text(GTK_ENTRY(hbox->folder_entry)); + if (str && *str) + action = filter_action_new(FLT_ACTION_COPY, str); + else + error_msg_ = _("Destination folder is not specified."); + break; + case PF_ACTION_NOT_RECEIVE: + action = filter_action_new(FLT_ACTION_NOT_RECEIVE, NULL); + break; + case PF_ACTION_DELETE: + action = filter_action_new(FLT_ACTION_DELETE, NULL); + break; + case PF_ACTION_EXEC: + str = gtk_entry_get_text(GTK_ENTRY(hbox->cmd_entry)); + if (str && *str) + action = filter_action_new(FLT_ACTION_EXEC, str); + else + error_msg_ = _("Command is not specified."); + break; + case PF_ACTION_EXEC_ASYNC: + str = gtk_entry_get_text(GTK_ENTRY(hbox->cmd_entry)); + if (str && *str) + action = filter_action_new(FLT_ACTION_EXEC_ASYNC, str); + else + error_msg_ = _("Command is not specified."); + break; + case PF_ACTION_MARK: + action = filter_action_new(FLT_ACTION_MARK, NULL); + break; + case PF_ACTION_COLOR_LABEL: + color = colorlabel_get_color_menu_active_item + (gtk_option_menu_get_menu + (GTK_OPTION_MENU(hbox->clabel_optmenu))); + action = filter_action_new(FLT_ACTION_COLOR_LABEL, + itos(color)); + break; + case PF_ACTION_MARK_READ: + action = filter_action_new(FLT_ACTION_MARK_READ, NULL); + break; + case PF_ACTION_FORWARD: + case PF_ACTION_FORWARD_AS_ATTACHMENT: + case PF_ACTION_REDIRECT: + break; + case PF_ACTION_STOP_EVAL: + action = filter_action_new(FLT_ACTION_STOP_EVAL, NULL); + break; + case PF_ACTION_SEPARATOR: + default: + break; + } + + if (error_msg) + *error_msg = error_msg_; + + return action; +} + static FilterRule *prefs_filter_edit_dialog_to_rule(void) { FilterRule *rule = NULL; @@ -1606,111 +1792,9 @@ static FilterRule *prefs_filter_edit_dialog_to_rule(void) for (cur = rule_edit_window.cond_edit.cond_hbox_list; cur != NULL; cur = cur->next) { CondHBox *hbox = (CondHBox *)cur->data; - GtkWidget *cond_type_menuitem; - CondMenuType cond_menu_type; - MatchMenuType match_menu_type; - const gchar *header_name; - const gchar *key_str; - gint int_value; - FilterCond *cond = NULL; - FilterMatchType match_type = FLT_CONTAIN; - FilterMatchFlag match_flag = 0; - SizeMatchType size_type; - AgeMatchType age_type; - - cond_type_menuitem = gtk_menu_get_active - (GTK_MENU(gtk_option_menu_get_menu - (GTK_OPTION_MENU(hbox->cond_type_optmenu)))); - cond_menu_type = GPOINTER_TO_INT - (g_object_get_data - (G_OBJECT(cond_type_menuitem), MENU_VAL_ID)); - - match_menu_type = menu_get_option_menu_active_index - (GTK_OPTION_MENU(hbox->match_type_optmenu)); - - key_str = gtk_entry_get_text(GTK_ENTRY(hbox->key_entry)); - - switch (match_menu_type) { - case PF_MATCH_CONTAIN: - match_type = FLT_CONTAIN; - break; - case PF_MATCH_NOT_CONTAIN: - match_type = FLT_CONTAIN; - match_flag |= FLT_NOT_MATCH; - break; - case PF_MATCH_EQUAL: - match_type = FLT_EQUAL; - break; - case PF_MATCH_NOT_EQUAL: - match_type = FLT_EQUAL; - match_flag |= FLT_NOT_MATCH; - break; - case PF_MATCH_REGEX: - match_type = FLT_REGEX; - break; - case PF_MATCH_NOT_REGEX: - match_type = FLT_REGEX; - match_flag |= FLT_NOT_MATCH; - break; - default: - break; - } - - switch (cond_menu_type) { - case PF_COND_HEADER: - header_name = g_object_get_data - (G_OBJECT(cond_type_menuitem), "header_str"); - cond = filter_cond_new(FLT_COND_HEADER, - match_type, match_flag, - header_name, key_str); - break; - case PF_COND_TO_OR_CC: - cond = filter_cond_new(FLT_COND_TO_OR_CC, match_type, - match_flag, NULL, key_str); - break; - case PF_COND_ANY_HEADER: - cond = filter_cond_new(FLT_COND_ANY_HEADER, match_type, - match_flag, NULL, key_str); - break; - case PF_COND_BODY: - cond = filter_cond_new(FLT_COND_BODY, match_type, - match_flag, NULL, key_str); - break; - case PF_COND_CMD_TEST: - if (key_str && *key_str) - cond = filter_cond_new(FLT_COND_CMD_TEST, - 0, 0, NULL, key_str); - else - error_msg = _("Command is not specified."); - break; - case PF_COND_SIZE: - size_type = menu_get_option_menu_active_index - (GTK_OPTION_MENU(hbox->size_match_optmenu)); - match_flag = size_type == PF_SIZE_LARGER - ? 0 : FLT_NOT_MATCH; - int_value = gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON(hbox->spin_btn)); - cond = filter_cond_new(FLT_COND_SIZE_GREATER, - 0, match_flag, NULL, - itos(int_value)); - break; - case PF_COND_AGE: - age_type = menu_get_option_menu_active_index - (GTK_OPTION_MENU(hbox->age_match_optmenu)); - match_flag = age_type == PF_AGE_LONGER - ? 0 : FLT_NOT_MATCH; - int_value = gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON(hbox->spin_btn)); - cond = filter_cond_new(FLT_COND_AGE_GREATER, - 0, match_flag, NULL, - itos(int_value)); - break; - case PF_COND_ACCOUNT: - case PF_COND_EDIT_HEADER: - default: - break; - } + FilterCond *cond; + cond = prefs_filter_edit_cond_hbox_to_cond(hbox, &error_msg); if (cond) cond_list = g_slist_append(cond_list, cond); else { @@ -1723,78 +1807,10 @@ static FilterRule *prefs_filter_edit_dialog_to_rule(void) for (cur = rule_edit_window.action_hbox_list; cur != NULL; cur = cur->next) { ActionHBox *hbox = (ActionHBox *)cur->data; - ActionMenuType action_menu_type; - const gchar *str; - guint color; - FilterAction *action = NULL; - - action_menu_type = prefs_filter_edit_get_action_hbox_type(hbox); - - switch (action_menu_type) { - case PF_ACTION_MOVE: - str = gtk_entry_get_text(GTK_ENTRY(hbox->folder_entry)); - if (str && *str) - action = filter_action_new(FLT_ACTION_MOVE, - str); - else - error_msg = _("Destination folder is not specified."); - break; - case PF_ACTION_COPY: - str = gtk_entry_get_text(GTK_ENTRY(hbox->folder_entry)); - if (str && *str) - action = filter_action_new(FLT_ACTION_COPY, - str); - else - error_msg = _("Destination folder is not specified."); - break; - case PF_ACTION_NOT_RECEIVE: - action = filter_action_new(FLT_ACTION_NOT_RECEIVE, - NULL); - break; - case PF_ACTION_DELETE: - action = filter_action_new(FLT_ACTION_DELETE, NULL); - break; - case PF_ACTION_EXEC: - str = gtk_entry_get_text(GTK_ENTRY(hbox->cmd_entry)); - if (str && *str) - action = filter_action_new(FLT_ACTION_EXEC, - str); - else - error_msg = _("Command is not specified."); - break; - case PF_ACTION_EXEC_ASYNC: - str = gtk_entry_get_text(GTK_ENTRY(hbox->cmd_entry)); - if (str && *str) - action = filter_action_new - (FLT_ACTION_EXEC_ASYNC, str); - else - error_msg = _("Command is not specified."); - break; - case PF_ACTION_MARK: - action = filter_action_new(FLT_ACTION_MARK, NULL); - break; - case PF_ACTION_COLOR_LABEL: - color = colorlabel_get_color_menu_active_item - (gtk_option_menu_get_menu - (GTK_OPTION_MENU(hbox->clabel_optmenu))); - action = filter_action_new(FLT_ACTION_COLOR_LABEL, - itos(color)); - break; - case PF_ACTION_MARK_READ: - action = filter_action_new(FLT_ACTION_MARK_READ, NULL); - break; - case PF_ACTION_FORWARD: - case PF_ACTION_FORWARD_AS_ATTACHMENT: - case PF_ACTION_REDIRECT: - break; - case PF_ACTION_STOP_EVAL: - action = filter_action_new(FLT_ACTION_STOP_EVAL, NULL); - break; - case PF_ACTION_SEPARATOR: - default: - break; - } + FilterAction *action; + action = prefs_filter_edit_action_hbox_to_action(hbox, + &error_msg); if (action) action_list = g_slist_append(action_list, action); else { diff --git a/src/prefs_filter_edit.h b/src/prefs_filter_edit.h index 80a27fae..99f9b1ce 100644 --- a/src/prefs_filter_edit.h +++ b/src/prefs_filter_edit.h @@ -134,6 +134,9 @@ FilterRule *prefs_filter_edit_open (FilterRule *rule, FilterCondEdit *prefs_filter_edit_cond_edit_create (void); void prefs_filter_edit_clear_cond_edit (FilterCondEdit *cond_edit); +void prefs_filter_edit_set_header_list (FilterCondEdit *cond_edit, + FilterRule *rule); + CondHBox *prefs_filter_edit_cond_hbox_create (FilterCondEdit *cond_edit); ActionHBox *prefs_filter_edit_action_hbox_create (void); @@ -156,4 +159,7 @@ void prefs_filter_edit_insert_cond_hbox (FilterCondEdit *cond_edit, CondHBox *hbox, gint pos); +FilterCond *prefs_filter_edit_cond_hbox_to_cond (CondHBox *hbox, + gchar **error_msg); + #endif /* __PREFS_FILTER_EDIT_H__ */ |