Proposal for adding two new signals to the send queue



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.

For now, both signals take no arguments but they could be modified in
the future, for example the stop-queue could notify about the number of
msgs correctly sent or so.

See the attached patch.

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;
@@ -301,6 +335,9 @@
 	priv->is_running = TRUE;
 	list = tny_simple_list_new ();
 
+	/* Emit the queue-start signal */
+	emit_queue_control_signals (self, TNY_SEND_QUEUE_START);
+
 	g_mutex_lock (priv->todo_lock);
 	{
 		GError *terror = NULL;
@@ -527,6 +564,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;
 }
 
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]