0.8.11claws7
authorChristoph Hohmann <reboot@gmx.ch>
Thu, 13 Mar 2003 15:31:22 +0000 (15:31 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Thu, 13 Mar 2003 15:31:22 +0000 (15:31 +0000)
* src/account.c
* src/folder.[ch]
* src/imap.c
* src/mainwindow.c
* src/mbox_folder.c
* src/mh.c
* src/news.c
* src/setup.c
        replace more folder type stuff with folder class stuff

ChangeLog.claws
configure.ac
src/account.c
src/folder.c
src/folder.h
src/imap.c
src/mainwindow.c
src/mbox_folder.c
src/mh.c
src/news.c
src/setup.c

index f6b36b8..a744935 100644 (file)
@@ -1,3 +1,15 @@
+2003-03-13 [christoph] 0.8.11claws7
+
+       * src/account.c
+       * src/folder.[ch]
+       * src/imap.c
+       * src/mainwindow.c
+       * src/mbox_folder.c
+       * src/mh.c
+       * src/news.c
+       * src/setup.c
+               replace more folder type stuff with folder class stuff
+
 2003-03-13 [melvin]    0.8.11claws6
 
        * src/prefs_actions.c
index 67aa9aa..7453737 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws6
+EXTRA_VERSION=claws7
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 8b87135..68304c8 100644 (file)
@@ -341,10 +341,10 @@ void account_add(void)
                Folder *folder;
 
                if (ac_prefs->protocol == A_IMAP4) {
-                       folder = folder_new(F_IMAP, ac_prefs->account_name,
+                       folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
                                            ac_prefs->recv_server);
                } else {
-                       folder = folder_new(F_NEWS, ac_prefs->account_name,
+                       folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
                                            ac_prefs->nntp_server);
                }
 
@@ -424,10 +424,10 @@ void account_set_missing_folder(void)
                        Folder *folder;
 
                        if (ap->protocol == A_IMAP4) {
-                               folder = folder_new(F_IMAP, ap->account_name,
+                               folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
                                                    ap->recv_server);
                        } else {
-                               folder = folder_new(F_NEWS, ap->account_name,
+                               folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
                                                    ap->nntp_server);
                        }
 
index e245f72..afa143d 100644 (file)
@@ -95,28 +95,15 @@ void folder_register_class(FolderClass *class)
        classlist = g_slist_append(classlist, class);
 }
 
-Folder *folder_new(FolderType type, const gchar *name, const gchar *path)
+Folder *folder_new(FolderClass *class, const gchar *name, const gchar *path)
 {
        Folder *folder = NULL;
        FolderItem *item;
 
+       g_return_val_if_fail(class != NULL, NULL);
+
        name = name ? name : path;
-       switch (type) {
-       case F_MBOX:
-               folder = mbox_folder_new(name, path);
-               break;
-       case F_MH:
-               folder = mh_folder_new(name, path);
-               break;
-       case F_IMAP:
-               folder = imap_folder_new(name, path);
-               break;
-       case F_NEWS:
-               folder = news_folder_new(name, path);
-               break;
-       default:
-               return NULL;
-       }
+       folder = class->new(name, path);
 
        /* Create root folder item */
        item = folder_item_new(folder, name, NULL);
@@ -185,20 +172,6 @@ void folder_remote_folder_destroy(RemoteFolder *rfolder)
                session_destroy(rfolder->session);
 }
 
-#if 0
-Folder *mbox_folder_new(const gchar *name, const gchar *path)
-{
-       /* not yet implemented */
-       return NULL;
-}
-
-Folder *maildir_folder_new(const gchar *name, const gchar *path)
-{
-       /* not yet implemented */
-       return NULL;
-}
-#endif
-
 FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path)
 {
        FolderItem *item = NULL;
@@ -604,14 +577,14 @@ FolderItem *folder_find_item_from_path(const gchar *path)
        return d[1];
 }
 
-static FolderClass *folder_get_class_from_string(const gchar *str)
+FolderClass *folder_get_class_from_string(const gchar *str)
 {
        GSList *classlist;
 
        classlist = folder_get_class_list();
        for (; classlist != NULL; classlist = g_slist_next(classlist)) {
                FolderClass *class = (FolderClass *) classlist->data;
-               if (g_strcasecmp(class->idstr, &str[1]) == 0)
+               if (g_strcasecmp(class->idstr, str) == 0)
                        return class;
        }
 
@@ -665,7 +638,7 @@ FolderItem *folder_find_item_from_identifier(const gchar *identifier)
                return folder_find_item_from_path(identifier);
        *p = '\0';
        p++;
-       class = folder_get_class_from_string(str);
+       class = folder_get_class_from_string(&str[1]);
        if (class == NULL)
                return folder_find_item_from_path(identifier);
 
@@ -2281,7 +2254,7 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
        Folder *folder;
        XMLNode *xmlnode;
        GList *list;
-       FolderType type = F_UNKNOWN;
+       FolderClass *class = NULL;
        const gchar *name = NULL;
        const gchar *path = NULL;
        PrefsAccount *account = NULL;
@@ -2302,18 +2275,9 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
                XMLAttr *attr = list->data;
 
                if (!attr || !attr->name || !attr->value) continue;
-               if (!strcmp(attr->name, "type")) {
-                       if (!strcasecmp(attr->value, "mh"))
-                               type = F_MH;
-                       else if (!strcasecmp(attr->value, "mbox"))
-                               type = F_MBOX;
-                       else if (!strcasecmp(attr->value, "maildir"))
-                               type = F_MAILDIR;
-                       else if (!strcasecmp(attr->value, "imap"))
-                               type = F_IMAP;
-                       else if (!strcasecmp(attr->value, "news"))
-                               type = F_NEWS;
-               } else if (!strcmp(attr->name, "name"))
+               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;
@@ -2333,10 +2297,10 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
                        ret_rcpt = *attr->value == '1' ? TRUE : FALSE;
        }
 
-       folder = folder_new(type, name, path);
+       folder = folder_new(class, name, path);
        g_return_val_if_fail(folder != NULL, FALSE);
        folder->account = account;
-       if (account && (type == F_IMAP || type == F_NEWS))
+       if (account != NULL)
                account->folder = REMOTE_FOLDER(folder);
        node->data = folder->node->data;
        g_node_destroy(folder->node);
@@ -2567,7 +2531,7 @@ static void folder_create_processing_folder(void)
                                      G_DIR_SEPARATOR_S, PROCESSING_FOLDER,
                                      NULL);
 
-       processing_folder = folder_new(F_MH, "PROCESSING", LOCAL_FOLDER(tmpparent)->rootpath);
+       processing_folder = folder_new(mh_get_class(), "PROCESSING", LOCAL_FOLDER(tmpparent)->rootpath);
        g_assert(processing_folder);
 
        if (!is_dir_exist(tmpname)) {
index 4bf0374..572e7f6 100644 (file)
@@ -155,75 +155,79 @@ struct _FolderClass
        gchar      *idstr;
 
        /* virtual functions */
-/*
-       GSList * (*get_msg_list)        (Folder         *folder,
-                                        FolderItem     *item,
-                                        gboolean        use_cache);
-*/
-       FolderItem *(*item_new)         (Folder         *folder);
-       void     (*item_destroy)        (Folder         *folder,
-                                        FolderItem     *item);
-       gchar *  (*fetch_msg)           (Folder         *folder,
-                                        FolderItem     *item,
-                                        gint            num);
-       MsgInfo * (*get_msginfo)        (Folder         *folder,
-                                        FolderItem     *item,
-                                        gint            num);
-       GSList  * (*get_msginfos)       (Folder         *folder,
-                                        FolderItem     *item,
-                                        GSList         *msgnum_list);
-       gint     (*add_msg)             (Folder         *folder,
-                                        FolderItem     *dest,
-                                        const gchar    *file,
-                                        gboolean        remove_source);
-       gint     (*move_msg)            (Folder         *folder,
-                                        FolderItem     *dest,
-                                        MsgInfo        *msginfo);
-       gint     (*move_msgs_with_dest) (Folder         *folder,
-                                        FolderItem     *dest,
-                                        GSList         *msglist);
-       gint     (*copy_msg)            (Folder         *folder,
-                                        FolderItem     *dest,
-                                        MsgInfo        *msginfo);
-       gint     (*copy_msgs_with_dest) (Folder         *folder,
-                                        FolderItem     *dest,
-                                        GSList         *msglist);
-       gint     (*remove_msg)          (Folder         *folder,
-                                        FolderItem     *item,
-                                        gint            num);
-       gint     (*remove_msgs)         (Folder         *folder,
-                                        FolderItem     *item,
-                                        GSList         *msglist);
-       gint     (*remove_all_msg)      (Folder         *folder,
-                                        FolderItem     *item);
-       gboolean (*is_msg_changed)      (Folder         *folder,
-                                        FolderItem     *item,
-                                        MsgInfo        *msginfo);
-       gint     (*scan)                (Folder         *folder);
-       gint     (*get_num_list)        (Folder         *folder,
-                                        FolderItem     *item,
-                                        GSList        **list);
-       void     (*scan_tree)           (Folder         *folder);
-
-       gint     (*create_tree)         (Folder         *folder);
-       FolderItem * (*create_folder)   (Folder         *folder,
-                                        FolderItem     *parent,
-                                        const gchar    *name);
-       gint     (*rename_folder)       (Folder         *folder,
-                                        FolderItem     *item,
-                                        const gchar    *name);
-       gint     (*remove_folder)       (Folder         *folder,
-                                        FolderItem     *item);
-
-       void     (*destroy)             (Folder         *folder);
-       void     (*update_mark)         (Folder         *folder,
-                                        FolderItem     *item);
-       void     (*change_flags)        (Folder         *folder,
-                                        FolderItem     *item,
-                                        MsgInfo        *info);
-       void     (*finished_copy)       (Folder * folder, FolderItem * item);
-       void     (*finished_remove)     (Folder * folder, FolderItem * item);
-       gboolean (*check_msgnum_validity) (Folder * folder, FolderItem * item);
+
+       /* Folder funtions */
+       Folder          *(*new)                 (const gchar    *name,
+                                                const gchar    *path);
+       void            (*destroy)              (Folder         *folder);
+       void            (*scan_tree)            (Folder         *folder);
+
+       gint            (*create_tree)          (Folder         *folder);
+
+       /* FolderItem functions */
+       FolderItem      *(*item_new)            (Folder         *folder);
+       void            (*item_destroy)         (Folder         *folder,
+                                                FolderItem     *item);
+       FolderItem      *(*create_folder)       (Folder         *folder,
+                                                FolderItem     *parent,
+                                                const gchar    *name);
+       gint            (*rename_folder)        (Folder         *folder,
+                                                FolderItem     *item,
+                                                const gchar    *name);
+       gint            (*remove_folder)        (Folder         *folder,
+                                                FolderItem     *item);
+       gint            (*get_num_list)         (Folder         *folder,
+                                                FolderItem     *item,
+                                                GSList        **list);
+       void            (*update_mark)          (Folder         *folder,
+                                                FolderItem     *item);
+       void            (*finished_copy)        (Folder         *folder,
+                                                FolderItem     *item);
+       void            (*finished_remove)      (Folder         *folder,
+                                                FolderItem * item);
+       gboolean        (*check_msgnum_validity)(Folder         *folder,
+                                                FolderItem * item);
+
+       /* Message functions */
+       MsgInfo         *(*get_msginfo)         (Folder         *folder,
+                                                FolderItem     *item,
+                                                gint            num);
+       GSList          *(*get_msginfos)        (Folder         *folder,
+                                                FolderItem     *item,
+                                                GSList         *msgnum_list);
+       gchar           *(*fetch_msg)           (Folder         *folder,
+                                                FolderItem     *item,
+                                                gint            num);
+       gint            (*add_msg)              (Folder         *folder,
+                                                FolderItem     *dest,
+                                                const gchar    *file,
+                                               gboolean         remove_source);
+       gint            (*move_msg)             (Folder         *folder,
+                                                FolderItem     *dest,
+                                                MsgInfo        *msginfo);
+       gint            (*move_msgs_with_dest)  (Folder         *folder,
+                                                FolderItem     *dest,
+                                                GSList         *msglist);
+       gint            (*copy_msg)             (Folder         *folder,
+                                                FolderItem     *dest,
+                                                MsgInfo        *msginfo);
+       gint            (*copy_msgs_with_dest)  (Folder         *folder,
+                                                FolderItem     *dest,
+                                                GSList         *msglist);
+       gint            (*remove_msg)           (Folder         *folder,
+                                                FolderItem     *item,
+                                                gint            num);
+       gint            (*remove_msgs)          (Folder         *folder,
+                                                FolderItem     *item,
+                                                GSList         *msglist);
+       gint            (*remove_all_msg)       (Folder         *folder,
+                                                FolderItem     *item);
+       gboolean        (*is_msg_changed)       (Folder         *folder,
+                                                FolderItem     *item,
+                                                MsgInfo        *msginfo);
+       void            (*change_flags)         (Folder         *folder,
+                                                FolderItem     *item,
+                                                MsgInfo        *info);
 };
 
 struct _LocalFolder
@@ -314,7 +318,7 @@ struct _FolderItemUpdateData
 
 void       folder_system_init          ();
 void       folder_register_class       (FolderClass    *class);
-Folder     *folder_new                 (FolderType      type,
+Folder     *folder_new                 (FolderClass    *type,
                                         const gchar    *name,
                                         const gchar    *path);
 void        folder_local_folder_init   (Folder         *folder,
@@ -362,6 +366,7 @@ Folder     *folder_find_from_path           (const gchar    *path);
 Folder     *folder_find_from_name              (const gchar    *name,
                                                 FolderClass    *class);
 FolderItem *folder_find_item_from_path         (const gchar    *path);
+FolderClass *folder_get_class_from_string      (const gchar    *str);
 gchar      *folder_get_identifier              (Folder         *folder);
 gchar      *folder_item_get_identifier         (FolderItem     *item);
 FolderItem *folder_find_item_from_identifier   (const gchar    *identifier);
index bc461dd..e6d4283 100644 (file)
@@ -299,11 +299,28 @@ FolderClass imap_class =
        F_IMAP,
        "imap",
 
+       /* Folder functions */
+       imap_folder_new,
+       imap_folder_destroy,
+       imap_scan_tree,
+       imap_create_tree,
+
+       /* FolderItem functions */
        imap_folder_item_new,
        imap_folder_item_destroy,
-       imap_fetch_msg,
+       imap_create_folder,
+       imap_rename_folder,
+       imap_remove_folder,
+       imap_get_num_list,
+       NULL,
+       NULL,
+       NULL,
+       imap_check_msgnum_validity,
+
+       /* Message functions */
        imap_get_msginfo,
        imap_get_msginfos,
+       imap_fetch_msg,
        imap_add_msg,
        imap_move_msg,
        NULL,
@@ -314,18 +331,6 @@ FolderClass imap_class =
        imap_remove_all_msg,
        imap_is_msg_changed,
        NULL,
-       imap_get_num_list,
-       imap_scan_tree,
-       imap_create_tree,
-       imap_create_folder,
-       imap_rename_folder,
-       imap_remove_folder,
-       imap_folder_destroy,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       imap_check_msgnum_validity,
 };
 
 FolderClass *imap_get_class()
index 2191fe8..0aa6c49 100644 (file)
@@ -1392,10 +1392,9 @@ void main_window_add_mailbox(MainWindow *mainwin)
                g_free(path);
                return;
        }
-       if (!strcmp(path, "Mail"))
-               folder = folder_new(F_MH, _("Mailbox"), path);
-       else
-               folder = folder_new(F_MH, g_basename(path), path);
+       folder = folder_new(folder_get_class_from_string("mh"), 
+                           !strcmp(path, "Mail") ? _("Mailbox") : g_basename(path),
+                           path);
        g_free(path);
 
        if (folder->class->create_tree(folder) < 0) {
@@ -1431,13 +1430,8 @@ void main_window_add_mbox(MainWindow *mainwin)
                return;
        }
 
-       /*
-       if (!strcmp(path, "Mail"))
-               folder = folder_new(F_MBOX, _("Mailbox"), path);
-               else
-       */
-
-       folder = folder_new(F_MBOX, g_basename(path), path);
+       folder = folder_new(folder_get_class_from_string("mbox"), 
+                           g_basename(path), path);
        g_free(path);
 
        if (folder->class->create_tree(folder) < 0) {
index 6ba8036..2f2a96c 100644 (file)
@@ -55,11 +55,28 @@ FolderClass mbox_class =
        F_MBOX,
        "mbox",
 
+       /* Folder functions */
+       mbox_folder_new,
+       mbox_folder_destroy,
        NULL,
+       mbox_create_tree,
+
+       /* FolderItem functions */
        NULL,
-       mbox_fetch_msg,
+       NULL,
+       mbox_create_folder,
+       mbox_rename_folder,
+       mbox_remove_folder,
+       mbox_get_num_list,
+       NULL,
+       NULL,
+       NULL,
+       mbox_check_msgnum_validity,
+
+       /* Message functions */
        mbox_get_msginfo,
        NULL,
+       mbox_fetch_msg,
        mbox_add_msg,
        NULL,
        NULL,
@@ -70,18 +87,6 @@ FolderClass mbox_class =
        mbox_remove_all_msg,
        NULL,
        NULL,
-       mbox_get_num_list,
-       NULL,
-       mbox_create_tree,
-       mbox_create_folder,
-       mbox_rename_folder,
-       mbox_remove_folder,
-       mbox_folder_destroy,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       mbox_check_msgnum_validity,
 };
 
 FolderClass *mbox_get_class()
index 3c0cf04..2a9ea02 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -113,11 +113,28 @@ FolderClass mh_class =
        F_MH,
        "mh",
 
+       /* Folder functions */
+       mh_folder_new,
+       mh_folder_destroy,
+       mh_scan_tree,
+       mh_create_tree,
+
+       /* FolderItem functions */
        NULL,
        NULL,
-       mh_fetch_msg,
+       mh_create_folder,
+       mh_rename_folder,
+       mh_remove_folder,
+       mh_get_num_list,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       
+       /* Message functions */
        mh_get_msginfo,
        NULL,
+       mh_fetch_msg,
        mh_add_msg,
        mh_move_msg,
        mh_move_msgs_with_dest,
@@ -128,18 +145,6 @@ FolderClass mh_class =
        mh_remove_all_msg,
        mh_is_msg_changed,
        NULL,
-       mh_get_num_list,
-       mh_scan_tree,
-       mh_create_tree,
-       mh_create_folder,
-       mh_rename_folder,
-       mh_remove_folder,
-       mh_folder_destroy,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
 };
 
 FolderClass *mh_get_class()
index 2d8eb1b..345d771 100644 (file)
@@ -111,29 +111,34 @@ FolderClass news_class =
        F_NEWS,
        "news",
 
+       /* Folder functions */
+       news_folder_new,
+       news_folder_destroy,
        NULL,
        NULL,
-       news_fetch_msg,
-       news_get_msginfo,
-       news_get_msginfos,
+
+       /* FolderItem functions */
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
-       news_remove_msg,
+       news_get_num_list,
        NULL,
        NULL,
        NULL,
        NULL,
-       news_get_num_list,
-       NULL,
+
+       /* Message functions */
+       news_get_msginfo,
+       news_get_msginfos,
+       news_fetch_msg,
        NULL,
        NULL,
        NULL,
        NULL,
-       news_folder_destroy,
        NULL,
+       news_remove_msg,
        NULL,
        NULL,
        NULL,
index 32b9fb5..3da133e 100644 (file)
@@ -29,6 +29,7 @@
 #include "alertpanel.h"
 #include "mainwindow.h"
 #include "gtkutils.h"
+#include "mh.h"
 
 #define SETUP_DIALOG_WIDTH     540
 
@@ -53,10 +54,7 @@ void setup(MainWindow *mainwin)
                return;
        }
 
-       if (!strcmp(path, "Mail"))
-               folder = folder_new(F_MH, _("Mailbox"), path);
-       else
-               folder = folder_new(F_MH, g_basename(path), path);
+       folder = folder_new(mh_get_class(), !strcmp(path, "Mail") ? _("Mailbox") : g_basename(path), path);
        g_free(path);
 
        if (folder->class->create_tree(folder) < 0) {