Fixes and optimization to folder dnd
authorColin Leroy <colin@colino.net>
Fri, 8 Nov 2002 15:42:57 +0000 (15:42 +0000)
committerColin Leroy <colin@colino.net>
Fri, 8 Nov 2002 15:42:57 +0000 (15:42 +0000)
ChangeLog.claws
configure.in
src/folder.c
src/folderview.c
src/prefs_folder_item.c
src/prefs_folder_item.h

index d7c4fec8325cb6d7e1e8ff7702ac3280d6971e03..5516d9ce77fd612f980f7c159b7f0726ceefc9dc 100644 (file)
@@ -1,3 +1,14 @@
+2002-11-08 [colin]     0.8.5claws94
+
+       * src/folder.c
+               Fixes to folder DND (prefs copy)
+       * src/folderview.c
+               Optimization for folder DND (don't rescan whole tree)
+               Added folderview_create_folder_node() for this 
+               optimization, so de-duped a bit the code
+       * src/prefs_folder_item.[ch]
+               Added prefs_folder_item_copy_prefs()    
+         
 2002-11-08 [paul]      0.8.5claws93
 
        * src/prefs_account.c
index f7c9aa90a13d8b1f6017e5d501fdcf1ba44a0f3a..db7d8702de26abc59b49dac9e2cdb961c97bb7b7 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws93
+EXTRA_VERSION=claws94
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index fd31aa5db5ad748f8371bb08f0f79f542f27469d..ded0943abaf17ab90157ecb5aeab4f805d7ca06a 100644 (file)
@@ -1437,42 +1437,50 @@ gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
 }
 */
                
-gint folder_item_move_recursive (FolderItem *src, FolderItem *dest) 
+FolderItem *folder_item_move_recursive (FolderItem *src, FolderItem *dest) 
 {
        GSList *mlist;
        GSList *cur;
        FolderItem *new_item;
        FolderItem *next_item;
        GNode *srcnode;
-
+       
        mlist = folder_item_get_msg_list(src);
 
        /* move messages */
        debug_print("Moving %s to %s\n", src->path, dest->path);
        new_item = folder_create_folder(dest, g_basename(src->path));
-       
        if (new_item == NULL) {
                printf("Can't create folder\n");
-               return -1;
+               return NULL;
        }
        
+       if (new_item->folder == NULL)
+               new_item->folder = dest->folder;
+
+       /* move messages */
        for (cur = mlist ; cur != NULL ; cur = cur->next) {
                MsgInfo * msginfo;
                msginfo = (MsgInfo *) cur->data;
                folder_item_move_msg(new_item, msginfo);
        }
+       
+       /*copy prefs*/
+       prefs_folder_item_copy_prefs(src, new_item);
+
+       /* recurse */
        srcnode = src->folder->node;    
        srcnode = g_node_find(srcnode, G_PRE_ORDER, G_TRAVERSE_ALL, src);
        srcnode = srcnode->children;
        while (srcnode != NULL) {
                if (srcnode && srcnode->data) {
                        next_item = (FolderItem*) srcnode->data;
-                       if (folder_item_move_recursive(next_item, new_item) != 0)
-                               return -1;
+                       if (folder_item_move_recursive(next_item, new_item) == NULL)
+                               return NULL;
                }
                srcnode = srcnode->next;
        }
-       return 0;
+       return new_item;
 }
 
 FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest)
@@ -1515,7 +1523,7 @@ FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest)
                return NULL;
        }
        debug_print("moving \"%s\" to \"%s\"\n", phys_srcpath, phys_dstpath);
-       if (folder_item_move_recursive(src, dest) != 0) {
+       if ((tmp = folder_item_move_recursive(src, dest)) == NULL) {
                alertpanel_error(_("Move failed !"));
                return NULL;
        }
@@ -1532,18 +1540,12 @@ FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest)
        
        folder_write_list();
 
-       /* rescan parents */
-       debug_print("rescanning foldertree ....\n");
-       folderview_rescan_tree(dest->folder);
-               
        g_free(srcpath);
        g_free(dstpath);
        g_free(phys_srcpath);
        g_free(phys_dstpath);
-       return folder_find_item_from_identifier(g_strconcat(dstpath, 
-                                                       G_DIR_SEPARATOR_S, 
-                                                       g_basename(srcpath), 
-                                                       NULL));
+
+       return tmp;
 }
 
 gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
index 0557ec56b02078bbc1a3429bf99e8e8ef85eef10..1a3b954dd2bccaa9054ba42410b26ad70f8b4c3c 100644 (file)
@@ -256,6 +256,9 @@ static void folderview_drag_data_get     (GtkWidget        *widget,
                                          guint             time,
                                          FolderView       *folderview);
 
+void folderview_create_folder_node       (FolderView       *folderview, 
+                                         FolderItem       *item);
+
 static void folderview_scoring_cb(FolderView *folderview, guint action,
                                  GtkWidget *widget);
 static void folderview_processing_cb(FolderView *folderview, guint action,
@@ -1688,12 +1691,15 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
 
        /* Save cache for old folder */
        /* We don't want to lose all caches if sylpheed crashed */
-       if(folderview->opened) {
+       if (folderview->opened) {
                FolderItem *olditem;
                
                olditem = gtk_ctree_node_get_row_data(ctree, folderview->opened);
-               folder_item_write_cache(olditem);
-               summary_save_prefs_to_folderitem(folderview->summaryview, olditem);
+               if (olditem) {
+                       /* will be null if we just moved the previously opened folder */
+                       folder_item_write_cache(olditem);
+                       summary_save_prefs_to_folderitem(folderview->summaryview, olditem);
+               }
        }
 
        /* CLAWS: set compose button type: news folder items 
@@ -1864,16 +1870,57 @@ static void folderview_update_tree_cb(FolderView *folderview, guint action,
        }
 }
 
+void folderview_create_folder_node_recursive(FolderView *folderview, FolderItem *item)
+{
+       GNode *srcnode;
+
+       folderview_create_folder_node(folderview, item);
+       
+       srcnode = item->folder->node;   
+       srcnode = g_node_find(srcnode, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       srcnode = srcnode->children;
+       while (srcnode != NULL) {
+               if (srcnode && srcnode->data) {
+                       FolderItem *next_item = (FolderItem*) srcnode->data;
+                       folderview_create_folder_node_recursive(folderview, next_item);
+               }
+               srcnode = srcnode->next;
+       }
+}
+
+void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
+       GtkCTreeNode *node, *parent_node;
+       
+       parent_node = gtk_ctree_find_by_row_data(ctree, NULL, item->parent);
+
+       gtk_clist_freeze(GTK_CLIST(ctree));
+
+       text[COL_FOLDER] = item->name;
+       node = gtk_ctree_insert_node(ctree, parent_node, NULL, text,
+                                    FOLDER_SPACING,
+                                    folderxpm, folderxpmmask,
+                                    folderopenxpm, folderopenxpmmask,
+                                    FALSE, FALSE);
+       gtk_ctree_expand(ctree, parent_node);
+       gtk_ctree_node_set_row_data(ctree, node, item);
+       if (normal_style)
+               gtk_ctree_node_set_row_style(ctree, node, normal_style);
+       folderview_sort_folders(folderview, folderview->selected, item->folder);
+
+       gtk_clist_thaw(GTK_CLIST(ctree));
+}
+
 static void folderview_new_folder_cb(FolderView *folderview, guint action,
                                     GtkWidget *widget)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
        FolderItem *item;
        FolderItem *new_item;
        gchar *new_folder;
        gchar *name, *name_;
-       GtkCTreeNode *node;
 
        if (!folderview->selected) return;
 
@@ -1914,21 +1961,7 @@ static void folderview_new_folder_cb(FolderView *folderview, guint action,
        } 
        g_free(new_folder);
 
-       gtk_clist_freeze(GTK_CLIST(ctree));
-
-       text[COL_FOLDER] = new_item->name;
-       node = gtk_ctree_insert_node(ctree, folderview->selected, NULL, text,
-                                    FOLDER_SPACING,
-                                    folderxpm, folderxpmmask,
-                                    folderopenxpm, folderopenxpmmask,
-                                    FALSE, FALSE);
-       gtk_ctree_expand(ctree, folderview->selected);
-       gtk_ctree_node_set_row_data(ctree, node, new_item);
-       if (normal_style)
-               gtk_ctree_node_set_row_style(ctree, node, normal_style);
-       folderview_sort_folders(folderview, folderview->selected, item->folder);
-
-       gtk_clist_thaw(GTK_CLIST(ctree));
+       folderview_create_folder_node(folderview, new_item);
 
        folder_write_list();
 }
@@ -1937,11 +1970,9 @@ static void folderview_new_mbox_folder_cb(FolderView *folderview, guint action,
                                          GtkWidget *widget)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
        FolderItem *item;
        FolderItem *new_item;
        gchar *new_folder;
-       GtkCTreeNode *node;
 
        if (!folderview->selected) return;
 
@@ -1966,21 +1997,7 @@ static void folderview_new_mbox_folder_cb(FolderView *folderview, guint action,
        g_free(new_folder);
        if (!new_item) return;
 
-       gtk_clist_freeze(GTK_CLIST(ctree));
-
-       text[COL_FOLDER] = new_item->name;
-       node = gtk_ctree_insert_node(ctree, folderview->selected, NULL, text,
-                                    FOLDER_SPACING,
-                                    folderxpm, folderxpmmask,
-                                    folderopenxpm, folderopenxpmmask,
-                                    FALSE, FALSE);
-       gtk_ctree_expand(ctree, folderview->selected);
-       gtk_ctree_node_set_row_data(ctree, node, new_item);
-       if (normal_style)
-               gtk_ctree_node_set_row_style(ctree, node, normal_style);
-       folderview_sort_folders(folderview, folderview->selected, item->folder);
-
-       gtk_clist_thaw(GTK_CLIST(ctree));
+       folderview_create_folder_node(folderview, new_item);
 
        folder_write_list();
 }
@@ -2219,8 +2236,6 @@ static void folderview_new_imap_folder_cb(FolderView *folderview, guint action,
                                          GtkWidget *widget)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
-       GtkCTreeNode *node;
        FolderItem *item;
        FolderItem *new_item;
        gchar *new_folder;
@@ -2270,21 +2285,7 @@ static void folderview_new_imap_folder_cb(FolderView *folderview, guint action,
        }
        g_free(new_folder);
 
-       gtk_clist_freeze(GTK_CLIST(ctree));
-
-       text[COL_FOLDER] = new_item->name;
-       node = gtk_ctree_insert_node(ctree, folderview->selected, NULL, text,
-                                    FOLDER_SPACING,
-                                    folderxpm, folderxpmmask,
-                                    folderopenxpm, folderopenxpmmask,
-                                    FALSE, FALSE);
-       gtk_ctree_expand(ctree, folderview->selected);
-       gtk_ctree_node_set_row_data(ctree, node, new_item);
-       if (normal_style)
-               gtk_ctree_node_set_row_style(ctree, node, normal_style);
-       folderview_sort_folders(folderview, folderview->selected, item->folder);
-
-       gtk_clist_thaw(GTK_CLIST(ctree));
+       folderview_create_folder_node(folderview, new_item);
 
        folder_write_list();
 }
@@ -2653,20 +2654,27 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                /* comes from folderview */
                char *source;
                char *buf;
-               FolderItem *new_item;
+               GtkCTreeNode *src_node;
+               FolderItem *new_item, *src_parent;
+               
                source = data->data + 17;
-               if (*source == 0)
-                       return;
                if (gtk_clist_get_selection_info
-                       (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0)
+                   (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0
+                   || *source == 0) {
+                       gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
                        return;
+               }
                node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
                item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
                src_item = folder_find_item_from_path(source);
-               if (!src_item)
-                       return;
-               if (src_item->stype != F_NORMAL)
+
+               if (!src_item || src_item->stype != F_NORMAL) {
+                       gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
                        return;
+               }
+               src_parent = src_item->parent;
+               src_node = gtk_ctree_find_by_row_data(GTK_CTREE(widget), NULL, src_item);
+
                buf = g_strdup_printf(_("Moving %s to %s..."), src_item->name, item->name);
                STATUSBAR_PUSH(folderview->mainwin, buf);
                g_free(buf);
@@ -2675,6 +2683,15 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                        gtk_drag_finish(drag_context, TRUE, TRUE, time);
                else
                        gtk_drag_finish(drag_context, FALSE, FALSE, time);
+               
+               if (src_node)
+                       gtk_ctree_remove_node(GTK_CTREE(widget), src_node);
+               else 
+                       debug_print("can't remove src node: is null\n");
+               
+               folderview_create_folder_node_recursive(folderview, new_item);
+               folderview_update_item(src_parent, TRUE);
+               folderview_update_item(new_item, TRUE);
                STATUSBAR_PUSH(folderview->mainwin, _("Done."));
                main_window_cursor_normal(folderview->mainwin);
                summary_clear_all(folderview->summaryview);
index 63a59bcaee4d76be9a66258faa5791182c9a74ff..086a97e7fe29c1e6a5f19d2fc90e95a1d86b0040 100644 (file)
@@ -710,3 +710,41 @@ static void folder_color_set_dialog_key_pressed(GtkWidget *widget,
        gtk_widget_destroy(color_dialog);
 }
 
+void prefs_folder_item_copy_prefs(FolderItem * src, FolderItem * dest)
+{
+       PrefsFolderItem old_prefs;
+       prefs_folder_item_read_config(src);
+       old_prefs = *src->prefs;
+
+       tmp_prefs.directory                     = g_strdup(old_prefs.directory);
+       tmp_prefs.sort_by_number                = old_prefs.sort_by_number;
+       tmp_prefs.sort_by_size                  = old_prefs.sort_by_size;
+       tmp_prefs.sort_by_date                  = old_prefs.sort_by_date;
+       tmp_prefs.sort_by_from                  = old_prefs.sort_by_from;
+       tmp_prefs.sort_by_subject               = old_prefs.sort_by_subject;
+       tmp_prefs.sort_by_score                 = old_prefs.sort_by_score;
+       tmp_prefs.sort_descending               = old_prefs.sort_descending;
+       tmp_prefs.enable_thread                 = old_prefs.enable_thread;
+       tmp_prefs.kill_score                    = old_prefs.kill_score;
+       tmp_prefs.important_score               = old_prefs.important_score;
+       /* FIXME!
+       tmp_prefs.scoring                       = g_slist_copy(old_prefs.scoring); 
+       tmp_prefs.processing                    = g_slist_copy(old_prefs.processing);
+       */
+       tmp_prefs.request_return_receipt        = old_prefs.request_return_receipt;
+       tmp_prefs.enable_default_to             = old_prefs.enable_default_to;
+       tmp_prefs.default_to                    = g_strdup(old_prefs.default_to);
+       tmp_prefs.enable_default_reply_to       = old_prefs.enable_default_reply_to;
+       tmp_prefs.default_reply_to              = old_prefs.default_reply_to;
+       tmp_prefs.enable_simplify_subject       = old_prefs.enable_simplify_subject;
+       tmp_prefs.simplify_subject_regexp       = g_strdup(old_prefs.simplify_subject_regexp);
+       tmp_prefs.enable_folder_chmod           = old_prefs.enable_folder_chmod;
+       tmp_prefs.folder_chmod                  = old_prefs.folder_chmod;
+       tmp_prefs.enable_default_account        = old_prefs.enable_default_account;
+       tmp_prefs.default_account               = old_prefs.default_account;
+       tmp_prefs.save_copy_to_folder           = old_prefs.save_copy_to_folder;
+       tmp_prefs.color                         = old_prefs.color;
+
+       *dest->prefs = tmp_prefs;
+       prefs_folder_item_save_config(dest);
+}
index a2aa0aab6954c79fb8979d621752ee7b96e8c2db..274a4d4625d2d34a10ecdf7f39ed65efaa7e3325 100644 (file)
@@ -74,5 +74,6 @@ PrefsFolderItem * prefs_folder_item_new(void);
 void prefs_folder_item_free(PrefsFolderItem * prefs);
 gint prefs_folder_item_get_sort_type(FolderItem * item);
 gint prefs_folder_item_get_sort_mode(FolderItem * item);
+void prefs_folder_item_copy_prefs(FolderItem * src, FolderItem * dest);
 
 #endif