g_utf8_pointer_to_offset returns offsets in char units and not in byte units.
[modest] / src / modest-protocol-registry.h
1 /* Copyright (c) 2007, 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 /* modest-account-settings.h */
32
33 #ifndef __MODEST_PROTOCOL_REGISTRY_H__
34 #define __MODEST_PROTOCOL_REGISTRY_H__
35
36 #include <glib-object.h>
37 #include "modest-protocol.h"
38 #include "modest-pair.h"
39
40 G_BEGIN_DECLS
41
42 #define MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS "connection"
43 #define MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS "auth"
44 #define MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS "transport-store"
45 #define MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS "store"
46 #define MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS "transport"
47 #define MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS "local-store"
48 #define MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS "remote-store"
49 #define MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS "secure"
50 #define MODEST_PROTOCOL_REGISTRY_HAS_LEAVE_ON_SERVER_PROTOCOLS "leave-on-server-available"
51 #define MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS "providers"
52 #define MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS "singleton-providers"
53 #define MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS "multi-mailbox-providers"
54 #define MODEST_PROTOCOL_REGISTRY_USE_ALTERNATE_PORT "use-alternate-port"
55 #define MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS "store-has-folders"
56 /* Accounts that cannot be the destination of messages or folders transfers */
57 #define MODEST_PROTOCOL_REGISTRY_STORE_FORBID_INCOMING_XFERS "store-forbid-incoming-xfers"
58 /* Accounts that do not allow to move messages or folders from */
59 #define MODEST_PROTOCOL_REGISTRY_STORE_FORBID_OUTGOING_XFERS "store-forbid-outgoing-xfers"
60 #define MODEST_PROTOCOL_REGISTRY_NO_AUTO_UPDATE_PROTOCOLS "no-auto-update"
61 #define MODEST_PROTOCOL_REGISTRY_STORE_LIMIT_HEADER_WINDOW "store-limit-header-window"
62
63 /* convenience macros */
64 #define MODEST_TYPE_PROTOCOL_REGISTRY             (modest_protocol_registry_get_type())
65 #define MODEST_PROTOCOL_REGISTRY(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_PROTOCOL_REGISTRY,ModestProtocolRegistry))
66 #define MODEST_PROTOCOL_REGISTRY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_PROTOCOL_REGISTRY,ModestProtocolRegistryClass))
67 #define MODEST_IS_PROTOCOL_REGISTRY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_PROTOCOL_REGISTRY))
68 #define MODEST_IS_PROTOCOL_REGISTRY_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_PROTOCOL_REGISTRY))
69 #define MODEST_PROTOCOL_REGISTRY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_PROTOCOL_REGISTRY,ModestProtocolRegistryClass))
70
71 /* a special type, equivalent to a NULL protocol */
72 #define MODEST_PROTOCOL_REGISTRY_TYPE_INVALID -1
73
74 /* The minimum priority custom protocols should take for their index */
75 #define MODEST_PROTOCOL_REGISTRY_USER_PRIORITY 100
76
77 /* macros to access the default configured protocols */
78 #define MODEST_PROTOCOLS_TRANSPORT_SMTP (modest_protocol_registry_get_smtp_type_id())
79 #define MODEST_PROTOCOLS_TRANSPORT_SENDMAIL (modest_protocol_registry_get_sendmail_type_id())
80 #define MODEST_PROTOCOLS_STORE_POP (modest_protocol_registry_get_pop_type_id())
81 #define MODEST_PROTOCOLS_STORE_IMAP (modest_protocol_registry_get_imap_type_id())
82 #define MODEST_PROTOCOLS_STORE_MAILDIR (modest_protocol_registry_get_maildir_type_id())
83 #define MODEST_PROTOCOLS_STORE_MBOX (modest_protocol_registry_get_mbox_type_id())
84 #define MODEST_PROTOCOLS_CONNECTION_NONE (modest_protocol_registry_get_none_connection_type_id ())
85 #define MODEST_PROTOCOLS_CONNECTION_TLS (modest_protocol_registry_get_tls_connection_type_id ())
86 #define MODEST_PROTOCOLS_CONNECTION_SSL (modest_protocol_registry_get_ssl_connection_type_id ())
87 #define MODEST_PROTOCOLS_CONNECTION_TLSOP (modest_protocol_registry_get_tlsop_connection_type_id ())
88 #define MODEST_PROTOCOLS_AUTH_NONE (modest_protocol_registry_get_none_auth_type_id ())
89 #define MODEST_PROTOCOLS_AUTH_PASSWORD (modest_protocol_registry_get_password_auth_type_id ())
90 #define MODEST_PROTOCOLS_AUTH_CRAMMD5 (modest_protocol_registry_get_crammd5_auth_type_id ())
91
92 /* properties available */
93 #define MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION "modest-security-account-option"
94 #define MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION "modest-auth-account-option"
95
96 /* translations */
97 #define MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX "translation-delete-mailbox" /* title string */
98 #define MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR "translation-connect-error" /* server name */
99 #define MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR "translation-auth-error" /* server name */
100 #define MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR "translation-account-connection-error" /* hostname */
101 #define MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE "translation-msg-not-available" /* subject */
102 #define MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE_LOST_HEADER "translation-msg-not-available-lost-header" /* subject */
103 #define MODEST_PROTOCOL_TRANSLATION_SSL_PROTO_NAME "translation-ssl-proto-name"
104
105
106 typedef struct _ModestProtocolRegistry      ModestProtocolRegistry;
107 typedef struct _ModestProtocolRegistryClass ModestProtocolRegistryClass;
108
109 typedef guint ModestProtocolRegistryType;
110
111 struct _ModestProtocolRegistry {
112         GObject parent;
113 };
114
115 struct _ModestProtocolRegistryClass {
116         GObjectClass parent_class;
117 };
118
119 /**
120  * modest_protocol_registry_get_type:
121  *
122  * Returns: GType of the account store
123  */
124 GType  modest_protocol_registry_get_type   (void) G_GNUC_CONST;
125
126 /**
127  * modest_protocol_registry_new:
128  *
129  * creates a new instance of #ModestProtocolRegistry
130  *
131  * Returns: a #ModestProtocolRegistry
132  */
133 ModestProtocolRegistry*    modest_protocol_registry_new (void);
134
135 /**
136  * modest_protocol_registry_add:
137  * @self: a #ModestProtocolRegistry
138  * @protocol: a #ModestProtocol
139  * @priority: priority establishes the order the protocols will be shown on listings
140  * @first_tag: a string
141  * @...: a %NULL terminated list of strings with the tags for the protocol
142  *
143  * Add @protocol to the registry @self, setting the proper identifying tags
144  */
145 void modest_protocol_registry_add (ModestProtocolRegistry *self, ModestProtocol *protocol, gint priority, const gchar *first_tag, ...);
146
147 /**
148  * modest_protocol_registry_get_all:
149  * @self: a #ModestProtocolRegistry
150  *
151  * obtains a list of all protocols registered in @self
152  *
153  * Returns: a newly allocated GSList of the protocols. Don't unref the protocols, only the list.
154  */
155 GSList *modest_protocol_registry_get_all (ModestProtocolRegistry *self);
156
157 /**
158  * modest_protocol_registry_get_by_tag:
159  * @self: a #ModestProtocolRegistry
160  * @tag: a string
161  *
162  * obtains a list of all protocols registered in @self tagged with @tag
163  *
164  * Returns: a newly allocated GSList of the protocols. Don't unref the protocol, only the list.
165  */
166 GSList *modest_protocol_registry_get_by_tag (ModestProtocolRegistry *self, const gchar *tag);
167
168 /**
169  * modest_protocol_registry_get_pair_list_by_tag:
170  * @self: a #ModestProtocolRegistry
171  * @tag: a string
172  *
173  * obtains a pair list of all protocols registered in @self tagged with @tag
174  *
175  * Returns: a newly allocated #ModestPairList of the protocols. Should be freed using
176  * modest_pair_list_free ()
177  */
178 ModestPairList *modest_protocol_registry_get_pair_list_by_tag (ModestProtocolRegistry *self, const gchar *tag);
179
180 /**
181  * modest_protocol_registry_get_protocol_by_name:
182  * @self: a #ModestProtocolRegistry
183  * @tag: a string
184  * @name: a string
185  *
186  * Obtains the protocol in registry @self, tagged with @tag and with @name
187  *
188  * Returns: the obtained #ModestProtocol, or %NULL if not found.
189  */
190 ModestProtocol *modest_protocol_registry_get_protocol_by_name (ModestProtocolRegistry *self, const gchar *tag, const gchar *name);
191
192 /**
193  * modest_protocol_registry_get_protocol_by_type:
194  * @self: a #ModestProtocolRegistry
195  * @type_id: a #ModestProtocolType
196  *
197  * Obtains the protocol in registry @self, identified by @type_id
198  *
199  * Returns: the obtained #ModestProtocol, or %NULL if not found.
200  */
201 ModestProtocol *modest_protocol_registry_get_protocol_by_type (ModestProtocolRegistry *self, ModestProtocolType type_id);
202
203 /**
204  * modest_protocol_registry_protocol_type_has_tag:
205  * @self: a #ModestProtocolRegistry
206  * @type_id: a #ModestProtocolType
207  * @tag: a string
208  *
209  * Checks if a protocol identified with @type_id has a specific @tag.
210  *
211  * Returns: %TRUE if @type_id protocol has @tag in registry @self
212  */
213 gboolean modest_protocol_registry_protocol_type_has_tag (ModestProtocolRegistry *self, ModestProtocolType type_id, const gchar *tag);
214
215 #define modest_protocol_registry_protocol_type_is_secure(registry,protocol_type) \
216         modest_protocol_registry_protocol_type_has_tag ((registry), (protocol_type), \
217                                                         MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)
218
219 #define modest_protocol_registry_protocol_type_is_provider(registry,protocol_type) \
220         modest_protocol_registry_protocol_type_has_tag ((registry), (protocol_type), \
221                                                         MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS)
222
223 #define modest_protocol_registry_protocol_type_is_singleton_provider(registry,protocol_type) \
224         modest_protocol_registry_protocol_type_has_tag ((registry), (protocol_type), \
225                                                         MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)
226
227 #define modest_protocol_registry_protocol_type_has_leave_on_server(registry,protocol_type) \
228         modest_protocol_registry_protocol_type_has_tag ((registry), (protocol_type), \
229                                                         MODEST_PROTOCOL_REGISTRY_HAS_LEAVE_ON_SERVER_PROTOCOLS)
230
231 /**
232  * @self: a #ModestProtocolRegistry
233  *
234  * Set default available protocols in Modest in @self
235  */
236 void modest_protocol_registry_set_to_default (ModestProtocolRegistry *self);
237
238 ModestProtocolType modest_protocol_registry_get_imap_type_id (void);
239 ModestProtocolType modest_protocol_registry_get_pop_type_id (void);
240 ModestProtocolType modest_protocol_registry_get_maildir_type_id (void);
241 ModestProtocolType modest_protocol_registry_get_mbox_type_id (void);
242 ModestProtocolType modest_protocol_registry_get_smtp_type_id (void);
243 ModestProtocolType modest_protocol_registry_get_sendmail_type_id (void);
244 ModestProtocolType modest_protocol_registry_get_none_connection_type_id (void);
245 ModestProtocolType modest_protocol_registry_get_tls_connection_type_id (void);
246 ModestProtocolType modest_protocol_registry_get_ssl_connection_type_id (void);
247 ModestProtocolType modest_protocol_registry_get_tlsop_connection_type_id (void);
248 ModestProtocolType modest_protocol_registry_get_none_auth_type_id (void);
249 ModestProtocolType modest_protocol_registry_get_password_auth_type_id (void);
250 ModestProtocolType modest_protocol_registry_get_crammd5_auth_type_id (void);
251
252 G_END_DECLS
253
254 #endif /* __MODEST_PROTOCOL_REGISTRY_H__ */