1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-service.h : Abstract class for an email service
3  *
4  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5  *
6  * This library is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
19  *          Michael Zucchi <notzed@ximian.com>
20  */
21 
22 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
23 #error "Only <camel/camel.h> can be included directly."
24 #endif
25 
26 #ifndef CAMEL_SERVICE_H
27 #define CAMEL_SERVICE_H
28 
29 #include <camel/camel-enums.h>
30 #include <camel/camel-object.h>
31 #include <camel/camel-url.h>
32 #include <camel/camel-provider.h>
33 #include <camel/camel-operation.h>
34 #include <camel/camel-settings.h>
35 
36 /* Standard GObject macros */
37 #define CAMEL_TYPE_SERVICE \
38 	(camel_service_get_type ())
39 #define CAMEL_SERVICE(obj) \
40 	(G_TYPE_CHECK_INSTANCE_CAST \
41 	((obj), CAMEL_TYPE_SERVICE, CamelService))
42 #define CAMEL_SERVICE_CLASS(cls) \
43 	(G_TYPE_CHECK_CLASS_CAST \
44 	((cls), CAMEL_TYPE_SERVICE, CamelServiceClass))
45 #define CAMEL_IS_SERVICE(obj) \
46 	(G_TYPE_CHECK_INSTANCE_TYPE \
47 	((obj), CAMEL_TYPE_SERVICE))
48 #define CAMEL_IS_SERVICE_CLASS(obj) \
49 	(G_TYPE_CHECK_CLASS_TYPE \
50 	((cls), CAMEL_TYPE_SERVICE))
51 #define CAMEL_SERVICE_GET_CLASS(obj) \
52 	(G_TYPE_INSTANCE_GET_CLASS \
53 	((obj), CAMEL_TYPE_SERVICE, CamelServiceClass))
54 #define CAMEL_TYPE_SERVICE_AUTH_TYPE \
55 	(camel_service_auth_type_get_type ())
56 
57 /**
58  * CAMEL_SERVICE_ERROR:
59  *
60  * Since: 2.32
61  **/
62 #define CAMEL_SERVICE_ERROR \
63 	(camel_service_error_quark ())
64 
65 G_BEGIN_DECLS
66 
67 struct _CamelSession;
68 
69 typedef struct _CamelService CamelService;
70 typedef struct _CamelServiceClass CamelServiceClass;
71 typedef struct _CamelServicePrivate CamelServicePrivate;
72 
73 /**
74  * CamelServiceError:
75  * @CAMEL_SERVICE_ERROR_INVALID: a generic service error code
76  * @CAMEL_SERVICE_ERROR_URL_INVALID: the URL for the service is invalid
77  * @CAMEL_SERVICE_ERROR_UNAVAILABLE: the service is unavailable
78  * @CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE: failed to authenitcate
79  * @CAMEL_SERVICE_ERROR_NOT_CONNECTED: the service is not connected
80  *
81  * Since: 2.32
82  **/
83 typedef enum {
84 	CAMEL_SERVICE_ERROR_INVALID,
85 	CAMEL_SERVICE_ERROR_URL_INVALID,
86 	CAMEL_SERVICE_ERROR_UNAVAILABLE,
87 	CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
88 	CAMEL_SERVICE_ERROR_NOT_CONNECTED
89 } CamelServiceError;
90 
91 struct _CamelService {
92 	CamelObject parent;
93 	CamelServicePrivate *priv;
94 };
95 
96 struct _CamelServiceClass {
97 	CamelObjectClass parent_class;
98 
99 	GType settings_type;
100 
101 	/* Non-Blocking Methods */
102 	gchar *		(*get_name)		(CamelService *service,
103 						 gboolean brief);
104 
105 	/* Synchronous I/O Methods */
106 	gboolean	(*connect_sync)		(CamelService *service,
107 						 GCancellable *cancellable,
108 						 GError **error);
109 	gboolean	(*disconnect_sync)	(CamelService *service,
110 						 gboolean clean,
111 						 GCancellable *cancellable,
112 						 GError **error);
113 	CamelAuthenticationResult
114 			(*authenticate_sync)	(CamelService *service,
115 						 const gchar *mechanism,
116 						 GCancellable *cancellable,
117 						 GError **error);
118 	GList *		(*query_auth_types_sync)
119 						(CamelService *service,
120 						 GCancellable *cancellable,
121 						 GError **error);
122 
123 	/* Padding for future expansion */
124 	gpointer reserved[20];
125 };
126 
127 /* query_auth_types returns a GList of these */
128 typedef struct {
129 	const gchar *name;               /* user-friendly name */
130 	const gchar *description;
131 	const gchar *authproto;
132 
133 	gboolean need_password;   /* needs a password to authenticate */
134 } CamelServiceAuthType;
135 
136 GType		camel_service_get_type		(void);
137 GQuark		camel_service_error_quark	(void) G_GNUC_CONST;
138 void		camel_service_migrate_files	(CamelService *service);
139 CamelURL *	camel_service_new_camel_url	(CamelService *service);
140 CamelServiceConnectionStatus
141 		camel_service_get_connection_status
142 						(CamelService *service);
143 const gchar *	camel_service_get_display_name	(CamelService *service);
144 gchar *		camel_service_dup_display_name	(CamelService *service);
145 void		camel_service_set_display_name	(CamelService *service,
146 						 const gchar *display_name);
147 const gchar *	camel_service_get_password	(CamelService *service);
148 gchar *		camel_service_dup_password	(CamelService *service);
149 void		camel_service_set_password	(CamelService *service,
150 						 const gchar *password);
151 const gchar *	camel_service_get_user_data_dir	(CamelService *service);
152 const gchar *	camel_service_get_user_cache_dir
153 						(CamelService *service);
154 gchar *		camel_service_get_name		(CamelService *service,
155 						 gboolean brief);
156 CamelProvider *	camel_service_get_provider	(CamelService *service);
157 GProxyResolver *
158 		camel_service_ref_proxy_resolver
159 						(CamelService *service);
160 void		camel_service_set_proxy_resolver
161 						(CamelService *service,
162 						 GProxyResolver *proxy_resolver);
163 struct _CamelSession *
164 		camel_service_ref_session	(CamelService *service);
165 CamelSettings *	camel_service_ref_settings	(CamelService *service);
166 void		camel_service_set_settings	(CamelService *service,
167 						 CamelSettings *settings);
168 const gchar *	camel_service_get_uid		(CamelService *service);
169 void		camel_service_queue_task	(CamelService *service,
170 						 GTask *task,
171 						 GTaskThreadFunc task_func);
172 gboolean	camel_service_connect_sync	(CamelService *service,
173 						 GCancellable *cancellable,
174 						 GError **error);
175 void		camel_service_connect		(CamelService *service,
176 						 gint io_priority,
177 						 GCancellable *cancellable,
178 						 GAsyncReadyCallback callback,
179 						 gpointer user_data);
180 gboolean	camel_service_connect_finish	(CamelService *service,
181 						 GAsyncResult *result,
182 						 GError **error);
183 gboolean	camel_service_disconnect_sync	(CamelService *service,
184 						 gboolean clean,
185 						 GCancellable *cancellable,
186 						 GError **error);
187 void		camel_service_disconnect	(CamelService *service,
188 						 gboolean clean,
189 						 gint io_priority,
190 						 GCancellable *cancellable,
191 						 GAsyncReadyCallback callback,
192 						 gpointer user_data);
193 gboolean	camel_service_disconnect_finish	(CamelService *service,
194 						 GAsyncResult *result,
195 						 GError **error);
196 CamelAuthenticationResult
197 		camel_service_authenticate_sync	(CamelService *service,
198 						 const gchar *mechanism,
199 						 GCancellable *cancellable,
200 						 GError **error);
201 void		camel_service_authenticate	(CamelService *service,
202 						 const gchar *mechanism,
203 						 gint io_priority,
204 						 GCancellable *cancellable,
205 						 GAsyncReadyCallback callback,
206 						 gpointer user_data);
207 CamelAuthenticationResult
208 		camel_service_authenticate_finish
209 						(CamelService *service,
210 						 GAsyncResult *result,
211 						 GError **error);
212 GList *		camel_service_query_auth_types_sync
213 						(CamelService *service,
214 						 GCancellable *cancellable,
215 						 GError **error);
216 void		camel_service_query_auth_types	(CamelService *service,
217 						 gint io_priority,
218 						 GCancellable *cancellable,
219 						 GAsyncReadyCallback callback,
220 						 gpointer user_data);
221 GList *		camel_service_query_auth_types_finish
222 						(CamelService *service,
223 						 GAsyncResult *result,
224 						 GError **error);
225 
226 GType		camel_service_auth_type_get_type(void);
227 CamelServiceAuthType *
228 		camel_service_auth_type_copy	(const CamelServiceAuthType *service_auth_type);
229 void		camel_service_auth_type_free	(CamelServiceAuthType *service_auth_type);
230 
231 G_END_DECLS
232 
233 #endif /* CAMEL_SERVICE_H */
234