1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <modest-tny-send-queue.h>
32 #include <tny-simple-list.h>
33 #include <tny-iterator.h>
34 #include <tny-folder.h>
35 #include <tny-camel-msg.h>
36 #include <modest-tny-account.h>
38 /* 'private'/'protected' functions */
39 static void modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass);
40 static void modest_tny_send_queue_finalize (GObject *obj);
41 static void modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class);
50 typedef struct _ModestTnySendQueuePrivate ModestTnySendQueuePrivate;
51 struct _ModestTnySendQueuePrivate {
52 TnyCamelTransportAccount *account;
54 #define MODEST_TNY_SEND_QUEUE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
55 MODEST_TYPE_TNY_SEND_QUEUE, \
56 ModestTnySendQueuePrivate))
58 static TnyCamelSendQueueClass *parent_class = NULL;
60 /* uncomment the following if you have defined any signals */
61 /* static guint signals[LAST_SIGNAL] = {0}; */
64 * this thread actually tries to send all the mails in the outbox
69 modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove)
71 g_warning (__FUNCTION__);
73 TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->cancel_func (self, remove);
77 modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg)
79 ModestTnySendQueuePrivate *priv;
81 g_return_if_fail (TNY_IS_SEND_QUEUE(self));
82 g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
84 g_warning (__FUNCTION__);
86 priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
88 /* FIXME: do something smart here... */
90 TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_func (self, msg);
94 modest_tny_send_queue_get_sentbox (TnySendQueue *self)
96 ModestTnySendQueuePrivate *priv;
98 g_warning (__FUNCTION__);
100 g_return_val_if_fail (self, NULL);
102 priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
104 return modest_tny_account_get_special_folder (TNY_ACCOUNT(priv->account),
105 TNY_FOLDER_TYPE_SENT);
110 modest_tny_send_queue_get_outbox (TnySendQueue *self)
112 ModestTnySendQueuePrivate *priv;
114 g_return_val_if_fail (self, NULL);
116 g_warning (__FUNCTION__);
118 priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
120 return modest_tny_account_get_special_folder (TNY_ACCOUNT(priv->account),
121 TNY_FOLDER_TYPE_OUTBOX);
126 modest_tny_send_queue_get_type (void)
128 static GType my_type = 0;
131 static const GTypeInfo my_info = {
132 sizeof(ModestTnySendQueueClass),
133 NULL, /* base init */
134 NULL, /* base finalize */
135 (GClassInitFunc) modest_tny_send_queue_class_init,
136 NULL, /* class finalize */
137 NULL, /* class data */
138 sizeof(ModestTnySendQueue),
140 (GInstanceInitFunc) modest_tny_send_queue_instance_init,
143 my_type = g_type_register_static (TNY_TYPE_CAMEL_SEND_QUEUE,
144 "ModestTnySendQueue",
152 modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass)
154 GObjectClass *gobject_class;
156 gobject_class = (GObjectClass*) klass;
158 parent_class = g_type_class_peek_parent (klass);
159 gobject_class->finalize = modest_tny_send_queue_finalize;
161 TNY_CAMEL_SEND_QUEUE_CLASS(klass)->add_func = modest_tny_send_queue_add;
162 TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_outbox_func = modest_tny_send_queue_get_outbox;
163 TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_sentbox_func = modest_tny_send_queue_get_sentbox;
164 TNY_CAMEL_SEND_QUEUE_CLASS(klass)->cancel_func = modest_tny_send_queue_cancel;
166 g_type_class_add_private (gobject_class, sizeof(ModestTnySendQueuePrivate));
170 modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class)
172 ModestTnySendQueue *self;
173 ModestTnySendQueuePrivate *priv;
175 self = (ModestTnySendQueue*)instance;
176 priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
178 priv->account = NULL;
182 modest_tny_send_queue_finalize (GObject *obj)
184 ModestTnySendQueuePrivate *priv;
185 priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (obj);
188 g_object_unref (priv->account);
189 priv->account = NULL;
192 G_OBJECT_CLASS(parent_class)->finalize (obj);
196 modest_tny_send_queue_new (TnyCamelTransportAccount *account)
198 ModestTnySendQueue *self;
199 ModestTnySendQueuePrivate *priv;
201 g_return_val_if_fail (TNY_IS_CAMEL_TRANSPORT_ACCOUNT(account), NULL);
203 self = MODEST_TNY_SEND_QUEUE(g_object_new(MODEST_TYPE_TNY_SEND_QUEUE, NULL));
204 priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
206 priv->account = account;
207 g_object_ref (G_OBJECT(priv->account));