New virtual method modest_account_protocol_decode_part_to_stream, to
[modest] / src / modest-account-protocol.h
1 /* Copyright (c) 2008, 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_ACCOUNT_PROTOCOL_H__
34 #define __MODEST_ACCOUNT_PROTOCOL_H__
35
36 #include "widgets/modest-account-settings-dialog.h"
37 #include "modest-protocol.h"
38 #include "widgets/modest-wizard-dialog.h"
39 #include "modest-pair.h"
40 #include <tny-account.h>
41 #include <tny-list.h>
42
43 G_BEGIN_DECLS
44
45 /* convenience macros */
46 #define MODEST_TYPE_ACCOUNT_PROTOCOL             (modest_account_protocol_get_type())
47 #define MODEST_ACCOUNT_PROTOCOL(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_ACCOUNT_PROTOCOL,ModestAccountProtocol))
48 #define MODEST_ACCOUNT_PROTOCOL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_ACCOUNT_PROTOCOL,ModestAccountProtocolClass))
49 #define MODEST_IS_ACCOUNT_PROTOCOL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_ACCOUNT_PROTOCOL))
50 #define MODEST_IS_ACCOUNT_PROTOCOL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_ACCOUNT_PROTOCOL))
51 #define MODEST_ACCOUNT_PROTOCOL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_ACCOUNT_PROTOCOL,ModestAccountProtocolClass))
52
53 typedef struct _ModestAccountProtocol      ModestAccountProtocol;
54 typedef struct _ModestAccountProtocolClass ModestAccountProtocolClass;
55
56 typedef enum {
57         MODEST_ACCOUNT_PROTOCOL_ICON_MAILBOX = 0,
58         MODEST_ACCOUNT_PROTOCOL_ICON_PROTOCOL,
59         MODEST_ACCOUNT_PROTOCOL_ICON_ACCOUNT,
60         MODEST_ACCOUNT_PROTOCOL_ICON_FOLDER,
61 } ModestAccountProtocolIconType;
62
63 typedef void (*ModestAccountProtocolCheckSupportFunc) (ModestAccountProtocol *self, 
64                                                        gboolean supported, gpointer userdata);
65 typedef void (*ModestAccountProtocolSaveRemoteDraftCallback) (ModestAccountProtocol *self,
66                                                               GError *error,
67                                                               const gchar *account_id,
68                                                               TnyMsg *new_remote_msg,
69                                                               TnyMsg *new_msg,
70                                                               TnyMsg *old_msg,
71                                                               gpointer userdata);
72
73
74 struct _ModestAccountProtocol {
75         ModestProtocol parent;
76 };
77
78 struct _ModestAccountProtocolClass {
79         ModestProtocolClass parent_class;
80
81         /* Virtual methods */
82         TnyAccount * (*create_account) (ModestAccountProtocol *self);
83         ModestAccountSettingsDialog* (*create_account_settings_dialog) (ModestAccountProtocol* self);
84         ModestPairList* (*get_easysetupwizard_tabs) (ModestAccountProtocol* self);
85         ModestWizardDialogResponseOverrideFunc (*get_wizard_response_override) (ModestAccountProtocol *self);
86         void (*save_settings) (ModestAccountProtocol *self, ModestAccountSettingsDialog *dialog, ModestAccountSettings *settings);
87         void (*save_wizard_settings) (ModestAccountProtocol *self, GList *wizard_pages, ModestAccountSettings *settings);
88         gboolean (*is_supported) (ModestAccountProtocol *self);
89         void (*check_support) (ModestAccountProtocol *self, ModestAccountProtocolCheckSupportFunc func, gpointer userdata);
90         gchar * (*get_from) (ModestAccountProtocol *self, const gchar *account_id, const gchar *mailbox);
91         ModestPairList * (*get_from_list) (ModestAccountProtocol *self, const gchar *account_id);
92         gchar * (*get_signature) (ModestAccountProtocol *self, const gchar *account_id, const gchar *mailbox, gboolean *has_signature);
93         const GdkPixbuf * (*get_icon) (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
94                                        GObject *object, guint icon_size);
95         gchar * (*get_service_name) (ModestAccountProtocol *self, const gchar *account_id, const gchar *mailbox);
96         const GdkPixbuf * (*get_service_icon) (ModestAccountProtocol *self, const gchar *account_id, const gchar *mailbox, guint icon_size);
97         void (*save_remote_draft) (ModestAccountProtocol *self, 
98                                    const gchar *account_id, TnyMsg *new_msg, TnyMsg *old_msg,
99                                    ModestAccountProtocolSaveRemoteDraftCallback callback,
100                                    gpointer userdata);
101         void (*cancel_check_support) (ModestAccountProtocol *self);
102         void (*wizard_finished) (ModestAccountProtocol *self);
103         gboolean (*decode_part_to_stream) (ModestAccountProtocol *protocol,
104                                            TnyMimePart *part,
105                                            TnyStream *stream,
106                                            GError *error);
107
108         /* Padding for future expansions */
109         void (*_reserved7) (void);
110         void (*_reserved8) (void);
111         void (*_reserved9) (void);
112         void (*_reserved10) (void);
113         void (*_reserved11) (void);
114         void (*_reserved12) (void);
115         void (*_reserved13) (void);
116         void (*_reserved14) (void);
117         void (*_reserved15) (void);
118         void (*_reserved16) (void);
119 };
120
121 /**
122  * modest_account_protocol_get_type:
123  *
124  * Returns: GType of the account protocol type
125  */
126 GType  modest_account_protocol_get_type   (void) G_GNUC_CONST;
127
128 /**
129  * modest_account_protocol_new:
130  *
131  * creates a new instance of #ModestAccountProtocol
132  *
133  * Returns: a #ModestAccountProtocol
134  */
135 ModestProtocol*    modest_account_protocol_new (const gchar *name, const gchar *display_name, 
136                                                 guint port, guint alternate_port,
137                                                 GType account_g_type);
138
139 /**
140  * modest_account_protocol_get_port:
141  * @self: a #ModestAccountProtocol
142  *
143  * get the protocol standard port
144  *
145  * Returns: a string
146  */
147 guint modest_account_protocol_get_port (ModestAccountProtocol *self);
148
149 /**
150  * modest_account_protocol_set_port:
151  * @self: a #ModestAccountProtocol
152  * @port: a #guint
153  *
154  * set @port as the protocol standard port
155  */
156 void         modest_account_protocol_set_port (ModestAccountProtocol *self,
157                                                guint port);
158
159 /**
160  * modest_account_protocol_get_alternate_port:
161  * @self: a #ModestAccountProtocol
162  *
163  * get the protocol standard alternate_port
164  *
165  * Returns: a #guint
166  */
167 guint modest_account_protocol_get_alternate_port (ModestAccountProtocol *self);
168
169 /**
170  * modest_account_protocol_set_alternate_port:
171  * @self: a #ModestAccountProtocol
172  * @alternate_port: a #guint
173  *
174  * set @alternate_port as the protocol alternate port
175  */
176 void         modest_account_protocol_set_alternate_port (ModestAccountProtocol *self,
177                                                          guint alternate_port);
178
179 /**
180  * modest_account_protocol_set_account_options:
181  * @self: a #ModestAccountProtocol
182  * @account_options: a #TnyList of account options and their values
183  *
184  * set the account options that will be passed to TnyCamelAccount for this protocol.
185  * This replaces previous option lists for this protocol
186  */
187 void modest_account_protocol_set_account_options (ModestAccountProtocol *self,
188                                                   TnyList *account_options);
189
190 /**
191  * modest_account_protocol_get_account_options:
192  * @self: a #ModestAccountProtocol
193  *
194  * obtain the account options for this account protocol.
195  *
196  * Returns: a caller-owner copy of the account options list.
197  */
198 TnyList *modest_account_protocol_get_account_options (ModestAccountProtocol *self);
199
200 /**
201  * modest_account_protocol_has_custom_secure_auth_mech:
202  * @self: a #ModestAccountProtocol
203  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
204  *
205  * checks whether there's a custom secure auth mech camel string for @auth_protocol_type.
206  *
207  * Returns: %TRUE if registered, %FALSE otherwise
208  */
209 gboolean
210 modest_account_protocol_has_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type);
211
212 /**
213  * modest_account_protocol_get_custom_secure_auth_mech:
214  * @self: a #ModestAccountProtocol
215  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
216  *
217  * obtains the secure auth mech of @auth_protocol_type in protocol. Be careful as %NULL does not imply
218  * there's no custom auth mech registered (you can register %NULL). To check if it's registered, just
219  * use modest_account_protocol_has_custom_secure_auth_mech().
220  *
221  * Returns: the secure auth mech for this auth protocol type that will be passed to camel.
222  */
223 const gchar *
224 modest_account_protocol_get_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type);
225
226 /**
227  * modest_account_protocol_unset_custom_secure_auth_mech:
228  * @self: a #ModestAccountProtocol
229  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
230  *
231  * Unsets the secure auth meth of @auth_protocol_type in protocol.
232  */
233 void
234 modest_account_protocol_unset_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type);
235
236 /**
237  * modest_account_protocol_set_custom_secure_auth_mech:
238  * @self: a #ModestAccountProtocol
239  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
240  * @secure_auth_mech: a string or %NULL
241  *
242  * sets the secure auth mech of @auth_protocol_type in protocol. Be careful as %NULL does not imply
243  * there's no custom auth mech registered (you can register %NULL). If you set %NULL you're regitering %NULL as the custom secure auth
244  * mechanism instead of unsetting it.
245  */
246 void
247 modest_account_protocol_set_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type, const gchar *secure_auth_mech);
248
249 /**
250  * modest_account_protocol_get_account_g_type:
251  * @self: a #ModestAccountProtocol
252  *
253  * get the protocol type used for factoring new TnyAccount
254  *
255  * Returns: a #GType
256  */
257 GType modest_account_protocol_get_account_g_type (ModestAccountProtocol *self);
258
259 /**
260  * modest_account_protocol_set_account_g_type:
261  * @self: a #ModestAccountProtocol
262  * @account_g_type: a #GType
263  *
264  * set @account_g_type as the type modest_account_protocol_create_account will
265  * instanciate
266  */
267 void         modest_account_protocol_set_account_g_type (ModestAccountProtocol *self,
268                                                          GType account_g_type);
269
270 /**
271  * modest_account_protocol_create_account:
272  * @self: a #ModestAccountProtocol
273  *
274  * create a new account instance for this protocol
275  *
276  * Returns: a #TnyAccount
277  */
278 TnyAccount * modest_account_protocol_create_account (ModestAccountProtocol *self);
279
280 /**
281  * modest_account_protocol_get_account_settings_dialog:
282  * @self: a #ModestAccountProtocol
283  * @account_name: the name of the account we're creating the dialog for
284  * 
285  * retrieves the account settings dialog used to setup the account
286  * represented by this protocol
287  * 
288  * Returns: a #ModestAccountSettingsDialog
289  **/
290 ModestAccountSettingsDialog* modest_account_protocol_get_account_settings_dialog (ModestAccountProtocol *self,
291                                                                                   const gchar *account_name);
292
293 ModestPairList* modest_account_protocol_get_easysetupwizard_tabs (ModestAccountProtocol *self);
294
295 /**
296  * modest_account_protocol_save_settings:
297  * @self: this #ModestAccountProtocol
298  * @dialog: a #ModestAccountSettingsDialog
299  * @settings: the #ModestAccountSettings
300  * 
301  * this function stores the values held by the account settings dialog
302  * in the account settings object that is passed as argument
303  *
304  * NOTE: this function provides a default implementation that calls
305  * the save_settings method of the acocunt settings dialog. So if your
306  * implementation do not do anything more just do not redefine it
307  **/
308 void modest_account_protocol_save_settings (ModestAccountProtocol *self, 
309                                             ModestAccountSettingsDialog *dialog,
310                                             ModestAccountSettings *settings);
311
312 /**
313  * modest_account_protocol_save_wizard_settings:
314  * @self: this #ModestAccountProtocol
315  * @wizard_pages: a list of #ModestEasysetupWizardPage
316  * @settings: the #ModestAccountSettings
317  * 
318  * this function stores the data input by the users in the wizard in
319  * the account settings object passed as argument
320  **/
321 void modest_account_protocol_save_wizard_settings (ModestAccountProtocol *self, 
322                                                    GList *wizard_pages,
323                                                    ModestAccountSettings *settings);
324
325 /**
326  * modest_account_protocol_get_wizard_response_override:
327  * @self: a #ModestAccountProtocol
328  *
329  * obtains the method that should be used to override wizard response behavior when the
330  * wizard is setting up this account type.
331  *
332  * Returns: a #ModestWizardDialogResponseOverrideFunc
333  */
334 ModestWizardDialogResponseOverrideFunc modest_account_protocol_get_wizard_response_override (ModestAccountProtocol *self);
335
336
337 /**
338  * modest_account_protocol_check_support:
339  * @self: a #ModestAccountProtocol
340  * @func: a #ModestAccountProtocolCheckSupportFunc
341  * @userdata: a gpointer
342  *
343  * This method checks asynchronously if the account protocol @self is
344  * supported. Once checked, @func will be called with the result in the
345  * mainloop.
346  *
347  * modest_account_protocol_is_supported() should return the cached response
348  * from this method.
349  */
350 void modest_account_protocol_check_support (ModestAccountProtocol *self, 
351                                             ModestAccountProtocolCheckSupportFunc func, 
352                                             gpointer userdata);
353
354 /**
355  * modest_account_protocol_cancel_check_support:
356  * @self: a #ModestAccountProtocol
357  *
358  * This method requests that the check support requests running should be
359  * immediately cancelled. Once this happens, is_supported should return %FALSE
360  * until a new succesful check_support request is finished.
361  */
362 void modest_account_protocol_cancel_check_support (ModestAccountProtocol *self);
363
364 /**
365  * modest_account_protocol_wizard_finished:
366  * @self: a #ModestAccountProtocol
367  *
368  * Method that let protocol know if the wizard has finished, for the case it's
369  * needed to do some stuff after check_support.
370  */
371 void modest_account_protocol_wizard_finished (ModestAccountProtocol *self);
372
373 /**
374  * modest_account_protocol_is_supported:
375  * @self: a #ModestAccountProtocol
376  *
377  * Determines if the account protocol is supported on this device.
378  *
379  * Returns: %TRUE if the protocol is supported, %FALSE otherwise
380  */
381 gboolean modest_account_protocol_is_supported (ModestAccountProtocol *self);
382
383 /**
384  * modest_account_protocol_get_from:
385  * @self: a #ModestAccountProtocol
386  * @account_id: a transport account name
387  * @mailbox: a mailbox
388  *
389  * Obtain the From: string for the account and mailbox. Should be used only
390  * with transports with multi mailbox support.
391  *
392  * Returns: a newly allocated string
393  */
394 gchar *modest_account_protocol_get_from (ModestAccountProtocol *self,
395                                          const gchar *account_id,
396                                          const gchar *mailbox);
397
398 /**
399  * modest_account_protocol_get_from_list:
400  * @self: a #ModestAccountProtocol
401  * @account_id: a transport account name
402  *
403  * Obtain a list of pairs (mailbox - From: string) for filling the From picker.
404  *
405  * Returns: a ModestPairList
406  */
407 ModestPairList *modest_account_protocol_get_from_list (ModestAccountProtocol *self,
408                                                        const gchar *account_id);
409
410 /**
411  * modest_account_protocol_get_signature:
412  * @self: a #ModestAccountProtocol
413  * @account_id: a transport account name
414  * @mailbox: a mailbox
415  *
416  * Obtain the signature string for the account and mailbox. Should be used only
417  * with transports with multi mailbox support.
418  *
419  * Returns: a newly allocated string
420  */
421 gchar *modest_account_protocol_get_signature (ModestAccountProtocol *self,
422                                               const gchar *account_id,
423                                               const gchar *mailbox,
424                                               gboolean *has_signature);
425
426 /**
427  * modest_account_protocol_get_icon:
428  * @self: a #ModestAccountProtocl
429  * @icon_type: a #ModestAccountProtocolIconType
430  * @object: a #GObject
431  * @icon_size: the icon size to get
432  *
433  * Returns a @self owned #GdkPixbuf with the icon for @icon_type and @object. @object type
434  * should match @icon_type.
435  *
436  * Returns: a #GdkPixbuf (don't free or manipulate this, just copy)
437  */
438 const GdkPixbuf * modest_account_protocol_get_icon (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
439                                                     GObject *object, guint icon_size);
440
441 /**
442  * modest_account_protocol_get_service_name:
443  * @self: a #ModestAccountProtocol
444  * @account_id: a transport account name
445  * @mailbox: a mailbox
446  *
447  * Obtain the service name string for the account and mailbox.
448  *
449  * Returns: a newly allocated string
450  */
451 gchar *modest_account_protocol_get_service_name (ModestAccountProtocol *self,
452                                                  const gchar *account_id,
453                                                  const gchar *mailbox);
454
455 /**
456  * modest_account_protocol_get_service_icon:
457  * @self: a #ModestAccountProtocol
458  * @account_id: a transport account name
459  * @mailbox: a mailbox
460  *
461  * Obtain the service icon for the account and mailbox.
462  *
463  * Returns: a protocol owned #GdkPixbuf
464  */
465 const GdkPixbuf *modest_account_protocol_get_service_icon (ModestAccountProtocol *self,
466                                                            const gchar *account_id,
467                                                            const gchar *mailbox,
468                                                            guint icon_size);
469
470 /**
471  * modest_account_protocol_save_remote_draft:
472  * @self: a #ModestAccountProtocol
473  * @account_id: a transport account_name
474  * @new_msg: the newly created message in local storage.
475  * @old_msg: the old message
476  * @callback: the code that should be executed on finishing the remote message saving
477  * @userdata: a #gpointer
478  *
479  * Saves the just-saved to local draft, into a remote storage.
480  */
481 void modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
482                                                     const gchar *account_id,
483                                                     TnyMsg *new_msg,
484                                                     TnyMsg *old_msg,
485                                                     ModestAccountProtocolSaveRemoteDraftCallback callback,
486                                                     gpointer userdata);
487
488 /**
489  * modest_account_protocol_decode_part_to_stream:
490  * @self: a #ModestAccountProtocol
491  * @part: a #TnyMimePart
492  * @stream: a #TnyStream
493  * @error: a #GError
494  *
495  * This virtual method delegates on the account protocol to decode @part
496  * into @stream. It just allows the provider to decode it as it needs
497  * (i.e. when the original message has a fake attachment, and provider
498  * can return the real attachment).
499  *
500  * Returns: %TRUE if @protocol does the decode operation, %FALSE if modest
501  * should do it.
502  */
503 gboolean
504 modest_account_protocol_decode_part_to_stream (ModestAccountProtocol *protocol,
505                                                TnyMimePart *part,
506                                                TnyStream *stream,
507                                                GError *error);
508
509
510
511 G_END_DECLS
512
513 #endif /* __MODEST_ACCOUNT_PROTOCOL_H__ */