0.9.7claws11
authorChristoph Hohmann <reboot@gmx.ch>
Wed, 3 Dec 2003 12:11:50 +0000 (12:11 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Wed, 3 Dec 2003 12:11:50 +0000 (12:11 +0000)
* src/folder.[ch]
* src/imap.c
* src/localfolder.[ch]
* src/mh.c
* src/news.c
* src/common/xml.[ch]
        add set_xml() and get_xml() virtual functions to FolderClass to
        save extra information for Folders (for example the rootpath
        only used by LocalFolder). The folderlist write function no
        longer needs to know the folder type to save this extra
        information.

ChangeLog.claws
configure.ac
src/common/xml.c
src/common/xml.h
src/folder.c
src/folder.h
src/imap.c
src/localfolder.c
src/localfolder.h
src/mh.c
src/news.c

index 349edc60541376556dc35219f8b562000a418a8f..303d3378869699c64ac4e8989e43cf6d58e0afea 100644 (file)
@@ -1,3 +1,17 @@
+2003-12-03 [christoph] 0.9.7claws11
+
+       * src/folder.[ch]
+       * src/imap.c
+       * src/localfolder.[ch]
+       * src/mh.c
+       * src/news.c
+       * src/common/xml.[ch]
+               add set_xml() and get_xml() virtual functions to FolderClass to
+               save extra information for Folders (for example the rootpath
+               only used by LocalFolder). The folderlist write function no
+               longer needs to know the folder type to save this extra
+               information.
+
 2003-12-02 [christoph] 0.9.7claws10
 
        * src/Makefile.am
index 2d35665afecf0179fdfe6ba3f46e46867ba6cd26..9545b7104d0d631727fbfda0284cf92e64fdfa21 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=7
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=10
+EXTRA_VERSION=11
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index c6713ae8f1a5bb8a3ab230443fd9b8d69c3ea455..ac76e1c024a3425a67bd848009770ab1f28ddd10 100644 (file)
@@ -548,3 +548,14 @@ static gint xml_get_parenthesis(XMLFile *file, gchar *buf, gint len)
 
        return 0;
 }
+
+void xml_tag_add_attr(XMLTag *tag, const gchar *name, gchar *value)
+{
+       XMLAttr *attr;
+
+       attr = g_new0(XMLAttr, 1);
+       attr->name = XML_STRING_ADD(name);
+       attr->value = value;
+
+       tag->attr = g_list_append(tag->attr, attr);
+}
index 337bb50e9810d2af25af830e2fa491601c2bfeb0..dadded5538f8c71bfdcc5155afa621bb5cfd3e07 100644 (file)
@@ -92,5 +92,8 @@ void xml_free_node            (XMLNode        *node);
 void xml_free_tree             (GNode          *node);
 
 void xml_free_tag              (XMLTag         *tag);
+void xml_tag_add_attr          (XMLTag         *tag,
+                                const gchar    *name, 
+                                gchar          *value);
 
 #endif /* __XML_H__ */
index 0872e7adc1cdf9cbf3227e5ec43de90333ab9949..10c96658589d25468e57b295f7a6031a943b799e 100644 (file)
@@ -143,6 +143,47 @@ void folder_destroy(Folder *folder)
        g_free(folder);
 }
 
+void folder_set_xml(Folder *folder, XMLTag *tag)
+{
+       GList *cur;
+
+       for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
+               XMLAttr *attr = (XMLAttr *) cur->data;
+
+               if (!attr || !attr->name || !attr->value) continue;
+               if (!strcmp(attr->name, "name")) {
+                       if (folder->name != NULL)
+                               g_free(folder->name);
+                       folder->name = g_strdup(attr->value);
+               } else if (!strcmp(attr->name, "account_id")) {
+                       PrefsAccount *account;
+
+                       account = account_find_from_id(atoi(attr->value));
+                       if (!account)
+                               g_warning("account_id: %s not found\n", attr->value);
+                       else {
+                               folder->account = account;
+                               account->folder = folder;
+                       }
+               }
+       }
+}
+
+XMLTag *folder_get_xml(Folder *folder)
+{
+       XMLTag *tag;
+
+       tag = g_new0(XMLTag, 1);
+       tag->tag = g_strdup("folder");
+
+       if (folder->name)
+               xml_tag_add_attr(tag, "name", g_strdup(folder->name));
+       if (folder->account)
+               xml_tag_add_attr(tag, "account_id", g_strdup_printf("%d", folder->account->account_id));
+
+       return tag;
+}
+
 FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path)
 {
        FolderItem *item = NULL;
@@ -287,18 +328,7 @@ void folder_item_destroy(FolderItem *item)
        }
 }
 
-static void add_xml_attr(XMLTag *tag, const gchar *name, gchar *value)
-{
-       XMLAttr *attr;
-
-       attr = g_new0(XMLAttr, 1);
-       attr->name = g_strdup(name);
-       attr->value = value;
-
-       tag->attr = g_list_append(tag->attr, attr);
-}
-
-void folder_item_set_attrs(Folder *folder, FolderItem *item, XMLTag *tag)
+void folder_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
 {
        GList *cur;
 
@@ -396,7 +426,7 @@ void folder_item_set_attrs(Folder *folder, FolderItem *item, XMLTag *tag)
        }
 }
 
-XMLTag *folder_item_get_attrs(Folder *folder, FolderItem *item)
+XMLTag *folder_item_get_xml(Folder *folder, FolderItem *item)
 {
        static gchar *folder_item_stype_str[] = {"normal", "inbox", "outbox",
                                                 "draft", "queue", "trash"};
@@ -409,37 +439,37 @@ XMLTag *folder_item_get_attrs(Folder *folder, FolderItem *item)
        tag = g_new0(XMLTag, 1);
        tag->tag = g_strdup("folderitem");
 
-       add_xml_attr(tag, "type", g_strdup(folder_item_stype_str[item->stype]));
+       xml_tag_add_attr(tag, "type", g_strdup(folder_item_stype_str[item->stype]));
        if (item->name)
-               add_xml_attr(tag, "name", g_strdup(item->name));
+               xml_tag_add_attr(tag, "name", g_strdup(item->name));
        if (item->path)
-               add_xml_attr(tag, "path", g_strdup(item->path));
+               xml_tag_add_attr(tag, "path", g_strdup(item->path));
        if (item->no_sub)
-               add_xml_attr(tag, "no_sub", g_strdup("1"));
+               xml_tag_add_attr(tag, "no_sub", g_strdup("1"));
        if (item->no_select)
-               add_xml_attr(tag, "no_select", g_strdup("1"));
-       add_xml_attr(tag, "collapsed", g_strdup(item->collapsed && item->node->children ? "1" : "0"));
-       add_xml_attr(tag, "thread_collapsed", g_strdup(item->thread_collapsed ? "1" : "0"));
-       add_xml_attr(tag, "threaded", g_strdup(item->threaded ? "1" : "0"));
-       add_xml_attr(tag, "hidereadmsgs", g_strdup(item->hide_read_msgs ? "1" : "0"));
+               xml_tag_add_attr(tag, "no_select", g_strdup("1"));
+       xml_tag_add_attr(tag, "collapsed", g_strdup(item->collapsed && item->node->children ? "1" : "0"));
+       xml_tag_add_attr(tag, "thread_collapsed", g_strdup(item->thread_collapsed ? "1" : "0"));
+       xml_tag_add_attr(tag, "threaded", g_strdup(item->threaded ? "1" : "0"));
+       xml_tag_add_attr(tag, "hidereadmsgs", g_strdup(item->hide_read_msgs ? "1" : "0"));
        if (item->ret_rcpt)
-               add_xml_attr(tag, "reqretrcpt", g_strdup("1"));
+               xml_tag_add_attr(tag, "reqretrcpt", g_strdup("1"));
 
        if (item->sort_key != SORT_BY_NONE) {
-               add_xml_attr(tag, "sort_key", g_strdup(sort_key_str[item->sort_key]));
-               add_xml_attr(tag, "sort_type", g_strdup(item->sort_type == SORT_ASCENDING ? "ascending" : "descending"));
+               xml_tag_add_attr(tag, "sort_key", g_strdup(sort_key_str[item->sort_key]));
+               xml_tag_add_attr(tag, "sort_type", g_strdup(item->sort_type == SORT_ASCENDING ? "ascending" : "descending"));
        }
 
-       add_xml_attr(tag, "mtime", g_strdup_printf("%ld", (unsigned long int) item->mtime));
-       add_xml_attr(tag, "new", g_strdup_printf("%d", item->new_msgs));
-       add_xml_attr(tag, "unread", g_strdup_printf("%d", item->unread_msgs));
-       add_xml_attr(tag, "unreadmarked", g_strdup_printf("%d", item->unreadmarked_msgs));
-       add_xml_attr(tag, "total", g_strdup_printf("%d", item->total_msgs));
+       xml_tag_add_attr(tag, "mtime", g_strdup_printf("%ld", (unsigned long int) item->mtime));
+       xml_tag_add_attr(tag, "new", g_strdup_printf("%d", item->new_msgs));
+       xml_tag_add_attr(tag, "unread", g_strdup_printf("%d", item->unread_msgs));
+       xml_tag_add_attr(tag, "unreadmarked", g_strdup_printf("%d", item->unreadmarked_msgs));
+       xml_tag_add_attr(tag, "total", g_strdup_printf("%d", item->total_msgs));
 
        if (item->account)
-               add_xml_attr(tag, "account_id", g_strdup_printf("%d", item->account->account_id));
+               xml_tag_add_attr(tag, "account_id", g_strdup_printf("%d", item->account->account_id));
        if (item->apply_sub)
-               add_xml_attr(tag, "apply_sub", g_strdup("1"));
+               xml_tag_add_attr(tag, "apply_sub", g_strdup("1"));
 
        return tag;
 }
@@ -2436,7 +2466,7 @@ static gboolean folder_build_tree(GNode *node, gpointer data)
        if (folder->klass->item_set_xml != NULL)
                folder->klass->item_set_xml(folder, item, xmlnode->tag);
        else
-               folder_item_set_attrs(folder, item, xmlnode->tag);
+               folder_item_set_xml(folder, item, xmlnode->tag);
        item->node = node;
        item->parent = FOLDER_ITEM(node->parent->data);
        item->folder = folder;
@@ -2462,12 +2492,7 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
        FolderItem *item;
        XMLNode *xmlnode;
        GList *list;
-       FolderClass *class = NULL;
-       const gchar *name = NULL;
-       const gchar *path = NULL;
-       PrefsAccount *account = NULL;
-       gboolean collapsed = FALSE, threaded = TRUE, apply_sub = FALSE;
-       gboolean ret_rcpt = FALSE, thread_collapsed = FALSE; /* CLAWS */
+       FolderClass *klass = NULL;
 
        if (g_node_depth(node) != 2) return FALSE;
        g_return_val_if_fail(node->data != NULL, FALSE);
@@ -2484,45 +2509,29 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
 
                if (!attr || !attr->name || !attr->value) continue;
                if (!strcmp(attr->name, "type"))
-                       class = folder_get_class_from_string(attr->value);
-               else if (!strcmp(attr->name, "name"))
-                       name = attr->value;
-               else if (!strcmp(attr->name, "path"))
-                       path = attr->value;
-               else if (!strcmp(attr->name, "collapsed"))
-                       collapsed = *attr->value == '1' ? TRUE : FALSE;
-               else if (!strcmp(attr->name, "thread_collapsed"))
-                       thread_collapsed = *attr->value == '1' ? TRUE : FALSE;
-               else if (!strcmp(attr->name, "threaded"))
-                       threaded = *attr->value == '1' ? TRUE : FALSE;
-               else if (!strcmp(attr->name, "account_id")) {
-                       account = account_find_from_id(atoi(attr->value));
-                       if (!account) g_warning("account_id: %s not found\n",
-                                               attr->value);
-               } else if (!strcmp(attr->name, "apply_sub"))
-                       apply_sub = *attr->value == '1' ? TRUE : FALSE;
-               else if (!strcmp(attr->name, "reqretrcpt"))
-                       ret_rcpt = *attr->value == '1' ? TRUE : FALSE;
+                       klass = folder_get_class_from_string(attr->value);
        }
 
-       folder = folder_new(class, name, path);
+       folder = folder_new(klass, "", "");
        g_return_val_if_fail(folder != NULL, FALSE);
-       folder->account = account;
-       if (account != NULL)
-               account->folder = folder;
+
        item = FOLDER_ITEM(folder->node->data);
+       
        node->data = item;
        item->node = node;
        g_node_destroy(folder->node);
        folder->node = node;
-       folder_add(folder);
-       item->collapsed = collapsed;
-       item->thread_collapsed = thread_collapsed;
-       item->threaded  = threaded;
-       item->account   = account;
-       item->apply_sub = apply_sub;
-       item->ret_rcpt  = ret_rcpt;
+       if (klass->set_xml)
+               klass->set_xml(folder, xmlnode->tag);
+       else
+               folder_set_xml(folder, xmlnode->tag);
+
+       if (folder->klass->item_set_xml != NULL)
+               folder->klass->item_set_xml(folder, item, xmlnode->tag);
+       else
+               folder_item_set_xml(folder, item, xmlnode->tag);
 
+       folder_add(folder);
        g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
                        folder_build_tree, folder);
 
@@ -2547,11 +2556,22 @@ static gchar *folder_get_list_path(void)
        fputs("\"", fp);                                \
 }
 
+gint xml_attr_cmp_name(gconstpointer _a, gconstpointer _b)
+{
+       XMLAttr *a = (XMLAttr *) _a;
+       XMLAttr *b = (XMLAttr *) _b;
+       gint ret;
+
+       return g_str_equal(a->name, b->name) ? 0 : 1;
+}
+
 static void folder_write_list_recursive(GNode *node, gpointer data)
 {
        FILE *fp = (FILE *)data;
        FolderItem *item;
        gint i, depth;
+       XMLTag *tag;
+       GList *cur;
 
        g_return_if_fail(node != NULL);
        g_return_if_fail(fp != NULL);
@@ -2563,43 +2583,44 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
        for (i = 0; i < depth; i++)
                fputs("    ", fp);
        if (depth == 1) {
-               Folder *folder = item->folder;
-
-               fprintf(fp, "<folder type=\"%s\"", folder->klass->idstr);
-               if (folder->name)
-                       PUT_ESCAPE_STR(fp, "name", folder->name);
-               if (FOLDER_TYPE(folder) == F_MH || 
-                   FOLDER_TYPE(folder) == F_MBOX || 
-                   FOLDER_TYPE(folder) == F_MAILDIR)
-                       PUT_ESCAPE_STR(fp, "path",
-                                      LOCAL_FOLDER(folder)->rootpath);
-               if (item->collapsed && node->children)
-                       fputs(" collapsed=\"1\"", fp);
-               if (folder->account)
-                       fprintf(fp, " account_id=\"%d\"",
-                               folder->account->account_id);
-               if (item->apply_sub)
-                       fputs(" apply_sub=\"1\"", fp);
-               if (item->ret_rcpt) 
-                       fputs(" reqretrcpt=\"1\"", fp);
-       } else {
-               XMLTag *tag;
+               XMLTag *folderitem_tag;
                GList *cur;
 
+               if (item->folder->klass->get_xml != NULL)
+                       tag = item->folder->klass->get_xml(item->folder);
+               else
+                       tag = folder_get_xml(item->folder);
+
                if (item->folder->klass->item_get_xml != NULL)
-                       tag = item->folder->klass->item_get_xml(item->folder, item);
+                       folderitem_tag = item->folder->klass->item_get_xml(item->folder, item);
                else
-                       tag = folder_item_get_attrs(item->folder, item);
+                       folderitem_tag = folder_item_get_xml(item->folder, item);
+               xml_tag_add_attr(tag, "type", g_strdup(item->folder->klass->idstr));
 
-               fprintf(fp, "<%s", tag->tag);
-               for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
+               for (cur = folderitem_tag->attr; cur != NULL; cur = g_list_next(cur)) {
                        XMLAttr *attr = (XMLAttr *) cur->data;
 
-                       fprintf(fp, " %s=\"", attr->name);
-                       xml_file_put_escape_str(fp, attr->value);
-                       fputs("\"", fp);
+                       if (g_list_find_custom(tag->attr, attr, xml_attr_cmp_name) == NULL)
+                               tag->attr = g_list_append(tag->attr, xml_copy_attr(attr));
                }
-               xml_free_tag(tag);
+               xml_free_tag(folderitem_tag);
+
+       } else {
+
+               if (item->folder->klass->item_get_xml != NULL)
+                       tag = item->folder->klass->item_get_xml(item->folder, item);
+               else
+                       tag = folder_item_get_xml(item->folder, item);
+
+       }
+
+       fprintf(fp, "<%s", tag->tag);
+       for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
+               XMLAttr *attr = (XMLAttr *) cur->data;
+
+               fprintf(fp, " %s=\"", attr->name);
+               xml_file_put_escape_str(fp, attr->value);
+               fputs("\"", fp);
        }
 
        if (node->children) {
@@ -2617,9 +2638,10 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
 
                for (i = 0; i < depth; i++)
                        fputs("    ", fp);
-               fprintf(fp, "</%s>\n", depth == 1 ? "folder" : "folderitem");
+               fprintf(fp, "</%s>\n", tag->tag);
        } else
                fputs(" />\n", fp);
+       xml_free_tag(tag);
 }
 
 static void folder_update_op_count_rec(GNode *node)
index 370bcc72b6519998608ef29634ec98665a77591f..739e3fdcd931f0684dfcce18005dd5d9f896057e 100644 (file)
@@ -161,6 +161,9 @@ struct _FolderClass
        Folder          *(*new_folder)          (const gchar    *name,
                                                 const gchar    *path);
        void            (*destroy_folder)       (Folder         *folder);
+       void             (*set_xml)             (Folder         *folder,
+                                                XMLTag         *tag);
+       XMLTag          *(*get_xml)             (Folder         *folder);
        gint            (*scan_tree)            (Folder         *folder);
 
        gint            (*create_tree)          (Folder         *folder);
@@ -323,8 +326,9 @@ void            folder_init                 (Folder         *folder,
 
 void        folder_destroy             (Folder         *folder);
 
-XMLTag            *folder_item_get_attrs       (Folder          *folder,
-                                        FolderItem      *item);
+void       folder_set_xml              (Folder          *folder,
+                                        XMLTag          *tag);
+XMLTag            *folder_get_xml              (Folder          *folder);
 
 FolderItem *folder_item_new            (Folder         *folder,
                                         const gchar    *name,
@@ -335,6 +339,12 @@ void        folder_item_remove             (FolderItem     *item);
 void        folder_item_remove_children        (FolderItem     *item);
 void        folder_item_destroy                (FolderItem     *item);
 
+void       folder_item_set_xml         (Folder          *folder,
+                                        FolderItem      *item,
+                                        XMLTag          *tag);
+XMLTag            *folder_item_get_xml         (Folder          *folder,
+                                        FolderItem      *item);
+
 void        folder_set_ui_func (Folder         *folder,
                                 FolderUIFunc    func,
                                 gpointer        data);
index b12f4b4100c36884a2c5a6de99c2ebb0da883583..492f692337a5036d0e5bfc9b0f83ece365eebe53 100644 (file)
@@ -447,6 +447,8 @@ static FolderClass imap_class =
        /* Folder functions */
        imap_folder_new,
        imap_folder_destroy,
+       NULL,
+       NULL,
        imap_scan_tree,
        imap_create_tree,
 
index 98a097d767952e037d1185505bc25a40686a112f..bd2115354344271f24463da4e0ed5e572eab9c64 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "folder.h"
 #include "localfolder.h"
+#include "xml.h"
 
 void folder_local_folder_init(Folder *folder, const gchar *name,
                              const gchar *path)
@@ -35,3 +36,35 @@ void folder_local_folder_destroy(LocalFolder *lfolder)
 
        g_free(lfolder->rootpath);
 }
+
+void folder_local_set_xml(Folder *_folder, XMLTag *tag)
+{
+       LocalFolder *folder = LOCAL_FOLDER(_folder);
+       GList *cur;
+
+       folder_set_xml(_folder, tag);
+
+       for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
+               XMLAttr *attr = (XMLAttr *) cur->data;
+
+               if (!attr || !attr->name || !attr->value) continue;
+               if (!strcmp(attr->name, "path")) {
+                       if (folder->rootpath != NULL)
+                               g_free(folder->rootpath);
+                       folder->rootpath = g_strdup(attr->value);
+               }
+       }
+}
+
+XMLTag *folder_local_get_xml(Folder *_folder)
+{
+       LocalFolder *folder = LOCAL_FOLDER(_folder);
+       XMLTag *tag;
+       XMLAttr *attr;
+
+       tag = folder_get_xml(_folder);
+
+       xml_tag_add_attr(tag, "path", g_strdup(folder->rootpath));
+
+       return tag;
+}
index 7c7e8f9846098b63b5a63018abe831684e3b3f16..b214fed0970b2c108f2dd00f2aa090f44b0c79ed 100644 (file)
@@ -35,8 +35,12 @@ struct _LocalFolder
        gchar *rootpath;
 };
 
-void   folder_local_folder_init        (Folder *folder, const gchar *name,
-                                        const gchar *path);
+void   folder_local_folder_init        (Folder         *folder,
+                                        const gchar    *name,
+                                        const gchar    *path);
 void   folder_local_folder_destroy     (LocalFolder    *lfolder);
+void   folder_local_set_xml            (Folder         *folder,
+                                        XMLTag         *tag);
+XMLTag *folder_local_get_xml           (Folder         *folder);
 
 #endif /* LOCALFOLDER_H */
index dd1338e70ce857cd076ce42f3c66d797dc04ffd2..4ff99775f273e328d65c3745c980e14da04b244f 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -113,6 +113,8 @@ static FolderClass mh_class =
        /* Folder functions */
        mh_folder_new,
        mh_folder_destroy,
+       folder_local_set_xml,
+       folder_local_get_xml,
        mh_scan_tree,
        mh_create_tree,
 
index 24a4adb21098f512dc147a7bbef1bf979984f8e1..b02ffd6e301a1c9e80778c133e56f27c2e0dd580 100644 (file)
@@ -141,6 +141,8 @@ static FolderClass news_class =
        news_folder_destroy,
        NULL,
        NULL,
+       NULL,
+       NULL,
 
        /* FolderItem functions */
        NULL,