New cancel_occurred attribute for the CamelImapFolder



I've just added a new 'cancel_occurred' attribute for the
CamelImapFolder, so if an IMAP update is cancelled by the user then
Camel doesn't try to update it again.

Philip review the patch 'cause we are touching dangerous parts of the
code here :-)

-- 
Alberto García González
http://people.igalia.com/berto/
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(revision 3399)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(working copy)
@@ -247,6 +247,7 @@
 
 	imap_folder->stopping = FALSE;
 	imap_folder->in_idle = FALSE;
+	imap_folder->cancel_occurred = FALSE;
 
 	imap_folder->gmsgstore = NULL;
 	imap_folder->gmsgstore_ticks = 0;
@@ -752,7 +753,7 @@
 
 		if (imap_folder->need_rescan) {
 			suc = imap_rescan (folder, exists, ex);
-			if (imap_folder->need_rescan)
+			if (imap_folder->need_rescan && !imap_folder->cancel_occurred)
 				camel_imap_folder_changed (folder, exists, NULL, ex);
 		} else if (exists > count)
 			camel_imap_folder_changed (folder, exists, NULL, ex);
@@ -3225,6 +3226,7 @@
    camel_folder_summary_prepare_hash (folder->summary);
 
    store->dontdistridlehack = TRUE;
+   imap_folder->cancel_occurred = FALSE;
 
    while (more)
    {
@@ -3244,9 +3246,14 @@
 
 	if (!camel_imap_command_start (store, folder, ex,
 		"UID SEARCH %d:%d ALL", seq + 1, MAX (1, MIN (seq + 1 + nextn, exists))))
-		{ if (!camel_operation_cancel_check (NULL))
-			g_warning ("IMAP error getting UIDs (1)");
-		 camel_operation_end (NULL); return; }
+		{
+			if (camel_operation_cancel_check (NULL))
+				imap_folder->cancel_occurred = TRUE;
+			else
+				g_warning ("IMAP error getting UIDs (1)");
+			camel_operation_end (NULL);
+			return;
+		}
 
 	more = FALSE;
 	needheaders = g_ptr_array_new ();
@@ -3254,7 +3261,9 @@
 
 	if (cnt == 0 && camel_exception_get_id (ex) == CAMEL_EXCEPTION_USER_CANCEL)
 	{
-		if (!camel_operation_cancel_check (NULL))
+		if (camel_operation_cancel_check (NULL))
+			imap_folder->cancel_occurred = TRUE;
+		else
 			g_warning ("IMAP error getting UIDs (1,1)");
 
 		g_ptr_array_foreach (needheaders, (GFunc)g_free, NULL);
@@ -3275,15 +3284,22 @@
 	{
 		if (!camel_imap_command_start (store, folder, ex,
 			"UID SEARCH %d:* ALL", seq + 1 + cnt))
-			{ if (!camel_operation_cancel_check (NULL))
-				g_warning ("IMAP error getting UIDs (2)");
-			  camel_operation_end (NULL);
-			  store->dontdistridlehack = FALSE; return; }
+			{
+				if (camel_operation_cancel_check (NULL))
+					imap_folder->cancel_occurred = TRUE;
+				else
+					g_warning ("IMAP error getting UIDs (2)");
+				camel_operation_end (NULL);
+				store->dontdistridlehack = FALSE;
+				return;
+			}
 		cnt = imap_get_uids (folder, store, ex, needheaders, (exists - seq) - cnt);
 
 		if (cnt == 0 && camel_exception_get_id (ex) == CAMEL_EXCEPTION_USER_CANCEL)
 		{
-			if (!camel_operation_cancel_check (NULL))
+			if (camel_operation_cancel_check (NULL))
+				imap_folder->cancel_occurred = TRUE;
+			else
 				g_warning ("IMAP error getting UIDs (2,1)");
 
 			g_ptr_array_foreach (needheaders, (GFunc)g_free, NULL);
@@ -3304,17 +3320,24 @@
 			needheaders = g_ptr_array_new ();
 			if (!camel_imap_command_start (store, folder, ex,
 				"UID FETCH 1:* (UID)")) /* Old less efficient style */
-				{ if (!camel_operation_cancel_check (NULL))
-					g_warning ("IMAP error getting UIDs (3)");
+				{
+					if (camel_operation_cancel_check (NULL))
+						imap_folder->cancel_occurred = TRUE;
+					else
+						g_warning ("IMAP error getting UIDs (3)");
 					camel_folder_summary_kill_hash (folder->summary);
-				  camel_operation_end (NULL);
-				  store->dontdistridlehack = FALSE; return; }
+					camel_operation_end (NULL);
+					store->dontdistridlehack = FALSE;
+					return;
+				}
 			camel_folder_summary_clear (folder->summary);
 			tcnt = cnt = imap_get_uids (folder, store, ex, needheaders, (exists - seq) - tcnt);
 
 			if (cnt == 0 && camel_exception_get_id (ex) == CAMEL_EXCEPTION_USER_CANCEL)
 			{
-				if (!camel_operation_cancel_check (NULL))
+				if (camel_operation_cancel_check (NULL))
+					imap_folder->cancel_occurred = TRUE;
+				else
 					g_warning ("IMAP error getting UIDs (3,1)");
 
 				g_ptr_array_foreach (needheaders, (GFunc)g_free, NULL);
@@ -3352,7 +3375,9 @@
 						       "UID FETCH %s (FLAGS RFC822.SIZE INTERNALDATE BODY.PEEK[%s])",
 						       uidset, header_spec))
 			{
-				if (!camel_operation_cancel_check (NULL))
+				if (camel_operation_cancel_check (NULL))
+					imap_folder->cancel_occurred = TRUE;
+				else
 					g_warning ("IMAP error getting headers (1)");
 				g_ptr_array_foreach (needheaders, (GFunc)g_free, NULL);
 				g_ptr_array_free (needheaders, TRUE);
@@ -3492,7 +3517,9 @@
 
 			if (type == CAMEL_IMAP_RESPONSE_ERROR)
 			{
-				if (!camel_operation_cancel_check (NULL))
+				if (camel_operation_cancel_check (NULL))
+					imap_folder->cancel_occurred = TRUE;
+				else
 					g_warning ("IMAP error getting headers (2)");
 				g_ptr_array_foreach (needheaders, (GFunc)g_free, NULL);
 				g_ptr_array_free (needheaders, TRUE);
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.h	(revision 3399)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.h	(working copy)
@@ -51,7 +51,7 @@
 	unsigned int read_only:1;
 	gchar *folder_dir;
 
-	gboolean do_push_email, stopping, in_idle;
+	gboolean do_push_email, stopping, in_idle, cancel_occurred;
 	guint gmsgstore_signal;
 	GStaticRecMutex *idle_lock;
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 3400)
+++ ChangeLog	(working copy)
@@ -1,3 +1,12 @@
+2008-02-14  Alberto Garcia Gonzalez <agarcia igalia com>
+
+	* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.[ch]:
+	Added new attribute: cancel_occurred
+	(imap_update_summary): Set cancel_occurred to TRUE when the
+	operation is cancelled by the user.
+	(camel_imap_folder_selected): Don't try to refresh the folder
+	again if a cancel has happened.
+
 2008-02-12  Alberto Garcia Gonzalez <agarcia igalia com>
 
 	* libtinymailui-gtk/tny-gtk-text-buffer-stream.c:


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