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