e99d31a33489ba4c8d7f6213a26976732a5ba6a4
[platform/upstream/evolution-data-server.git] / camel / camel-session.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-session.h : Abstract class for an email session */
3
4 /*
5  *
6  * Author :
7  *  Bertrand Guiheneuf <bertrand@helixcode.com>
8  *
9  * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of version 2 of the GNU General Public
13  * License as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  */
25
26
27 #ifndef CAMEL_SESSION_H
28 #define CAMEL_SESSION_H 1
29
30
31 #ifdef __cplusplus
32 extern "C" {
33 #pragma }
34 #endif /* __cplusplus }*/
35
36 #include <camel/camel-object.h>
37 #include <camel/camel-provider.h>
38 #include <camel/camel-junk-plugin.h>
39
40 #include <e-util/e-msgport.h>
41
42 #define CAMEL_SESSION_TYPE     (camel_session_get_type ())
43 #define CAMEL_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SESSION_TYPE, CamelSession))
44 #define CAMEL_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SESSION_TYPE, CamelSessionClass))
45 #define CAMEL_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SESSION_TYPE))
46
47
48 typedef gboolean (*CamelTimeoutCallback) (gpointer data);
49 typedef enum {
50         CAMEL_SESSION_ALERT_INFO,
51         CAMEL_SESSION_ALERT_WARNING,
52         CAMEL_SESSION_ALERT_ERROR
53 } CamelSessionAlertType;
54
55 struct _CamelSession
56 {
57         CamelObject parent_object;
58         struct _CamelSessionPrivate *priv;
59
60         char *storage_path;
61         GHashTable *providers, *modules;
62         gboolean online;
63
64         CamelJunkPlugin *junk_plugin;
65         gboolean check_junk;
66 };
67
68 #ifdef ENABLE_THREADS
69 typedef struct _CamelSessionThreadOps CamelSessionThreadOps;
70 typedef struct _CamelSessionThreadMsg CamelSessionThreadMsg;
71 #endif
72
73 typedef struct {
74         CamelObjectClass parent_class;
75
76         void            (*register_provider) (CamelSession *session,
77                                               CamelProvider *provider);
78         GList *         (*list_providers)    (CamelSession *session,
79                                               gboolean load);
80         CamelProvider * (*get_provider)      (CamelSession *session,
81                                               const char *url_string,
82                                               CamelException *ex);
83
84         CamelService *  (*get_service)       (CamelSession *session,
85                                               const char *url_string,
86                                               CamelProviderType type,
87                                               CamelException *ex);
88         char *          (*get_storage_path)  (CamelSession *session,
89                                               CamelService *service,
90                                               CamelException *ex);
91
92         char *          (*get_password)      (CamelSession *session,
93                                               const char *prompt,
94                                               gboolean reprompt,
95                                               gboolean secret,
96                                               CamelService *service,
97                                               const char *item,
98                                               CamelException *ex);
99         void            (*forget_password)   (CamelSession *session,
100                                               CamelService *service,
101                                               const char *item,
102                                               CamelException *ex);
103         gboolean        (*alert_user)        (CamelSession *session,
104                                               CamelSessionAlertType type,
105                                               const char *prompt,
106                                               gboolean cancel);
107
108         CamelFilterDriver * (*get_filter_driver) (CamelSession *session,
109                                                   const char *type,
110                                                   CamelException *ex);
111 #ifdef ENABLE_THREADS
112         /* mechanism for creating and maintaining multiple threads of control */
113         void *(*thread_msg_new)(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
114         void (*thread_msg_free)(CamelSession *session, CamelSessionThreadMsg *msg);
115         int (*thread_queue)(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
116         void (*thread_wait)(CamelSession *session, int id);
117         void (*thread_status)(CamelSession *session, CamelSessionThreadMsg *msg, const char *text, int pc);
118 #endif
119         
120 } CamelSessionClass;
121
122
123 /* public methods */
124
125 /* Standard Camel function */
126 CamelType camel_session_get_type (void);
127
128
129 void            camel_session_construct             (CamelSession *session,
130                                                      const char *storage_path);
131
132 void            camel_session_register_provider     (CamelSession *session,
133                                                      CamelProvider *provider);
134 GList *         camel_session_list_providers        (CamelSession *session,
135                                                      gboolean load);
136
137 CamelProvider * camel_session_get_provider          (CamelSession *session,
138                                                      const char *url_string,
139                                                      CamelException *ex);
140
141 CamelService *  camel_session_get_service           (CamelSession *session,
142                                                      const char *url_string,
143                                                      CamelProviderType type,
144                                                      CamelException *ex);
145 CamelService *  camel_session_get_service_connected (CamelSession *session, 
146                                                      const char *url_string,
147                                                      CamelProviderType type, 
148                                                      CamelException *ex);
149
150 #define camel_session_get_store(session, url_string, ex) \
151         ((CamelStore *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_STORE, ex))
152 #define camel_session_get_transport(session, url_string, ex) \
153         ((CamelTransport *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_TRANSPORT, ex))
154
155 char *             camel_session_get_storage_path   (CamelSession *session,
156                                                      CamelService *service,
157                                                      CamelException *ex);
158
159 char *             camel_session_get_password       (CamelSession *session,
160                                                      const char *prompt,
161                                                      gboolean reprompt,
162                                                      gboolean secret,
163                                                      CamelService *service,
164                                                      const char *item,
165                                                      CamelException *ex);
166 void               camel_session_forget_password    (CamelSession *session,
167                                                      CamelService *service,
168                                                      const char *item,
169                                                      CamelException *ex);
170 gboolean           camel_session_alert_user         (CamelSession *session,
171                                                      CamelSessionAlertType type,
172                                                      const char *prompt,
173                                                      gboolean cancel);
174
175 gboolean           camel_session_is_online          (CamelSession *session);
176 void               camel_session_set_online         (CamelSession *session,
177                                                      gboolean online);
178
179 CamelFilterDriver *camel_session_get_filter_driver  (CamelSession *session,
180                                                      const char *type,
181                                                      CamelException *ex);
182
183 gboolean           camel_session_check_junk         (CamelSession *session);
184 void               camel_session_set_check_junk     (CamelSession *session, gboolean check_junk);
185
186 #ifdef ENABLE_THREADS
187 struct _CamelSessionThreadOps {
188         void (*receive)(CamelSession *session, struct _CamelSessionThreadMsg *m);
189         void (*free)(CamelSession *session, struct _CamelSessionThreadMsg *m);
190 };
191
192 struct _CamelSessionThreadMsg {
193         EMsg msg;
194
195         int id;
196
197         CamelException ex;
198         CamelSessionThreadOps *ops;
199         struct _CamelOperation *op;
200         CamelSession *session;
201
202         void *data; /* free for implementation to define, not used by camel, do not use in client code */
203         /* user fields follow */
204 };
205
206 void *camel_session_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
207 void camel_session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg);
208 int camel_session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
209 void camel_session_thread_wait(CamelSession *session, int id);
210
211 #endif
212
213 #ifdef __cplusplus
214 }
215 #endif /* __cplusplus */
216
217 #endif /* CAMEL_SESSION_H */