Properly use the account protocol api to fetch streams from attachments
[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                                            gssize *written,
107                                            GError **error);
108         gboolean (*decode_part_to_stream_async) (ModestAccountProtocol *protocol,
109                                                  TnyMimePart *part, 
110                                                  TnyStream *stream, 
111                                                  TnyMimePartCallback callback, 
112                                                  TnyStatusCallback status_callback, 
113                                                  gpointer user_data);
114
115         /* Padding for future expansions */
116         void (*_reserved8) (void);
117         void (*_reserved9) (void);
118         void (*_reserved10) (void);
119         void (*_reserved11) (void);
120         void (*_reserved12) (void);
121         void (*_reserved13) (void);
122         void (*_reserved14) (void);
123         void (*_reserved15) (void);
124         void (*_reserved16) (void);
125 };
126
127 /**
128  * modest_account_protocol_get_type:
129  *
130  * Returns: GType of the account protocol type
131  */
132 GType  modest_account_protocol_get_type   (void) G_GNUC_CONST;
133
134 /**
135  * modest_account_protocol_new:
136  *
137  * creates a new instance of #ModestAccountProtocol
138  *
139  * Returns: a #ModestAccountProtocol
140  */
141 ModestProtocol*    modest_account_protocol_new (const gchar *name, const gchar *display_name, 
142                                                 guint port, guint alternate_port,
143                                                 GType account_g_type);
144
145 /**
146  * modest_account_protocol_get_port:
147  * @self: a #ModestAccountProtocol
148  *
149  * get the protocol standard port
150  *
151  * Returns: a string
152  */
153 guint modest_account_protocol_get_port (ModestAccountProtocol *self);
154
155 /**
156  * modest_account_protocol_set_port:
157  * @self: a #ModestAccountProtocol
158  * @port: a #guint
159  *
160  * set @port as the protocol standard port
161  */
162 void         modest_account_protocol_set_port (ModestAccountProtocol *self,
163                                                guint port);
164
165 /**
166  * modest_account_protocol_get_alternate_port:
167  * @self: a #ModestAccountProtocol
168  *
169  * get the protocol standard alternate_port
170  *
171  * Returns: a #guint
172  */
173 guint modest_account_protocol_get_alternate_port (ModestAccountProtocol *self);
174
175 /**
176  * modest_account_protocol_set_alternate_port:
177  * @self: a #ModestAccountProtocol
178  * @alternate_port: a #guint
179  *
180  * set @alternate_port as the protocol alternate port
181  */
182 void         modest_account_protocol_set_alternate_port (ModestAccountProtocol *self,
183                                                          guint alternate_port);
184
185 /**
186  * modest_account_protocol_set_account_options:
187  * @self: a #ModestAccountProtocol
188  * @account_options: a #TnyList of account options and their values
189  *
190  * set the account options that will be passed to TnyCamelAccount for this protocol.
191  * This replaces previous option lists for this protocol
192  */
193 void modest_account_protocol_set_account_options (ModestAccountProtocol *self,
194                                                   TnyList *account_options);
195
196 /**
197  * modest_account_protocol_get_account_options:
198  * @self: a #ModestAccountProtocol
199  *
200  * obtain the account options for this account protocol.
201  *
202  * Returns: a caller-owner copy of the account options list.
203  */
204 TnyList *modest_account_protocol_get_account_options (ModestAccountProtocol *self);
205
206 /**
207  * modest_account_protocol_has_custom_secure_auth_mech:
208  * @self: a #ModestAccountProtocol
209  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
210  *
211  * checks whether there's a custom secure auth mech camel string for @auth_protocol_type.
212  *
213  * Returns: %TRUE if registered, %FALSE otherwise
214  */
215 gboolean
216 modest_account_protocol_has_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type);
217
218 /**
219  * modest_account_protocol_get_custom_secure_auth_mech:
220  * @self: a #ModestAccountProtocol
221  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
222  *
223  * obtains the secure auth mech of @auth_protocol_type in protocol. Be careful as %NULL does not imply
224  * there's no custom auth mech registered (you can register %NULL). To check if it's registered, just
225  * use modest_account_protocol_has_custom_secure_auth_mech().
226  *
227  * Returns: the secure auth mech for this auth protocol type that will be passed to camel.
228  */
229 const gchar *
230 modest_account_protocol_get_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type);
231
232 /**
233  * modest_account_protocol_unset_custom_secure_auth_mech:
234  * @self: a #ModestAccountProtocol
235  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
236  *
237  * Unsets the secure auth meth of @auth_protocol_type in protocol.
238  */
239 void
240 modest_account_protocol_unset_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type);
241
242 /**
243  * modest_account_protocol_set_custom_secure_auth_mech:
244  * @self: a #ModestAccountProtocol
245  * @auth_protocol_type: a #ModestProtocolType for an auth protocol
246  * @secure_auth_mech: a string or %NULL
247  *
248  * sets the secure auth mech of @auth_protocol_type in protocol. Be careful as %NULL does not imply
249  * there's no custom auth mech registered (you can register %NULL). If you set %NULL you're regitering %NULL as the custom secure auth
250  * mechanism instead of unsetting it.
251  */
252 void
253 modest_account_protocol_set_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type, const gchar *secure_auth_mech);
254
255 /**
256  * modest_account_protocol_get_account_g_type:
257  * @self: a #ModestAccountProtocol
258  *
259  * get the protocol type used for factoring new TnyAccount
260  *
261  * Returns: a #GType
262  */
263 GType modest_account_protocol_get_account_g_type (ModestAccountProtocol *self);
264
265 /**
266  * modest_account_protocol_set_account_g_type:
267  * @self: a #ModestAccountProtocol
268  * @account_g_type: a #GType
269  *
270  * set @account_g_type as the type modest_account_protocol_create_account will
271  * instanciate
272  */
273 void         modest_account_protocol_set_account_g_type (ModestAccountProtocol *self,
274                                                          GType account_g_type);
275
276 /**
277  * modest_account_protocol_create_account:
278  * @self: a #ModestAccountProtocol
279  *
280  * create a new account instance for this protocol
281  *
282  * Returns: a #TnyAccount
283  */
284 TnyAccount * modest_account_protocol_create_account (ModestAccountProtocol *self);
285
286 /**
287  * modest_account_protocol_get_account_settings_dialog:
288  * @self: a #ModestAccountProtocol
289  * @account_name: the name of the account we're creating the dialog for
290  * 
291  * retrieves the account settings dialog used to setup the account
292  * represented by this protocol
293  * 
294  * Returns: a #ModestAccountSettingsDialog
295  **/
296 ModestAccountSettingsDialog* modest_account_protocol_get_account_settings_dialog (ModestAccountProtocol *self,
297                                                                                   const gchar *account_name);
298
299 ModestPairList* modest_account_protocol_get_easysetupwizard_tabs (ModestAccountProtocol *self);
300
301 /**
302  * modest_account_protocol_save_settings:
303  * @self: this #ModestAccountProtocol
304  * @dialog: a #ModestAccountSettingsDialog
305  * @settings: the #ModestAccountSettings
306  * 
307  * this function stores the values held by the account settings dialog
308  * in the account settings object that is passed as argument
309  *
310  * NOTE: this function provides a default implementation that calls
311  * the save_settings method of the acocunt settings dialog. So if your
312  * implementation do not do anything more just do not redefine it
313  **/
314 void modest_account_protocol_save_settings (ModestAccountProtocol *self, 
315                                             ModestAccountSettingsDialog *dialog,
316                                             ModestAccountSettings *settings);
317
318 /**
319  * modest_account_protocol_save_wizard_settings:
320  * @self: this #ModestAccountProtocol
321  * @wizard_pages: a list of #ModestEasysetupWizardPage
322  * @settings: the #ModestAccountSettings
323  * 
324  * this function stores the data input by the users in the wizard in
325  * the account settings object passed as argument
326  **/
327 void modest_account_protocol_save_wizard_settings (ModestAccountProtocol *self, 
328                                                    GList *wizard_pages,
329                                                    ModestAccountSettings *settings);
330
331 /**
332  * modest_account_protocol_get_wizard_response_override:
333  * @self: a #ModestAccountProtocol
334  *
335  * obtains the method that should be used to override wizard response behavior when the
336  * wizard is setting up this account type.
337  *
338  * Returns: a #ModestWizardDialogResponseOverrideFunc
339  */
340 ModestWizardDialogResponseOverrideFunc modest_account_protocol_get_wizard_response_override (ModestAccountProtocol *self);
341
342
343 /**
344  * modest_account_protocol_check_support:
345  * @self: a #ModestAccountProtocol
346  * @func: a #ModestAccountProtocolCheckSupportFunc
347  * @userdata: a gpointer
348  *
349  * This method checks asynchronously if the account protocol @self is
350  * supported. Once checked, @func will be called with the result in the
351  * mainloop.
352  *
353  * modest_account_protocol_is_supported() should return the cached response
354  * from this method.
355  */
356 void modest_account_protocol_check_support (ModestAccountProtocol *self, 
357                                             ModestAccountProtocolCheckSupportFunc func, 
358                                             gpointer userdata);
359
360 /**
361  * modest_account_protocol_cancel_check_support:
362  * @self: a #ModestAccountProtocol
363  *
364  * This method requests that the check support requests running should be
365  * immediately cancelled. Once this happens, is_supported should return %FALSE
366  * until a new succesful check_support request is finished.
367  */
368 void modest_account_protocol_cancel_check_support (ModestAccountProtocol *self);
369
370 /**
371  * modest_account_protocol_wizard_finished:
372  * @self: a #ModestAccountProtocol
373  *
374  * Method that let protocol know if the wizard has finished, for the case it's
375  * needed to do some stuff after check_support.
376  */
377 void modest_account_protocol_wizard_finished (ModestAccountProtocol *self);
378
379 /**
380  * modest_account_protocol_is_supported:
381  * @self: a #ModestAccountProtocol
382  *
383  * Determines if the account protocol is supported on this device.
384  *
385  * Returns: %TRUE if the protocol is supported, %FALSE otherwise
386  */
387 gboolean modest_account_protocol_is_supported (ModestAccountProtocol *self);
388
389 /**
390  * modest_account_protocol_get_from:
391  * @self: a #ModestAccountProtocol
392  * @account_id: a transport account name
393  * @mailbox: a mailbox
394  *
395  * Obtain the From: string for the account and mailbox. Should be used only
396  * with transports with multi mailbox support.
397  *
398  * Returns: a newly allocated string
399  */
400 gchar *modest_account_protocol_get_from (ModestAccountProtocol *self,
401                                          const gchar *account_id,
402                                          const gchar *mailbox);
403
404 /**
405  * modest_account_protocol_get_from_list:
406  * @self: a #ModestAccountProtocol
407  * @account_id: a transport account name
408  *
409  * Obtain a list of pairs (mailbox - From: string) for filling the From picker.
410  *
411  * Returns: a ModestPairList
412  */
413 ModestPairList *modest_account_protocol_get_from_list (ModestAccountProtocol *self,
414                                                        const gchar *account_id);
415
416 /**
417  * modest_account_protocol_get_signature:
418  * @self: a #ModestAccountProtocol
419  * @account_id: a transport account name
420  * @mailbox: a mailbox
421  *
422  * Obtain the signature string for the account and mailbox. Should be used only
423  * with transports with multi mailbox support.
424  *
425  * Returns: a newly allocated string
426  */
427 gchar *modest_account_protocol_get_signature (ModestAccountProtocol *self,
428                                               const gchar *account_id,
429                                               const gchar *mailbox,
430                                               gboolean *has_signature);
431
432 /**
433  * modest_account_protocol_get_icon:
434  * @self: a #ModestAccountProtocl
435  * @icon_type: a #ModestAccountProtocolIconType
436  * @object: a #GObject
437  * @icon_size: the icon size to get
438  *
439  * Returns a @self owned #GdkPixbuf with the icon for @icon_type and @object. @object type
440  * should match @icon_type.
441  *
442  * Returns: a #GdkPixbuf (don't free or manipulate this, just copy)
443  */
444 const GdkPixbuf * modest_account_protocol_get_icon (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
445                                                     GObject *object, guint icon_size);
446
447 /**
448  * modest_account_protocol_get_service_name:
449  * @self: a #ModestAccountProtocol
450  * @account_id: a transport account name
451  * @mailbox: a mailbox
452  *
453  * Obtain the service name string for the account and mailbox.
454  *
455  * Returns: a newly allocated string
456  */
457 gchar *modest_account_protocol_get_service_name (ModestAccountProtocol *self,
458                                                  const gchar *account_id,
459                                                  const gchar *mailbox);
460
461 /**
462  * modest_account_protocol_get_service_icon:
463  * @self: a #ModestAccountProtocol
464  * @account_id: a transport account name
465  * @mailbox: a mailbox
466  *
467  * Obtain the service icon for the account and mailbox.
468  *
469  * Returns: a protocol owned #GdkPixbuf
470  */
471 const GdkPixbuf *modest_account_protocol_get_service_icon (ModestAccountProtocol *self,
472                                                            const gchar *account_id,
473                                                            const gchar *mailbox,
474                                                            guint icon_size);
475
476 /**
477  * modest_account_protocol_save_remote_draft:
478  * @self: a #ModestAccountProtocol
479  * @account_id: a transport account_name
480  * @new_msg: the newly created message in local storage.
481  * @old_msg: the old message
482  * @callback: the code that should be executed on finishing the remote message saving
483  * @userdata: a #gpointer
484  *
485  * Saves the just-saved to local draft, into a remote storage.
486  */
487 void modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
488                                                     const gchar *account_id,
489                                                     TnyMsg *new_msg,
490                                                     TnyMsg *old_msg,
491                                                     ModestAccountProtocolSaveRemoteDraftCallback callback,
492                                                     gpointer userdata);
493
494 /**
495  * modest_account_protocol_decode_part_to_stream:
496  * @self: a #ModestAccountProtocol
497  * @part: a #TnyMimePart
498  * @stream: a #TnyStream
499  * @written: a #gssize pointer, with the number of bytes written
500  * @error: a #GError
501  *
502  * This virtual method delegates on the account protocol to decode @part
503  * into @stream. It just allows the provider to decode it as it needs
504  * (i.e. when the original message has a fake attachment, and provider
505  * can return the real attachment).
506  *
507  * Returns: %TRUE if @protocol does the decode operation, %FALSE if modest
508  * should do it.
509  */
510 gboolean
511 modest_account_protocol_decode_part_to_stream (ModestAccountProtocol *protocol,
512                                                TnyMimePart *part,
513                                                TnyStream *stream,
514                                                gssize *written,
515                                                GError **error);
516
517 /**
518  * modest_account_protocol_decode_part_to_stream_async:
519  * @self: a #ModestAccountProtocol
520  * @part: a #TnyMimePart
521  * @stream: a #TnyStream
522  *
523  * This virtual method delegates on the account protocol to decode @part
524  * into @stream, but asynchronously.
525  *
526  * Returns: %TRUE if @protocol does the decode operation (then we shouldn't expect
527  * callback to happen from this call, %FALSE if modest should do it.
528  */
529 gboolean modest_account_protocol_decode_part_to_stream_async (ModestAccountProtocol *self,
530                                                               TnyMimePart *part, 
531                                                               TnyStream *stream, 
532                                                               TnyMimePartCallback callback, 
533                                                               TnyStatusCallback status_callback, 
534                                                               gpointer user_data);
535
536
537 G_END_DECLS
538
539 #endif /* __MODEST_ACCOUNT_PROTOCOL_H__ */