Modified webpage: now tinymail repository is in gitorious.
[modest] / src / modest-account-protocol.c
index 44b0e53..850be4e 100644 (file)
@@ -32,6 +32,7 @@
 #include "modest-account-mgr-helpers.h"
 #include "widgets/modest-default-account-settings-dialog.h"
 #include "modest-runtime.h"
+#include "modest-marshal.h"
 
 enum {
        PROP_0,
@@ -47,6 +48,8 @@ struct _ModestAccountProtocolPrivate {
        TnyList *account_options;
        GHashTable *custom_auth_mechs;
        GType account_g_type;
+
+       GHashTable *account_dialogs;
 };
 
 /* 'private'/'protected' functions */
@@ -80,6 +83,62 @@ static void modest_account_protocol_save_wizard_settings_default (ModestAccountP
                                                                  GList *wizard_pages,
                                                                  ModestAccountSettings *settings);
 
+static ModestWizardDialogResponseOverrideFunc 
+modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self);
+
+static void modest_account_protocol_check_support_default (ModestAccountProtocol *self,
+                                                          ModestAccountProtocolCheckSupportFunc func,
+                                                          gpointer userdata);
+static void modest_account_protocol_cancel_check_support_default (ModestAccountProtocol *self);
+static void modest_account_protocol_wizard_finished_default (ModestAccountProtocol *self);
+static gboolean modest_account_protocol_decode_part_to_stream_default (ModestAccountProtocol *protocol,
+                                                                      TnyMimePart *part,
+                                                                      const gchar *stream_uri,
+                                                                      TnyStream *stream,
+                                                                      gssize *written,
+                                                                      GError **error);
+static gboolean modest_account_protocol_decode_part_to_stream_async_default (ModestAccountProtocol *protocol,
+                                                                            TnyMimePart *self, 
+                                                                            const gchar *stream_uri,
+                                                                            TnyStream *stream, 
+                                                                            TnyMimePartCallback callback, 
+                                                                            TnyStatusCallback status_callback, 
+                                                                            gpointer user_data);
+static gboolean modest_account_protocol_is_supported_default (ModestAccountProtocol *self);
+static gchar *modest_account_protocol_get_from_default (ModestAccountProtocol *self,
+                                                       const gchar *account_id,
+                                                       const gchar *mailbox);
+static ModestPairList *modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
+                                                                     const gchar *account_id);
+static gchar *modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
+                                                            const gchar *account_id,
+                                                            const gchar *mailbox,
+                                                            gboolean *has_signature);
+static const GdkPixbuf *modest_account_protocol_get_icon_default (ModestAccountProtocol *self,
+                                                                 ModestAccountProtocolIconType icon_type, 
+                                                                 GObject *object, 
+                                                                 guint icon_size);
+
+static gchar *modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
+                                                               const gchar *account_id,
+                                                               const gchar *mailbox);
+
+static const GdkPixbuf *modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
+                                                                         const gchar *account_id,
+                                                                         const gchar *mailbox,
+                                                                         guint icon_size);
+static void modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
+                                                              const gchar *account_id,
+                                                              TnyMsg *new_msg,
+                                                              TnyMsg *old_msg,
+                                                              ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                                              gpointer userdata);
+static gboolean
+modest_account_protocol_handle_calendar_default (ModestAccountProtocol *self,
+                                                ModestWindow *window,
+                                                TnyMimePart *calendar_part,
+                                                GtkContainer *container);
+
 /* globals */
 static GObjectClass *parent_class = NULL;
 
@@ -160,6 +219,37 @@ modest_account_protocol_class_init (ModestAccountProtocolClass *klass)
                modest_account_protocol_save_wizard_settings_default;
        account_class->create_account =
                modest_account_protocol_create_account_default;
+       account_class->get_wizard_response_override =
+               modest_account_protocol_get_wizard_response_override_default;
+       account_class->is_supported =
+               modest_account_protocol_is_supported_default;
+       account_class->check_support =
+               modest_account_protocol_check_support_default;
+       account_class->cancel_check_support =
+               modest_account_protocol_cancel_check_support_default;
+       account_class->wizard_finished =
+               modest_account_protocol_wizard_finished_default;
+       account_class->decode_part_to_stream =
+               modest_account_protocol_decode_part_to_stream_default;
+       account_class->decode_part_to_stream_async =
+               modest_account_protocol_decode_part_to_stream_async_default;
+       account_class->get_from =
+               modest_account_protocol_get_from_default;
+       account_class->get_from_list =
+               modest_account_protocol_get_from_list_default;
+       account_class->get_signature =
+               modest_account_protocol_get_signature_default;
+       account_class->get_icon =
+               modest_account_protocol_get_icon_default;
+       account_class->get_service_name =
+               modest_account_protocol_get_service_name_default;
+       account_class->get_service_icon =
+               modest_account_protocol_get_service_icon_default;
+       account_class->save_remote_draft =
+               modest_account_protocol_save_remote_draft_default;
+       account_class->handle_calendar =
+               modest_account_protocol_handle_calendar_default;
+
 }
 
 static void
@@ -174,6 +264,30 @@ modest_account_protocol_instance_init (ModestAccountProtocol *obj)
        priv->account_g_type = 0;
        priv->account_options = tny_simple_list_new ();
        priv->custom_auth_mechs = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
+
+       priv->account_dialogs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+}
+
+static gboolean
+remove_account (const gchar *account_name, GObject *account, GObject *account_to_remove)
+{
+       return (account == account_to_remove);
+}
+
+static void
+account_dialog_weak_handler (ModestAccountProtocol *self, GObject *where_the_object_was)
+{
+       ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
+
+       g_hash_table_foreach_remove (priv->account_dialogs, (GHRFunc) remove_account, where_the_object_was);
+}
+
+static gboolean
+dialogs_remove (const gchar *account_name, GObject *account_dialog, ModestAccountProtocol *self)
+{
+       g_object_weak_unref (account_dialog, (GWeakNotify) account_dialog_weak_handler, self);
+
+       return TRUE;
 }
 
 static void   
@@ -182,6 +296,11 @@ modest_account_protocol_finalize   (GObject *obj)
        ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
        ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (protocol);
 
+       if (priv->account_dialogs) {
+               g_hash_table_foreach_remove (priv->account_dialogs, (GHRFunc) dialogs_remove, obj);
+               g_hash_table_destroy (priv->account_dialogs);
+       }
+
        if (priv->account_options)
                g_object_unref (priv->account_options);
        priv->account_options = NULL;
@@ -337,6 +456,7 @@ modest_account_protocol_set_account_options (ModestAccountProtocol *self,
        priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
 
        if (priv->account_options) {
+               g_object_unref (priv->account_options);
                priv->account_options = NULL;
        }
        priv->account_options = tny_list_copy (list);
@@ -434,29 +554,33 @@ modest_account_protocol_get_account_settings_dialog (ModestAccountProtocol *self
 {
        ModestAccountSettingsDialog *dialog;
        ModestAccountSettings *settings;
+       ModestAccountProtocolPrivate *priv;
+
+       priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
+       dialog = g_hash_table_lookup (priv->account_dialogs, account_name);
+
+       if (dialog == NULL) {
+
+               dialog = MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->create_account_settings_dialog (self);
 
-       dialog = MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->create_account_settings_dialog (self);
-       
-       /* Load settings */
-       settings = modest_account_mgr_load_account_settings (modest_runtime_get_account_mgr (), 
-                                                            account_name);
-       modest_account_settings_dialog_load_settings (dialog, settings);
-       
-       /* TODO: Those methods should be removed from the
-          interface and moved to specific implementations */
-/*     modest_account_settings_dialog_switch_to_user_info (dialog); */
-/*     modest_account_settings_dialog_check_allow_changes (dialog); */
-       
-       /* TODO: review this. When the dialog is closed, reconnect */
-       /*                      g_signal_connect (dialog, "response",  */
-       /*                                        G_CALLBACK (on_account_settings_dialog_response),  */
-       /*                                        self); */
-       
-       /* Close dialog on response */
-       g_signal_connect_swapped (dialog,
-                                 "response",
-                                 G_CALLBACK (gtk_widget_destroy),
-                                 dialog);
+               /* Check existence of dialog */
+               if (dialog == NULL)
+                       return NULL;
+
+               /* Load settings */
+               settings = modest_account_mgr_load_account_settings (modest_runtime_get_account_mgr (),
+                                                                    account_name);
+               modest_account_settings_dialog_load_settings (dialog, settings);
+
+               /* Close dialog on response */
+               g_signal_connect_swapped (dialog,
+                                         "response",
+                                         G_CALLBACK (gtk_widget_destroy),
+                                         dialog);
+
+               g_hash_table_insert (priv->account_dialogs, g_strdup (account_name), dialog);
+               g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) account_dialog_weak_handler, self);
+       }
 
        return dialog;
 }
@@ -521,3 +645,286 @@ modest_account_protocol_save_wizard_settings_default (ModestAccountProtocol *sel
 
        g_warning ("You must implement save_wizard_settings");
 }
+
+static ModestWizardDialogResponseOverrideFunc
+modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return NULL;
+}
+
+ModestWizardDialogResponseOverrideFunc
+modest_account_protocol_get_wizard_response_override (ModestAccountProtocol *self)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_wizard_response_override (self);   
+}
+
+static gboolean
+modest_account_protocol_is_supported_default (ModestAccountProtocol *self)
+{
+       return TRUE;
+}
+
+gboolean
+modest_account_protocol_is_supported (ModestAccountProtocol *self)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->is_supported (self);
+}
+
+static void
+modest_account_protocol_check_support_default (ModestAccountProtocol *self,
+                                              ModestAccountProtocolCheckSupportFunc func,
+                                              gpointer userdata)
+{
+       if (func)
+               func (self, TRUE, userdata);
+}
+
+void
+modest_account_protocol_check_support (ModestAccountProtocol *self,
+                                      ModestAccountProtocolCheckSupportFunc func,
+                                      gpointer userdata)
+{
+       MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->check_support (self, func, userdata);
+}
+
+static void
+modest_account_protocol_cancel_check_support_default (ModestAccountProtocol *self)
+{
+       return;
+}
+
+void
+modest_account_protocol_cancel_check_support (ModestAccountProtocol *self)
+{
+       MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->cancel_check_support (self);
+}
+
+static void
+modest_account_protocol_wizard_finished_default (ModestAccountProtocol *self)
+{
+       return;
+}
+
+void
+modest_account_protocol_wizard_finished (ModestAccountProtocol *self)
+{
+       MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->wizard_finished (self);
+}
+
+static gboolean
+modest_account_protocol_decode_part_to_stream_default (ModestAccountProtocol *self,
+                                                      TnyMimePart *part,
+                                                      const gchar *stream_uri,
+                                                      TnyStream *stream,
+                                                      gssize *written,
+                                                      GError **error)
+{
+       /* By default account protocols do not handle themselves the transfer */
+       return FALSE;
+}
+
+gboolean
+modest_account_protocol_decode_part_to_stream (ModestAccountProtocol *self,
+                                              TnyMimePart *part,
+                                              const gchar *stream_uri,
+                                              TnyStream *stream,
+                                              gssize *written,
+                                              GError **error)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->decode_part_to_stream (self,
+                                                                               part,
+                                                                               stream_uri,
+                                                                               stream,
+                                                                               written,
+                                                                               error);
+}
+
+static gboolean
+modest_account_protocol_decode_part_to_stream_async_default (ModestAccountProtocol *self,
+                                                            TnyMimePart *part,
+                                                            const gchar *stream_uri,
+                                                            TnyStream *stream, 
+                                                            TnyMimePartCallback callback, 
+                                                            TnyStatusCallback status_callback, 
+                                                            gpointer user_data)
+{
+       /* By default account protocols do not handle themselves the transfer */
+       return FALSE;
+}
+
+gboolean
+modest_account_protocol_decode_part_to_stream_async (ModestAccountProtocol *self,
+                                                    TnyMimePart *part, 
+                                                    const gchar *stream_uri,
+                                                    TnyStream *stream, 
+                                                    TnyMimePartCallback callback, 
+                                                    TnyStatusCallback status_callback, 
+                                                    gpointer user_data)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->decode_part_to_stream_async (self,
+                                                                                     part,
+                                                                                     stream_uri,
+                                                                                     stream,
+                                                                                     callback,
+                                                                                     status_callback,
+                                                                                     user_data);
+}
+
+gchar *
+modest_account_protocol_get_from (ModestAccountProtocol *self,
+                                 const gchar *account_id,
+                                 const gchar *mailbox)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from (self, account_id, mailbox);
+}
+static gchar *
+modest_account_protocol_get_from_default (ModestAccountProtocol *self,
+                                         const gchar *account_id,
+                                         const gchar *mailbox)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return NULL;
+}
+
+ModestPairList *
+modest_account_protocol_get_from_list (ModestAccountProtocol *self,
+                                      const gchar *account_id)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from_list (self, account_id);
+}
+static ModestPairList *
+modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
+                                              const gchar *account_id)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return NULL;
+}
+
+gchar *
+modest_account_protocol_get_signature (ModestAccountProtocol *self,
+                                      const gchar *account_id,
+                                      const gchar *mailbox,
+                                      gboolean *has_signature)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_signature (self, account_id, mailbox, has_signature);
+}
+
+static gchar *
+modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
+                                              const gchar *account_id,
+                                              const gchar *mailbox,
+                                              gboolean *has_signature)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+       if (has_signature)
+               *has_signature = FALSE;
+
+       return NULL;
+}
+
+const GdkPixbuf*
+modest_account_protocol_get_icon (ModestAccountProtocol *self,
+                                 ModestAccountProtocolIconType icon_type,
+                                 GObject *object,
+                                 guint icon_size)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_icon (self, icon_type, object, icon_size);
+}
+
+static const GdkPixbuf * 
+modest_account_protocol_get_icon_default (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
+                                         GObject *object, guint icon_size)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return NULL;
+}
+
+gchar *
+modest_account_protocol_get_service_name (ModestAccountProtocol *self,
+                                         const gchar *account_id,
+                                         const gchar *mailbox)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_name (self, account_id, mailbox);
+}
+
+static gchar *
+modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
+                                                 const gchar *account_id,
+                                                 const gchar *mailbox)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return NULL;
+}
+
+const GdkPixbuf *
+modest_account_protocol_get_service_icon (ModestAccountProtocol *self,
+                                         const gchar *account_id,
+                                         const gchar *mailbox,
+                                         guint icon_size)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_icon (self, account_id, mailbox, icon_size);
+}
+
+static const GdkPixbuf *
+modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
+                                                 const gchar *account_id,
+                                                 const gchar *mailbox,
+                                                 guint icon_size)
+{
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
+
+       return NULL;
+}
+
+void
+modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
+                                          const gchar *account_id,
+                                          TnyMsg *new_msg,
+                                          TnyMsg *old_msg,
+                                          ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                          gpointer userdata)
+{
+       MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_remote_draft (self, account_id, 
+                                                                    new_msg, old_msg,
+                                                                    callback, userdata);
+}
+
+static void
+modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
+                                                  const gchar *account_id,
+                                                  TnyMsg *new_msg,
+                                                  TnyMsg *old_msg,
+                                                  ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                                  gpointer userdata)
+{
+       if (callback) {
+               callback (self, NULL, account_id, NULL, new_msg, old_msg, userdata);
+       }
+}
+
+gboolean
+modest_account_protocol_handle_calendar (ModestAccountProtocol *self,
+                                        ModestWindow *window,
+                                        TnyMimePart *calendar_part,
+                                        GtkContainer *container)
+{
+       return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->handle_calendar (self, window, 
+                                                                         calendar_part, container);
+}
+
+static gboolean
+modest_account_protocol_handle_calendar_default (ModestAccountProtocol *self,
+                                                ModestWindow *window,
+                                                TnyMimePart *calendar_part,
+                                                GtkContainer *container)
+{
+       return FALSE;
+}