static int
on_modest_tny_send_queue_compare_id(gconstpointer info, gconstpointer msg_id)
{
+ g_return_val_if_fail (info && ((SendInfo*)info)->msg_id && msg_id, -1);
+
return strcmp( ((SendInfo*)info)->msg_id, msg_id);
}
}
static void
-modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg, GError **err)
+_on_added_to_outbox (TnySendQueue *self, gboolean cancelled, TnyMsg *msg, GError *err, gpointer user_data)
{
+ ModestTnySendQueuePrivate *priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE(self);
+ TnyHeader *header = NULL;
+ SendInfo *info = NULL;
+ GList* existing = NULL;
+ const gchar* msg_id = NULL;
+
g_return_if_fail (TNY_IS_SEND_QUEUE(self));
g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
- TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_func (self, msg, err); /* FIXME */
+ header = tny_msg_get_header (msg);
+ msg_id = modest_tny_send_queue_get_msg_id (header);
+/* msg_id = tny_header_get_message_id (header); */
+ g_return_if_fail(msg_id != NULL);
- /* We cannot access the uid of the message here because it might
- * just have been created. Wait for it being added to outbox. */
+ /* Put newly added message in WAITING state */
+ existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_id);
+ if(existing != NULL)
+ {
+ //g_assert(info->status == MODEST_TNY_SEND_QUEUE_SUSPENDED ||
+ // info->status == MODEST_TNY_SEND_QUEUE_FAILED);
+
+ info = existing->data;
+ info->status = MODEST_TNY_SEND_QUEUE_WAITING;
+ }
+ else
+ {
+
+ info = g_slice_new (SendInfo);
+
+ info->msg_id = strdup(msg_id);
+ info->status = MODEST_TNY_SEND_QUEUE_WAITING;
+ g_queue_push_tail (priv->queue, info);
+ }
+
+ g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
+
+ g_object_unref(G_OBJECT(header));
+}
+
+void
+modest_tny_send_queue_add (ModestTnySendQueue *self, TnyMsg *msg, GError **err)
+{
+ g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE(self));
+ g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
+
+ tny_send_queue_add_async (TNY_SEND_QUEUE(self),
+ msg,
+ _on_added_to_outbox,
+ NULL,
+ NULL);
}
+
static void
_add_message (ModestTnySendQueue *self, TnyHeader *header)
{
/* Check if it already exists on queue */
existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_uid);
- if(existing != NULL) return;
-
+ if(existing != NULL)
+ break;
+
/* Check if its being edited */
mgr = modest_runtime_get_window_mgr ();
editing = modest_window_mgr_find_registered_header (mgr, header, NULL);
- if (editing) return;
+ if (editing)
+ break;
/* Add new meesage info */
info = g_slice_new (SendInfo);
g_queue_push_tail (priv->queue, info);
break;
default:
- goto frees;
+ break;
}
/* Free */
- frees:
g_free(msg_uid);
}
return folder;
}
-static void
-modest_tny_send_queue_update(TnyFolderObserver *self,
- TnyFolderChange *change)
-{
- ModestTnySendQueuePrivate *priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE(self);
- TnyHeader *header = NULL;
- TnyMsg *msg = tny_folder_change_get_received_msg(change);
- SendInfo *info = NULL;
- GList* existing = NULL;
- const gchar* msg_id = NULL;
- TnyFolder* outbox = NULL;
-
- if(msg)
- {
- outbox = tny_send_queue_get_outbox(TNY_SEND_QUEUE(self));
- header = tny_msg_get_header(msg);
-
- msg_id = tny_header_get_message_id (header);
- g_assert(msg_id != NULL);
-
- /* Put newly added message in WAITING state */
- existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_id);
- if(existing != NULL)
- {
- //g_assert(info->status == MODEST_TNY_SEND_QUEUE_SUSPENDED ||
- // info->status == MODEST_TNY_SEND_QUEUE_FAILED);
-
- info = existing->data;
- info->status = MODEST_TNY_SEND_QUEUE_WAITING;
- }
- else
- {
-
- info = g_slice_new (SendInfo);
-
- info->msg_id = strdup(msg_id);
- info->status = MODEST_TNY_SEND_QUEUE_WAITING;
- g_queue_push_tail (priv->queue, info);
- }
-
- g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
-
- g_object_unref(G_OBJECT(msg));
- g_object_unref(G_OBJECT(header));
- g_object_unref(G_OBJECT(outbox));
- }
-}
-
-static void
-modest_tny_send_queue_folder_observer_init(gpointer g, gpointer iface_data)
-{
- TnyFolderObserverIface *klass = (TnyFolderObserverIface *)g;
- klass->update_func = modest_tny_send_queue_update;
-}
-
GType
modest_tny_send_queue_get_type (void)
{
NULL
};
- static const GInterfaceInfo tny_folder_observer_info = {
- (GInterfaceInitFunc) modest_tny_send_queue_folder_observer_init,
- NULL,
- NULL
- };
-
my_type = g_type_register_static (TNY_TYPE_CAMEL_SEND_QUEUE,
"ModestTnySendQueue",
&my_info, 0);
-
- g_type_add_interface_static(my_type, TNY_TYPE_FOLDER_OBSERVER,
- &tny_folder_observer_info);
}
return my_type;
}
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = modest_tny_send_queue_finalize;
- TNY_CAMEL_SEND_QUEUE_CLASS(klass)->add_func = modest_tny_send_queue_add;
TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_outbox_func = modest_tny_send_queue_get_outbox;
TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_sentbox_func = modest_tny_send_queue_get_sentbox;
TNY_CAMEL_SEND_QUEUE_CLASS(klass)->cancel_func = modest_tny_send_queue_cancel;
g_queue_foreach (priv->queue, (GFunc)modest_tny_send_queue_info_free, NULL);
g_queue_free (priv->queue);
- printf("Finalize called\n");
-
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
tny_camel_send_queue_set_transport_account (TNY_CAMEL_SEND_QUEUE(self),
account);
- /* TODO: Does this produce cyclic references? */
- tny_folder_add_observer(modest_tny_send_queue_get_outbox(TNY_SEND_QUEUE(self)),
- TNY_FOLDER_OBSERVER(self));
-
/* Connect signals to control when a msg is being or has been sent */
g_signal_connect (G_OBJECT(self), "msg-sending",
G_CALLBACK(_on_msg_start_sending),
/* Get status info */
item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
- g_return_if_fail (item != NULL);
- info = item->data;
- info->status = MODEST_TNY_SEND_QUEUE_SENDING;
-
- /* Set current status item */
- g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
- priv->current = item;
+ if (!item)
+ g_warning ("%s: item should not be NULL", __FUNCTION__);
+ else {
+ info = item->data;
+ info->status = MODEST_TNY_SEND_QUEUE_SENDING;
+
+ /* Set current status item */
+ g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
+ priv->current = item;
+ }
/* free */
g_free (msg_id);
/* Get status info */
item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
- g_return_if_fail(item != NULL);
-
- /* Remove status info */
- modest_tny_send_queue_info_free (item->data);
- g_queue_delete_link (priv->queue, item);
- priv->current = NULL;
+ if (!item)
+ g_warning ("%s: item should not be NULL", __FUNCTION__);
+ else {
- modest_platform_information_banner (NULL, NULL, _("mcen_ib_message_sent"));
+ /* Remove status info */
+ modest_tny_send_queue_info_free (item->data);
+ g_queue_delete_link (priv->queue, item);
+ priv->current = NULL;
+
+ modest_platform_information_banner (NULL, NULL, _("mcen_ib_message_sent"));
+ }
/* free */
g_free(msg_id);
info = g_slice_new (SendInfo);
info->msg_id = strdup(msg_uid);
g_queue_push_tail (priv->queue, info);
- }
- else {
+ } else
info = item->data;
- }
/* Keep in queue so that we remember that the opertion has failed */
/* and was not just cancelled */