* Fixed a lot of reference leaks
[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                 g_object_unref (connection_specific_account);
89         } else {
90                 TNY_CAMEL_TRANSPORT_ACCOUNT_CLASS(parent_class)->send (self, msg, err);
91         }
92 }
93
94 static void
95 modest_transport_account_decorator_class_init (ModestTransportAccountDecoratorClass *klass)
96 {
97         GObjectClass *gobject_class;
98         TnyCamelTransportAccountClass *transport_class;
99
100         gobject_class = (GObjectClass*) klass;
101         transport_class = (TnyCamelTransportAccountClass *) klass;
102         
103         parent_class            = g_type_class_peek_parent (klass);
104         gobject_class->finalize = modest_transport_account_decorator_finalize;
105
106         transport_class->send = modest_transport_account_decorator_send;
107
108 /*      g_type_class_add_private (gobject_class, sizeof(ModestTransportAccountDecoratorPrivate)); */
109 }
110
111 static void
112 modest_transport_account_decorator_instance_init (GTypeInstance *instance, gpointer g_class)
113 {
114 /*      ModestTransportAccountDecoratorPrivate *priv; */
115
116 /*      priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (instance); */
117 }
118
119 static void
120 modest_transport_account_decorator_finalize (GObject *obj)
121 {
122 /*      ModestTransportAccountDecoratorPrivate *priv; */
123                 
124 /*      priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (obj); */
125
126         G_OBJECT_CLASS(parent_class)->finalize (obj);
127 }
128
129 ModestTransportAccountDecorator*
130 modest_transport_account_decorator_new (void)
131 {
132         ModestTransportAccountDecorator *self;
133 /*      ModestTransportAccountDecoratorPrivate *priv; */
134         
135         self = MODEST_TRANSPORT_ACCOUNT_DECORATOR(g_object_new(MODEST_TYPE_TRANSPORT_ACCOUNT_DECORATOR, NULL));
136 /*      priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (self); */
137
138         return self;
139 }
140
141 GType
142 modest_transport_account_decorator_get_type (void)
143 {
144         static GType my_type = 0;
145
146         if (my_type == 0) {
147                 static const GTypeInfo my_info = {
148                         sizeof(ModestTransportAccountDecoratorClass),
149                         NULL,           /* base init */
150                         NULL,           /* base finalize */
151                         (GClassInitFunc) modest_transport_account_decorator_class_init,
152                         NULL,           /* class finalize */
153                         NULL,           /* class data */
154                         sizeof(ModestTransportAccountDecorator),
155                         0,              /* n_preallocs */
156                         (GInstanceInitFunc) modest_transport_account_decorator_instance_init,
157                         NULL
158                 };
159                 
160                 my_type = g_type_register_static (TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT,
161                                                   "ModestTransportAccountDecorator",
162                                                   &my_info, 0);
163         }
164         return my_type;
165 }
166