fix english ;)
[claws.git] / src / prefs_filtering.c
index 1faf4b8fc1bfed2a324ba26750a58a2cafa788cc..61848d0432e4e1dbdce2b8222203cdef70573f53 100644 (file)
@@ -115,6 +115,8 @@ static void prefs_filtering_action_selection_changed(GtkList *list,
                                                     gpointer user_data);
                                          
 static void prefs_filtering_reset_dialog(void);
+static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data);
+static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data);
 
 static FolderItem * cur_item = NULL;
 
@@ -325,7 +327,7 @@ static void prefs_filtering_create(void)
 
        gchar *title[1];
 
-       debug_print("Creating filtering setting window...\n");
+       debug_print("Creating filtering configuration window...\n");
 
        window = gtk_window_new (GTK_WINDOW_DIALOG);
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);
@@ -344,7 +346,8 @@ static void prefs_filtering_create(void)
        gtk_widget_grab_default (ok_btn);
 
        gtk_window_set_title (GTK_WINDOW(window),
-                             _("Filtering setting"));
+                                   _("Filtering/Processing configuration"));
+
        gtk_signal_connect (GTK_OBJECT(window), "delete_event",
                            GTK_SIGNAL_FUNC(prefs_filtering_deleted), NULL);
        gtk_signal_connect (GTK_OBJECT(window), "key_press_event",
@@ -518,13 +521,13 @@ static void prefs_filtering_create(void)
        gtk_widget_show (btn_hbox);
        gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
 
-       reg_btn = gtk_button_new_with_label (_("Register"));
+       reg_btn = gtk_button_new_with_label (_("Add"));
        gtk_widget_show (reg_btn);
        gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
        gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
                            GTK_SIGNAL_FUNC (prefs_filtering_register_cb), NULL);
 
-       subst_btn = gtk_button_new_with_label (_(" Substitute "));
+       subst_btn = gtk_button_new_with_label (_("  Replace  "));
        gtk_widget_show (subst_btn);
        gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
        gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
@@ -550,7 +553,7 @@ static void prefs_filtering_create(void)
                                        GTK_POLICY_AUTOMATIC,
                                        GTK_POLICY_AUTOMATIC);
 
-       title[0] = _("Registered rules");
+       title[0] = _("Current filtering/processing rules");
        cond_clist = gtk_clist_new_with_titles(1, title);
        gtk_widget_show (cond_clist);
        gtk_container_add (GTK_CONTAINER (cond_scrolledwin), cond_clist);
@@ -609,22 +612,52 @@ static void prefs_filtering_update_hscrollbar(void)
 }
 
 void prefs_filtering_rename_path(const gchar *old_path, const gchar *new_path)
+{
+       GList * cur;
+       gchar *paths[2] = {NULL, NULL};
+       paths[0] = (gchar*)old_path;
+       paths[1] = (gchar*)new_path;
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_filtering_rename_path_func, paths);
+       }
+       prefs_filtering_rename_path_func(NULL, paths);
+}
+
+static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
 {
        GSList *cur;
+       gchar *old_path, *new_path;
        gchar *base;
        gchar *prefix;
        gchar *suffix;
        gchar *dest_path;
+       gchar *old_path_with_sep;
        gint destlen;
        gint prefixlen;
        gint oldpathlen;
+       FolderItem *item;
+
+       old_path = ((gchar **)data)[0];
+       new_path = ((gchar **)data)[1];
 
-       g_return_if_fail(old_path != NULL);
-       g_return_if_fail(new_path != NULL);
+       g_return_val_if_fail(old_path != NULL, FALSE);
+       g_return_val_if_fail(new_path != NULL, FALSE);
 
        oldpathlen = strlen(old_path);
+       old_path_with_sep = g_strconcat(old_path,G_DIR_SEPARATOR_S,NULL);
+       if (node == NULL)
+               cur = global_processing;
+       else {
+               item = node->data;
+               if (!item || !item->prefs) 
+                       return FALSE;
+               cur = item->prefs->processing;
+       }
 
-       for (cur = global_processing; cur != NULL; cur = cur->next) {
+       for (; cur != NULL; cur = cur->next) {
                FilteringProp   *filtering = (FilteringProp *)cur->data;
                FilteringAction *action = filtering->action;
 
@@ -656,28 +689,76 @@ void prefs_filtering_rename_path(const gchar *old_path, const gchar *new_path)
                                g_free(prefix);
                                g_free(action->destination);
                                action->destination = dest_path;
+                       } else { /* for non-leaf folders */
+                               /* compare with trailing slash */
+                               if (!strncmp(old_path_with_sep, action->destination, oldpathlen+1)) {
+                                       
+                                       suffix = action->destination + oldpathlen + 1;
+                                       dest_path = g_strconcat(new_path,
+                                                               G_DIR_SEPARATOR_S,
+                                                               suffix, NULL);
+                                       g_free(action->destination);
+                                       action->destination = dest_path;
+                               }
+                       }
+               } else {
+                       /* folder-moving a leaf */
+                       if (!strcmp(old_path, action->destination)) {           
+                               dest_path = g_strdup(new_path);
+                               g_free(action->destination);
+                               action->destination = dest_path;
                        }
                }
        }
-
+       g_free(old_path_with_sep);
        prefs_matcher_write_config();
+
+       return FALSE;
 }
 
 void prefs_filtering_delete_path(const gchar *path)
 {
-       GSList *cur;
+       GList * cur;
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_filtering_delete_path_func, (gchar *)path);
+       }
+       prefs_filtering_delete_path_func(NULL, (gchar *)path);
+}
+
+static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data)
+{
+       GSList *cur, *orig;
        GSList *next;
+       gchar *path = (gchar *)data;
        gchar *suffix;
        gint destlen;
        gint prefixlen;
        gint pathlen;
-
-       g_return_if_fail(path != NULL);
+       FolderItem *item;
+       
+       g_return_val_if_fail(path != NULL, FALSE);
 
        pathlen = strlen(path);
-       for (cur = global_processing; cur != NULL; cur = next) {
+       if (node == NULL)
+               cur = global_processing;
+       else {
+               item = node->data;
+               if (!item || !item->prefs)
+                       return FALSE;
+               cur = item->prefs->processing;
+       }
+       orig = cur;
+       
+       for (; cur != NULL; cur = cur->next) {
                FilteringProp *filtering = (FilteringProp *)cur->data;
-               FilteringAction *action = filtering->action;
+               FilteringAction *action;
+               if (!cur->data)
+                       break;
+               
+               action = filtering->action;
                next = cur->next;
 
                if (!action->destination) continue;
@@ -690,13 +771,27 @@ void prefs_filtering_delete_path(const gchar *path)
 
                        if (suffix && !strncmp(path, suffix, pathlen)) {
                                filteringprop_free(filtering);
-                               global_processing = 
-                                       g_slist_remove(global_processing, filtering);
+                               orig = g_slist_remove(orig, filtering);
                        }
+               } else if (strcmp(action->destination, path) == 0) {
+                       filteringprop_free(filtering);
+                       orig = g_slist_remove(orig, filtering);
+
                }
        }
 
+       if (node == NULL)
+               global_processing = orig;
+       else {
+               item = node->data;
+               if (!item || !item->prefs)
+                       return FALSE;
+               item->prefs->processing = orig;
+       }
+
        prefs_matcher_write_config();
+
+       return FALSE;
 }
 
 static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
@@ -839,7 +934,7 @@ static void prefs_filtering_condition_define(void)
        if (*cond_str != '\0') {
                matchers = matcher_parser_get_cond(cond_str);
                if (matchers == NULL)
-                       alertpanel_error(_("Match string is not valid."));
+                       alertpanel_error(_("Condition string is not valid."));
        }
 
        prefs_matcher_open(matchers, prefs_filtering_condition_define_done);
@@ -852,7 +947,7 @@ static void prefs_filtering_condition_define(void)
 /* register / substitute delete buttons */
 
 
-static FilteringProp * prefs_filtering_dialog_to_filtering(void)
+static FilteringProp * prefs_filtering_dialog_to_filtering(gboolean alert)
 {
        MatcherList * cond;
        gchar * cond_str;
@@ -867,7 +962,7 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        
        cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
        if (*cond_str == '\0') {
-               alertpanel_error(_("Score is not set."));
+               if(alert == TRUE) alertpanel_error(_("Condition string is empty."));
                return NULL;
        }
 
@@ -885,7 +980,7 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        case ACTION_EXECUTE:
                destination = gtk_entry_get_text(GTK_ENTRY(filtering.dest_entry));
                if (*destination == '\0') {
-                       alertpanel_error(_("Destination is not set."));
+                       if(alert == TRUE) alertpanel_error(_("Destination is not set."));
                        return NULL;
                }
                break;
@@ -907,7 +1002,7 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        cond = matcher_parser_get_cond(cond_str);
 
        if (cond == NULL) {
-               alertpanel_error(_("Match string is not valid."));
+               if(alert == TRUE) alertpanel_error(_("Condition string is not valid."));
                filteringaction_free(action);
                return NULL;
        }
@@ -921,7 +1016,7 @@ static void prefs_filtering_register_cb(void)
 {
        FilteringProp * prop;
        
-       prop = prefs_filtering_dialog_to_filtering();
+       prop = prefs_filtering_dialog_to_filtering(TRUE);
        if (prop == NULL)
                return;
        prefs_filtering_clist_set_row(-1, prop);
@@ -942,7 +1037,7 @@ static void prefs_filtering_substitute_cb(void)
        row = GPOINTER_TO_INT(clist->selection->data);
        if (row == 0) return;
 
-       prop = prefs_filtering_dialog_to_filtering();
+       prop = prefs_filtering_dialog_to_filtering(TRUE);
        if (prop == NULL)
                return;
        prefs_filtering_clist_set_row(row, prop);
@@ -1325,6 +1420,31 @@ static void prefs_filtering_key_pressed(GtkWidget *widget, GdkEventKey *event,
 
 static void prefs_filtering_ok(void)
 {
+       FilteringProp * prop;
+       gchar * str;
+       gchar * filtering_str;
+       gint row = 1;
+        AlertValue val;
+       
+       prop = prefs_filtering_dialog_to_filtering(FALSE);
+       if (prop != NULL) {
+               str = filteringprop_to_string(prop);
+               while (gtk_clist_get_text(GTK_CLIST(filtering.cond_clist),
+                                         row, 0, &filtering_str)) {
+                       if (strcmp(filtering_str, str) == 0) break;
+                       row++;
+               }
+               if (strcmp(filtering_str, str) != 0) {
+                        val = alertpanel(_("Entry not registered"),
+                                        _("The entry was not registered\nAre you really finished?"),
+                                        _("Yes"), _("No"), NULL);
+                        if (G_ALERTDEFAULT != val) {
+                               g_free(str);
+                               return;
+                        }
+               }
+               g_free(str);
+       }
        prefs_filtering_set_list();
        prefs_matcher_write_config();
        prefs_filtering_close();