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 <modest-runtime.h>
34 #include <modest-platform.h>
36 #include <tny-camel-header.h>
37 #include <tny-camel-mime-part.h>
38 #include <tny-camel-msg.h>
40 #include "modest-tny-platform-factory.h"
41 #include "modest-tny-account-store.h"
42 #ifdef MODEST_USE_MOZEMBED
43 #include <widgets/modest-mozembed-msg-view.h>
45 #include <widgets/modest-gtkhtml-msg-view.h>
48 /* 'private'/'protected' functions */
49 static void modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass);
50 static void modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj);
51 static void modest_tny_platform_factory_finalize (GObject *obj);
52 static GObject *modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
53 GObjectConstructParam *construct_params);
54 static void tny_platform_factory_init (gpointer g, gpointer iface_data);
56 static TnyAccountStore* modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self);
57 static TnyDevice* modest_tny_platform_factory_new_device (TnyPlatformFactory *self);
58 static TnyMsgView* modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self);
59 static TnyMsg* modest_tny_platform_factory_new_msg (TnyPlatformFactory *self);
60 static TnyMimePart* modest_tny_platform_factory_new_mime_part (TnyPlatformFactory *self);
69 typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate;
70 struct _ModestTnyPlatformFactoryPrivate {};
72 #define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
73 MODEST_TYPE_TNY_PLATFORM_FACTORY, \
74 ModestTnyPlatformFactoryPrivate))
76 static GObjectClass *parent_class = NULL;
77 static ModestTnyPlatformFactory *singleton = NULL;
80 modest_tny_platform_factory_get_type (void)
82 static GType my_type = 0;
84 static const GTypeInfo my_info = {
85 sizeof(ModestTnyPlatformFactoryClass),
87 NULL, /* base finalize */
88 (GClassInitFunc) modest_tny_platform_factory_class_init,
89 NULL, /* class finalize */
90 NULL, /* class data */
91 sizeof(ModestTnyPlatformFactory),
93 (GInstanceInitFunc) modest_tny_platform_factory_init,
97 static const GInterfaceInfo tny_platform_factory_info = {
98 (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
99 NULL, /* interface_finalize */
100 NULL /* interface_data */
103 my_type = g_type_register_static (G_TYPE_OBJECT,
104 "ModestTnyPlatformFactory",
107 g_type_add_interface_static (my_type, TNY_TYPE_PLATFORM_FACTORY,
108 &tny_platform_factory_info);
114 modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass)
116 GObjectClass *gobject_class;
118 gobject_class = (GObjectClass*) klass;
119 parent_class = g_type_class_peek_parent (klass);
121 gobject_class->finalize = modest_tny_platform_factory_finalize;
122 gobject_class->constructor = modest_tny_platform_factory_constructor;
124 g_type_class_add_private (gobject_class, sizeof(ModestTnyPlatformFactoryPrivate));
128 modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
134 modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
135 GObjectConstructParam *construct_params)
140 object = G_OBJECT_CLASS (parent_class)->constructor (type,
141 n_construct_params, construct_params);
143 singleton = MODEST_TNY_PLATFORM_FACTORY (object);
145 object = G_OBJECT (singleton);
146 g_object_freeze_notify (G_OBJECT (singleton));
153 modest_tny_platform_factory_finalize (GObject *obj)
155 G_OBJECT_CLASS(parent_class)->finalize (obj);
159 tny_platform_factory_init (gpointer g, gpointer iface_data)
161 TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;
163 klass->new_account_store_func = modest_tny_platform_factory_new_account_store;
164 klass->new_device_func = modest_tny_platform_factory_new_device;
165 klass->new_msg_view_func = modest_tny_platform_factory_new_msg_view;
166 klass->new_msg_func = modest_tny_platform_factory_new_msg;
167 klass->new_mime_part_func = modest_tny_platform_factory_new_mime_part;
172 modest_tny_platform_factory_get_instance (void)
174 ModestTnyPlatformFactory *self = g_object_new (MODEST_TYPE_TNY_PLATFORM_FACTORY, NULL);
176 return TNY_PLATFORM_FACTORY (self);
179 static TnyAccountStore *
180 modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self)
182 return TNY_ACCOUNT_STORE(modest_tny_account_store_new
183 (modest_runtime_get_account_mgr(),
184 modest_runtime_get_device()));
188 modest_tny_platform_factory_new_device (TnyPlatformFactory *self)
190 return modest_platform_get_new_device ();
194 modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self)
196 /* Here we'll select one of the implementations available */
197 #ifdef MODEST_USE_MOZEMBED
198 return g_object_new (MODEST_TYPE_MOZEMBED_MSG_VIEW, NULL);
200 return g_object_new (MODEST_TYPE_GTKHTML_MSG_VIEW, NULL);
205 modest_tny_platform_factory_new_msg (TnyPlatformFactory *self)
207 return tny_camel_msg_new ();
212 modest_tny_platform_factory_new_mime_part (TnyPlatformFactory *self)
214 return tny_camel_mime_part_new ();