fix a segfault when move fails
authorColin Leroy <colin@colino.net>
Fri, 8 Nov 2002 20:29:43 +0000 (20:29 +0000)
committerColin Leroy <colin@colino.net>
Fri, 8 Nov 2002 20:29:43 +0000 (20:29 +0000)
fix forgetting folder's processing rules

ChangeLog.claws
configure.in
src/filtering.c
src/filtering.h
src/folderview.c
src/matcher.c
src/matcher.h
src/prefs_folder_item.c

index 8e17124..4ce1680 100644 (file)
@@ -1,3 +1,15 @@
+2002-11-08 [colin]     0.8.5claws98
+
+       * src/folderview.c
+               Fixes in case of failure
+       * src/filtering.[ch]    
+               Add function to duplicate a FilteringProp
+       * src/matcher.[ch]
+               Add function to duplicate a MatcherProp
+       * src/prefs_folder_item.c
+               Save folder's processing rules when copying 
+               its prefs
+
 2002-11-08 [colin]     0.8.5claws97
        
        * src/folderview.c
index e0f0785..0699b95 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws97
+EXTRA_VERSION=claws98
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 9cbc909..02ae111 100644 (file)
@@ -92,6 +92,36 @@ FilteringProp * filteringprop_new(MatcherList * matchers,
        return filtering;
 }
 
+FilteringProp * filteringprop_copy(FilteringProp *src)
+{
+       FilteringProp * new;
+       GSList *tmp;
+       
+       new = g_new0(FilteringProp, 1);
+       new->matchers = g_new0(MatcherList, 1);
+       new->action = g_new0(FilteringAction, 1);
+       for (tmp = src->matchers->matchers; tmp != NULL && tmp->data != NULL;) {
+               MatcherProp *matcher = (MatcherProp *)tmp->data;
+               
+               new->matchers->matchers = g_slist_append(new->matchers->matchers,
+                                                  matcherprop_copy(matcher));
+               tmp = tmp->next;
+       }
+       new->matchers->bool_and = src->matchers->bool_and;
+       new->action->type = src->action->type;
+       new->action->account_id = src->action->account_id;
+       if (src->action->destination)
+               new->action->destination = g_strdup(src->action->destination);
+       else 
+               new->action->destination = NULL;
+       if (src->action->unesc_destination)
+               new->action->unesc_destination = g_strdup(src->action->unesc_destination);
+       else
+               new->action->unesc_destination = NULL;
+       new->action->labelcolor = src->action->labelcolor;
+       return new;
+}
+
 void filteringprop_free(FilteringProp * prop)
 {
        matcherlist_free(prop->matchers);
index 3c1bb21..839051c 100644 (file)
@@ -72,6 +72,8 @@ gchar * filteringprop_to_string(FilteringProp *prop);
 void prefs_filtering_clear();
 void prefs_filtering_free(GSList *prefs_filtering);
 
+FilteringProp * filteringprop_copy(FilteringProp *src);
+
 extern GSList * global_processing;
 
 #endif
index 3cd450e..e0031ec 100644 (file)
@@ -2694,30 +2694,31 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                STATUSBAR_PUSH(folderview->mainwin, buf);
                g_free(buf);
                main_window_cursor_wait(folderview->mainwin);
-               if ((new_item = folder_item_move_to(src_item, item)) != NULL)
+               if ((new_item = folder_item_move_to(src_item, item)) != NULL) {
                        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_recursive(new_item, TRUE);
-               if (new_item)
+                       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_recursive(new_item, TRUE);
                        gtk_sctree_sort_recursive(GTK_CTREE(widget), 
                                gtk_ctree_find_by_row_data(GTK_CTREE(widget), 
                                        NULL, new_item->parent));
-               STATUSBAR_PUSH(folderview->mainwin, _("Done."));
-               main_window_cursor_normal(folderview->mainwin);
-               summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
-               folderview->selected = NULL;
-               if (new_item)
+                       STATUSBAR_PUSH(folderview->mainwin, _("Done."));
+                       main_window_cursor_normal(folderview->mainwin);
+                       summary_clear_all(folderview->summaryview);
+                       folderview->opened = NULL;
+                       folderview->selected = NULL;
                        folderview_select(folderview, new_item);
+               } else {
+                       gtk_drag_finish(drag_context, FALSE, FALSE, time);
+                       STATUSBAR_PUSH(folderview->mainwin, _("Done."));
+                       main_window_cursor_normal(folderview->mainwin);
+               }                       
        }
 }
 
index 1afd165..53e369a 100644 (file)
@@ -246,6 +246,27 @@ void matcherprop_free(MatcherProp * prop)
        g_free(prop);
 }
 
+MatcherProp *matcherprop_copy(MatcherProp *src)
+{
+       MatcherProp *prop = g_new0(MatcherProp, 1);
+       prop->criteria    = src->criteria;
+       if (src->header)
+               prop->header = g_strdup(src->header);
+       else    
+               prop->header = NULL;
+       if (src->expr)
+               prop->expr        = g_strdup(src->expr);
+       else
+               prop->expr = NULL;
+       prop->matchtype   = src->matchtype;
+       if (src->preg != NULL)
+               memcpy(prop->preg, src->preg, sizeof(regex_t));
+       else 
+               prop->preg = NULL;
+       prop->value       = src->value;
+       prop->error       = src->error; 
+       return prop;            
+}
 
 /* ****************** wrapper for file reading ************** */
 
index b19b5a0..aad7031 100644 (file)
@@ -112,6 +112,8 @@ MatcherProp * matcherprop_unquote_new(gint criteria, gchar * header,
 void matcherprop_free(MatcherProp * prop);
 MatcherProp * matcherprop_parse(gchar ** str);
 
+MatcherProp * matcherprop_copy(MatcherProp *src);
+
 gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info);
 
 MatcherList * matcherlist_new(GSList * matchers, gboolean bool_and);
index 086a97e..f90f48e 100644 (file)
@@ -39,6 +39,7 @@
 #include "addr_compl.h"
 #include "prefs_scoring.h"
 #include "gtkutils.h"
+#include "filtering.h"
 
 PrefsFolderItem tmp_prefs;
 
@@ -712,38 +713,46 @@ static void folder_color_set_dialog_key_pressed(GtkWidget *widget,
 
 void prefs_folder_item_copy_prefs(FolderItem * src, FolderItem * dest)
 {
-       PrefsFolderItem old_prefs;
+       GSList *tmp_prop_list = NULL, *tmp;
        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;
+
+       tmp_prefs.directory                     = g_strdup(src->prefs->directory);
+       tmp_prefs.sort_by_number                = src->prefs->sort_by_number;
+       tmp_prefs.sort_by_size                  = src->prefs->sort_by_size;
+       tmp_prefs.sort_by_date                  = src->prefs->sort_by_date;
+       tmp_prefs.sort_by_from                  = src->prefs->sort_by_from;
+       tmp_prefs.sort_by_subject               = src->prefs->sort_by_subject;
+       tmp_prefs.sort_by_score                 = src->prefs->sort_by_score;
+       tmp_prefs.sort_descending               = src->prefs->sort_descending;
+       tmp_prefs.enable_thread                 = src->prefs->enable_thread;
+       tmp_prefs.kill_score                    = src->prefs->kill_score;
+       tmp_prefs.important_score               = src->prefs->important_score;
        /* FIXME!
-       tmp_prefs.scoring                       = g_slist_copy(old_prefs.scoring); 
-       tmp_prefs.processing                    = g_slist_copy(old_prefs.processing);
+       tmp_prefs.scoring                       = g_slist_copy(src->prefs->scoring); 
        */
-       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;
+
+       for (tmp = src->prefs->processing; tmp != NULL && tmp->data != NULL;) {
+               FilteringProp *prop = (FilteringProp *)tmp->data;
+               
+               tmp_prop_list = g_slist_append(tmp_prop_list,
+                                          filteringprop_copy(prop));
+               tmp = tmp->next;
+       }
+       tmp_prefs.processing                    = tmp_prop_list;
+       
+       tmp_prefs.request_return_receipt        = src->prefs->request_return_receipt;
+       tmp_prefs.enable_default_to             = src->prefs->enable_default_to;
+       tmp_prefs.default_to                    = g_strdup(src->prefs->default_to);
+       tmp_prefs.enable_default_reply_to       = src->prefs->enable_default_reply_to;
+       tmp_prefs.default_reply_to              = src->prefs->default_reply_to;
+       tmp_prefs.enable_simplify_subject       = src->prefs->enable_simplify_subject;
+       tmp_prefs.simplify_subject_regexp       = g_strdup(src->prefs->simplify_subject_regexp);
+       tmp_prefs.enable_folder_chmod           = src->prefs->enable_folder_chmod;
+       tmp_prefs.folder_chmod                  = src->prefs->folder_chmod;
+       tmp_prefs.enable_default_account        = src->prefs->enable_default_account;
+       tmp_prefs.default_account               = src->prefs->default_account;
+       tmp_prefs.save_copy_to_folder           = src->prefs->save_copy_to_folder;
+       tmp_prefs.color                         = src->prefs->color;
 
        *dest->prefs = tmp_prefs;
        prefs_folder_item_save_config(dest);