diff options
-rw-r--r-- | mail/ChangeLog | 20 | ||||
-rw-r--r-- | mail/em-account-editor.c | 59 | ||||
-rw-r--r-- | mail/mail-config.c | 114 | ||||
-rw-r--r-- | mail/mail-config.h | 3 | ||||
-rw-r--r-- | mail/mail-errors.xml | 7 | ||||
-rw-r--r-- | mail/mail-errors.xml.h | 4 | ||||
-rw-r--r-- | mail/mail-ops.c | 77 | ||||
-rw-r--r-- | mail/mail-ops.h | 3 |
8 files changed, 162 insertions, 125 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 752865b4c9..ad57a40fa2 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,23 @@ +2004-10-11 Not Zed <NotZed@Ximian.com> + + ** See bug #67014. + + * mail-errors.xml: added "checking-service" error. + + * em-account-editor.c (em_account_editor_construct): keep track of + the dialogue + (emae_editor_destroyed): , and clean up when destroyed. + + * em-account-editor.c (emae_check_authtype) + (emae_check_authtype_response, emae_check_authtype_done): handle + checking authtype gui here. + + * mail-config.c (check_service_describe, check_service_check) + (check_response, mail_config_check_service): removed. + + * mail-ops.c (mail_check_service): moved here from mail-config, + and modified to be a re-usable threaded function. + 2004-10-18 Not Zed <NotZed@Ximian.com> ** See bug #68006. diff --git a/mail/em-account-editor.c b/mail/em-account-editor.c index d80bc9edbd..5cfde83efb 100644 --- a/mail/em-account-editor.c +++ b/mail/em-account-editor.c @@ -123,6 +123,9 @@ typedef struct _EMAccountEditorService { struct _GtkButton *check_supported; struct _GtkToggleButton *needs_auth; + struct _GtkWidget *check_dialog; + int check_id; + GList *authtypes; /* if "Check supported" */ CamelProvider *provider; CamelProviderType type; @@ -1407,19 +1410,51 @@ emae_setup_authtype(EMAccountEditor *emae, EMAccountEditorService *service) return (GtkWidget *)dropdown; } +static void emae_check_authtype_done(const char *uri, CamelProviderType type, GList *types, void *data) +{ + EMAccountEditorService *service = data; + + if (service->check_dialog) { + if (service->authtypes) + g_list_free(service->authtypes); + + service->authtypes = g_list_copy(types); + emae_setup_authtype(service->emae, service); + gtk_widget_destroy(service->check_dialog); + } + + if (service->emae->editor) + gtk_widget_set_sensitive(service->emae->editor, TRUE); + + service->check_id = -1; + g_object_unref(service->emae); +} + +static void emae_check_authtype_response(GtkWidget *d, int button, EMAccountEditorService *service) +{ + mail_msg_cancel(service->check_id); + gtk_widget_destroy(service->check_dialog); + service->check_dialog = NULL; + + if (service->emae->editor) + gtk_widget_set_sensitive(service->emae->editor, TRUE); +} + static void emae_check_authtype(GtkWidget *w, EMAccountEditorService *service) { EMAccountEditor *emae = service->emae; const char *uri; - if (service->authtypes) { - g_list_free(service->authtypes); - service->authtypes = NULL; - } - + /* TODO: do we need to remove the auth mechanism from the uri? */ uri = e_account_get_string(emae->account, emae_service_info[service->type].account_uri_key); - if (mail_config_check_service(uri, service->type, &service->authtypes, (GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emae->editor))) - emae_setup_authtype(emae, service); + g_object_ref(emae); + + service->check_dialog = e_error_new((GtkWindow *)gtk_widget_get_toplevel(emae->editor), + "mail:checking-service", NULL); + g_signal_connect(service->check_dialog, "response", G_CALLBACK(emae_check_authtype_response), service); + gtk_widget_show(service->check_dialog); + gtk_widget_set_sensitive(emae->editor, FALSE); + service->check_id = mail_check_service(uri, service->type, emae_check_authtype_done, service); } static void @@ -2331,6 +2366,13 @@ emae_commit(EConfig *ec, GSList *items, void *data) e_account_list_save(accounts); } +static void +emae_editor_destroyed(GtkWidget *dialog, EMAccountEditor *emae) +{ + emae->editor = NULL; + g_object_unref(emae); +} + void em_account_editor_construct(EMAccountEditor *emae, EAccount *account, em_account_editor_t type) { @@ -2435,5 +2477,6 @@ em_account_editor_construct(EMAccountEditor *emae, EAccount *account, em_account e_config_set_target((EConfig *)ec, (EConfigTarget *)target); emae->editor = e_config_create_window((EConfig *)ec, NULL, type==EMAE_NOTEBOOK?_("Account Editor"):_("Evolution Account Assistant")); - /* FIXME: need to hook onto destroy as required */ + g_object_ref(emae); + g_signal_connect(emae->editor, "destroy", G_CALLBACK(emae_editor_destroyed), emae); } diff --git a/mail/mail-config.c b/mail/mail-config.c index c16113d4ab..c1c8adf02d 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -878,120 +878,6 @@ mail_config_folder_to_cachename (CamelFolder *folder, const char *prefix) return filename; } - -/* Async service-checking/authtype-lookup code. */ -struct _check_msg { - struct _mail_msg msg; - - const char *url; - CamelProviderType type; - GList **authtypes; - gboolean *success; -}; - -static char * -check_service_describe (struct _mail_msg *mm, int complete) -{ - return g_strdup (_("Checking Service")); -} - -static void -check_service_check (struct _mail_msg *mm) -{ - struct _check_msg *m = (struct _check_msg *)mm; - CamelService *service = NULL; - - camel_operation_register(mm->cancel); - - service = camel_session_get_service (session, m->url, m->type, &mm->ex); - if (!service) { - camel_operation_unregister(mm->cancel); - return; - } - - if (m->authtypes) - *m->authtypes = camel_service_query_auth_types (service, &mm->ex); - else - camel_service_connect (service, &mm->ex); - - camel_object_unref (service); - *m->success = !camel_exception_is_set(&mm->ex); - - camel_operation_unregister(mm->cancel); -} - -static struct _mail_msg_op check_service_op = { - check_service_describe, - check_service_check, - NULL, - NULL -}; - -static void -check_response (GtkDialog *dialog, int button, gpointer data) -{ - int *msg_id = data; - - mail_msg_cancel (*msg_id); -} - -/** - * mail_config_check_service: - * @url: service url - * @type: provider type - * @authtypes: set to list of supported authtypes on return if non-%NULL. - * - * Checks the service for validity. If @authtypes is non-%NULL, it will - * be filled in with a list of supported authtypes. - * - * Return value: %TRUE on success or %FALSE on error. - **/ -gboolean -mail_config_check_service (const char *url, CamelProviderType type, GList **authtypes, GtkWindow *window) -{ - static GtkWidget *dialog = NULL; - gboolean ret = FALSE; - struct _check_msg *m; - GtkWidget *label; - int id; - - if (dialog) { - gdk_window_raise (dialog->window); - *authtypes = NULL; - return FALSE; - } - - m = mail_msg_new (&check_service_op, NULL, sizeof(*m)); - m->url = url; - m->type = type; - m->authtypes = authtypes; - m->success = &ret; - - id = m->msg.seq; - e_thread_put(mail_thread_new, (EMsg *)m); - - /* FIXME: make this use e-error. - * It has to be modal otherwise we can get nasty re-entrancy whilst waiting for the - * subthread to complete. - * FIXME: make this whole function async to deal with this issue */ - dialog = gtk_dialog_new_with_buttons(_("Connecting to server..."), window, - GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - NULL); - label = gtk_label_new (_("Connecting to server...")); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG (dialog)->vbox), - label, TRUE, TRUE, 10); - g_signal_connect(dialog, "response", G_CALLBACK (check_response), &id); - gtk_widget_show_all (dialog); - - mail_msg_wait(id); - - gtk_widget_destroy (dialog); - dialog = NULL; - - return ret; -} - ESignatureList * mail_config_get_signatures (void) { diff --git a/mail/mail-config.h b/mail/mail-config.h index 3618e9465c..679dabeb7d 100644 --- a/mail/mail-config.h +++ b/mail/mail-config.h @@ -161,9 +161,6 @@ void mail_config_uri_deleted (GCompareFunc uri_cmp, const char *uri); char *mail_config_folder_to_cachename (struct _CamelFolder *folder, const char *prefix); char *mail_config_folder_to_safe_url (struct _CamelFolder *folder); -/* Ugh, this totally does not belong in this module */ -gboolean mail_config_check_service (const char *url, CamelProviderType type, GList **authtypes, struct _GtkWindow *window); - GType evolution_mail_config_get_type (void); gboolean evolution_mail_config_factory_init (void); diff --git a/mail/mail-errors.xml b/mail/mail-errors.xml index 04208457a5..a71b35962d 100644 --- a/mail/mail-errors.xml +++ b/mail/mail-errors.xml @@ -318,6 +318,13 @@ You can choose to ignore this folder, overwrite or append its contents, or quit. you can accept its license.</secondary> </error> + <error id="checking-service" type="info"> + <title>Querying server</title> + <primary>Please wait.</primary> + <secondary>Querying server for a list of supported authentication mechanisms.</secondary> + <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/> + </error> + <error id="gw-accountsetup-error" type="error"> <primary>Unable to connect to the GroupWise server.</primary> diff --git a/mail/mail-errors.xml.h b/mail/mail-errors.xml.h index 52c4ece276..25ac53aeba 100644 --- a/mail/mail-errors.xml.h +++ b/mail/mail-errors.xml.h @@ -236,6 +236,10 @@ char *s = N_("Unable to read license file."); char *s = N_("Cannot read the license file \"{0}\", due to an\n" " installation problem. You will not be able to use this provider until\n" " you can accept its license."); +/* mail:checking-service primary */ +char *s = N_("Please wait."); +/* mail:checking-service secondary */ +char *s = N_("Querying server for a list of supported authentication mechanisms."); /* mail:gw-accountsetup-error primary */ char *s = N_("Unable to connect to the GroupWise\n" "server."); diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 51de559c8e..c4cb73e908 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -2265,3 +2265,80 @@ mail_execute_shell_command (CamelFilterDriver *driver, int argc, char **argv, vo gnome_execute_async_fds (NULL, argc, argv, TRUE); } + +/* Async service-checking/authtype-lookup code. */ +struct _check_msg { + struct _mail_msg msg; + + char *url; + CamelProviderType type; + GList *authtypes; + + void (*done)(const char *url, CamelProviderType type, GList *types, void *data); + void *data; +}; + +static char * +check_service_describe(struct _mail_msg *mm, int complete) +{ + return g_strdup(_("Checking Service")); +} + +static void +check_service_check(struct _mail_msg *mm) +{ + struct _check_msg *m = (struct _check_msg *)mm; + CamelService *service; + + service = camel_session_get_service(session, m->url, m->type, &mm->ex); + if (!service) { + camel_operation_unregister(mm->cancel); + return; + } + + m->authtypes = camel_service_query_auth_types(service, &mm->ex); + camel_object_unref(service); +} + +static void +check_service_done(struct _mail_msg *mm) +{ + struct _check_msg *m = (struct _check_msg *)mm; + + if (m->done) + m->done(m->url, m->type, m->authtypes, m->data); +} + +static void +check_service_free(struct _mail_msg *mm) +{ + struct _check_msg *m = (struct _check_msg *)mm; + + g_free(m->url); + g_list_free(m->authtypes); +} + +static struct _mail_msg_op check_service_op = { + check_service_describe, + check_service_check, + check_service_done, + check_service_free, +}; + +int +mail_check_service(const char *url, CamelProviderType type, void (*done)(const char *url, CamelProviderType type, GList *authtypes, void *data), void *data) +{ + struct _check_msg *m; + int id; + + m = mail_msg_new (&check_service_op, NULL, sizeof(*m)); + m->url = g_strdup(url); + m->type = type; + m->done = done; + m->data = data; + + id = m->msg.seq; + e_thread_put(mail_thread_new, (EMsg *)m); + + return id; +} diff --git a/mail/mail-ops.h b/mail/mail-ops.h index 7751ea337f..8527994eaa 100644 --- a/mail/mail-ops.h +++ b/mail/mail-ops.h @@ -154,6 +154,9 @@ int mail_store_set_offline(CamelStore *store, gboolean offline, /* filter driver execute shell command async callback */ void mail_execute_shell_command (CamelFilterDriver *driver, int argc, char **argv, void *data); +int mail_check_service(const char *url, CamelProviderType type, + void (*done)(const char *url, CamelProviderType type, GList *authtypes, void *data), void *data); + #ifdef __cplusplus } #endif /* __cplusplus */ |