0.8.8claws18
[claws.git] / src / folder.c
index 28770c6f65c3514385bf015fb6e36e011f0d7a99..8a18558ee32a564806e863b6152e6f85362d36fc 100644 (file)
 #include "utils.h"
 #include "xml.h"
 #include "codeconv.h"
-#include "prefs.h"
+#include "prefs_gtk.h"
 #include "account.h"
 #include "filtering.h"
 #include "scoring.h"
 #include "prefs_folder_item.h"
 #include "procheader.h"
-#include "statusbar.h"
+#include "hooks.h"
+#include "log.h"
 
 /* Dependecies to be removed ?! */
 #include "prefs_common.h"
@@ -1145,6 +1146,8 @@ gint folder_item_scan(FolderItem *item)
                                                unreadcnt++;
                                        if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
                                                unreadmarkedcnt++;
+                                       if (procmsg_msg_has_flagged_parent(newmsginfo, MSG_IGNORE_THREAD))
+                                               procmsg_msginfo_set_flags(newmsginfo, MSG_IGNORE_THREAD, 0);
                                        procmsg_msginfo_free(newmsginfo);
                                }                                       
 
@@ -1156,6 +1159,8 @@ gint folder_item_scan(FolderItem *item)
                                        unreadcnt++;
                                if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
                                        unreadmarkedcnt++;
+                               if (procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD))
+                                       procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                        }
                        totalcnt++;
                        procmsg_msginfo_free(msginfo);
@@ -1203,6 +1208,8 @@ gint folder_item_scan(FolderItem *item)
                                        unreadcnt++;
                                if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
                                        unreadmarkedcnt++;
+                               if (procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD))
+                                       procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                                totalcnt++;
                                procmsg_msginfo_free(msginfo);
                        }
@@ -1225,6 +1232,8 @@ gint folder_item_scan(FolderItem *item)
                                    unreadcnt++;
                                if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
                                        unreadmarkedcnt++;
+                               if (procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD))
+                                       procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                                totalcnt++;
                                procmsg_msginfo_free(msginfo);
                                debug_print("Added newly found message %d to cache.\n", num);
@@ -1477,6 +1486,8 @@ gint folder_item_add_msg(FolderItem *dest, const gchar *file,
                                dest->unread++;
                        if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
                                dest->unreadmarked++;
+                       if (procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD))
+                               procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                        dest->total++;
                        dest->need_update = TRUE;
 
@@ -1538,13 +1549,11 @@ FolderItem *folder_item_move_recursive (FolderItem *src, FolderItem *dest)
                MsgInfo * msginfo;
                cnt++;
                if (cnt%500)
-                       statusbar_print_all(_("Moving %s to %s (%d%%)..."), src->name, 
+                       log_message(_("Moving %s to %s (%d%%)...\n"), src->name, 
                                        new_item->path,
                                        100*cnt/g_slist_length(mlist));
                msginfo = (MsgInfo *) cur->data;
                folder_item_move_msg(new_item, msginfo);
-               if (cnt%500)
-                       statusbar_pop_all();
 
                procmsg_msginfo_free(msginfo);
        }
@@ -1590,8 +1599,8 @@ FolderItem *folder_item_move_recursive (FolderItem *src, FolderItem *dest)
 gint folder_item_move_to(FolderItem *src, FolderItem *dest, FolderItem **new_item)
 {
        FolderItem *tmp = dest->parent;
-       char * src_identifier, * dst_identifier, * new_identifier;
-       char * phys_srcpath, * phys_dstpath;
+       gchar * src_identifier, * dst_identifier;
+       gchar * phys_srcpath, * phys_dstpath;
        GNode *src_node;
        
        while (tmp) {
@@ -1691,6 +1700,8 @@ gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
                                dest->unread++;
                        if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
                                dest->unreadmarked++;
+                       if (procmsg_msg_has_flagged_parent(newmsginfo, MSG_IGNORE_THREAD))
+                               procmsg_msginfo_set_flags(newmsginfo, MSG_IGNORE_THREAD, 0);
                        dest->total++;
                        dest->need_update = TRUE;
 
@@ -1804,6 +1815,8 @@ gint folder_item_move_msgs_with_dest(FolderItem *dest, GSList *msglist)
                                        dest->unread++;
                                if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
                                        dest->unreadmarked++;
+                               if (procmsg_msg_has_flagged_parent(newmsginfo, MSG_IGNORE_THREAD))
+                                       procmsg_msginfo_set_flags(newmsginfo, MSG_IGNORE_THREAD, 0);
                                dest->total++;
                                dest->need_update = TRUE;
 
@@ -1906,6 +1919,8 @@ gint folder_item_copy_msg(FolderItem *dest, MsgInfo *msginfo)
                                dest->unread++;
                        if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
                                dest->unreadmarked++;
+                       if (procmsg_msg_has_flagged_parent(newmsginfo, MSG_IGNORE_THREAD))
+                               procmsg_msginfo_set_flags(newmsginfo, MSG_IGNORE_THREAD, 0);
                        dest->total++;
                        dest->need_update = TRUE;
 
@@ -1997,6 +2012,8 @@ gint folder_item_copy_msgs_with_dest(FolderItem *dest, GSList *msglist)
                                        dest->unread++;
                                if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
                                        dest->unreadmarked++;
+                               if (procmsg_msg_has_flagged_parent(newmsginfo, MSG_IGNORE_THREAD))
+                                       procmsg_msginfo_set_flags(newmsginfo, MSG_IGNORE_THREAD, 0);
                                dest->total++;
                                dest->need_update = TRUE;
 
@@ -2246,6 +2263,8 @@ static gboolean folder_build_tree(GNode *node, gpointer data)
                                sort_key = SORT_BY_UNREAD;
                        else if (!strcmp(attr->value, "mime"))
                                sort_key = SORT_BY_MIME;
+                       else if (!strcmp(attr->value, "to"))
+                               sort_key = SORT_BY_TO;
                        else if (!strcmp(attr->value, "locked"))
                                sort_key = SORT_BY_LOCKED;
                } else if (!strcmp(attr->name, "sort_type")) {
@@ -2401,7 +2420,8 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
                                                 "draft", "queue", "trash"};
        static gchar *sort_key_str[] = {"none", "number", "size", "date",
                                        "from", "subject", "score", "label",
-                                       "mark", "unread", "mime", "locked" };
+                                       "mark", "unread", "mime", "to", 
+                                       "locked"};
        g_return_if_fail(node != NULL);
        g_return_if_fail(fp != NULL);
 
@@ -2730,74 +2750,24 @@ void folder_item_apply_processing(FolderItem *item)
 /*
  *  Callback handling for FolderItem content changes
  */
-GSList *folder_item_update_callbacks_list = NULL;
-gint   folder_item_update_callbacks_nextid = 0;
-
-struct FolderItemUpdateCallback
-{
-       gint                    id;
-       FolderItemUpdateFunc    func;
-       gpointer                data;
-};
-
-gint folder_item_update_callback_register(FolderItemUpdateFunc func, gpointer data)
-{
-       struct FolderItemUpdateCallback *callback;
-
-       g_return_val_if_fail(func != NULL, -1);
-
-       folder_item_update_callbacks_nextid++;
-
-       callback = g_new0(struct FolderItemUpdateCallback, 1);
-       callback->id = folder_item_update_callbacks_nextid;
-       callback->func = func;
-       callback->data = data;
-
-       folder_item_update_callbacks_list =
-               g_slist_append(folder_item_update_callbacks_list, callback);
-
-       return folder_item_update_callbacks_nextid;
-}
-
-void folder_item_update_callback_unregister(gint id)
-{
-       GSList *list, *next;
-
-       for (list = folder_item_update_callbacks_list; list != NULL; list = next) {
-               struct FolderItemUpdateCallback *callback;
-
-               next = list->next;
-
-               callback = list->data;
-               if (callback->id == id) {
-                       folder_item_update_callbacks_list =
-                               g_slist_remove(folder_item_update_callbacks_list, callback);
-                       g_free(callback);
-               }
-       }
-}
-
-static void folder_item_update_callback_execute(FolderItem *item, gboolean contentchange)
-{
-       GSList *list;
-
-       for (list = folder_item_update_callbacks_list; list != NULL; list = list->next) {
-               struct FolderItemUpdateCallback *callback;
-
-               callback = list->data;
-               callback->func(item, contentchange, callback->data);
-       }
-}
-
 void folder_update_item(FolderItem *item, gboolean contentchange)
 {
-       folder_item_update_callback_execute(item, contentchange);
+       FolderItemUpdateData source;
+       
+       source.item = item;
+       source.content_change = contentchange;
+       hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
 }
 
 static void folder_update_item_func(FolderItem *item, gpointer contentchange)
 {
+       FolderItemUpdateData source;
+
        if (item->need_update) {
-               folder_item_update_callback_execute(item, GPOINTER_TO_INT(contentchange));
+               source.item = item;
+               source.content_change = GPOINTER_TO_INT(contentchange);
+               hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
+
                item->need_update = FALSE;
        }
 }
@@ -2810,13 +2780,21 @@ void folder_update_items_when_required(gboolean contentchange)
 void folder_update_item_recursive(FolderItem *item, gboolean update_summary)
 {
        GNode *node = item->folder->node;       
+       FolderItemUpdateData source;
+
        node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
        node = node->children;
-       folder_item_update_callback_execute(item, update_summary);
+
+       source.item = item;
+       source.content_change = update_summary; 
+       hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
        while (node != NULL) {
                if (node && node->data) {
                        FolderItem *next_item = (FolderItem*) node->data;
-                       folder_item_update_callback_execute(next_item, update_summary);
+
+                       source.item = next_item;
+                       source.content_change = update_summary; 
+                       hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
                }
                node = node->next;
        }