From c585c8203f54c07e91104bdb6623124e5f795a2d Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 9 Aug 2002 16:50:07 +0000 Subject: When a URI is changed, try to copy over threaded view settings, preview 2002-08-09 Peter Williams * mail-config.c (mail_config_uri_renamed): When a URI is changed, try to copy over threaded view settings, preview pane shown settings, headers, hide state, tree expansion, and GAL view files. (uri_to_evname): New utility function. svn path=/trunk/; revision=17751 --- mail/ChangeLog | 7 ++++++ mail/mail-config.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) (limited to 'mail') diff --git a/mail/ChangeLog b/mail/ChangeLog index 6b1afcda89..83a94b7950 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,10 @@ +2002-08-09 Peter Williams + + * mail-config.c (mail_config_uri_renamed): When a URI is changed, + try to copy over threaded view settings, preview pane shown settings, + headers, hide state, tree expansion, and GAL view files. + (uri_to_evname): New utility function. + 2002-08-08 Jeffrey Stedfast * mail-account-gui.c (mail_account_gui_save): Instead of comparing diff --git a/mail/mail-config.c b/mail/mail-config.c index 491885f32c..0db4017ad8 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -2442,12 +2442,39 @@ mail_config_get_default_transport (void) return NULL; } +static char * +uri_to_evname (const char *uri, const char *prefix) +{ + char *safe; + char *tmp; + + safe = g_strdup (uri); + e_filename_make_safe (safe); + /* blah, easiest thing to do */ + if (prefix[0] == '*') + tmp = g_strdup_printf ("%s/%s%s.xml", evolution_dir, prefix + 1, safe); + else + tmp = g_strdup_printf ("%s/%s%s", evolution_dir, prefix, safe); + g_free (safe); + return tmp; +} + void mail_config_uri_renamed(GCompareFunc uri_cmp, const char *old, const char *new) { MailConfigAccount *ac; const GSList *l; int work = 0; + gpointer oldkey, newkey, hashkey; + gpointer val; + char *oldname, *newname; + char *cachenames[] = { "config/hidestate-", + "config/et-expanded-", + "config/et-header-", + "*views/mail/current_view-", + "*views/mail/custom_view-", + NULL }; + int i; l = mail_config_get_accounts(); while (l) { @@ -2465,6 +2492,43 @@ mail_config_uri_renamed(GCompareFunc uri_cmp, const char *old, const char *new) l = l->next; } + oldkey = uri_to_key (old); + newkey = uri_to_key (new); + + /* call this to load the hash table and the key */ + mail_config_get_thread_list (old); + if (g_hash_table_lookup_extended (config->threaded_hash, oldkey, &hashkey, &val)) { + /*printf ("changing key in threaded_hash\n");*/ + g_hash_table_remove (config->threaded_hash, hashkey); + g_hash_table_insert (config->threaded_hash, newkey, val); + work = 2; + } + + /* ditto */ + mail_config_get_show_preview (old); + if (g_hash_table_lookup_extended (config->preview_hash, oldkey, &hashkey, &val)) { + /*printf ("changing key in preview_hash\n");*/ + g_hash_table_remove (config->preview_hash, hashkey); + g_hash_table_insert (config->preview_hash, newkey, val); + work = 2; + } + + g_free (oldkey); + if (work != 2) + g_free (newkey); + + /* ignore return values or if the files exist or + * not, doesn't matter */ + + for (i = 0; cachenames[i]; i++) { + oldname = uri_to_evname (old, cachenames[i]); + newname = uri_to_evname (new, cachenames[i]); + /*printf ("** renaming %s to %s\n", oldname, newname);*/ + rename (oldname, newname); + g_free (oldname); + g_free (newname); + } + /* nasty ... */ if (work) mail_config_write(); -- cgit v1.2.3