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.
30 /* modest-tny-platform-factory.c */
33 #include <tny-camel-header.h>
34 #include <tny-camel-mime-part.h>
35 #include <tny-camel-msg.h>
37 /* MODES_PLATFORM_ID: 1 ==> gtk, 2==> maemo */
38 #if MODEST_PLATFORM_ID==1
39 #include <tny-gnome-device.h>
40 #elif MODEST_PLATFORM_ID==2
41 #include <tny-maemo-device.h>
44 #include "modest-tny-platform-factory.h"
45 #include "modest-tny-account-store.h"
47 /* 'private'/'protected' functions */
48 static void modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass);
49 static void modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj);
50 static void modest_tny_platform_factory_finalize (GObject *obj);
51 static GObject *modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
52 GObjectConstructParam *construct_params);
53 static void tny_platform_factory_init (gpointer g, gpointer iface_data);
55 static TnyAccountStore* modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self);
56 static TnyDevice* modest_tny_platform_factory_new_device (TnyPlatformFactory *self);
57 static TnyMsgView* modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self);
58 static TnyMsg* modest_tny_platform_factory_new_msg (TnyPlatformFactory *self);
59 static TnyMimePart* modest_tny_platform_factory_new_mime_part (TnyPlatformFactory *self);
60 static TnyHeader* modest_tny_platform_factory_new_header (TnyPlatformFactory *self);
70 typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate;
71 struct _ModestTnyPlatformFactoryPrivate {
72 ModestTnyAccountStore *account_store;
74 ModestAccountMgr *account_mgr;
75 ModestMailOperationQueue *mail_op_queue;
78 #define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
79 MODEST_TYPE_TNY_PLATFORM_FACTORY, \
80 ModestTnyPlatformFactoryPrivate))
82 static GObjectClass *parent_class = NULL;
83 static ModestTnyPlatformFactory *singleton = NULL;
85 /* uncomment the following if you have defined any signals */
86 /* static guint signals[LAST_SIGNAL] = {0}; */
89 modest_tny_platform_factory_get_type (void)
91 static GType my_type = 0;
93 static const GTypeInfo my_info = {
94 sizeof(ModestTnyPlatformFactoryClass),
96 NULL, /* base finalize */
97 (GClassInitFunc) modest_tny_platform_factory_class_init,
98 NULL, /* class finalize */
99 NULL, /* class data */
100 sizeof(ModestTnyPlatformFactory),
102 (GInstanceInitFunc) modest_tny_platform_factory_init,
106 static const GInterfaceInfo tny_platform_factory_info = {
107 (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
108 NULL, /* interface_finalize */
109 NULL /* interface_data */
112 my_type = g_type_register_static (G_TYPE_OBJECT,
113 "ModestTnyPlatformFactory",
116 g_type_add_interface_static (my_type, TNY_TYPE_PLATFORM_FACTORY,
117 &tny_platform_factory_info);
123 modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass)
125 GObjectClass *gobject_class;
127 gobject_class = (GObjectClass*) klass;
128 parent_class = g_type_class_peek_parent (klass);
130 gobject_class->finalize = modest_tny_platform_factory_finalize;
131 gobject_class->constructor = modest_tny_platform_factory_constructor;
133 g_type_class_add_private (gobject_class, sizeof(ModestTnyPlatformFactoryPrivate));
137 modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
139 ModestTnyPlatformFactoryPrivate *priv;
140 priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(obj);
142 priv->account_mgr = NULL;
144 priv->account_store = NULL;
145 priv->mail_op_queue = NULL;
149 modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
150 GObjectConstructParam *construct_params)
155 object = G_OBJECT_CLASS (parent_class)->constructor (type,
156 n_construct_params, construct_params);
158 singleton = MODEST_TNY_PLATFORM_FACTORY (object);
160 object = G_OBJECT (singleton);
161 g_object_freeze_notify (G_OBJECT (singleton));
168 modest_tny_platform_factory_finalize (GObject *obj)
170 ModestTnyPlatformFactoryPrivate *priv;
172 priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(obj);
174 if (priv->account_mgr)
175 g_object_unref (priv->account_mgr);
178 g_object_unref (priv->conf);
180 if (priv->account_store)
181 g_object_unref (priv->account_store);
183 if (priv->mail_op_queue)
184 g_object_unref (priv->mail_op_queue);
186 G_OBJECT_CLASS(parent_class)->finalize (obj);
190 tny_platform_factory_init (gpointer g, gpointer iface_data)
192 TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;
194 klass->new_account_store_func = modest_tny_platform_factory_new_account_store;
195 klass->new_device_func = modest_tny_platform_factory_new_device;
196 klass->new_msg_view_func = modest_tny_platform_factory_new_msg_view;
197 klass->new_msg_func = modest_tny_platform_factory_new_msg;
198 klass->new_mime_part_func = modest_tny_platform_factory_new_mime_part;
199 klass->new_header_func = modest_tny_platform_factory_new_header;
205 modest_tny_platform_factory_get_instance (void)
207 ModestTnyPlatformFactory *self = g_object_new (MODEST_TYPE_TNY_PLATFORM_FACTORY, NULL);
209 return TNY_PLATFORM_FACTORY (self);
212 static TnyAccountStore *
213 modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self)
215 ModestTnyPlatformFactoryPrivate *priv;
217 priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(self);
219 if (!priv->account_store) {
220 if (!priv->account_mgr)
221 modest_tny_platform_factory_get_modest_account_mgr_instance (self);
223 priv->account_store = modest_tny_account_store_new (priv->account_mgr);
226 return TNY_ACCOUNT_STORE (priv->account_store);
230 modest_tny_platform_factory_new_device (TnyPlatformFactory *self)
232 /* MODES_PLATFORM_ID: 1 ==> gtk, 2==> maemo */
233 #if MODEST_PLATFORM_ID==1
234 return TNY_DEVICE (tny_gnome_device_new ());
235 #elif MODEST_PLATFORM_ID==2
236 return TNY_DEVICE (tny_maemo_device_new ());
239 #endif /* MODEST_PLATFORM */
243 modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self)
250 modest_tny_platform_factory_new_msg (TnyPlatformFactory *self)
252 return tny_camel_msg_new ();
257 modest_tny_platform_factory_new_mime_part (TnyPlatformFactory *self)
259 return tny_camel_mime_part_new ();
264 modest_tny_platform_factory_new_header (TnyPlatformFactory *self)
266 return tny_camel_header_new ();
271 modest_tny_platform_factory_get_modest_account_mgr_instance (TnyPlatformFactory *fact)
273 ModestTnyPlatformFactoryPrivate *priv;
275 priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
277 if (!priv->account_mgr) {
279 modest_tny_platform_factory_get_modest_conf_instance (fact);
281 priv->account_mgr = modest_account_mgr_new (priv->conf);
284 return priv->account_mgr;
288 modest_tny_platform_factory_get_modest_conf_instance (TnyPlatformFactory *fact)
290 ModestTnyPlatformFactoryPrivate *priv;
292 priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
295 priv->conf = modest_conf_new ();
300 ModestMailOperationQueue*
301 modest_tny_platform_factory_get_modest_mail_operation_queue_instance (TnyPlatformFactory *fact)
303 ModestTnyPlatformFactoryPrivate *priv;
305 priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
307 if (!priv->mail_op_queue)
308 priv->mail_op_queue = modest_mail_operation_queue_new ();
310 return priv->mail_op_queue;