Updated translatable strings
[modest] / src / modest-protocol-info.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 #include <glib/gi18n.h>
31 #include <string.h> /* strcmp */
32 #include <modest-protocol-info.h>
33 #include <modest-pair.h>
34
35
36 typedef struct {
37         ModestProtocol   proto;
38         const gchar*     name;
39         const gchar*     display_name;
40 } ProtocolInfo;
41
42 static const ProtocolInfo ProtocolMap[] = {
43         { MODEST_PROTOCOL_TRANSPORT_SENDMAIL, "sendmail", N_("Sendmail") },
44         { MODEST_PROTOCOL_TRANSPORT_SMTP,     "smtp",     N_("SMTP Server") },
45         
46         { MODEST_PROTOCOL_STORE_POP,          "pop",      N_("POP3") },
47         { MODEST_PROTOCOL_STORE_IMAP,         "imap",     N_("IMAPv4") },
48         { MODEST_PROTOCOL_STORE_MAILDIR,      "maildir",  N_("Maildir") },
49         { MODEST_PROTOCOL_STORE_MBOX,         "mbox",     N_("MBox") },     
50
51         { MODEST_PROTOCOL_SECURITY_NONE,      "none",     N_("None") },   
52         { MODEST_PROTOCOL_SECURITY_SSL,       "ssl",      N_("SSL") },   
53         { MODEST_PROTOCOL_SECURITY_TLS,       "tls",      N_("TLS") },
54         { MODEST_PROTOCOL_SECURITY_TLS_OP,    "tls-op",   N_("TLS when possible") }, /* op stands for optional */
55
56         { MODEST_PROTOCOL_AUTH_NONE,          "none",     N_("None") },
57         { MODEST_PROTOCOL_AUTH_PASSWORD,      "password", N_("Password") }
58 };
59 const guint PROTOCOL_MAP_SIZE = sizeof(ProtocolMap)/sizeof(ProtocolInfo);
60
61
62 GSList*
63 modest_protocol_info_get_protocol_list (ModestProtocolType type)
64 {
65         GSList *proto_list = NULL;
66         int i;
67         
68         g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN &&
69                               type < MODEST_PROTOCOL_TYPE_NUM,
70                               NULL);
71                 
72         for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) {
73                 ProtocolInfo info = (ProtocolInfo)ProtocolMap[i];
74                 if (modest_protocol_info_get_protocol_type(info.proto) == type)
75                         proto_list = g_slist_append (proto_list, GINT_TO_POINTER(info.proto));
76         }
77         return proto_list;
78 }
79
80
81
82 ModestPairList*
83 modest_protocol_info_get_protocol_pair_list (ModestProtocolType type)
84 {
85         ModestPairList *proto_list = NULL;
86         int i;
87         
88         g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN && type < MODEST_PROTOCOL_TYPE_NUM,
89                               NULL);
90
91         for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) {
92                 ProtocolInfo info = (ProtocolInfo)ProtocolMap[i];
93                 if (modest_protocol_info_get_protocol_type(info.proto) == type)
94                         proto_list = g_slist_append (proto_list,
95                                                      (gpointer)modest_pair_new(
96                                                              (gpointer)info.name,
97                                                              (gpointer)info.display_name,
98                                                              FALSE));                   
99         }
100         return proto_list;
101 }
102
103
104 ModestProtocolType
105 modest_protocol_info_get_protocol_type (ModestProtocol proto)
106 {
107         switch (proto) {
108         case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
109         case MODEST_PROTOCOL_TRANSPORT_SMTP:
110                 return MODEST_PROTOCOL_TYPE_TRANSPORT;
111                 
112         case MODEST_PROTOCOL_STORE_POP:
113         case MODEST_PROTOCOL_STORE_IMAP:
114         case MODEST_PROTOCOL_STORE_MAILDIR:
115         case MODEST_PROTOCOL_STORE_MBOX:
116                 return MODEST_PROTOCOL_TYPE_STORE;
117
118         case MODEST_PROTOCOL_SECURITY_NONE:
119         case MODEST_PROTOCOL_SECURITY_SSL:   
120         case MODEST_PROTOCOL_SECURITY_TLS:
121         case MODEST_PROTOCOL_SECURITY_TLS_OP:
122                 return MODEST_PROTOCOL_TYPE_SECURITY;
123
124         case MODEST_PROTOCOL_AUTH_NONE:
125         case MODEST_PROTOCOL_AUTH_PASSWORD:
126                 return MODEST_PROTOCOL_TYPE_AUTH;
127                 
128         default:
129                 return MODEST_PROTOCOL_TYPE_UNKNOWN;
130         }
131 }
132
133
134 ModestProtocol
135 modest_protocol_info_get_protocol (const gchar* name)
136 {
137         int i;
138         g_return_val_if_fail (name, MODEST_PROTOCOL_UNKNOWN);
139
140         for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) {
141                 ProtocolInfo info = (ProtocolInfo)ProtocolMap[i];
142                 if (strcmp(name, info.name) == 0)
143                         return info.proto;
144         }
145         
146         return MODEST_PROTOCOL_UNKNOWN;
147 }
148
149
150
151
152 /* get either the name or the display_name for the protocol */
153 static const gchar*
154 get_protocol_string (ModestProtocol proto, gboolean get_name)
155 {
156         int i;
157         g_return_val_if_fail (modest_protocol_info_get_protocol_type(proto) !=
158                               MODEST_PROTOCOL_TYPE_UNKNOWN, NULL);
159         
160         for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) {
161                 ProtocolInfo info = (ProtocolInfo)ProtocolMap[i];
162                 if (info.proto == proto)
163                         return get_name ? info.name : info.display_name;        
164         }
165         g_return_val_if_reached (NULL);
166 }
167
168 const gchar*
169 modest_protocol_info_get_protocol_name (ModestProtocol proto)
170 {
171         return get_protocol_string (proto, TRUE);
172 }
173
174
175 const gchar*
176 modest_protocol_info_get_protocol_display_name (ModestProtocol proto)
177 {
178         return get_protocol_string (proto, FALSE);
179 }
180
181
182 gboolean
183 modest_protocol_info_protocol_is_local_store (ModestProtocol proto)
184 {
185         g_return_val_if_fail (modest_protocol_info_get_protocol_type (proto) !=
186                               MODEST_PROTOCOL_TYPE_UNKNOWN, FALSE);
187
188         /* may add MH later */
189         return proto == MODEST_PROTOCOL_STORE_MBOX || proto == MODEST_PROTOCOL_STORE_MAILDIR;
190 }
191
192