[evolution] Consolidate MailFolderCache signal handlers.



commit c26b075886474052689aa2c4b30de3024bf69370
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Sep 2 11:11:11 2011 -0400

    Consolidate MailFolderCache signal handlers.
    
    Merging the "folder-deleted" and "folder-renamed" signal handlers in
    mail-config.c into the ones in e-mail-backend.c makes the account-mgmt
    branch a little easier, since e-mail-backend.c has resources I can't
    easily get to from mail-config.c.

 mail/e-mail-backend.c |  177 +++++++++++++++++++++++++++++++++++++++++++++++++
 mail/mail-config.c    |  162 --------------------------------------------
 2 files changed, 177 insertions(+), 162 deletions(-)
---
diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index 647edf8..c9ee133 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -29,6 +29,7 @@
 #include "e-mail-backend.h"
 
 #include <string.h>
+#include <glib/gstdio.h>
 #include <libedataserver/e-data-server-util.h>
 
 #include "e-util/e-account-utils.h"
@@ -90,6 +91,29 @@ mail_shell_backend_get_config_dir (EShellBackend *backend)
 	return mail_session_get_config_dir ();
 }
 
+static gchar *
+mail_backend_uri_to_evname (const gchar *uri,
+                            const gchar *prefix)
+{
+	const gchar *data_dir;
+	gchar *basename;
+	gchar *filename;
+	gchar *safe;
+
+	/* Converts a folder URI to a GalView filename. */
+
+	data_dir = mail_session_get_data_dir ();
+
+	safe = g_strdup (uri);
+	e_filename_make_safe (safe);
+	basename = g_strdup_printf ("%s%s.xml", prefix, safe);
+	filename = g_build_filename (data_dir, basename, NULL);
+	g_free (basename);
+	g_free (safe);
+
+	return filename;
+}
+
 /* Callback for various asynchronous CamelStore operations where
  * the EActivity's reference count is used as a counting semaphore. */
 static void
@@ -339,6 +363,76 @@ mail_backend_folder_deleted_cb (MailFolderCache *folder_cache,
                                 const gchar *folder_name,
                                 EMailBackend *backend)
 {
+	CamelStoreClass *class;
+	EAccountList *account_list;
+	EIterator *iterator;
+	const gchar *local_drafts_folder_uri;
+	const gchar *local_sent_folder_uri;
+	gboolean write_config = FALSE;
+	gchar *uri;
+
+	/* Check whether the deleted folder was a designated Drafts or
+	 * Sent folder for any mail account, and if so revert the setting
+	 * to the equivalent local folder, which is always present. */
+
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->compare_folder_name != NULL);
+
+	local_drafts_folder_uri =
+		e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_DRAFTS);
+	local_sent_folder_uri =
+		e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_SENT);
+
+	uri = e_mail_folder_uri_build (store, folder_name);
+
+	account_list = e_get_account_list ();
+	iterator = e_list_get_iterator (E_LIST (account_list));
+
+	while (e_iterator_is_valid (iterator)) {
+		EAccount *account;
+
+		/* XXX EIterator misuses const. */
+		account = (EAccount *) e_iterator_get (iterator);
+
+		if (account->sent_folder_uri != NULL) {
+			gboolean match;
+
+			match = class->compare_folder_name (
+				account->sent_folder_uri, uri);
+
+			if (match) {
+				g_free (account->sent_folder_uri);
+				account->sent_folder_uri =
+					g_strdup (local_sent_folder_uri);
+				write_config = TRUE;
+			}
+		}
+
+		if (account->drafts_folder_uri != NULL) {
+			gboolean match;
+
+			match = class->compare_folder_name (
+				account->drafts_folder_uri, uri);
+
+			if (match) {
+				g_free (account->drafts_folder_uri);
+				account->drafts_folder_uri =
+					g_strdup (local_drafts_folder_uri);
+				write_config = TRUE;
+			}
+		}
+
+		e_iterator_next (iterator);
+	}
+
+	g_object_unref (iterator);
+	g_free (uri);
+
+	if (write_config)
+		mail_config_write ();
+
+	/* This does something completely different.
+	 * XXX Make it a separate signal handler? */
 	mail_filter_delete_folder (backend, store, folder_name);
 }
 
@@ -349,6 +443,89 @@ mail_backend_folder_renamed_cb (MailFolderCache *folder_cache,
                                 const gchar *new_folder_name,
                                 EMailBackend *backend)
 {
+	CamelStoreClass *class;
+	EAccountList *account_list;
+	EIterator *iterator;
+	gboolean write_config = FALSE;
+	gchar *old_uri;
+	gchar *new_uri;
+	gint ii;
+
+	const gchar *cachenames[] = {
+		"views/current_view-",
+		"views/custom_view-"
+	};
+
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->compare_folder_name != NULL);
+
+	old_uri = e_mail_folder_uri_build (store, old_folder_name);
+	new_uri = e_mail_folder_uri_build (store, new_folder_name);
+
+	account_list = e_get_account_list ();
+	iterator = e_list_get_iterator (E_LIST (account_list));
+
+	while (e_iterator_is_valid (iterator)) {
+		EAccount *account;
+
+		/* XXX EIterator misuses const. */
+		account = (EAccount *) e_iterator_get (iterator);
+
+		if (account->sent_folder_uri != NULL) {
+			gboolean match;
+
+			match = class->compare_folder_name (
+				account->sent_folder_uri, old_uri);
+
+			if (match) {
+				g_free (account->sent_folder_uri);
+				account->sent_folder_uri = g_strdup (new_uri);
+				write_config = TRUE;
+			}
+		}
+
+		if (account->drafts_folder_uri != NULL) {
+			gboolean match;
+
+			match = class->compare_folder_name (
+				account->drafts_folder_uri, old_uri);
+
+			if (match) {
+				g_free (account->drafts_folder_uri);
+				account->drafts_folder_uri = g_strdup (new_uri);
+				write_config = TRUE;
+			}
+		}
+
+		e_iterator_next (iterator);
+	}
+
+	g_object_unref (iterator);
+
+	if (write_config)
+		mail_config_write ();
+
+	/* Rename GalView files. */
+
+	for (ii = 0; ii < G_N_ELEMENTS (cachenames); ii++) {
+		gchar *oldname;
+		gchar *newname;
+
+		oldname = mail_backend_uri_to_evname (old_uri, cachenames[ii]);
+		newname = mail_backend_uri_to_evname (new_uri, cachenames[ii]);
+
+		/* Ignore errors; doesn't matter. */
+		g_rename (oldname, newname);
+
+		g_free (oldname);
+		g_free (newname);
+	}
+
+	g_free (old_uri);
+	g_free (new_uri);
+
+	/* This does something completely different.
+	 * XXX Make it a separate signal handler? */
 	mail_filter_rename_folder (
 		backend, store, old_folder_name, new_folder_name);
 }
diff --git a/mail/mail-config.c b/mail/mail-config.c
index 2e67281..2428c4b 100644
--- a/mail/mail-config.c
+++ b/mail/mail-config.c
@@ -28,7 +28,6 @@
 #endif
 
 #include <gtk/gtk.h>
-#include <glib/gstdio.h>
 
 #include <libedataserver/e-data-server-util.h>
 #include <e-util/e-util.h>
@@ -40,7 +39,6 @@
 #include "e-mail-local.h"
 #include "e-mail-folder-utils.h"
 #include "mail-config.h"
-#include "mail-folder-cache.h"
 #include "mail-tools.h"
 
 typedef struct {
@@ -216,23 +214,6 @@ mail_config_get_sync_timeout (void)
 	return res;
 }
 
-static gchar *
-uri_to_evname (const gchar *uri, const gchar *prefix)
-{
-	const gchar *data_dir;
-	gchar *safe;
-	gchar *tmp;
-
-	data_dir = mail_session_get_data_dir ();
-
-	safe = g_strdup (uri);
-	e_filename_make_safe (safe);
-	tmp = g_strdup_printf ("%s/%s%s.xml", data_dir, prefix, safe);
-	g_free (safe);
-
-	return tmp;
-}
-
 gchar *
 mail_config_folder_to_cachename (CamelFolder *folder, const gchar *prefix)
 {
@@ -291,146 +272,12 @@ mail_config_get_lookup_book_local_only (void)
 	return config->book_lookup_local_only;
 }
 
-static void
-folder_deleted_cb (MailFolderCache *cache,
-                   CamelStore *store,
-                   const gchar *folder_name,
-                   gpointer user_data)
-{
-	CamelStoreClass *class;
-	EAccountList *account_list;
-	EIterator *iterator;
-	const gchar *local_drafts_folder_uri;
-	const gchar *local_sent_folder_uri;
-	gboolean write_config = FALSE;
-	gchar *uri;
-
-	class = CAMEL_STORE_GET_CLASS (store);
-
-	/* assumes these can't be removed ... */
-	local_drafts_folder_uri =
-		e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_DRAFTS);
-	local_sent_folder_uri =
-		e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_SENT);
-
-	uri = e_mail_folder_uri_build (store, folder_name);
-
-	account_list = e_get_account_list ();
-	iterator = e_list_get_iterator (E_LIST (account_list));
-
-	while (e_iterator_is_valid (iterator)) {
-		EAccount *account;
-
-		/* XXX EIterator misuses const. */
-		account = (EAccount *) e_iterator_get (iterator);
-
-		if (account->sent_folder_uri && class->compare_folder_name (
-				account->sent_folder_uri, uri)) {
-			g_free (account->sent_folder_uri);
-			account->sent_folder_uri =
-				g_strdup (local_sent_folder_uri);
-			write_config = TRUE;
-		}
-
-		if (account->drafts_folder_uri && class->compare_folder_name (
-				account->drafts_folder_uri, uri)) {
-			g_free (account->drafts_folder_uri);
-			account->drafts_folder_uri =
-				g_strdup (local_drafts_folder_uri);
-			write_config = TRUE;
-		}
-
-		e_iterator_next (iterator);
-	}
-
-	g_object_unref (iterator);
-	g_free (uri);
-
-	/* nasty again */
-	if (write_config)
-		mail_config_write ();
-}
-
-static void
-folder_renamed_cb (MailFolderCache *cache,
-                   CamelStore *store,
-                   const gchar *old_folder_name,
-                   const gchar *new_folder_name,
-                   gpointer user_data)
-{
-	CamelStoreClass *class;
-	EAccountList *account_list;
-	EAccount *account;
-	EIterator *iterator;
-	gboolean write_config = FALSE;
-	gchar *old_uri;
-	gchar *new_uri;
-	gint i;
-
-	const gchar *cachenames[] = {
-		"views/current_view-",
-		"views/custom_view-",
-		NULL };
-
-	class = CAMEL_STORE_GET_CLASS (store);
-
-	old_uri = e_mail_folder_uri_build (store, old_folder_name);
-	new_uri = e_mail_folder_uri_build (store, new_folder_name);
-
-	account_list = e_get_account_list ();
-	iterator = e_list_get_iterator (E_LIST (account_list));
-
-	while (e_iterator_is_valid (iterator)) {
-		account = (EAccount *) e_iterator_get (iterator);
-
-		if (account->sent_folder_uri && class->compare_folder_name (
-				account->sent_folder_uri, old_uri)) {
-			g_free (account->sent_folder_uri);
-			account->sent_folder_uri = g_strdup (new_uri);
-			write_config = TRUE;
-		}
-
-		if (account->drafts_folder_uri && class->compare_folder_name (
-				account->drafts_folder_uri, old_uri)) {
-			g_free (account->drafts_folder_uri);
-			account->drafts_folder_uri = g_strdup (new_uri);
-			write_config = TRUE;
-		}
-
-		e_iterator_next (iterator);
-	}
-
-	g_object_unref (iterator);
-
-	/* ignore return values or if the files exist or
-	 * not, doesn't matter */
-
-	for (i = 0; cachenames[i]; i++) {
-		gchar *oldname;
-		gchar *newname;
-
-		oldname = uri_to_evname (old_uri, cachenames[i]);
-		newname = uri_to_evname (new_uri, cachenames[i]);
-		g_rename (oldname, newname);
-		g_free (oldname);
-		g_free (newname);
-	}
-
-	g_free (old_uri);
-	g_free (new_uri);
-
-	/* nasty ... */
-	if (write_config)
-		mail_config_write ();
-}
-
 /* Config struct routines */
 void
 mail_config_init (EMailSession *session)
 {
 	GConfClient *client;
 	GConfClientNotifyFunc func;
-	MailFolderCache *folder_cache;
 	const gchar *key;
 
 	g_return_if_fail (E_IS_MAIL_SESSION (session));
@@ -515,14 +362,5 @@ mail_config_init (EMailSession *session)
 
 	gconf_jh_check_changed (client, 0, NULL, session);
 
-	folder_cache = e_mail_session_get_folder_cache (session);
-
-	g_signal_connect (
-		folder_cache, "folder-deleted",
-		(GCallback) folder_deleted_cb, NULL);
-	g_signal_connect (
-		folder_cache, "folder-renamed",
-		(GCallback) folder_renamed_cb, NULL);
-
 	g_object_unref (client);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]