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;
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);
}
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;
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;
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)