* src/compose.c
[claws.git] / src / folder.c
index 35d804b..ca34d08 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "intl.h"
 #include "folder.h"
 
 #include "intl.h"
 #include "folder.h"
-#include "folderview.h"
 #include "session.h"
 #include "imap.h"
 #include "news.h"
 #include "session.h"
 #include "imap.h"
 #include "news.h"
 #include "xml.h"
 #include "codeconv.h"
 #include "prefs.h"
 #include "xml.h"
 #include "codeconv.h"
 #include "prefs.h"
-#include "prefs_common.h"
 #include "account.h"
 #include "account.h"
-#include "prefs_account.h"
 #include "filtering.h"
 #include "scoring.h"
 #include "prefs_folder_item.h"
 #include "procheader.h"
 #include "statusbar.h"
 
 #include "filtering.h"
 #include "scoring.h"
 #include "prefs_folder_item.h"
 #include "procheader.h"
 #include "statusbar.h"
 
+/* Dependecies to be removed ?! */
+#include "prefs_common.h"
+#include "prefs_account.h"
+#include "prefs_folder_item.h"
+
 static GList *folder_list = NULL;
 
 static void folder_init                (Folder         *folder,
 static GList *folder_list = NULL;
 
 static void folder_init                (Folder         *folder,
@@ -443,6 +445,8 @@ void folder_scan_tree(Folder *folder)
        folder_persist_prefs_free(pptable);
 
        prefs_matcher_read_config();
        folder_persist_prefs_free(pptable);
 
        prefs_matcher_read_config();
+
+       folder_write_list();
 }
 
 FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
 }
 
 FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
@@ -943,7 +947,8 @@ gint folder_item_scan(FolderItem *item)
        GSList *folder_list = NULL, *cache_list = NULL, *folder_list_cur, *cache_list_cur, *new_list = NULL;
        guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
        guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
        GSList *folder_list = NULL, *cache_list = NULL, *folder_list_cur, *cache_list_cur, *new_list = NULL;
        guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
        guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
-
+       gboolean contentchange = FALSE;
+    
        g_return_val_if_fail(item != NULL, -1);
        if (item->path == NULL) return -1;
 
        g_return_val_if_fail(item != NULL, -1);
        if (item->path == NULL) return -1;
 
@@ -1042,6 +1047,8 @@ gint folder_item_scan(FolderItem *item)
                        else
                                folder_cur_num = G_MAXINT;
 
                        else
                                folder_cur_num = G_MAXINT;
 
+                       contentchange = TRUE;
+
                        continue;
                }
 
                        continue;
                }
 
@@ -1061,6 +1068,8 @@ gint folder_item_scan(FolderItem *item)
                        else
                                cache_cur_num = G_MAXINT;
 
                        else
                                cache_cur_num = G_MAXINT;
 
+                       contentchange = TRUE;
+
                        continue;
                }
 
                        continue;
                }
 
@@ -1110,6 +1119,8 @@ gint folder_item_scan(FolderItem *item)
                        else
                                folder_cur_num = G_MAXINT;
 
                        else
                                folder_cur_num = G_MAXINT;
 
+                       contentchange = TRUE;
+
                        continue;
                }
        }
                        continue;
                }
        }
@@ -1168,7 +1179,7 @@ gint folder_item_scan(FolderItem *item)
        
        g_slist_free(new_list);
 
        
        g_slist_free(new_list);
 
-       folderview_update_item(item, FALSE);
+       folder_update_item(item, contentchange);
 
        return 0;
 }
 
        return 0;
 }
@@ -2395,13 +2406,14 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
                fputs(" />\n", fp);
 }
 
                fputs(" />\n", fp);
 }
 
-static void folder_update_op_count_rec(GNode *node) {
+static void folder_update_op_count_rec(GNode *node)
+{
        FolderItem *fitem = FOLDER_ITEM(node->data);
 
        if (g_node_depth(node) > 0) {
                if (fitem->op_count > 0) {
                        fitem->op_count = 0;
        FolderItem *fitem = FOLDER_ITEM(node->data);
 
        if (g_node_depth(node) > 0) {
                if (fitem->op_count > 0) {
                        fitem->op_count = 0;
-                       folderview_update_item(fitem, 0);
+                       folder_update_item(fitem, FALSE);
                }
                if (node->children) {
                        GNode *child;
                }
                if (node->children) {
                        GNode *child;
@@ -2622,7 +2634,101 @@ void folder_item_apply_processing(FolderItem *item)
                procmsg_msginfo_free(msginfo);
        }
        
                procmsg_msginfo_free(msginfo);
        }
        
-       folderview_update_items_when_required(FALSE);
+       folder_update_items_when_required(FALSE);
 
        g_slist_free(mlist);
 }
 
        g_slist_free(mlist);
 }
+
+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);
+}
+
+static void folder_update_item_func(FolderItem *item, gpointer data)
+{
+       gboolean contentchange = GPOINTER_TO_INT(data);
+       
+       if (item->need_update) {
+               folder_item_update_callback_execute(item, contentchange);
+               item->need_update = FALSE;
+       }
+}
+
+void folder_update_items_when_required(gboolean contentchange)
+{
+       folder_func_to_all_folders(folder_update_item_func, GINT_TO_POINTER(contentchange));
+}
+
+void folder_update_item_recursive(FolderItem *item, gboolean update_summary)
+{
+       GNode *node = item->folder->node;       
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
+       folder_item_update_callback_execute(item, update_summary);
+       while (node != NULL) {
+               if (node && node->data) {
+                       FolderItem *next_item = (FolderItem*) node->data;
+                       folder_item_update_callback_execute(next_item, update_summary);
+               }
+               node = node->next;
+       }
+}