* src/modest-tny-account-store.[ch]:
[modest] / src / modest-transport-account-decorator.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-transport-account-decorator.h>
32 #include <modest-tny-account-store.h>
33 #include <modest-tny-account.h>
34 #include <modest-runtime.h>
35 #include <tny-simple-list.h>
36 #include <tny-iterator.h>
37 #include <tny-folder.h>
38 #include <modest-marshal.h>
39 #include <string.h> /* strcmp */
40
41 /* 'private'/'protected' functions */
42 static void modest_transport_account_decorator_class_init (ModestTransportAccountDecoratorClass *klass);
43 static void modest_transport_account_decorator_finalize   (GObject *obj);
44 static void modest_transport_account_decorator_instance_init (GTypeInstance *instance, gpointer g_class);
45 static void modest_transport_account_decorator_send (TnyTransportAccount *self, TnyMsg *msg, GError **err);
46
47 /* list my signals  */
48 /* enum { */
49 /*      /\* MY_SIGNAL_1, *\/ */
50 /*      /\* MY_SIGNAL_2, *\/ */
51 /*      LAST_SIGNAL */
52 /* }; */
53
54 /* typedef struct _ModestTransportAccountDecoratorPrivate ModestTransportAccountDecoratorPrivate; */
55 /* struct _ModestTransportAccountDecoratorPrivate { */
56 /* }; */
57
58 /* #define MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \ */
59 /*                                                    MODEST_TYPE_TRANSPORT_ACCOUNT_DECORATOR, \ */
60 /*                                                    ModestTransportAccountDecoratorPrivate)) */
61
62 /* globals */
63 static TnyCamelTransportAccountClass *parent_class = NULL;
64
65 /* uncomment the following if you have defined any signals */
66 /* static guint signals[LAST_SIGNAL] = {0}; */
67
68 /*
69  * this thread actually tries to send all the mails in the outbox and keeps
70  * track of their state.
71  */
72 static void
73 modest_transport_account_decorator_send (TnyTransportAccount *self, TnyMsg *msg, GError **err)
74 {
75         TnyTransportAccount *connection_specific_account = NULL;
76 /*      ModestTransportAccountDecoratorPrivate *priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (self); */
77         ModestTnyAccountStore *store = modest_runtime_get_account_store ();
78         const gchar *account_name;
79
80         account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (self));
81         if (account_name) {
82                 connection_specific_account = TNY_TRANSPORT_ACCOUNT 
83                         (modest_tny_account_store_get_smtp_specific_transport_account_for_open_connection (store, account_name));
84         }
85         
86         if (connection_specific_account) {
87                 tny_transport_account_send (connection_specific_account, msg, err);
88         } else {
89                 TNY_CAMEL_TRANSPORT_ACCOUNT_CLASS(parent_class)->send_func (self, msg, err);
90         }
91 }
92
93 static void
94 modest_transport_account_decorator_class_init (ModestTransportAccountDecoratorClass *klass)
95 {
96         GObjectClass *gobject_class;
97         TnyCamelTransportAccountClass *transport_class;
98
99         gobject_class = (GObjectClass*) klass;
100         transport_class = (TnyCamelTransportAccountClass *) klass;
101         
102         parent_class            = g_type_class_peek_parent (klass);
103         gobject_class->finalize = modest_transport_account_decorator_finalize;
104
105         transport_class->send_func = modest_transport_account_decorator_send;
106
107 /*      g_type_class_add_private (gobject_class, sizeof(ModestTransportAccountDecoratorPrivate)); */
108 }
109
110 static void
111 modest_transport_account_decorator_instance_init (GTypeInstance *instance, gpointer g_class)
112 {
113 /*      ModestTransportAccountDecoratorPrivate *priv; */
114
115 /*      priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (instance); */
116 }
117
118 static void
119 modest_transport_account_decorator_finalize (GObject *obj)
120 {
121 /*      ModestTransportAccountDecoratorPrivate *priv; */
122                 
123 /*      priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (obj); */
124
125         G_OBJECT_CLASS(parent_class)->finalize (obj);
126 }
127
128 ModestTransportAccountDecorator*
129 modest_transport_account_decorator_new (void)
130 {
131         ModestTransportAccountDecorator *self;
132 /*      ModestTransportAccountDecoratorPrivate *priv; */
133         
134         self = MODEST_TRANSPORT_ACCOUNT_DECORATOR(g_object_new(MODEST_TYPE_TRANSPORT_ACCOUNT_DECORATOR, NULL));
135 /*      priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (self); */
136
137         return self;
138 }
139
140 GType
141 modest_transport_account_decorator_get_type (void)
142 {
143         static GType my_type = 0;
144
145         if (my_type == 0) {
146                 static const GTypeInfo my_info = {
147                         sizeof(ModestTransportAccountDecoratorClass),
148                         NULL,           /* base init */
149                         NULL,           /* base finalize */
150                         (GClassInitFunc) modest_transport_account_decorator_class_init,
151                         NULL,           /* class finalize */
152                         NULL,           /* class data */
153                         sizeof(ModestTransportAccountDecorator),
154                         0,              /* n_preallocs */
155                         (GInstanceInitFunc) modest_transport_account_decorator_instance_init,
156                         NULL
157                 };
158                 
159                 my_type = g_type_register_static (TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT,
160                                                   "ModestTransportAccountDecorator",
161                                                   &my_info, 0);
162         }
163         return my_type;
164 }
165