static void _on_queue_start (TnySendQueue *self,
gpointer user_data);
+static void _on_queue_stop (TnySendQueue *self,
+ gpointer data);
+
static void modest_tny_send_queue_add_async (TnySendQueue *self,
TnyMsg *msg,
TnySendQueueAddCallback callback,
/* last was send receive operation?*/
gboolean requested_send_receive;
+
+ gboolean sending;
};
#define MODEST_TNY_SEND_QUEUE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
priv->current = NULL;
priv->outbox = NULL;
priv->sentbox = NULL;
+ priv->sending = FALSE;
}
static void
modest_tny_send_queue_finalize (GObject *obj)
{
ModestTnySendQueuePrivate *priv;
-
+
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (obj);
g_queue_foreach (priv->queue, (GFunc)modest_tny_send_queue_info_free, NULL);
ModestTnySendQueue *self;
TnyIterator *iter;
GetHeadersInfo *info;
+ ModestMailOperation *wakeup_op;
info = (GetHeadersInfo *) user_data;
self = MODEST_TNY_SEND_QUEUE (info->queue);
}
/* Reenable suspended items */
- modest_tny_send_queue_wakeup (self);
+ wakeup_op = modest_mail_operation_new (NULL);
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+ wakeup_op);
+ modest_mail_operation_queue_wakeup (wakeup_op, MODEST_TNY_SEND_QUEUE (self));
/* Frees */
g_object_unref (iter);
g_signal_connect (G_OBJECT(self), "error-happened",
G_CALLBACK(_on_msg_error_happened),
NULL);
+
g_signal_connect (G_OBJECT (self), "queue-start",
G_CALLBACK (_on_queue_start),
NULL);
+ g_signal_connect (G_OBJECT (self), "queue-stop",
+ G_CALLBACK (_on_queue_stop),
+ NULL);
priv->requested_send_receive = FALSE;
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
- return priv->current != NULL;
+ return priv->sending;
}
ModestTnySendQueueStatus
g_free(msg_uid);
return;
}
-
+
info = item->data;
/* Keep in queue so that we remember that the opertion has failed */
if (err->code == TNY_SYSTEM_ERROR_CANCEL) {
info->status = MODEST_TNY_SEND_QUEUE_SUSPENDED;
} else {
- if (err->code == TNY_SERVICE_ERROR_CONNECT) {
- TnyCamelTransportAccount* transport;
- TnyTransportAccount *conn_specific;
-
- transport = tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self));
- if (transport) {
- gchar *message;
- ModestTnyAccountStore *acc_store;
- const gchar *acc_name;
-
- acc_store = modest_runtime_get_account_store();
- acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (transport));
- conn_specific = (TnyTransportAccount *)
- modest_tny_account_store_get_transport_account_for_open_connection (acc_store, acc_name);
- if (conn_specific) {
- message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"),
- tny_account_get_hostname (TNY_ACCOUNT (conn_specific)));
- g_object_unref (conn_specific);
- } else {
- message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"),
- tny_account_get_hostname (TNY_ACCOUNT (transport)));
- }
- modest_platform_run_alert_dialog (message, FALSE);
- g_free (message);
- g_object_unref (transport);
- }
- }
info->status = MODEST_TNY_SEND_QUEUE_FAILED;
}
priv->current = NULL;
-
+
/* Notify status has changed */
g_signal_emit (self, signals[STATUS_CHANGED_SIGNAL], 0, info->msg_id, info->status);
_on_queue_start (TnySendQueue *self,
gpointer data)
{
+ ModestTnySendQueuePrivate *priv;
ModestMailOperation *mail_op;
mail_op = modest_mail_operation_new (NULL);
mail_op);
modest_mail_operation_run_queue (mail_op, MODEST_TNY_SEND_QUEUE (self));
g_object_unref (mail_op);
+
+ priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+ priv->sending = TRUE;
+}
+
+static void
+_on_queue_stop (TnySendQueue *self,
+ gpointer data)
+{
+ ModestTnySendQueuePrivate *priv;
+
+ priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+ priv->sending = FALSE;
}
static void
return status;
}
+typedef struct _WakeupHelper {
+ ModestTnySendQueue *self;
+ ModestTnySendQueueWakeupFunc callback;
+ gpointer userdata;
+} WakeupHelper;
+
+static void
+wakeup_sync_cb (TnyFolder *self, gboolean cancelled, GError *err, gpointer userdata)
+{
+ WakeupHelper *helper = (WakeupHelper *) userdata;
+
+ if (helper->callback) {
+ helper->callback (helper->self, cancelled, err, helper->userdata);
+ }
+ g_object_unref (helper->self);
+ g_slice_free (WakeupHelper, helper);
+}
+
static void
wakeup_get_headers_async_cb (TnyFolder *folder,
gboolean cancelled,
ModestTnySendQueue *self;
ModestTnySendQueuePrivate *priv;
TnyIterator *iter;
+ WakeupHelper *helper = (WakeupHelper *) user_data;
- self = MODEST_TNY_SEND_QUEUE (user_data);
+ self = MODEST_TNY_SEND_QUEUE (helper->self);
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
if (cancelled || err) {
g_debug ("Failed to wake up the headers of the send queue");
g_object_unref (self);
+ if (helper->callback) {
+ helper->callback (helper->self, cancelled, err, helper->userdata);
+ }
+ g_object_unref (helper->self);
+ g_slice_free (WakeupHelper, helper);
return;
}
/* Notify view */
msg_id = modest_tny_send_queue_get_msg_id (header);
item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
- info = (SendInfo *) item->data;
+ if (!item) {
+ info = g_slice_new (SendInfo);
+ info->msg_id = msg_id;
+ g_queue_push_tail (priv->queue, info);
+ } else {
+ info = (SendInfo *) item->data;
+ g_free (msg_id);
+ }
info->status = MODEST_TNY_SEND_QUEUE_WAITING;
- g_signal_emit (self, signals[STATUS_CHANGED_SIGNAL], 0, info->msg_id, info->status);
-
- /* Frees */
- g_free (msg_id);
+ g_signal_emit (self, signals[STATUS_CHANGED_SIGNAL], 0, info->msg_id, info->status);
}
/* Frees */
}
/* Make changes persistent on disk */
- tny_folder_sync_async (priv->outbox, FALSE, NULL, NULL, NULL);
+ tny_folder_sync_async (priv->outbox, FALSE, wakeup_sync_cb, NULL, helper);
/* Frees */
g_object_unref (iter);
g_object_unref (headers);
- g_object_unref (self);
}
-
void
-modest_tny_send_queue_wakeup (ModestTnySendQueue *self)
+modest_tny_send_queue_wakeup (ModestTnySendQueue *self,
+ ModestTnySendQueueWakeupFunc callback,
+ gpointer userdata)
{
ModestTnySendQueuePrivate *priv;
TnyList *headers;
+ WakeupHelper *helper;
g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE (self));
-
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+ helper = g_slice_new (WakeupHelper);
+ helper->self = g_object_ref (self);
+ helper->callback = callback;
+ helper->userdata = userdata;
+
headers = tny_simple_list_new ();
tny_folder_get_headers_async (priv->outbox, headers, TRUE,
wakeup_get_headers_async_cb,
- NULL, g_object_ref (self));
+ NULL, helper);
}
gboolean