X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodest-account-protocol.c;h=9256c028fa9a186b9a1596d84e5819244bb718a2;hb=fa8f6bccc4b6a4f8725848ac8f2c655603266e59;hp=066fe09b281371dac84b17632dd0a98830182e19;hpb=627c4af6ac85444cc3256fa568baf4a8d62178ae;p=modest diff --git a/src/modest-account-protocol.c b/src/modest-account-protocol.c index 066fe09..9256c02 100644 --- a/src/modest-account-protocol.c +++ b/src/modest-account-protocol.c @@ -47,6 +47,8 @@ struct _ModestAccountProtocolPrivate { TnyList *account_options; GHashTable *custom_auth_mechs; GType account_g_type; + + GHashTable *account_dialogs; }; /* 'private'/'protected' functions */ @@ -174,6 +176,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 +208,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 +368,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,33 +466,29 @@ modest_account_protocol_get_account_settings_dialog (ModestAccountProtocol *self { ModestAccountSettingsDialog *dialog; ModestAccountSettings *settings; + ModestAccountProtocolPrivate *priv; - 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); */ - - /* Set modal */ - modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), - GTK_WINDOW (dialog)); + 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); - /* TODO: review this. When the dialog is closed, reconnect */ - /* g_signal_connect (dialog, "response", */ - /* G_CALLBACK (on_account_settings_dialog_response), */ - /* 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); - /* Close dialog on response */ - g_signal_connect_swapped (dialog, - "response", - G_CALLBACK (gtk_widget_destroy), - dialog); + /* 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; }