2007-09-16 [colin] 3.0.0cvs15
authorColin Leroy <colin@colino.net>
Sun, 16 Sep 2007 09:55:56 +0000 (09:55 +0000)
committerColin Leroy <colin@colino.net>
Sun, 16 Sep 2007 09:55:56 +0000 (09:55 +0000)
* src/prefs_filtering.c
* src/prefs_filtering.h
* src/prefs_filtering_action.c
* src/common/tags.c
Fix tags issues: tags with spaces, renaming
tags.

ChangeLog
PATCHSETS
configure.ac
src/common/tags.c
src/prefs_filtering.c
src/prefs_filtering.h
src/prefs_filtering_action.c

index 6d7cec370b94a8a07634c33f347a3b524488b3c7..0698a4179aae31c83abf0694d27fd7e39a090238 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-09-16 [colin]     3.0.0cvs15
+
+       * src/prefs_filtering.c
+       * src/prefs_filtering.h
+       * src/prefs_filtering_action.c
+       * src/common/tags.c
+               Fix tags issues: tags with spaces, renaming
+               tags.
+
 2007-09-16 [colin]     3.0.0cvs14
 
        * src/folderview.c
index 0b1229b460d4ef213d9cd287473aac4cf8437734..3930cc796183691c08976c8b077a20343d2967bc 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.17.2.27 -r 1.17.2.28 po/sr.po;  ) > 3.0.0cvs12.patchset
 ( cvs diff -u -r 1.382.2.407 -r 1.382.2.408 src/compose.c;  ) > 3.0.0cvs13.patchset
 ( cvs diff -u -r 1.207.2.181 -r 1.207.2.182 src/folderview.c;  cvs diff -u -r 1.115.2.166 -r 1.115.2.167 src/main.c;  cvs diff -u -r 1.274.2.210 -r 1.274.2.211 src/mainwindow.c;  ) > 3.0.0cvs14.patchset
+( cvs diff -u -r 1.59.2.57 -r 1.59.2.58 src/prefs_filtering.c;  cvs diff -u -r 1.6.2.7 -r 1.6.2.8 src/prefs_filtering.h;  cvs diff -u -r 1.1.4.39 -r 1.1.4.40 src/prefs_filtering_action.c;  cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/common/tags.c;  ) > 3.0.0cvs15.patchset
index db2a463856c5827b814ec9e854b21bb1ad447170..3ec0e2560a9bea1333aae4572e99837fab9e039c 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=14
+EXTRA_VERSION=15
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index b9ced957161fd00fb473b16e38c3ed6292cec042..970b37a28c0e268cc8f28d7530a4aa72b0a0ccb6 100644 (file)
@@ -69,11 +69,19 @@ void tags_read_tags(void)
                fclose(fp);
                return;
        }
-       while (fscanf(fp, "%d\t%254s\n", &id, tmp) == 2) {
+       while (fgets(&tmp, sizeof(tmp), fp) != NULL) {
+               gchar *sep = strchr(tmp, '\t');
+               gchar *tag_name = sep?(sep+1):NULL;
+               
+               if (!tag_name || !sep)
+                       continue;
+               g_strstrip(tag_name);
+               *(sep) = '\0';
+               id = atoi(tmp);
                g_hash_table_insert(tags_table,
-                                   GINT_TO_POINTER(id), g_strdup(tmp));
+                                   GINT_TO_POINTER(id), g_strdup(tag_name));
                g_hash_table_insert(tags_reverse_table,
-                                   g_strdup(tmp), GINT_TO_POINTER(id));                
+                                   g_strdup(tag_name), GINT_TO_POINTER(id));           
        }
        
        fclose(fp);
@@ -128,6 +136,7 @@ void tags_write_tags(void)
        }
 
        if (data.error) {
+               fclose(fp);
                g_free(file);
                g_free(file_new);
                return;
@@ -139,9 +148,9 @@ void tags_write_tags(void)
                g_free(file_new);
                return;
        }
-       
-       if (g_rename(file, file_new) < 0) {
-               FILE_OP_ERROR(file, "g_rename");
+
+       if (rename_force(file, file_new) < 0) {
+               FILE_OP_ERROR(file, "rename_force");
        }
 
        g_free(file);
@@ -175,11 +184,15 @@ void tags_remove_tag(gint id)
        g_hash_table_remove(tags_table, GINT_TO_POINTER(id));
 }
 
+/* extern decl. to avoid including ../prefs_filtering.h */
+extern void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag);
+
 void tags_update_tag(gint id, const gchar *tag)
 {
        gchar *old_tag = g_hash_table_lookup(tags_table, GINT_TO_POINTER(id));
 
        if (old_tag) {
+               prefs_filtering_rename_tag(old_tag, tag);
                g_hash_table_remove(tags_reverse_table, old_tag);
        }
 
index 79cb6f32a6188c04184a3481e5870fe217fa0bf0..5177c64edcdeae0e3cf2ff8a2760a3b1d0005815 100644 (file)
@@ -117,6 +117,7 @@ static void prefs_filtering_action_define(void);
 static gint prefs_filtering_list_view_set_row  (gint row, FilteringProp * prop);
                                          
 static void prefs_filtering_reset_dialog       (void);
+static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data);
 static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data);
 static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data);
 
@@ -534,6 +535,30 @@ static void prefs_filtering_create(void)
        filtering.account_label  = account_label;
 }
 
+static void rename_tag(GSList * filters,
+                       const gchar * old_tag, const gchar * new_tag);
+
+void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag)
+{
+       GList * cur;
+       const gchar *tags[2] = {NULL, NULL};
+       tags[0] = old_tag;
+       tags[1] = new_tag;
+       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_tag_func, tags);
+       }
+        
+       rename_tag(pre_global_processing, old_tag, new_tag);
+       rename_tag(post_global_processing, old_tag, new_tag);
+       rename_tag(filtering_rules, old_tag, new_tag);
+        
+       prefs_matcher_write_config();
+}
+
+
 static void rename_path(GSList * filters,
                        const gchar * old_path, const gchar * new_path);
 
@@ -582,7 +607,11 @@ static void rename_path(GSList * filters,
 
                         FilteringAction *action = action_cur->data;
                         
-                        if (!action->destination) continue;
+                        if (action->type == MATCHACTION_SET_TAG ||
+                           action->type == MATCHACTION_UNSET_TAG)
+                               continue;
+                        if (!action->destination) 
+                               continue;
                         
                         destlen = strlen(action->destination);
                         
@@ -660,6 +689,59 @@ static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
        return FALSE;
 }
 
+static void rename_tag(GSList * filters,
+                       const gchar * old_tag, const gchar * new_tag)
+{
+        GSList * action_cur;
+        GSList * cur;
+
+       for (cur = filters; cur != NULL; cur = cur->next) {
+               FilteringProp   *filtering = (FilteringProp *)cur->data;
+                
+                for(action_cur = filtering->action_list ; action_cur != NULL ;
+                    action_cur = action_cur->next) {
+
+                        FilteringAction *action = action_cur->data;
+                        
+                        if (action->type != MATCHACTION_SET_TAG &&
+                           action->type != MATCHACTION_UNSET_TAG)
+                               continue;
+                        if (!action->destination)
+                               continue;
+                        if (!strcmp(action->destination, old_tag)) {
+                               g_free(action->destination);
+                               action->destination = g_strdup(new_tag);
+                       }
+                }
+        }
+}
+
+static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data)
+{
+       GSList *filters;
+       const gchar * old_tag;
+        const gchar * new_tag;
+        const gchar ** tags;
+       FolderItem *item;
+        
+        tags = data;
+       old_tag = tags[0];
+       new_tag = tags[1];
+
+       g_return_val_if_fail(old_tag != NULL, FALSE);
+       g_return_val_if_fail(new_tag != NULL, FALSE);
+       g_return_val_if_fail(node != NULL, FALSE);
+
+        item = node->data;
+        if (!item || !item->prefs)
+                return FALSE;
+        filters = item->prefs->processing;
+
+        rename_tag(filters, old_tag, new_tag);
+
+       return FALSE;
+}
+
 void prefs_filtering_delete_path(const gchar *path)
 {
        GList * cur;
@@ -700,7 +782,11 @@ static void delete_path(GSList ** p_filters, const gchar * path)
                         
                         action = action_cur->data;
                         
-                        if (!action->destination) continue;
+                        if (action->type == MATCHACTION_SET_TAG ||
+                           action->type == MATCHACTION_UNSET_TAG)
+                               continue;
+                        if (!action->destination) 
+                               continue;
                         
                         destlen = strlen(action->destination);
                         
index 44fa46bba5e8cba0d845d63f07c278444e7b5381..b2cb66e1c883582b43de8bd9ae7ea881232e3eb5 100644 (file)
@@ -49,4 +49,6 @@ void prefs_filtering_rename_path      (const gchar    *old_path,
                                         const gchar    *new_path);
 void prefs_filtering_delete_path       (const gchar    *path);
 
+void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag);
+
 #endif /* __PREFS_FILTERING_H__ */
index a54faa21c8cc4f8e22f6019b45a7fd5c65b94967..687f2c78d896ed3a57e8b8fbf838f771d04a4f6f 100644 (file)
@@ -1173,7 +1173,8 @@ static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
  */
 static void prefs_filtering_action_cancel(void)
 {
-       gtk_widget_hide(filtering_action.window);
+       gtk_widget_destroy(filtering_action.window);
+       filtering_action.window = NULL;
        inc_unlock();
 }
 
@@ -1199,7 +1200,8 @@ static void prefs_filtering_action_ok(void)
         }
         g_slist_free(action_list);
 
-       gtk_widget_hide(filtering_action.window);
+       gtk_widget_destroy(filtering_action.window);
+       filtering_action.window = NULL;
         inc_unlock();
 }