2007-05-21 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-mail-operation-queue.c
index cf536b9..1893768 100644 (file)
@@ -139,8 +139,9 @@ modest_mail_operation_queue_finalize (GObject *obj)
        g_mutex_lock (priv->queue_lock);
 
        if (priv->op_queue) {
+               /* Cancel all */
                if (!g_queue_is_empty (priv->op_queue))
-                       g_queue_foreach (priv->op_queue, (GFunc) g_object_unref, NULL);
+                       modest_mail_operation_queue_cancel_all (MODEST_MAIL_OPERATION_QUEUE (obj));
                g_queue_free (priv->op_queue);
        }
 
@@ -193,24 +194,37 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
        g_queue_remove (priv->op_queue, mail_op);
        g_mutex_unlock (priv->queue_lock);
 
-       /* HACK see the documentation of the function. Remove this
-          call when tinymail provides accurate progress values */
-       _modest_mail_operation_notify_end (mail_op);
+       {
+               const GError *err;
+               err = modest_mail_operation_get_error (mail_op);
+               if (err)
+                       g_printerr ("Error in %s: %s", __FUNCTION__, err->message);
+       }
 
        /* Notify observers */
        g_signal_emit (self, signals[QUEUE_CHANGED_SIGNAL], 0,
                       mail_op, MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED);
 
-       /* TODO: errors? */
-       {
-               const GError *err = modest_mail_operation_get_error (mail_op);
-               if (err)
-                       g_warning (err->message);
-       }
-
        /* Free object */
+       modest_runtime_verify_object_last_ref (mail_op, "");
        g_object_unref (G_OBJECT (mail_op));
-       modest_runtime_verify_object_death (mail_op, "");
+}
+
+guint 
+modest_mail_operation_queue_num_elements (ModestMailOperationQueue *self)
+{
+       ModestMailOperationQueuePrivate *priv;
+       guint length = 0;
+
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION_QUEUE (self), 0);
+       
+       priv = MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(self);
+
+       g_mutex_lock (priv->queue_lock);
+       length = g_queue_get_length (priv->op_queue);
+       g_mutex_unlock (priv->queue_lock);
+
+       return length;
 }