0.8.5claws179
[claws.git] / src / prefs_filtering.c
index 733ca89b1c281a439925259d5d26205404158db5..104cc7a44275c97b149a8fcf6117b540507fc4da 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;
 
@@ -316,7 +318,6 @@ static void prefs_filtering_create(void)
        GtkWidget *up_btn;
        GtkWidget *down_btn;
 
-       GtkWidget *dummy;
 
        GList *combo_items;
        gint i;
@@ -326,7 +327,7 @@ static void prefs_filtering_create(void)
 
        gchar *title[1];
 
-       debug_print(_("Creating filtering setting window...\n"));
+       debug_print("Creating filtering setting window...\n");
 
        window = gtk_window_new (GTK_WINDOW_DIALOG);
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);
@@ -610,22 +611,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;
 
@@ -657,28 +688,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;
@@ -694,10 +773,17 @@ void prefs_filtering_delete_path(const gchar *path)
                                global_processing = 
                                        g_slist_remove(global_processing, filtering);
                        }
+               } else if (strcmp(action->destination, path) == 0) {
+                       filteringprop_free(filtering);
+                       orig = 
+                               g_slist_remove(orig, filtering);
+
                }
        }
 
        prefs_matcher_write_config();
+
+       return FALSE;
 }
 
 static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
@@ -759,7 +845,6 @@ static void prefs_filtering_set_list(void)
        FilteringProp *prop;
        GSList * cur;
        gchar * filtering_str;
-       gchar * tmp;
        GSList * prefs_filtering;
 
        if (cur_item == NULL)
@@ -839,9 +924,6 @@ static void prefs_filtering_condition_define(void)
        cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
 
        if (*cond_str != '\0') {
-               gchar * tmp;
-               
-               /* tmp = cond_str; */
                matchers = matcher_parser_get_cond(cond_str);
                if (matchers == NULL)
                        alertpanel_error(_("Match string is not valid."));
@@ -863,13 +945,12 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        gchar * cond_str;
        FilteringProp * prop;
        FilteringAction * action;
-       gchar * tmp;
        gint list_id;
        gint action_id;
        gint action_type;
        gint account_id;
        gchar * destination;
-       gint labelcolor;
+       gint labelcolor = 0;
        
        cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
        if (*cond_str == '\0') {
@@ -1104,7 +1185,6 @@ static void prefs_filtering_select(GtkCList *clist, gint row, gint column,
                                GdkEvent *event)
 {
        FilteringProp * prop;
-       gchar * tmp;
        gchar * filtering_str;
 
        if (row == 0) {