2011-11-21 [pawel] 3.7.10cvs97
authorPaweł Pękala <c0rn@gazeta.pl>
Mon, 21 Nov 2011 22:14:42 +0000 (22:14 +0000)
committerPaweł Pękala <c0rn@gazeta.pl>
Mon, 21 Nov 2011 22:14:42 +0000 (22:14 +0000)
* src/account.c
* src/prefs_filtering.c
* src/prefs_filtering.h
Fix bug #2404 'matcherrc updates upon account renaming'
Fix bug #2406 'some part of accountrc not updated upon
account rename'
Renaming account cause changing of it's root folder prefix
from #<type>/<old_name> to #<type>/<new_name> so every
path directing to it must be altered. Fix paths in account
preferences, global processing and filtering rules, folder
processing rules upon rename

ChangeLog
PATCHSETS
configure.ac
src/account.c
src/prefs_filtering.c
src/prefs_filtering.h

index 7ea1bb0df94571eeb104a74dc5a9bea06fb4b1ff..1fd7405c1457b9b37a37836c7224e5906f2b060c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-11-21 [pawel]     3.7.10cvs97
+
+       * src/account.c
+       * src/prefs_filtering.c
+       * src/prefs_filtering.h
+               Fix bug #2404 'matcherrc updates upon account renaming'
+               Fix bug #2406 'some part of accountrc not updated upon
+               account rename'
+               Renaming account cause changing of it's root folder prefix
+               from #<type>/<old_name> to #<type>/<new_name> so every
+               path directing to it must be altered. Fix paths in account
+               preferences, global processing and filtering rules, folder
+               processing rules upon rename
+
 2011-11-20 [pawel]     3.7.10cvs96
 
        * src/filtering.c
index 7b99b48b0d17c6d8403e6690d5533eeb6919eeb8..2ba0b6430b25ac4f75ccc47c18ef24eb01a23253 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.83.2.182 -r 1.83.2.183 src/mimeview.c;  ) > 3.7.10cvs94.patchset
 ( cvs diff -u -r 1.60.2.75 -r 1.60.2.76 src/prefs_actions.c;  cvs diff -u -r 1.59.2.84 -r 1.59.2.85 src/prefs_filtering.c;  cvs diff -u -r 1.12.2.79 -r 1.12.2.80 src/prefs_template.c;  ) > 3.7.10cvs95.patchset
 ( cvs diff -u -r 1.60.2.58 -r 1.60.2.59 src/filtering.c;  cvs diff -u -r 1.21.2.19 -r 1.21.2.20 src/filtering.h;  cvs diff -u -r 1.60.2.76 -r 1.60.2.77 src/prefs_actions.c;  ) > 3.7.10cvs96.patchset
+( cvs diff -u -r 1.61.2.101 -r 1.61.2.102 src/account.c;  cvs diff -u -r 1.59.2.85 -r 1.59.2.86 src/prefs_filtering.c;  cvs diff -u -r 1.6.2.10 -r 1.6.2.11 src/prefs_filtering.h;  ) > 3.7.10cvs97.patchset
index 516b55447f7d1ce94a1600801ef1eff75c62eab5..89630bbfceb1c0889160c0dace25e591a31f0e67 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=10
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=96
+EXTRA_VERSION=97
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 3cc9db48205751e24a00467466730457c95f6f54..474bea162c6a3641223a2385105d2ab79e41348e 100644 (file)
@@ -118,6 +118,8 @@ static void account_list_view_add   (PrefsAccount   *ac_prefs);
 static void account_list_view_set      (void);
 
 static void account_list_set           (void);
+static void account_rename_path_prefix (const gchar    *old_prefix,
+                                        const gchar    *new_prefix);
 
 typedef struct FindAccountInStore {
        gint             account_id;
@@ -442,7 +444,7 @@ void account_add(void)
 void account_open(PrefsAccount *ac_prefs)
 {
        gboolean prev_default;
-       gchar *ac_name;
+       gchar *ac_name, *old_prefix, *new_prefix;
        gboolean account_dirty = FALSE;
 
        cm_return_if_fail(ac_prefs != NULL);
@@ -458,10 +460,18 @@ void account_open(PrefsAccount *ac_prefs)
                        account_set_as_default(ac_prefs);
 
                if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
+                       old_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
                        folder_set_name(FOLDER(ac_prefs->folder),
                                        ac_prefs->account_name);
                        folderview_set_all();
                        folder_prefs_save_config_recursive(FOLDER(ac_prefs->folder));
+                       new_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
+
+                       account_rename_path_prefix(old_prefix, new_prefix);
+                       prefs_filtering_rename_path_prefix(old_prefix, new_prefix);
+                       
+                       g_free(old_prefix);
+                       g_free(new_prefix);
                }
 
                account_write_config_all();
@@ -560,6 +570,32 @@ void account_rename_path(const gchar *old_id, const gchar *new_id)
 
 #undef CHECK_CHANGE_FOLDER
 
+#define CHANGE_FOLDER_PREFIX(folder) {                                         \
+       if (folder && g_str_has_prefix(folder, old_prefix)) {                   \
+               gchar *new_path = g_strconcat(new_prefix,                       \
+                                  (folder + strlen(old_prefix)), NULL);        \
+               g_free(folder);                                                 \
+               folder = new_path;                                              \
+       }                                                                       \
+}
+
+static void account_rename_path_prefix(const gchar *old_prefix,
+                               const gchar *new_prefix)
+{
+       GList *cur = account_list;
+       for (; cur != NULL; cur = g_list_next(cur)) {
+               PrefsAccount *ap = (PrefsAccount *)cur->data;
+               CHANGE_FOLDER_PREFIX(ap->inbox);
+               CHANGE_FOLDER_PREFIX(ap->local_inbox);
+               CHANGE_FOLDER_PREFIX(ap->queue_folder);
+               CHANGE_FOLDER_PREFIX(ap->sent_folder);
+               CHANGE_FOLDER_PREFIX(ap->draft_folder);
+               CHANGE_FOLDER_PREFIX(ap->trash_folder);
+       }
+}
+
+#undef CHANGE_FOLDER_PREFIX
+
 FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
                                       SpecialFolderItemType type)
 {
index cb0f70d0d07ab670aa8b8db5e4dd336fd63d914b..ffdd8a45e5732aab3a07866f26c4b2e68b3e75bc 100644 (file)
@@ -765,6 +765,83 @@ static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
        return FALSE;
 }
 
+static void rename_path_prefix(GSList *filters, const gchar *old_prefix,
+                               const gchar *new_prefix)
+{
+        GSList *action_cur, *cur;
+        gchar *new_path;
+        
+       for (cur = filters; cur != NULL; cur = cur->next) {
+               FilteringProp   *filtering = (FilteringProp *)cur->data;
+                
+                for(action_cur = filtering->action_list ; action_cur != NULL ;
+                    action_cur = action_cur->next) {
+
+                        FilteringAction *action = action_cur->data;
+                        
+                        if (action->type == MATCHACTION_SET_TAG ||
+                           action->type == MATCHACTION_UNSET_TAG)
+                               continue;
+                        if (!action->destination)
+                               continue;
+                       if (!g_str_has_prefix(action->destination, old_prefix))
+                               continue;
+                       
+                       new_path = g_strconcat(new_prefix,
+                               (action->destination + strlen(old_prefix)), NULL);
+                       g_free(action->destination);
+                       action->destination = new_path;
+               }
+       }
+}
+
+static gboolean prefs_filtering_rename_path_prefix_func(GNode *node, gpointer data)
+{
+       GSList *filters;
+       const gchar * old_prefix;
+        const gchar * new_prefix;
+        const gchar ** paths;
+       FolderItem *item;
+        
+        paths = data;
+       old_prefix = paths[0];
+       new_prefix = paths[1];
+
+       cm_return_val_if_fail(old_prefix != NULL, FALSE);
+       cm_return_val_if_fail(new_prefix != NULL, FALSE);
+       cm_return_val_if_fail(node != NULL, FALSE);
+
+        item = node->data;
+        if (!item || !item->prefs)
+                return FALSE;
+        filters = item->prefs->processing;
+
+        rename_path_prefix(filters, old_prefix, new_prefix);
+
+       return FALSE;
+}
+
+void prefs_filtering_rename_path_prefix(const gchar *old_prefix,
+                                       const gchar *new_prefix)
+{
+       GList * cur;
+       const gchar *paths[2] = {NULL, NULL};
+       paths[0] = old_prefix;
+       paths[1] = new_prefix;
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_filtering_rename_path_prefix_func, paths);
+       }
+        
+       rename_path_prefix(pre_global_processing, old_prefix, new_prefix);
+       rename_path_prefix(post_global_processing, old_prefix, new_prefix);
+       rename_path_prefix(filtering_rules, old_prefix, new_prefix);
+        
+       prefs_matcher_write_config();
+}
+
 static void rename_tag(GSList * filters,
                        const gchar * old_tag, const gchar * new_tag)
 {
index d224383ba7e8e791bc0bee8b4dc0aa51eaf5065b..247918c7d873d2fa4bffad79c448388807b2fc44 100644 (file)
@@ -47,6 +47,8 @@ void prefs_filtering_open(GSList ** p_processing,
 
 void prefs_filtering_rename_path       (const gchar    *old_path,
                                         const gchar    *new_path);
+void prefs_filtering_rename_path_prefix        (const gchar    *old_prefix,
+                                        const gchar    *new_prefix);
 void prefs_filtering_delete_path       (const gchar    *path);
 
 void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag);