* Fixes NB#96696, do not use -export-dynamic to reduce the symbols to be exported
[modest] / src / modest-tny-send-queue.c
index bb103ab..9fec6ce 100644 (file)
@@ -73,6 +73,9 @@ static void _on_msg_error_happened (TnySendQueue *self,
 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, 
@@ -108,6 +111,8 @@ struct _ModestTnySendQueuePrivate {
 
        /* 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), \
@@ -399,22 +404,24 @@ modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class)
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (instance);
        priv->queue = g_queue_new();
        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);
        g_queue_free (priv->queue);
 
+       G_OBJECT_CLASS(parent_class)->finalize (obj);
        g_object_unref (priv->outbox);
        g_object_unref (priv->sentbox);
-
-       G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
 typedef struct {
@@ -505,10 +512,14 @@ modest_tny_send_queue_new (TnyCamelTransportAccount *account)
        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;
 
@@ -544,7 +555,7 @@ modest_tny_send_queue_sending_in_progress (ModestTnySendQueue* self)
        
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
        
-       return priv->current != NULL;
+       return priv->sending;
 }
 
 ModestTnySendQueueStatus
@@ -698,12 +709,26 @@ _on_msg_error_happened (TnySendQueue *self,
                } 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;                                 
-                                       message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), 
-                                                                  tny_account_get_hostname (TNY_ACCOUNT (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);
@@ -725,6 +750,7 @@ static void
 _on_queue_start (TnySendQueue *self,
                 gpointer data)
 {
+       ModestTnySendQueuePrivate *priv;
        ModestMailOperation *mail_op;
 
        mail_op = modest_mail_operation_new (NULL);
@@ -732,6 +758,19 @@ _on_queue_start (TnySendQueue *self,
                                         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 
@@ -843,12 +882,16 @@ wakeup_get_headers_async_cb (TnyFolder *folder,
                        /* 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 */