2009-01-17 [colin] 3.7.0cvs37
[claws.git] / src / common / tags.c
index 5457de0ec4e52e7b248707bb12ce5d8c4208fead..c55e3d7140e4b9be219fa90fc00c10c38d42243f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 2007-2009 The Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -50,7 +50,7 @@ void tags_read_tags(void)
                        TAGS_RC, NULL);
        gchar tmp[255];
        gint id;
-       FILE *fp = fopen(file, "rb");
+       FILE *fp = g_fopen(file, "rb");
        
        g_free(file);
 
@@ -77,11 +77,17 @@ void tags_read_tags(void)
                        continue;
                g_strstrip(tag_name);
                *(sep) = '\0';
-               id = atoi(tmp);
-               g_hash_table_insert(tags_table,
-                                   GINT_TO_POINTER(id), g_strdup(tag_name));
-               g_hash_table_insert(tags_reverse_table,
-                                   g_strdup(tag_name), GINT_TO_POINTER(id));           
+               if (strcmp(tag_name, "NonJunk") && 
+                   strcmp(tag_name, "NotJunk") && 
+                   strcmp(tag_name, "NoJunk") && 
+                   strcmp(tag_name, "$Forwarded") && 
+                   strcmp(tag_name, "Junk")) {
+                       id = atoi(tmp);
+                       g_hash_table_insert(tags_table,
+                                           GINT_TO_POINTER(id), g_strdup(tag_name));
+                       g_hash_table_insert(tags_reverse_table,
+                                           g_strdup(tag_name), GINT_TO_POINTER(id));
+               }
        }
        
        fclose(fp);
@@ -116,10 +122,10 @@ void tags_write_tags(void)
                        TAGS_RC, NULL);
        TagWriteData data;
 
-       FILE *fp = fopen(file, "wb");
+       FILE *fp = g_fopen(file, "wb");
                        
        if (!fp) {
-               FILE_OP_ERROR(file, "fopen");
+               FILE_OP_ERROR(file, "g_fopen");
                g_free(file);
                g_free(file_new);
                return;
@@ -165,13 +171,21 @@ gint tags_add_tag(const gchar *tag)
        if (g_hash_table_lookup(tags_reverse_table, tag))
                return -1;
 
-       tag_max_id++;
-       g_hash_table_insert(tags_table, GINT_TO_POINTER(tag_max_id), 
-               g_strdup(tag));
-       g_hash_table_insert(tags_reverse_table, g_strdup(tag),
-               GINT_TO_POINTER(tag_max_id));
-       
-       return tag_max_id;
+       if (strcmp(tag, "NonJunk") && 
+           strcmp(tag, "NotJunk") && 
+           strcmp(tag, "NoJunk") && 
+           strcmp(tag, "$Forwarded") && 
+           strcmp(tag, "Junk")) {
+               tag_max_id++;
+               g_hash_table_insert(tags_table, GINT_TO_POINTER(tag_max_id), 
+                       g_strdup(tag));
+               g_hash_table_insert(tags_reverse_table, g_strdup(tag),
+                       GINT_TO_POINTER(tag_max_id));
+
+               return tag_max_id;
+       } else {
+               return -1;
+       }
 }
 
 void tags_remove_tag(gint id)
@@ -191,15 +205,21 @@ 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);
+       if (strcmp(tag, "NonJunk") && 
+           strcmp(tag, "NotJunk") && 
+           strcmp(tag, "NoJunk") && 
+           strcmp(tag, "$Forwarded") && 
+           strcmp(tag, "Junk")) {
+               if (old_tag) {
+                       prefs_filtering_rename_tag(old_tag, tag);
+                       g_hash_table_remove(tags_reverse_table, old_tag);
+               }
+
+               g_hash_table_replace(tags_table, GINT_TO_POINTER(id), 
+                       g_strdup(tag));
+               g_hash_table_insert(tags_reverse_table, g_strdup(tag),
+                       GINT_TO_POINTER(id));
        }
-
-       g_hash_table_replace(tags_table, GINT_TO_POINTER(id), 
-               g_strdup(tag));
-       g_hash_table_insert(tags_reverse_table, g_strdup(tag),
-               GINT_TO_POINTER(id));
 }
 
 const gchar *tags_get_tag(gint id)
@@ -240,3 +260,7 @@ GSList *tags_get_list(void)
        return data.list;
 }
 
+guint tags_get_size(void)
+{
+       return g_hash_table_size(tags_table);
+}