* include modest-platform.h, to remove compile warnign
[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
43 /* 'private'/'protected' functions */
44 static void modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass);
45 static void modest_tny_platform_factory_init       (ModestTnyPlatformFactory *obj);
46 static void modest_tny_platform_factory_finalize   (GObject *obj);
47 static GObject *modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
48                                                          GObjectConstructParam *construct_params);
49 static void tny_platform_factory_init (gpointer g, gpointer iface_data);
50
51 static TnyAccountStore* modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self);
52 static TnyDevice*       modest_tny_platform_factory_new_device        (TnyPlatformFactory *self);
53 static TnyMsgView*      modest_tny_platform_factory_new_msg_view      (TnyPlatformFactory *self);
54 static TnyMsg*          modest_tny_platform_factory_new_msg           (TnyPlatformFactory *self);
55 static TnyMimePart*     modest_tny_platform_factory_new_mime_part     (TnyPlatformFactory *self);
56 static TnyHeader*       modest_tny_platform_factory_new_header        (TnyPlatformFactory *self);
57
58
59 /* list my signals  */
60 enum {
61         /* MY_SIGNAL_1, */
62         /* MY_SIGNAL_2, */
63         LAST_SIGNAL
64 };
65
66 typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate;
67 struct _ModestTnyPlatformFactoryPrivate {};
68
69 #define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
70                                                          MODEST_TYPE_TNY_PLATFORM_FACTORY, \
71                                                          ModestTnyPlatformFactoryPrivate))
72 /* globals */
73 static GObjectClass *parent_class = NULL;
74 static ModestTnyPlatformFactory *singleton = NULL;
75
76 GType
77 modest_tny_platform_factory_get_type (void)
78 {
79         static GType my_type = 0;
80         if (!my_type) {
81                 static const GTypeInfo my_info = {
82                         sizeof(ModestTnyPlatformFactoryClass),
83                         NULL,           /* base init */
84                         NULL,           /* base finalize */
85                         (GClassInitFunc) modest_tny_platform_factory_class_init,
86                         NULL,           /* class finalize */
87                         NULL,           /* class data */
88                         sizeof(ModestTnyPlatformFactory),
89                         1,              /* n_preallocs */
90                         (GInstanceInitFunc) modest_tny_platform_factory_init,
91                         NULL
92                 };
93
94                 static const GInterfaceInfo tny_platform_factory_info = {
95                         (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
96                         NULL,         /* interface_finalize */
97                         NULL          /* interface_data */
98                 };
99
100                 my_type = g_type_register_static (G_TYPE_OBJECT,
101                                                   "ModestTnyPlatformFactory",
102                                                   &my_info, 0);
103
104                 g_type_add_interface_static (my_type, TNY_TYPE_PLATFORM_FACTORY, 
105                                              &tny_platform_factory_info);
106         }
107         return my_type;
108 }
109
110 static void
111 modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass)
112 {
113         GObjectClass *gobject_class;
114
115         gobject_class = (GObjectClass*) klass;
116         parent_class            = g_type_class_peek_parent (klass);
117
118         gobject_class->finalize = modest_tny_platform_factory_finalize;
119         gobject_class->constructor = modest_tny_platform_factory_constructor;
120
121         g_type_class_add_private (gobject_class, sizeof(ModestTnyPlatformFactoryPrivate));
122 }
123
124 static void
125 modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
126 {
127         /* empty */
128 }
129
130 static GObject*
131 modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
132                                          GObjectConstructParam *construct_params)
133 {
134         GObject *object;
135
136         if (!singleton) {
137                 object = G_OBJECT_CLASS (parent_class)->constructor (type,
138                                 n_construct_params, construct_params);
139
140                 singleton = MODEST_TNY_PLATFORM_FACTORY (object);
141         } else {
142                 object = G_OBJECT (singleton);
143                 g_object_freeze_notify (G_OBJECT (singleton));
144         }
145
146         return object;
147 }
148
149 static void
150 modest_tny_platform_factory_finalize (GObject *obj)
151 {
152         G_OBJECT_CLASS(parent_class)->finalize (obj);
153 }
154
155 static void
156 tny_platform_factory_init (gpointer g, gpointer iface_data)
157 {
158         TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;
159
160         klass->new_account_store_func = modest_tny_platform_factory_new_account_store;
161         klass->new_device_func        = modest_tny_platform_factory_new_device;
162         klass->new_msg_view_func      = modest_tny_platform_factory_new_msg_view;
163         klass->new_msg_func           = modest_tny_platform_factory_new_msg;
164         klass->new_mime_part_func     = modest_tny_platform_factory_new_mime_part;
165         klass->new_header_func        = modest_tny_platform_factory_new_header;
166
167         return;
168 }
169
170 TnyPlatformFactory *
171 modest_tny_platform_factory_get_instance (void)
172 {
173         ModestTnyPlatformFactory *self = g_object_new (MODEST_TYPE_TNY_PLATFORM_FACTORY, NULL);
174
175         return TNY_PLATFORM_FACTORY (self);
176 }
177
178 static TnyAccountStore *
179 modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self)
180 {
181         return TNY_ACCOUNT_STORE(modest_tny_account_store_new
182                                  (modest_runtime_get_account_mgr(),
183                                   modest_runtime_get_device()));
184 }
185
186 static TnyDevice *
187 modest_tny_platform_factory_new_device (TnyPlatformFactory *self)
188 {
189         return modest_platform_get_new_device ();
190 }
191
192 static TnyMsgView*
193 modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self)
194 {
195         /* TODO */
196         return NULL;
197 }
198
199 static TnyMsg*
200 modest_tny_platform_factory_new_msg (TnyPlatformFactory *self)
201 {
202         return tny_camel_msg_new ();
203 }
204
205
206 static TnyMimePart*
207 modest_tny_platform_factory_new_mime_part (TnyPlatformFactory *self)
208 {
209         return tny_camel_mime_part_new ();
210 }
211
212
213 static TnyHeader*
214 modest_tny_platform_factory_new_header (TnyPlatformFactory *self)
215 {
216         return tny_camel_header_new ();
217 }