diff options
author | Rodrigo Moya <rodrigo@gnome-db.org> | 2011-11-14 20:08:57 +0800 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2011-11-14 20:08:57 +0800 |
commit | 7ab5ae3fc72516cceeb09a48bc5a39f7b57933de (patch) | |
tree | f1d1afbfa9d8c97dc691a2d241c9ec368fdf67d3 /mail/em-account-editor.c | |
parent | cda52538315c481bc3b11ff2db40f7165113d1ab (diff) | |
parent | c4308051159a37f16521b881f59259861998f4ae (diff) | |
download | gsoc2013-evolution-7ab5ae3fc72516cceeb09a48bc5a39f7b57933de.tar.gz gsoc2013-evolution-7ab5ae3fc72516cceeb09a48bc5a39f7b57933de.tar.zst gsoc2013-evolution-7ab5ae3fc72516cceeb09a48bc5a39f7b57933de.zip |
Merge branch 'master' into wip/gsettings
Diffstat (limited to 'mail/em-account-editor.c')
-rw-r--r-- | mail/em-account-editor.c | 590 |
1 files changed, 526 insertions, 64 deletions
diff --git a/mail/em-account-editor.c b/mail/em-account-editor.c index 04d69ad211..2bc3bf3d81 100644 --- a/mail/em-account-editor.c +++ b/mail/em-account-editor.c @@ -69,6 +69,7 @@ #include "em-utils.h" #include "mail-ops.h" #include "mail-mt.h" +#include "mail-guess-servers.h" #if defined (HAVE_NSS) && defined (ENABLE_SMIME) #include "smime/gui/e-cert-selector.h" @@ -81,24 +82,6 @@ #define d(x) -static ServerData mail_servers[] = { - { "gmail", "imap.gmail.com", "smtp.gmail.com", "imap", - CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT }, - { "googlemail", "imap.gmail.com", "smtp.gmail.com", "imap", - CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT }, - { "yahoo", "pop3.yahoo.com", "smtp.yahoo.com", "pop", - CAMEL_NETWORK_SECURITY_METHOD_NONE }, - { "aol", "imap.aol.com", "smtp.aol.com", "imap", - CAMEL_NETWORK_SECURITY_METHOD_NONE }, - { "msn", "pop3.email.msn.com", "smtp.email.msn.com", "pop", - CAMEL_NETWORK_SECURITY_METHOD_NONE, "@", "@"}, - { "hotmail", "pop3.live.com", "smtp.live.com", "pop", - CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT, "@", "@"}, - { "live.com", "pop3.live.com", "smtp.live.com", "pop", - CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT, "@", "@"}, - -}; - /* econfig item for the extra config hings */ struct _receive_options_item { EMConfigItem item; @@ -214,14 +197,41 @@ struct _EMAccountEditorPrivate { GtkButton *smime_encrypt_key_select; GtkButton *smime_encrypt_key_clear; + /* Review */ + GtkLabel *review_name; + GtkLabel *review_email; + GtkLabel *send_name; + GtkLabel *send_stype; + GtkLabel *send_saddress; + GtkLabel *send_encryption; + GtkLabel *receive_name; + GtkLabel *receive_stype; + GtkLabel *receive_saddress; + GtkLabel *receive_encryption; + GtkWidget *review_box; + + /* google and yahoo specific data*/ + gboolean is_gmail; + gboolean is_yahoo; + + GtkWidget *calendar; + GtkWidget *gcontacts; + GtkWidget *info_label; + + GtkWidget *account_label; + GtkWidget *gmail_link; + GtkWidget *yahoo_cal_box; + GtkWidget *yahoo_cal_entry; + /* for e-config callbacks, each page sets up its widgets, then they are dealed out by the get_widget callback in order*/ GHashTable *widgets; /* for assistant page preparation */ guint identity_set : 1; guint receive_set : 1; + guint receive_opt_set : 1; guint send_set : 1; - guint management_set : 1; + guint review_set : 1; ServerData *selected_server; }; @@ -251,7 +261,6 @@ enum { static void em_account_editor_construct (EMAccountEditor *emae, EMAccountEditorType type, const gchar *id); static void emae_account_folder_changed (EMFolderSelectionButton *folder, EMAccountEditor *emae); -static ServerData * emae_check_servers (const gchar *email); static gpointer parent_class; @@ -1138,7 +1147,6 @@ emae_init (EMAccountEditor *emae) emae, EM_TYPE_ACCOUNT_EDITOR, EMAccountEditorPrivate); emae->priv->selected_server = NULL; - emae->emae_check_servers = emae_check_servers; emae->priv->source.emae = emae; emae->priv->transport.emae = emae; emae->priv->widgets = g_hash_table_new (g_str_hash, g_str_equal); @@ -1146,6 +1154,9 @@ emae_init (EMAccountEditor *emae) /* Pick default storage and transport protocols. */ emae->priv->source.protocol = "imapx"; emae->priv->transport.protocol = "smtp"; + + emae->priv->is_gmail = FALSE; + emae->priv->is_yahoo = FALSE; } GType @@ -2202,10 +2213,12 @@ emae_service_provider_changed (EMAccountEditorService *service) { EConfig *config; EMConfigTargetSettings *target; - CamelProvider *provider; + CamelProvider *provider = NULL; const gchar *description; - provider = camel_provider_get (service->protocol, NULL); + /* Protocol is NULL when server type is 'None'. */ + if (service->protocol != NULL) + provider = camel_provider_get (service->protocol, NULL); description = (provider != NULL) ? provider->description : ""; gtk_label_set_text (service->description, description); @@ -2376,7 +2389,7 @@ emae_refresh_providers (EMAccountEditor *emae, if (!(mail_or_news_domain && provider->object_types[service->type] && (service->type != CAMEL_PROVIDER_STORE || - (provider->flags & CAMEL_PROVIDER_IS_SOURCE) != 0)) + (provider->flags & CAMEL_PROVIDER_IS_SOURCE) != 0)) /* hardcode not showing providers who's transport is done in the store */ || (service->type == CAMEL_PROVIDER_TRANSPORT && CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (provider))) @@ -2554,7 +2567,7 @@ emae_setup_service (EMAccountEditor *emae, GtkBuilder *builder) { struct _service_info *info = &emae_service_info[service->type]; - CamelProvider *provider; + CamelProvider *provider = NULL; CamelURL *url; /* GtkComboBox internalizes ID strings, which for the provider @@ -2564,7 +2577,9 @@ emae_setup_service (EMAccountEditor *emae, service->protocol = g_intern_string (url->protocol); camel_url_free (url); - provider = camel_provider_get (service->protocol, NULL); + /* Protocol is NULL when server type is 'None'. */ + if (service->protocol != NULL) + provider = camel_provider_get (service->protocol, NULL); /* Extract all widgets we need from the builder file. */ @@ -2814,9 +2829,9 @@ emae_create_basic_assistant_page (EMAccountEditor *emae, } else if (g_ascii_strcasecmp (page_id, "transport_page") == 0) { title = _("Sending Email"); label = _("Please enter information about the way you will send mail. If you are not sure, ask your system administrator or Internet Service Provider."); - } else if (g_ascii_strcasecmp (page_id, "management_page") == 0) { - title = _("Account Information"); - label = _("Please enter a descriptive name for this account below.\nThis name will be used for display purposes only."); + } else if (g_ascii_strcasecmp (page_id, "review_page") == 0) { + title = _("Review Account"); + label = _("Time to check things over before we try and connect to the server and fetch your mail."); } else if (g_ascii_strcasecmp (page_id, "finish_page") == 0) { page_type = GTK_ASSISTANT_PAGE_CONFIRM; fill_space = TRUE; @@ -3577,7 +3592,7 @@ emae_send_page (EConfig *ec, GtkWidget *w; GtkBuilder *builder; - provider = emae_get_store_provider (emae); + provider = emae_get_transport_provider (emae); if (provider == NULL) return NULL; @@ -4124,7 +4139,7 @@ static EMConfigItem emae_editor_items[] = { static gboolean emae_editor_items_translated = FALSE; static GtkWidget * -emae_management_page (EConfig *ec, +emae_review_page (EConfig *ec, EConfigItem *item, GtkWidget *parent, GtkWidget *old, @@ -4134,16 +4149,35 @@ emae_management_page (EConfig *ec, EMAccountEditor *emae = data; EMAccountEditorPrivate *priv = emae->priv; GtkWidget *w; + GtkBuilder *builder; + + builder = gtk_builder_new (); + e_load_ui_builder_definition (builder, "mail-config.ui"); - w = priv->management_frame; + priv->review_name = (GtkLabel*) e_builder_get_widget (builder, "personal-name-entry"); + priv->review_email = (GtkLabel*) e_builder_get_widget (builder, "personal-email-entry"); + priv->receive_stype = (GtkLabel*) e_builder_get_widget (builder, "receive_server_type"); + priv->send_stype = (GtkLabel*) e_builder_get_widget (builder, "send_server_type"); + priv->receive_saddress = (GtkLabel*) e_builder_get_widget (builder, "receive_server_address"); + priv->send_saddress = (GtkLabel*) e_builder_get_widget (builder, "send_server_address"); + priv->receive_name = (GtkLabel*) e_builder_get_widget (builder, "receive_username"); + priv->send_name = (GtkLabel*) e_builder_get_widget (builder, "send_username"); + priv->receive_encryption = (GtkLabel*) e_builder_get_widget (builder, "receive_encryption"); + priv->send_encryption = (GtkLabel*) e_builder_get_widget (builder, "send_encryption"); + + w = e_builder_get_widget (builder, item->label); + priv->review_box = gtk_vbox_new (FALSE, 2); + gtk_widget_show (priv->review_box); if (((EConfig *) priv->config)->type == E_CONFIG_ASSISTANT) { GtkWidget *page; page = emae_create_basic_assistant_page ( emae, GTK_ASSISTANT (parent), - "management_page", position); + "review_page", position); - gtk_widget_reparent (w, page); + gtk_box_pack_start (GTK_BOX (page), w, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (page), priv->review_box, FALSE, FALSE, 0); + gtk_widget_reparent (priv->management_frame, page); w = page; } @@ -4199,7 +4233,7 @@ static EMConfigItem emae_assistant_items[] = { { E_CONFIG_SECTION_TABLE, (gchar *) "40.defaults/00.folders", (gchar *) "special-folders-table", emae_widget_glade }, { E_CONFIG_SECTION_TABLE, (gchar *) "40.defaults/10.composing", (gchar *) "composing-messages-table", emae_widget_glade }, - { E_CONFIG_PAGE, (gchar *) "40.management", (gchar *) "management_frame", emae_management_page }, + { E_CONFIG_PAGE, (gchar *) "50.review", (gchar *) "vboxReviewBorder", emae_review_page }, { E_CONFIG_PAGE_FINISH, (gchar *) "999.end", (gchar *) "finish_page", emae_widget_assistant_page }, { 0 }, @@ -4238,7 +4272,7 @@ static gboolean emae_service_complete (EMAccountEditor *emae, EMAccountEditorService *service) { - CamelProvider *provider; + CamelProvider *provider = NULL; const gchar *host = NULL; const gchar *path = NULL; const gchar *user = NULL; @@ -4251,7 +4285,9 @@ emae_service_complete (EMAccountEditor *emae, gboolean need_port; gboolean need_user; - provider = camel_provider_get (service->protocol, NULL); + /* Protocol is NULL when server type is 'None'. */ + if (service->protocol != NULL) + provider = camel_provider_get (service->protocol, NULL); if (provider == NULL) return TRUE; @@ -4301,17 +4337,93 @@ emae_service_complete (EMAccountEditor *emae, static ServerData * emae_check_servers (const gchar *email) { - gint len = G_N_ELEMENTS (mail_servers), i; - gchar *server = strchr (email, '@'); - - server++; + ServerData *sdata = g_new0 (ServerData, 1); + EmailProvider *provider = g_new0 (EmailProvider, 1); + gchar *dupe = g_strdup (email); + gchar *tmp; + + /* FIXME: Find a way to free the provider once given to account settings. */ + provider->email = (gchar *) email; + tmp = strchr (email, '@'); + tmp++; + provider->domain = tmp; + tmp = strchr (dupe, '@'); + *tmp = 0; + provider->username = (gchar *) g_quark_to_string (g_quark_from_string (dupe)); + g_free (dupe); + + if (!mail_guess_servers (provider)) { + g_free (provider); + g_free (sdata); + return NULL; + } + /*printf("Recv: %s\n%s(%s), %s by %s \n Send: %s\n%s(%s), %s by %s\n via %s to %s\n", + provider->recv_type, provider->recv_hostname, provider->recv_port, provider->recv_username, provider->recv_auth, + provider->send_type, provider->send_hostname, provider->send_port, provider->send_username, provider->send_auth, + provider->recv_socket_type, provider->send_socket_type); */ + + sdata->recv = provider->recv_hostname; + sdata->recv_port = provider->recv_port; + sdata->send = provider->send_hostname; + sdata->send_port = provider->send_port; + if (strcmp (provider->recv_type, "pop3") == 0) + sdata->proto = g_strdup ("pop"); + else if (strcmp (provider->recv_type, "imap") == 0) + sdata->proto = g_strdup ("imapx"); + else + sdata->proto = provider->recv_type; + if (provider->recv_socket_type) { + CamelNetworkSecurityMethod method; + + if (g_ascii_strcasecmp (provider->recv_socket_type, "SSL") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT; + else if (g_ascii_strcasecmp (provider->recv_socket_type, "secure") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT; + else if (g_ascii_strcasecmp (provider->recv_socket_type, "STARTTLS") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT; + else if (g_ascii_strcasecmp (provider->recv_socket_type, "TLS") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT; + else + method = CAMEL_NETWORK_SECURITY_METHOD_NONE; + + sdata->security_method = method; + sdata->recv_security_method = method; + } - for (i = 0; i < len; i++) { - if (strstr (server, mail_servers[i].key) != NULL) - return &mail_servers[i]; + if (provider->send_socket_type) { + CamelNetworkSecurityMethod method; + + if (g_ascii_strcasecmp (provider->send_socket_type, "SSL") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT; + else if (g_ascii_strcasecmp (provider->send_socket_type, "secure") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT; + else if (g_ascii_strcasecmp (provider->send_socket_type, "STARTTLS") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT; + else if (g_ascii_strcasecmp (provider->send_socket_type, "TLS") == 0) + method = CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT; + else + method = CAMEL_NETWORK_SECURITY_METHOD_NONE; + + sdata->send_security_method = method; } - return NULL; + sdata->send_auth = provider->send_auth; + sdata->recv_auth = provider->recv_auth; + sdata->send_user = provider->send_username; + sdata->recv_user = provider->recv_username; + + g_free (provider); + + return sdata; +} + +static void +emae_destroy_widget (GtkWidget *widget) +{ + if (widget && GTK_IS_WIDGET (widget)) { + gtk_widget_destroy (widget); + widget = NULL; + } } static gboolean @@ -4355,7 +4467,6 @@ emae_check_complete (EConfig *ec, if (!emae->priv->receive_set) { ServerData *sdata; gchar *user, *at; - gchar *uri = g_strdup (e_account_get_string (account, E_ACCOUNT_SOURCE_URL)); CamelURL *url; emae->priv->receive_set = 1; @@ -4366,16 +4477,21 @@ emae_check_complete (EConfig *ec, user[at - tmp] = 0; at++; - sdata = emae->priv->selected_server = emae->emae_check_servers (tmp); - if (new_account && uri && (url = camel_url_new (uri, NULL)) != NULL) { + sdata = emae->priv->selected_server = emae_check_servers (tmp); + if (new_account && (url = emae_account_url (emae, E_ACCOUNT_SOURCE_URL))) { const gchar *use_user = user; + gchar *uri; + refresh = TRUE; if (sdata && sdata->recv_user && *sdata->recv_user) use_user = g_str_equal (sdata->recv_user, "@") ? tmp : sdata->recv_user; + + camel_url_set_user (url, use_user); gtk_entry_set_text (emae->priv->source.username, use_user); if (sdata != NULL) { CamelNetworkSecurityMethod method; + if (sdata->recv_security_method != CAMEL_NETWORK_SECURITY_METHOD_NONE) method = sdata->recv_security_method; else @@ -4383,15 +4499,21 @@ emae_check_complete (EConfig *ec, g_object_set (emae->priv->source.settings, "security-method", method, NULL); camel_url_set_protocol (url, sdata->proto); + emae->priv->source.protocol = sdata->proto; camel_url_set_host (url, sdata->recv); if (sdata->recv_port && *sdata->recv_port) camel_url_set_port (url, atoi (sdata->recv_port)); + + e_account_set_bool (account, E_ACCOUNT_SOURCE_AUTO_CHECK, TRUE); + e_account_set_bool (account, E_ACCOUNT_SOURCE_SAVE_PASSWD, TRUE); + if (g_strcmp0 (url->protocol, "pop") == 0) + e_account_set_bool (account, E_ACCOUNT_SOURCE_KEEP_ON_SERVER, TRUE); + gtk_entry_set_text (emae->priv->source.hostname, sdata->recv); gtk_entry_set_text (emae->priv->transport.hostname, sdata->send); } else { camel_url_set_host (url, ""); } - g_free (uri); uri = camel_url_to_string (url, 0); e_account_set_string (account, E_ACCOUNT_SOURCE_URL, uri); if (sdata != NULL && sdata->recv_auth && *sdata->recv_auth) @@ -4400,16 +4522,15 @@ emae_check_complete (EConfig *ec, sdata->recv_auth); camel_url_free (url); + g_free (uri); } else gtk_entry_set_text (emae->priv->source.username, user); - g_free (uri); } } else if (!strcmp (pageid, "30.send")) { if (!emae->priv->send_set) { CamelURL *url; gchar *at, *user; - gchar *uri = (gchar *) e_account_get_string (account, E_ACCOUNT_TRANSPORT_URL); ServerData *sdata; emae->priv->send_set = 1; @@ -4421,9 +4542,10 @@ emae_check_complete (EConfig *ec, at++; sdata = emae->priv->selected_server; - if (sdata != NULL && uri && (url = camel_url_new (uri, NULL)) != NULL) { + if (sdata != NULL && (url = emae_account_url (emae, E_ACCOUNT_TRANSPORT_URL))) { CamelNetworkSecurityMethod method; const gchar *use_user = user; + gchar *uri; refresh = TRUE; @@ -4440,10 +4562,13 @@ emae_check_complete (EConfig *ec, if (sdata->send_user && *sdata->send_user) use_user = g_str_equal (sdata->send_user, "@") ? tmp : sdata->send_user; + + camel_url_set_user (url, use_user); gtk_entry_set_text (emae->priv->transport.username, use_user); uri = camel_url_to_string (url, 0); e_account_set_string (account, E_ACCOUNT_TRANSPORT_URL, uri); + e_account_set_bool (account, E_ACCOUNT_TRANSPORT_SAVE_PASSWD, TRUE); g_free (uri); camel_url_free (url); gtk_toggle_button_set_active (emae->priv->transport.needs_auth, TRUE); @@ -4453,27 +4578,32 @@ emae_check_complete (EConfig *ec, sdata->send_auth); else emae_authtype_changed (emae->priv->transport.authtype, &emae->priv->transport); - uri = (gchar *) e_account_get_string (account, E_ACCOUNT_TRANSPORT_URL); } else gtk_entry_set_text (emae->priv->transport.username, user); } } else if (!strcmp (pageid, "20.receive_options")) { - CamelProvider *provider; + if (!emae->priv->receive_opt_set) { + CamelProvider *provider; - provider = emae_get_store_provider (emae); + provider = emae_get_store_provider (emae); - if (provider != NULL - && emae->priv->extra_provider != provider) { - emae->priv->extra_provider = provider; - emae_auto_detect (emae); + if (provider != NULL + && emae->priv->extra_provider != provider) { + emae->priv->extra_provider = provider; + emae_auto_detect (emae); + } + + emae->priv->receive_opt_set = 1; } - } else if (!strcmp (pageid, "40.management")) { - if (!emae->priv->management_set) { + } else if (!strcmp (pageid, "50.review")) { + if (!emae->priv->review_set) { gchar *template; guint i = 0, len; + gchar *uri, *enc, *buff, *cal_name; + CamelURL *url; + CamelNetworkSecurityMethod method; - emae->priv->management_set = 1; tmp = e_account_get_string (account, E_ACCOUNT_ID_ADDRESS); len = strlen (tmp); template = g_alloca (len + 14); @@ -4482,6 +4612,122 @@ emae_check_complete (EConfig *ec, sprintf (template + len, " (%d)", i++); gtk_entry_set_text (emae->priv->identity_entries[0], template); + + gtk_label_set_text (emae->priv->review_name, e_account_get_string (account, E_ACCOUNT_ID_NAME)); + gtk_label_set_text (emae->priv->review_email, e_account_get_string (account, E_ACCOUNT_ID_ADDRESS)); + uri = (gchar * ) e_account_get_string (account, E_ACCOUNT_SOURCE_URL); + if (uri && (url = camel_url_new (uri, NULL))) { + gtk_label_set_text (emae->priv->receive_stype, url->protocol); + gtk_label_set_text (emae->priv->receive_saddress, url->host); + gtk_label_set_text (emae->priv->receive_name, url->user); + g_object_get (emae->priv->source.settings, "security-method", &method, NULL); + if (method == CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT) + enc = g_strdup (_("Always(SSL)")); + else if (method == CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT) + enc = g_strdup (_("When possible(TLS)")); + else + enc = g_strdup (_("Never")); + + gtk_label_set_text (emae->priv->receive_encryption, enc); + g_free (enc); + } + uri = (gchar * ) e_account_get_string (account, E_ACCOUNT_TRANSPORT_URL); + if (uri && (url = camel_url_new (uri, NULL))) { + gtk_label_set_text (emae->priv->send_stype, url->protocol); + gtk_label_set_text (emae->priv->send_saddress, url->host); + gtk_label_set_text (emae->priv->send_name, url->user); + g_object_get (emae->priv->transport.settings, "security-method", &method, NULL); + if (method == CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT) + enc = g_strdup (_("Always(SSL)")); + else if (method == CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT) + enc = g_strdup (_("When possible(TLS)")); + else + enc = g_strdup (_("Never")); + + gtk_label_set_text (emae->priv->send_encryption, enc); + g_free (enc); + } + + if (g_strrstr (account->source->url, "gmail") || g_strrstr (account->source->url, "googlemail")) { + emae->priv->is_gmail = TRUE; + + emae_destroy_widget (emae->priv->gcontacts); + emae_destroy_widget (emae->priv->calendar); + emae_destroy_widget (emae->priv->account_label); + emae_destroy_widget (emae->priv->gmail_link); + + emae->priv->gcontacts = gtk_check_button_new_with_mnemonic (_("Setup Google con_tacts with Evolution")); + emae->priv->calendar = gtk_check_button_new_with_mnemonic (_("Setup Google ca_lendar with Evolution")); + + gtk_toggle_button_set_active ((GtkToggleButton *) emae->priv->gcontacts, TRUE); + gtk_toggle_button_set_active ((GtkToggleButton *) emae->priv->calendar, TRUE); + + gtk_widget_show (emae->priv->gcontacts); + gtk_widget_show (emae->priv->calendar); + + emae->priv->account_label = gtk_label_new (NULL); + buff = g_markup_printf_escaped ("<span size=\"large\" weight=\"bold\">%s</span>", _("Google account settings:")); + gtk_label_set_markup ((GtkLabel *) emae->priv->account_label, buff); + g_free (buff); + gtk_widget_show (emae->priv->account_label); + + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->account_label, FALSE, FALSE, 0); + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->gcontacts, FALSE, FALSE, 0); + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->calendar, FALSE, FALSE, 0); + + emae->priv->gmail_link = gtk_link_button_new_with_label ("https://mail.google.com/mail/?ui=2&shva=1#settings/fwdandpop", _("You may need to enable IMAP access.")); + gtk_widget_show (emae->priv->gmail_link); + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->gmail_link, FALSE, FALSE, 0); + + } else if ((g_strrstr(account->source->url, "yahoo.") || g_strrstr(account->source->url, "ymail.") + || g_strrstr(account->source->url, "rocketmail."))) { + + emae->priv->is_yahoo = TRUE; + + emae_destroy_widget (emae->priv->calendar); + emae_destroy_widget (emae->priv->info_label); + emae_destroy_widget (emae->priv->yahoo_cal_entry); + emae_destroy_widget (emae->priv->account_label); + emae_destroy_widget (emae->priv->yahoo_cal_box); + + emae->priv->calendar = gtk_check_button_new_with_mnemonic (_("Setup _Yahoo calendar with Evolution")); + + gtk_toggle_button_set_active ((GtkToggleButton *) emae->priv->calendar, TRUE); + + emae->priv->info_label = gtk_label_new (_("Yahoo calendars are named as firstname_lastname. We have tried to form the calendar name. So please confirm and re-enter the calendar name if it is not correct.")); + gtk_label_set_line_wrap ((GtkLabel *) emae->priv->info_label, TRUE); + gtk_label_set_line_wrap_mode ((GtkLabel *) emae->priv->info_label, PANGO_WRAP_WORD); + gtk_label_set_selectable ((GtkLabel *) emae->priv->info_label, TRUE); + + gtk_widget_show (emae->priv->calendar); + gtk_widget_show (emae->priv->info_label); + + emae->priv->account_label = gtk_label_new (NULL); + buff = g_markup_printf_escaped ("<span size=\"large\" weight=\"bold\">%s</span>", _("Yahoo account settings:")); + gtk_label_set_markup ((GtkLabel *) emae->priv->account_label, buff); + g_free (buff); + gtk_widget_show (emae->priv->account_label); + +#define PACK_IN_BOX_AND_TEXT(txt,box,child,num) { GtkWidget *txtlbl = gtk_label_new_with_mnemonic (txt); gtk_label_set_mnemonic_widget ((GtkLabel*)txtlbl, child); box = gtk_hbox_new (FALSE, 12); gtk_box_pack_start ((GtkBox *)box, txtlbl, FALSE, FALSE, num); gtk_box_pack_start ((GtkBox *)box, child, FALSE, FALSE, num); gtk_widget_show_all (box);} + + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->account_label, FALSE, FALSE, 0); + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->calendar, FALSE, FALSE, 0); + + emae->priv->yahoo_cal_entry = gtk_entry_new (); + gtk_widget_show (emae->priv->yahoo_cal_entry); + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->info_label, FALSE, FALSE, 0); + PACK_IN_BOX_AND_TEXT(_("Yahoo Calen_dar name:"), emae->priv->yahoo_cal_box, emae->priv->yahoo_cal_entry, 0); + gtk_box_pack_start ((GtkBox *) emae->priv->review_box, emae->priv->yahoo_cal_box, FALSE, FALSE, 0); + cal_name = g_strdup (e_account_get_string (account, E_ACCOUNT_ID_NAME)); + cal_name = g_strdelimit(cal_name, " ", '_'); + gtk_entry_set_text ((GtkEntry *) emae->priv->yahoo_cal_entry, cal_name); + g_free (cal_name); +#undef PACK_IN_BOX_AND_TEXT + } else { + emae->priv->is_gmail = FALSE; + emae->priv->is_yahoo = FALSE; + } + } } } @@ -4530,13 +4776,13 @@ emae_check_complete (EConfig *ec, } } - if (ok && (pageid == NULL || !strcmp (pageid, "40.management"))) { + if (ok && (pageid == NULL || !strcmp (pageid, "50.review"))) { ok = (tmp = e_account_get_string (account, E_ACCOUNT_NAME)) && tmp[0] && ((ea = e_get_account_by_name (tmp)) == NULL || ea == original_account); if (!ok) { - d (printf ("management page incomplete\n")); + d (printf ("review page incomplete\n")); } } @@ -4589,6 +4835,211 @@ forget_password_if_needed (EAccount *original_account, } } +#define CALENDAR_CALDAV_URI "caldav://%s@www.google.com/calendar/dav/%s/events" +#define GMAIL_CALENDAR_LOCATION "://www.google.com/calendar/feeds/" +#define CALENDAR_DEFAULT_PATH "/private/full" +#define SELECTED_CALENDARS "/apps/evolution/calendar/display/selected_calendars" +#define YAHOO_CALENDAR_LOCATION "%s@caldav.calendar.yahoo.com/dav/%s/Calendar/%s" + +static gchar * +sanitize_user_mail (const gchar *user) +{ + if (!user) + return NULL; + + if (strstr (user, "%40") != NULL) { + return g_strdup (user); + } else if (!is_email (user)) { + return g_strconcat (user, "%40gmail.com", NULL); + } else { + gchar *tmp = g_malloc0 (sizeof (gchar) * (1 + strlen (user) + 2)); + gchar *at = strchr (user, '@'); + + strncpy (tmp, user, at - user); + strcat (tmp, "%40"); + strcat (tmp, at + 1); + + return tmp; + } +} + +static void +setup_google_addressbook (EMAccountEditor *emae) +{ + GConfClient *gconf; + ESourceList *slist; + ESourceGroup *sgrp; + GSList *sources; + gboolean source_already_exists = FALSE; + CamelURL *url; + gchar * username; + + gconf = gconf_client_get_default (); + slist = e_source_list_new_for_gconf (gconf, "/apps/evolution/addressbook/sources" ); + sgrp = e_source_list_ensure_group (slist, _("Google"), "google://", TRUE); + url = emae_account_url (emae, E_ACCOUNT_SOURCE_URL); + username = g_strdup (url->user); + + sources = e_source_group_peek_sources (sgrp); + for (; sources; sources = sources->next) { + ESource *existing = (ESource *) sources->data; + if (!g_strcmp0 (e_source_peek_relative_uri (existing), username)) { + source_already_exists = TRUE; + break; + } + } + + if (!source_already_exists) { + ESource *abook; + + /* FIXME: Not sure if we should localize 'Contacts' */ + abook = e_source_new ("Contacts", ""); + e_source_set_property (abook, "default", "true"); + e_source_set_property (abook, "offline_sync", "1"); + e_source_set_property (abook, "auth", "plain/password"); + e_source_set_property (abook, "use-ssl", "true"); + e_source_set_property (abook, "remember_password", "true"); + e_source_set_property (abook, "refresh-interval", "86400"); + e_source_set_property (abook, "completion", "true"); + e_source_set_property (abook, "username", username); + + e_source_group_add_source (sgrp, abook, -1); + e_source_set_relative_uri (abook, username); + e_source_list_sync (slist, NULL); + + g_object_unref (abook); + } + + g_free (username); + g_object_unref (slist); + g_object_unref (sgrp); + g_object_unref (gconf); +} + +static void +setup_google_calendar (EMAccountEditor *emae) +{ + GConfClient *gconf; + ESourceList *slist; + ESourceGroup *sgrp; + ESource *calendar; + gchar *sanitize_uname, *username; + gchar *abs_uri, *rel_uri; + GSList *ids, *temp; + CamelURL *url; + + gconf = gconf_client_get_default (); + slist = e_source_list_new_for_gconf (gconf, "/apps/evolution/calendar/sources"); + sgrp = e_source_list_ensure_group (slist, _("Google"), "google://", TRUE); + url = emae_account_url (emae, E_ACCOUNT_SOURCE_URL); + username = g_strdup (url->user); + + /* FIXME: Not sure if we should localize 'Calendar' */ + calendar = e_source_new ("Calendar", ""); + e_source_set_property (calendar, "ssl", "1"); + e_source_set_property (calendar, "refresh", "30"); + e_source_set_property (calendar, "auth", "1"); + e_source_set_property (calendar, "offline_sync", "1"); + e_source_set_property (calendar, "username", username); + e_source_set_property (calendar, "setup-username", username); + e_source_set_property (calendar, "default", "true"); + e_source_set_property (calendar, "alarm", "true"); + e_source_set_readonly (calendar, FALSE); + + e_source_group_add_source (sgrp, calendar, -1); + + sanitize_uname = sanitize_user_mail (username); + + abs_uri = g_strdup_printf (CALENDAR_CALDAV_URI, sanitize_uname, username); + e_source_set_absolute_uri (calendar, abs_uri); + + rel_uri = g_strconcat ("https", GMAIL_CALENDAR_LOCATION, sanitize_uname, CALENDAR_DEFAULT_PATH, NULL); + e_source_set_relative_uri (calendar, rel_uri); + + e_source_list_sync (slist, NULL); + + ids = gconf_client_get_list (gconf, SELECTED_CALENDARS, GCONF_VALUE_STRING, NULL); + ids = g_slist_append (ids, g_strdup (e_source_peek_uid (calendar))); + gconf_client_set_list (gconf, SELECTED_CALENDARS, GCONF_VALUE_STRING, ids, NULL); + temp = ids; + + for (; temp != NULL; temp = g_slist_next (temp)) + g_free (temp->data); + + g_free (username); + g_slist_free (ids); + g_free (abs_uri); + g_free (rel_uri); + g_free (sanitize_uname); + g_object_unref (slist); + g_object_unref (sgrp); + g_object_unref (calendar); + g_object_unref (gconf); +} + +static void +setup_yahoo_calendar (EMAccountEditor *emae) +{ + GConfClient *gconf; + ESourceList *slist; + ESourceGroup *sgrp; + ESource *calendar; + gchar *sanitize_uname; + gchar *abs_uri, *rel_uri; + GSList *ids, *temp; + const gchar *email; + + gconf = gconf_client_get_default (); + email = e_account_get_string (em_account_editor_get_modified_account (emae), E_ACCOUNT_ID_ADDRESS); + slist = e_source_list_new_for_gconf (gconf, "/apps/evolution/calendar/sources"); + sgrp = e_source_list_peek_group_by_base_uri (slist, "caldav://"); + if (!sgrp) { + sgrp = e_source_list_ensure_group (slist, _("CalDAV"), "caldav://", TRUE); + } + + printf("Setting up Yahoo Calendar: list:%p CalDAVGrp: %p\n", slist, sgrp); + + /* FIXME: Not sure if we should localize 'Calendar' */ + calendar = e_source_new ("Yahoo", ""); + e_source_set_property (calendar, "ssl", "1"); + e_source_set_property (calendar, "refresh", "30"); + e_source_set_property (calendar, "refresh-type", "0"); + e_source_set_property (calendar, "auth", "1"); + e_source_set_property (calendar, "offline_sync", "1"); + e_source_set_property (calendar, "username", email); + e_source_set_property (calendar, "default", "true"); + e_source_set_property (calendar, "alarm", "true"); + + e_source_set_readonly (calendar, FALSE); + + sanitize_uname = sanitize_user_mail (email); + + abs_uri = g_strdup_printf ("caldav://%s@caldav.calendar.yahoo.com/dav/%s/Calendar/%s/", + sanitize_uname, email, gtk_entry_get_text ((GtkEntry *) emae->priv->yahoo_cal_entry)); + rel_uri = g_strdup_printf (YAHOO_CALENDAR_LOCATION, sanitize_uname, email, gtk_entry_get_text ((GtkEntry *) emae->priv->yahoo_cal_entry)); + e_source_set_relative_uri (calendar, rel_uri); + + e_source_group_add_source (sgrp, calendar, -1); + e_source_list_sync (slist, NULL); + + ids = gconf_client_get_list (gconf, SELECTED_CALENDARS, GCONF_VALUE_STRING, NULL); + ids = g_slist_append (ids, g_strdup (e_source_peek_uid (calendar))); + gconf_client_set_list (gconf, SELECTED_CALENDARS, GCONF_VALUE_STRING, ids, NULL); + temp = ids; + + for (; temp != NULL; temp = g_slist_next (temp)) + g_free (temp->data); + + g_slist_free (ids); + g_free (abs_uri); + g_free (rel_uri); + g_free (sanitize_uname); + g_object_unref (slist); + g_object_unref (sgrp); + g_object_unref (calendar); + g_object_unref (gconf); +} + static void emae_commit (EConfig *ec, EMAccountEditor *emae) @@ -4605,6 +5056,17 @@ emae_commit (EConfig *ec, modified_account = em_account_editor_get_modified_account (emae); original_account = em_account_editor_get_original_account (emae); + /* check for google and yahoo specific settings */ + if (!original_account && emae->priv->is_gmail) { + if (gtk_toggle_button_get_active ((GtkToggleButton *) emae->priv->gcontacts)) + setup_google_addressbook (emae); + if (gtk_toggle_button_get_active ((GtkToggleButton *) emae->priv->calendar)) + setup_google_calendar (emae); + } else if (!original_account && emae->priv->is_gmail) { + if (gtk_toggle_button_get_active ((GtkToggleButton *) emae->priv->calendar)) + setup_yahoo_calendar (emae); + } + /* Do some last minute tweaking. */ settings = emae->priv->source.settings; |