#include "modest-marshal.h"
#include "modest-mail-operation-queue.h"
#include "modest-runtime.h"
+#include "modest-debug.h"
/* 'private'/'protected' functions */
static void modest_mail_operation_queue_class_init (ModestMailOperationQueueClass *klass);
}
static void
+print_queue_item (ModestMailOperation *op, const gchar* prefix)
+{
+ gchar *op_str = modest_mail_operation_to_string (op);
+ g_debug ("%s: %s",
+ prefix ? prefix : "",
+ op_str);
+ g_free (op_str);
+}
+
+static void
on_finalize_foreach(gpointer op,
gpointer user_data)
{
* the lock acquired. */
g_signal_handlers_disconnect_by_func (mail_op, G_CALLBACK (on_operation_finished), user_data);
+ MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "cancel/remove"););
+
modest_mail_operation_cancel (mail_op);
g_queue_remove (priv->op_queue, mail_op);
g_object_unref (G_OBJECT (mail_op));
g_mutex_lock (priv->queue_lock);
+ MODEST_DEBUG_BLOCK (
+ g_debug ("%s; items in queue: %d",
+ __FUNCTION__, g_queue_get_length (priv->op_queue));
+ g_queue_foreach (priv->op_queue, (GFunc)print_queue_item, "in queue");
+ );
+
+
if (priv->op_queue) {
/* Cancel all */
if (!g_queue_is_empty (priv->op_queue)) {
g_mutex_lock (priv->queue_lock);
g_queue_push_tail (priv->op_queue, g_object_ref (mail_op));
g_mutex_unlock (priv->queue_lock);
+
+ MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "add"););
/* Get notified when the operation ends to remove it from the
queue. We connect it using the *after* because we want to
g_queue_remove (priv->op_queue, mail_op);
g_mutex_unlock (priv->queue_lock);
+ MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "remove"););
+
g_signal_handlers_disconnect_by_func (G_OBJECT (mail_op),
G_CALLBACK (on_operation_finished),
self);
priv = MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(self);
+ MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "cancel"););
+
/* This triggers a progess_changed signal in which we remove
* the operation from the queue. */
modest_mail_operation_cancel (mail_op);
void (*queue_empty) (ModestMailOperationQueue *self);
};
+
/* member functions */
GType modest_mail_operation_queue_get_type (void) G_GNUC_CONST;
modest_mail_operation_notify_start (self);
modest_mail_operation_notify_end (self);
}
+
+
+gchar*
+modest_mail_operation_to_string (ModestMailOperation *self)
+{
+ const gchar *type, *status, *account_id;
+ ModestMailOperationPrivate *priv = NULL;
+
+ g_return_val_if_fail (self, NULL);
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
+
+ switch (priv->op_type) {
+ case MODEST_MAIL_OPERATION_TYPE_SEND: type= "SEND"; break;
+ case MODEST_MAIL_OPERATION_TYPE_RECEIVE: type= "RECEIVE"; break;
+ case MODEST_MAIL_OPERATION_TYPE_OPEN: type= "OPEN"; break;
+ case MODEST_MAIL_OPERATION_TYPE_DELETE: type= "DELETE"; break;
+ case MODEST_MAIL_OPERATION_TYPE_INFO: type= "INFO"; break;
+ case MODEST_MAIL_OPERATION_TYPE_UNKNOWN: type= "UNKNOWN"; break;
+ default: type = "UNEXPECTED"; break;
+ }
+
+ switch (priv->status) {
+ case MODEST_MAIL_OPERATION_STATUS_INVALID: status= "INVALID"; break;
+ case MODEST_MAIL_OPERATION_STATUS_SUCCESS: status= "SUCCESS"; break;
+ case MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS: status= "FINISHED-WITH-ERRORS"; break;
+ case MODEST_MAIL_OPERATION_STATUS_FAILED: status= "FAILED"; break;
+ case MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS: status= "IN-PROGRESS"; break;
+ case MODEST_MAIL_OPERATION_STATUS_CANCELED: status= "CANCELLED"; break;
+ default: status= "UNEXPECTED"; break;
+ }
+
+ account_id = priv->account ? tny_account_get_id (priv->account) : "";
+
+ return g_strdup_printf ("%p \"%s\" (%s) [%s] {%d/%d} '%s'", self, account_id,type, status,
+ priv->done, priv->total,
+ priv->error && priv->error->message ? priv->error->message : "");
+}
**/
void modest_mail_operation_noop (ModestMailOperation *self);
+
+/**
+ * modest_mail_operation_to_string:
+ * @self: a #ModestMailOperation
+ *
+ * get a string representation of the mail operation (for debugging)
+ *
+ * Returns: a newly allocated string
+ **/
+gchar* modest_mail_operation_to_string (ModestMailOperation *self);
+
+
G_END_DECLS
#endif /* __MODEST_MAIL_OPERATION_H__ */
}
if (!show_ui_without_top_application_method) {
- g_print ("modest: not showing UI\n");
- g_print ("modest: use 'modest showui' to start with UI\n");
+ g_print ("modest: use 'modest showui' to start from cmdline with UI\n");
}
if (!g_thread_supported())
#include <modest-platform.h>
#include <widgets/modest-window-mgr.h>
#include <modest-marshal.h>
+#include <modest-debug.h>
#include <string.h> /* strcmp */
/* 'private'/'protected' functions */
g_slice_free(SendInfo, info);
}
+static void
+print_queue_item (gpointer data, gpointer user_data)
+{
+ SendInfo *info = (SendInfo*)data;
+ const gchar *status;
+
+ switch (info->status) {
+ case MODEST_TNY_SEND_QUEUE_UNKNOWN: status = "UNKNOWN"; break;
+ case MODEST_TNY_SEND_QUEUE_WAITING: status = "WAITING"; break;
+ case MODEST_TNY_SEND_QUEUE_SUSPENDED: status = "SUSPENDED"; break;
+ case MODEST_TNY_SEND_QUEUE_SENDING: status = "SENDING"; break;
+ case MODEST_TNY_SEND_QUEUE_FAILED: status = "FAILED"; break;
+ default: status= "UNEXPECTED"; break;
+ }
+
+ g_debug ("\"%s\" => [%s]", info->msg_id, status);
+}
+
static GList*
modest_tny_send_queue_lookup_info (ModestTnySendQueue *self, const gchar *msg_id)
{
ModestTnySendQueuePrivate *priv;
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+ MODEST_DEBUG_BLOCK (
+ g_debug ("items in the send queue (%d):",
+ g_queue_get_length (priv->queue));
+ g_queue_foreach (priv->queue, print_queue_item, NULL);
+ );
+
return g_queue_find_custom (priv->queue, msg_id, on_modest_tny_send_queue_compare_id);
}
/* Get status info */
item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
if (!item)
- g_warning ("%s: item should not be NULL", __FUNCTION__);
+ g_warning ("%s: item (%s) should not be NULL",
+ __FUNCTION__, msg_id ? msg_id : "<none>");
else {
info = item->data;
info->status = MODEST_TNY_SEND_QUEUE_SENDING;