6c92281803cd08cd02c1986c92eee92e3e619bb8
[modest] / src / modest-tny-send-queue.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30
31 #include <modest-tny-send-queue.h>
32
33 /* 'private'/'protected' functions */
34 static void modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass);
35 static void modest_tny_send_queue_init       (ModestTnySendQueue *obj);
36 static void modest_tny_send_queue_finalize   (GObject *obj);
37 /* list my signals  */
38 enum {
39         /* MY_SIGNAL_1, */
40         /* MY_SIGNAL_2, */
41         LAST_SIGNAL
42 };
43
44 typedef struct _ModestTnySendQueuePrivate ModestTnySendQueuePrivate;
45 struct _ModestTnySendQueuePrivate {
46         TnyTransportAccount *account;
47         
48 };
49 #define MODEST_TNY_SEND_QUEUE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
50                                                    MODEST_TYPE_TNY_SEND_QUEUE, \
51                                                    ModestTnySendQueuePrivate))
52 /* globals */
53 static TnySendQueueClass *parent_class = NULL;
54
55 /* uncomment the following if you have defined any signals */
56 /* static guint signals[LAST_SIGNAL] = {0}; */
57
58
59 static void
60 modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove)
61 {
62         MODEST_TNY_SENT_QUEUE_GET_CLASS(self)->cancel_func (self, remove);
63 }
64
65 static void
66 modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg)
67 {
68         MODEST_TNY_SENT_QUEUE_GET_CLASS(self)->add_func (self, msg);
69 }
70
71
72 static void
73 modest_tny_send_queue_get_sentbox (TnySendQueue *self)
74 {
75         MODEST_TNY_SENT_QUEUE_GET_CLASS(self)->get_sentbox (self);
76 }
77
78
79 static void
80 modest_tny_send_queue_get_outbox (TnySendQueue *self, TnyMsg *msg)
81 {
82         MODEST_TNY_SENT_QUEUE_GET_CLASS(self)->get_outbox (self);
83 }
84
85
86
87
88 static void
89 modest_tny_send_queue_cancel_default (TnySendQueue *self, gboolean remove)
90 {
91         /* FIXME */
92 }
93
94
95 static void
96 modest_tny_send_queue_add_default (TnySendQueue *self, TnyMsg *msg)
97 {
98         ModestTnySendQueuePriv *priv; 
99
100         g_return_if_fail (self, NULL);
101         g_return_if_fail (TNY_IS_CAMEL_MSG(msg), NULL);
102         
103         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
104
105         /* FIXME */
106         
107 }
108
109
110 static TnyFolder*
111 modest_tny_send_queue_get_sentbox_default (TnySendQueue *self)
112 {
113         ModestTnySendQueuePriv *priv; 
114         
115         g_return_val_if_fail (self, NULL);
116
117         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
118         
119         return modest_tny_account_get_special_folder (priv->account,
120                                                       TNY_FOLDER_TYPE_SENT);
121 }
122
123
124 static TnyFolder*
125 modest_tny_send_queue_get_outbox_default (TnySendQueue *self)
126 {
127         ModestTnySendQueuePriv *priv; 
128
129         g_return_val_if_fail (self, NULL);
130         
131         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
132
133         return modest_tny_account_get_special_folder (priv->account,
134                                                       TNY_FOLDER_TYPE_OUTBOX);
135 }
136
137
138
139
140 GType
141 modest_tny_send_queue_get_type (void)
142 {
143         static GType my_type = 0;
144         if (!my_type) {
145                 static const GTypeInfo my_info = {
146                         sizeof(ModestTnySendQueueClass),
147                         NULL,           /* base init */
148                         NULL,           /* base finalize */
149                         (GClassInitFunc) modest_tny_send_queue_class_init,
150                         NULL,           /* class finalize */
151                         NULL,           /* class data */
152                         sizeof(ModestTnySendQueue),
153                         1,              /* n_preallocs */
154                         (GInstanceInitFunc) modest_tny_send_queue_init,
155                         NULL
156                 };
157                 my_type = g_type_register_static (TNY__TYPE__SEND_QUEUE,
158                                                   "ModestTnySendQueue",
159                                                   &my_info, 0);
160         }
161         return my_type;
162 }
163
164
165 static void
166 modest_tny_send_queue_init (gpointer g, gpointer iface_data)
167 {
168         TnySendQueueIface *klass = (TnySendQueueIface*)g;
169         
170         klass->add_func         = modest_tny_send_queue_add;
171         klass->get_outbox_func  = modest_tny_send_queue_get_outbox;
172         klass->get_sentbox_func = modest_tny_send_queue_get_sentbox;
173         klass->cancel_func      = modest_tny_send_queue_cancel;
174 }
175
176
177
178 static void
179 modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass)
180 {
181         GObjectClass *gobject_class;
182
183         gobject_class = (GObjectClass*) klass;
184         
185         parent_class            = g_type_class_peek_parent (klass);
186         gobject_class->finalize = modest_tny_send_queue_finalize;
187
188         klass->add_func         = modest_tny_send_queue_add_default;
189         klass->get_outbox_func  = modest_tny_send_queue_get_outbox_default;
190         klass->get_sentbox_func = modest_tny_send_queue_get_sentbox_default;
191         klass->cancel_func      = modest_tny_send_queue_cancel_default;
192
193         g_type_class_add_private (gobject_class, sizeof(ModestTnySendQueuePrivate));
194 }
195
196 static void
197 modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class)
198 {
199         ModestTnySendQueue *self;  
200         ModestTnySendQueuePriv *priv; 
201
202         self = (ModestTnySendQueue*)instance;
203         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
204
205         priv->account = NULL;
206 }
207
208 static void
209 modest_tny_send_queue_finalize (GObject *obj)
210 {
211         ModestTnySendQueuePriv *priv; 
212         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (obj);
213         
214         if (priv->account) {
215                 g_object_unref (priv->account);
216                 priv->account = NULL;
217         }
218         
219         G_OBJECT_CLASS(parent_class)->finalize (obj);
220 }
221
222 ModestTnySendQueue*
223 modest_tny_send_queue_new (TnyTransportAccount *account)
224 {
225         ModestTnySendQueue *self;
226         ModestTnySendQueuePrivate *priv;
227
228         g_return_val_if_fail (account, NULL);
229         
230         self = MODEST_TNY_SEND_QUEUE(g_object_new(MODEST_TYPE_TNY_SEND_QUEUE, NULL));
231         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
232
233         priv->account = account;
234         g_object_ref (G_OBJECT(priv->account));
235         
236         return self;
237 }
238