* Fixes NB#103682, correctly select the default region
[modest] / src / modest-tny-platform-factory.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 /* modest-tny-platform-factory.c */
31 #include <config.h>
32
33 #include <modest-runtime.h>
34 #include <modest-platform.h>
35
36 #include <tny-camel-header.h>
37 #include <tny-camel-mime-part.h>
38 #include <tny-camel-msg.h>
39
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>
44 #else
45 #include <widgets/modest-gtkhtml-msg-view.h>
46 #endif
47
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);
55
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);
61
62 /* list my signals  */
63 enum {
64         /* MY_SIGNAL_1, */
65         /* MY_SIGNAL_2, */
66         LAST_SIGNAL
67 };
68
69 /* PRIVATE area commented as it's empty now. If you enable this again remember to enable also
70  * private area registration in class init */
71
72 /* typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate; */
73 /* struct _ModestTnyPlatformFactoryPrivate {}; */
74
75 /* #define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \ */
76 /*                                                          MODEST_TYPE_TNY_PLATFORM_FACTORY, \ */
77 /*                                                          ModestTnyPlatformFactoryPrivate)) */
78
79 /* globals */
80 static GObjectClass *parent_class = NULL;
81 static ModestTnyPlatformFactory *singleton = NULL;
82
83 GType
84 modest_tny_platform_factory_get_type (void)
85 {
86         static GType my_type = 0;
87         if (!my_type) {
88                 static const GTypeInfo my_info = {
89                         sizeof(ModestTnyPlatformFactoryClass),
90                         NULL,           /* base init */
91                         NULL,           /* base finalize */
92                         (GClassInitFunc) modest_tny_platform_factory_class_init,
93                         NULL,           /* class finalize */
94                         NULL,           /* class data */
95                         sizeof(ModestTnyPlatformFactory),
96                         1,              /* n_preallocs */
97                         (GInstanceInitFunc) modest_tny_platform_factory_init,
98                         NULL
99                 };
100
101                 static const GInterfaceInfo tny_platform_factory_info = {
102                         (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
103                         NULL,         /* interface_finalize */
104                         NULL          /* interface_data */
105                 };
106
107                 my_type = g_type_register_static (G_TYPE_OBJECT,
108                                                   "ModestTnyPlatformFactory",
109                                                   &my_info, 0);
110
111                 g_type_add_interface_static (my_type, TNY_TYPE_PLATFORM_FACTORY, 
112                                              &tny_platform_factory_info);
113         }
114         return my_type;
115 }
116
117 static void
118 modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass)
119 {
120         GObjectClass *gobject_class;
121
122         gobject_class = (GObjectClass*) klass;
123         parent_class            = g_type_class_peek_parent (klass);
124
125         gobject_class->finalize = modest_tny_platform_factory_finalize;
126         gobject_class->constructor = modest_tny_platform_factory_constructor;
127
128 /*      g_type_class_add_private (gobject_class, sizeof(ModestTnyPlatformFactoryPrivate)); */
129 }
130
131 static void
132 modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
133 {
134         /* empty */
135 }
136
137 static GObject*
138 modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
139                                          GObjectConstructParam *construct_params)
140 {
141         GObject *object;
142
143         if (!singleton) {
144                 object = G_OBJECT_CLASS (parent_class)->constructor (type,
145                                 n_construct_params, construct_params);
146
147                 singleton = MODEST_TNY_PLATFORM_FACTORY (object);
148         } else {
149                 object = G_OBJECT (singleton);
150                 g_object_freeze_notify (G_OBJECT (singleton));
151         }
152
153         return object;
154 }
155
156 static void
157 modest_tny_platform_factory_finalize (GObject *obj)
158 {
159         G_OBJECT_CLASS(parent_class)->finalize (obj);
160 }
161
162 static void
163 tny_platform_factory_init (gpointer g, gpointer iface_data)
164 {
165         TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;
166
167         klass->new_account_store = modest_tny_platform_factory_new_account_store;
168         klass->new_device        = modest_tny_platform_factory_new_device;
169         klass->new_msg_view      = modest_tny_platform_factory_new_msg_view;
170         klass->new_msg           = modest_tny_platform_factory_new_msg;
171         klass->new_mime_part     = modest_tny_platform_factory_new_mime_part;
172         return;
173 }
174
175 TnyPlatformFactory *
176 modest_tny_platform_factory_get_instance (void)
177 {
178         ModestTnyPlatformFactory *self = g_object_new (MODEST_TYPE_TNY_PLATFORM_FACTORY, NULL);
179
180         return TNY_PLATFORM_FACTORY (self);
181 }
182
183 static TnyAccountStore *
184 modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self)
185 {
186         return TNY_ACCOUNT_STORE(modest_tny_account_store_new
187                                  (modest_runtime_get_account_mgr(),
188                                   modest_runtime_get_device()));
189 }
190
191 static TnyDevice *
192 modest_tny_platform_factory_new_device (TnyPlatformFactory *self)
193 {
194         return modest_platform_get_new_device ();
195 }
196
197 static TnyMsgView*
198 modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self)
199 {
200         /* Here we'll select one of the implementations available */
201 #ifdef MODEST_USE_MOZEMBED
202         return g_object_new (MODEST_TYPE_MOZEMBED_MSG_VIEW, NULL);
203 #else
204         return g_object_new (MODEST_TYPE_GTKHTML_MSG_VIEW, NULL);
205 #endif
206 }
207
208 static TnyMsg*
209 modest_tny_platform_factory_new_msg (TnyPlatformFactory *self)
210 {
211         return tny_camel_msg_new ();
212 }
213
214
215 static TnyMimePart*
216 modest_tny_platform_factory_new_mime_part (TnyPlatformFactory *self)
217 {
218         return tny_camel_mime_part_new ();
219 }
220
221