Re: Proposal for adding two new signals to the send queue



Sergio Villar Senin wrote:
> Hi,
> 
> from MUA developer's POV I think it'd be quite interesting to have two
> new signals in the send queue that inform about the status of the send
> queue, one of them would be issued when the queue starts to process the
> messages and the other one would be sent when the queue stops to process
> messages. Both would be emitted always even though none message was
> processed.

Second version of the patch, now the signal is issued just before
creating the thread. This could be more useful because the thread could
be theoretically delayed for some time, and with the new patch the
client application could receive the signal before.

Br
Index: libtinymail-camel/tny-camel-send-queue.c
===================================================================
--- libtinymail-camel/tny-camel-send-queue.c	(revision 3290)
+++ libtinymail-camel/tny-camel-send-queue.c	(working copy)
@@ -174,7 +174,7 @@
 	if (apriv)
 		tny_lockable_lock (apriv->session->priv->ui_lock);
 	g_signal_emit (info->self, tny_send_queue_signals [info->signal_id], 
-		0, info->header, info->msg, info->i, info->total);
+		       0, info->header, info->msg, info->i, info->total);	
 	if (apriv)
 		tny_lockable_unlock (apriv->session->priv->ui_lock);
 
@@ -281,6 +281,40 @@
 	return;
 }
 
+
+static gboolean
+emit_queue_control_signals_on_mainloop (gpointer data)
+{
+	ControlInfo *info = data;
+	TnyCamelSendQueuePriv *priv = TNY_CAMEL_SEND_QUEUE_GET_PRIVATE (info->self);
+	TnyCamelAccountPriv *apriv = NULL;
+
+	if (priv && priv->trans_account)
+		apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (priv->trans_account);
+	if (apriv)
+		tny_lockable_lock (apriv->session->priv->ui_lock);
+	g_signal_emit (info->self, tny_send_queue_signals [info->signal_id], 0);	
+	if (apriv)
+		tny_lockable_unlock (apriv->session->priv->ui_lock);
+
+	return NULL;
+}
+
+static void
+emit_queue_control_signals (TnySendQueue *self, guint signal_id)
+{
+	ControlInfo *info = g_slice_new0 (ControlInfo);
+
+	info->self = g_object_ref (self);
+	info->signal_id = signal_id;
+
+	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+			 emit_queue_control_signals_on_mainloop, info, 
+			 destroy_control_info);
+	
+	return;
+}
+
 typedef struct {
 	TnySendQueue *self;
 	TnyDevice *device;
@@ -527,6 +561,9 @@
 	g_object_unref (info->self);
 	g_slice_free (MainThreadInfo, info);
 
+	/* Emit the queue-stop signal */
+	emit_queue_control_signals (self, TNY_SEND_QUEUE_STOP);
+
 	return NULL;
 }
 
@@ -541,10 +578,18 @@
 		TnySessionCamelPriv *spriv = ((TnySessionCamel *) apriv->session)->priv;
 
 		if (spriv->device && TNY_IS_DEVICE (spriv->device)) {
-			MainThreadInfo *info = g_slice_new0 (MainThreadInfo);
+			MainThreadInfo *info;
+
+			info = g_slice_new0 (MainThreadInfo);
 			info->self = g_object_ref (self);
 			info->device = g_object_ref (spriv->device);
+
+			emit_queue_control_signals (self, TNY_SEND_QUEUE_START);
+
 			priv->thread = g_thread_create (thread_main, info, FALSE, NULL);
+
+			if (priv->thread == NULL)
+				emit_queue_control_signals (self, TNY_SEND_QUEUE_STOP);
 		}
 	}
 
Index: libtinymail/tny-send-queue.c
===================================================================
--- libtinymail/tny-send-queue.c	(revision 3290)
+++ libtinymail/tny-send-queue.c	(working copy)
@@ -241,6 +241,37 @@
 				      NULL, NULL,
 				      tny_marshal_VOID__OBJECT_OBJECT_POINTER,
 				      G_TYPE_NONE, 3, TNY_TYPE_HEADER, TNY_TYPE_MSG, G_TYPE_POINTER);
+
+/**
+ * TnySendQueue::queue-start
+ * @self: a #TnySendQueue, the object on which the signal is emitted
+ *
+ * Emitted when the queue starts to process messages
+ **/
+		tny_send_queue_signals[TNY_SEND_QUEUE_START] =
+			g_signal_new ("queue-start",
+				      TNY_TYPE_SEND_QUEUE,
+				      G_SIGNAL_RUN_FIRST,
+				      G_STRUCT_OFFSET (TnySendQueueIface, queue_start),
+				      NULL, NULL,
+				      g_cclosure_marshal_VOID__VOID,
+				      G_TYPE_NONE, 0);
+
+/**
+ * TnySendQueue::queue-stop
+ * @self: a #TnySendQueue, the object on which the signal is emitted
+ *
+ * Emitted when the queue stops to process messages
+ **/
+		tny_send_queue_signals[TNY_SEND_QUEUE_STOP] =
+			g_signal_new ("queue-stop",
+				      TNY_TYPE_SEND_QUEUE,
+				      G_SIGNAL_RUN_FIRST,
+				      G_STRUCT_OFFSET (TnySendQueueIface, queue_stop),
+				      NULL, NULL,
+				      g_cclosure_marshal_VOID__VOID,
+				      G_TYPE_NONE, 0);
+
 		
 		initialized = TRUE;
 	}
Index: libtinymail/tny-send-queue.h
===================================================================
--- libtinymail/tny-send-queue.h	(revision 3290)
+++ libtinymail/tny-send-queue.h	(working copy)
@@ -45,6 +45,8 @@
 	TNY_SEND_QUEUE_MSG_SENDING,
 	TNY_SEND_QUEUE_MSG_SENT,
 	TNY_SEND_QUEUE_ERROR_HAPPENED,
+	TNY_SEND_QUEUE_START,
+	TNY_SEND_QUEUE_STOP,
 	TNY_SEND_QUEUE_LAST_SIGNAL
 };
 
@@ -65,6 +67,8 @@
 	void (*msg_sending) (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, guint nth, guint total);
 	void (*msg_sent) (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, guint nth, guint total);
 	void (*error_happened) (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, gpointer user_data);
+	void (*queue_start) (TnySendQueue *self, gpointer user_data);
+	void (*queue_stop) (TnySendQueue *self, gpointer user_data);
 
 	/* methods */
 	void (*add_func) (TnySendQueue *self, TnyMsg *msg, GError **err);


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