Because we don't want Mr Van Hoof to get bored...



another patch to be reviewed. I'll explain the problem and then the fix

problem is that IMAP accounts use two queues, one for the "normal"
operations and another one just for message retrieval. Thing is that if
you have a reconnection or a connection request in the "normal" queue,
it could happen that the user requests a get_msg_async or a
find_msg_async that would be redirected to the other queue. User could
think that the connection will take place before but that don't have to
be true as both petitions go in different paths.

What I did is add a new queue item flag called CONNECT_ITEM that
identifies calls to set_online function, and if the user issues a
get_msg_async or a find_msg_async while a CONNECT_ITEM is pending then
that petition will go through the "normal" queue, that's it, it'll wait
for the account connection.

Br
Index: libtinymail-camel/tny-camel-queue-priv.h
===================================================================
--- libtinymail-camel/tny-camel-queue-priv.h	(revision 3747)
+++ libtinymail-camel/tny-camel-queue-priv.h	(working copy)
@@ -74,6 +74,7 @@
 	TNY_CAMEL_QUEUE_SYNC_ITEM = 1<<5, 
 	TNY_CAMEL_QUEUE_REFRESH_ITEM = 1<<6,
 	TNY_CAMEL_QUEUE_AUTO_CANCELLABLE_ITEM = 1<<7,
+	TNY_CAMEL_QUEUE_CONNECT_ITEM = 1<<8,
 } TnyCamelQueueItemFlags;
 
 GType tny_camel_queue_get_type (void);
@@ -83,6 +84,7 @@
 void _tny_camel_queue_launch (TnyCamelQueue *queue, GThreadFunc func, GSourceFunc callback, GDestroyNotify destroyer, GSourceFunc cancel_callback, GDestroyNotify cancel_destroyer, gboolean *cancel_field, gpointer data, gsize data_size, const gchar *name);
 void _tny_camel_queue_remove_items (TnyCamelQueue *queue, TnyCamelQueueItemFlags flags);
 void _tny_camel_queue_cancel_remove_items (TnyCamelQueue *queue, TnyCamelQueueItemFlags flags);
+gboolean _tny_camel_queue_has_items (TnyCamelQueue *queue, TnyCamelQueueItemFlags flags);
 
 G_END_DECLS
 
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c	(revision 3747)
+++ libtinymail-camel/tny-camel-folder.c	(working copy)
@@ -2669,7 +2669,9 @@
 	/* thread reference header */
 	g_object_ref (info->header);
 
-	if (!TNY_IS_CAMEL_POP_FOLDER (self))
+	if (!TNY_IS_CAMEL_POP_FOLDER (self) && 
+	    !_tny_camel_queue_has_items (TNY_FOLDER_PRIV_GET_QUEUE (priv), 
+					 TNY_CAMEL_QUEUE_RECONNECT_ITEM | TNY_CAMEL_QUEUE_CONNECT_ITEM))
 		queue = TNY_FOLDER_PRIV_GET_MSG_QUEUE (priv);
 	else
 		queue = TNY_FOLDER_PRIV_GET_QUEUE (priv);
@@ -2845,7 +2847,9 @@
 	_tny_camel_folder_reason (priv);
 	g_object_ref (info->self);
 
-	if (!TNY_IS_CAMEL_POP_FOLDER (self))
+	if (!TNY_IS_CAMEL_POP_FOLDER (self) && 
+	    !_tny_camel_queue_has_items (TNY_FOLDER_PRIV_GET_QUEUE (priv), 
+					 TNY_CAMEL_QUEUE_RECONNECT_ITEM | TNY_CAMEL_QUEUE_CONNECT_ITEM))
 		queue = TNY_FOLDER_PRIV_GET_MSG_QUEUE (priv);
 	else
 		queue = TNY_FOLDER_PRIV_GET_QUEUE (priv);
Index: libtinymail-camel/tny-camel-queue.c
===================================================================
--- libtinymail-camel/tny-camel-queue.c	(revision 3747)
+++ libtinymail-camel/tny-camel-queue.c	(working copy)
@@ -488,6 +488,32 @@
 	return;
 }
 
+gboolean 
+_tny_camel_queue_has_items (TnyCamelQueue *queue, TnyCamelQueueItemFlags flags)
+{
+	GList *copy = NULL;
+	gboolean retval = FALSE;
+
+	g_static_rec_mutex_lock (queue->lock);
+	copy = queue->list;
+	while (copy)
+	{
+		QueueItem *item = copy->data;
+
+		if (item && (item->flags & flags)) 
+		{
+			tny_debug ("TnyCamelQueue: %s found\n", item->name);
+			retval = TRUE;
+			break;
+		}
+		
+		copy = g_list_next (copy);
+	}
+	g_static_rec_mutex_unlock (queue->lock);
+
+	return retval;
+}
+
 static void 
 tny_camel_queue_class_init (TnyCamelQueueClass *class)
 {
Index: libtinymail-camel/tny-camel-store-account.c
===================================================================
--- libtinymail-camel/tny-camel-store-account.c	(revision 3747)
+++ libtinymail-camel/tny-camel-store-account.c	(working copy)
@@ -2045,7 +2045,7 @@
 		tny_camel_store_account_queue_going_online_cancelled_destroy,
 		NULL,
 		info, sizeof (GoingOnlineInfo),
-		TNY_CAMEL_QUEUE_RECONNECT_ITEM|TNY_CAMEL_QUEUE_CANCELLABLE_ITEM,
+		TNY_CAMEL_QUEUE_CONNECT_ITEM|TNY_CAMEL_QUEUE_CANCELLABLE_ITEM,
 		__FUNCTION__);
 
 	return;


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