make folder properties persistent so they are properly restored after rescanning...
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 30 Dec 2001 01:27:14 +0000 (01:27 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 30 Dec 2001 01:27:14 +0000 (01:27 +0000)
ChangeLog.claws
configure.in
src/folder.c
src/folder.h
src/mh.c

index 0216d27..f0cf1e0 100644 (file)
@@ -1,3 +1,11 @@
+2001-12-30 [alfons]    0.6.6claws31
+
+       * src/mh.c
+       * src/folder.[ch]
+               make folder properties (like threading and sorting) persistent
+               (closes bug #497424 "rescan folder tree resets proprieties")
+               currently this is only for MH folders. 
+
 2001-12-29 [melvin]    0.6.6claws30
 
        * src/string_match.[ch]
index 2a42e29..d047195 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws30
+EXTRA_VERSION=claws31
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index ab44655..35dbbf9 100644 (file)
@@ -68,6 +68,11 @@ static void folder_write_list_recursive      (GNode          *node,
 static void folder_update_op_count_rec (GNode          *node);
 
 
+static void folder_get_persist_prefs_recursive
+                                       (GNode *node, GHashTable *pptable);
+static gboolean persist_prefs_free     (gpointer key, gpointer val, gpointer data);
+
+
 Folder *folder_new(FolderType type, const gchar *name, const gchar *path)
 {
        Folder *folder = NULL;
@@ -1611,3 +1616,88 @@ FolderItem *folder_get_default_processing(void)
        return processing_folder_item;
 }
 
+/* folder_persist_prefs_new() - return hash table with persistent
+ * settings (and folder name as key). 
+ * (note that in claws other options are in the PREFS_FOLDER_ITEM_RC
+ * file, so those don't need to be included in PersistPref yet) 
+ */
+GHashTable *folder_persist_prefs_new(Folder *folder)
+{
+       GHashTable *pptable;
+
+       g_return_val_if_fail(folder, NULL);
+       pptable = g_hash_table_new(g_str_hash, g_str_equal);
+       folder_get_persist_prefs_recursive(folder->node, pptable);
+       return pptable;
+}
+
+void folder_persist_prefs_free(GHashTable *pptable)
+{
+       g_return_if_fail(pptable);
+       g_hash_table_foreach_remove(pptable, persist_prefs_free, NULL);
+       g_hash_table_destroy(pptable);
+}
+
+const PersistPrefs *folder_get_persist_prefs(GHashTable *pptable, const char *name)
+{
+       if (pptable == NULL || name == NULL) return NULL;
+       return g_hash_table_lookup(pptable, name);
+}
+
+void folder_item_restore_persist_prefs(FolderItem *item, GHashTable *pptable)
+{
+       const PersistPrefs *pp;
+
+       pp = folder_get_persist_prefs(pptable, item->path); 
+       if (!pp) return;
+
+       /* CLAWS: since not all folder properties have been migrated to 
+        * folderlist.xml, we need to call the old stuff first before
+        * setting things that apply both to Main and Claws. */
+       prefs_folder_item_read_config(item); 
+        
+       item->collapsed = pp->collapsed;
+       item->threaded  = pp->threaded;
+       item->ret_rcpt  = pp->ret_rcpt;
+       item->hide_read_msgs = pp->hide_read_msgs;
+}
+
+static void folder_get_persist_prefs_recursive(GNode *node, GHashTable *pptable)
+{
+       FolderItem *item = FOLDER_ITEM(node->data);
+       PersistPrefs *pp;
+       GNode *child, *cur;
+
+       g_return_if_fail(node != NULL);
+       g_return_if_fail(item != NULL);
+
+       /* FIXME: item->path == NULL for top level folder, so this means that 
+        * properties of MH folder root will not be stored. Not quite important, 
+        * because the top level folder properties are not special anyway. */
+       if (item->path) {
+               pp = g_new0(PersistPrefs, 1);
+               g_return_if_fail(pp != NULL);
+               pp->collapsed = item->collapsed;
+               pp->threaded  = item->threaded;
+               pp->ret_rcpt  = item->ret_rcpt; 
+               pp->hide_read_msgs = item->hide_read_msgs;
+               g_hash_table_insert(pptable, item->path, pp);
+       }               
+
+       if (node->children) {
+               child = node->children;
+               while (child) {
+                       cur = child;
+                       child = cur->next;
+                       folder_get_persist_prefs_recursive(cur, pptable);
+               }
+       }       
+}
+
+static gboolean persist_prefs_free(gpointer key, gpointer val, gpointer data)
+{
+       if (val) 
+               g_free(val);
+       return TRUE;    
+}
+
index fd611ce..aaee65b 100644 (file)
@@ -235,6 +235,14 @@ struct _FolderItem
        PrefsFolderItem * prefs;
 };
 
+typedef struct {
+       guint   collapsed       : 1;
+       guint   threaded        : 1;
+       guint   hide_read_msgs  : 1; /* CLAWS */
+       guint   ret_rcpt        : 1; /* CLAWS */
+} PersistPrefs;
+
+
 Folder     *folder_new         (FolderType      type,
                                 const gchar    *name,
                                 const gchar    *path);
@@ -310,4 +318,11 @@ gchar *folder_item_get_mark_file   (FolderItem     *item);
 gchar * folder_item_get_identifier(FolderItem * item);
 FolderItem * folder_find_item_from_identifier(const gchar *identifier);
 
+GHashTable *folder_persist_prefs_new   (Folder *folder);
+void folder_persist_prefs_free         (GHashTable *pptable);
+const PersistPrefs *folder_get_persist_prefs
+                                       (GHashTable *pptable, const char *name);
+
+void folder_item_restore_persist_prefs (FolderItem *item, GHashTable *pptable);
+
 #endif /* __FOLDER_H__ */
index 4f166f3..42fcc1c 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -47,7 +47,8 @@ static GSList  *mh_get_uncached_msgs          (GHashTable     *msg_table,
                                                 FolderItem     *item);
 static MsgInfo *mh_parse_msg                   (const gchar    *file,
                                                 FolderItem     *item);
-static void    mh_scan_tree_recursive          (FolderItem     *item);
+static void    mh_scan_tree_recursive          (FolderItem     *item, 
+                                                GHashTable *pptable);
 
 static gboolean mh_rename_folder_func          (GNode          *node,
                                                 gpointer        data);
@@ -673,9 +674,12 @@ void mh_scan_tree(Folder *folder)
 {
        FolderItem *item;
        gchar *rootpath;
+       GHashTable *pptable;
 
        g_return_if_fail(folder != NULL);
 
+       pptable = folder_persist_prefs_new(folder);
+
        folder_tree_destroy(folder);
        item = folder_item_new(folder->name, NULL);
        item->folder = folder;
@@ -688,7 +692,9 @@ void mh_scan_tree(Folder *folder)
        }
        g_free(rootpath);
 
-       mh_scan_tree_recursive(item);
+       mh_scan_tree_recursive(item, pptable);
+       
+       folder_persist_prefs_free(pptable);
 }
 
 #define MAKE_DIR_IF_NOT_EXIST(dir) \
@@ -1000,7 +1006,7 @@ static gboolean mh_is_maildir(const gchar *path)
               mh_is_maildir_one(path, "tmp");
 }
 
-static void mh_scan_tree_recursive(FolderItem *item)
+static void mh_scan_tree_recursive(FolderItem *item, GHashTable *pptable)
 {
        DIR *dp;
        struct dirent *d;
@@ -1067,7 +1073,8 @@ static void mh_scan_tree_recursive(FolderItem *item)
                                        item->folder->trash = new_item;
                                }
                        }
-                       mh_scan_tree_recursive(new_item);
+                       folder_item_restore_persist_prefs(new_item, pptable);
+                       mh_scan_tree_recursive(new_item, pptable);
                } else if (to_number(d->d_name) != -1) n_msg++;
 
                g_free(entry);