diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-05-27 01:09:33 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-05-27 01:09:33 +0800 |
commit | c9ec8c3f4dce2b02c91268529977770364ef87fe (patch) | |
tree | d574f2be1b5438407e59e2fead1321766c9bbc83 /capplet/settings | |
parent | 6fec6bf39467dd32625847be1b021a7e5bc94d76 (diff) | |
parent | 96538878911586a9e9ca26b81e1916c04e538980 (diff) | |
download | gsoc2013-evolution-c9ec8c3f4dce2b02c91268529977770364ef87fe.tar.gz gsoc2013-evolution-c9ec8c3f4dce2b02c91268529977770364ef87fe.tar.zst gsoc2013-evolution-c9ec8c3f4dce2b02c91268529977770364ef87fe.zip |
Merge branch 'express2'
Diffstat (limited to 'capplet/settings')
-rw-r--r-- | capplet/settings/mail-account-view.c | 500 | ||||
-rw-r--r-- | capplet/settings/mail-account-view.h | 1 | ||||
-rw-r--r-- | capplet/settings/mail-guess-servers.c | 22 |
3 files changed, 470 insertions, 53 deletions
diff --git a/capplet/settings/mail-account-view.c b/capplet/settings/mail-account-view.c index 6e2299b308..54401412e2 100644 --- a/capplet/settings/mail-account-view.c +++ b/capplet/settings/mail-account-view.c @@ -26,14 +26,31 @@ #include <glib/gi18n.h> #include "mail-account-view.h" +#include <libedataserverui/e-passwords.h> +#include <libedataserver/e-source-group.h> +#include <libedataserver/e-source-list.h> #include <libedataserver/e-account-list.h> #include "mail-view.h" #include "e-util/e-config.h" #include "mail/mail-config.h" +#include "mail/mail-session.h" #include "mail-guess-servers.h" struct _MailAccountViewPrivate { GtkWidget *tab_str; + + GtkWidget *calendar; + GtkWidget *gcontacts; + GtkWidget *gmail_info_label; + + gboolean is_gmail; + gboolean is_yahoo; + gboolean do_gcontacts; + gboolean do_calendar; + + gchar *username; + + GtkWidget *yahoo_cal_entry; }; G_DEFINE_TYPE (MailAccountView, mail_account_view, GTK_TYPE_VBOX) @@ -47,6 +64,7 @@ enum { ERROR_NO_FULLNAME = 1, ERROR_NO_EMAIL = 2, ERROR_INVALID_EMAIL = 3, + ERROR_NO_PASSWORD = 4, }; struct _dialog_errors { @@ -56,6 +74,7 @@ struct _dialog_errors { { ERROR_NO_FULLNAME, N_("Please enter your full name.") }, { ERROR_NO_EMAIL, N_("Please enter your email address.") }, { ERROR_INVALID_EMAIL, N_("The email address you have entered is invalid.") }, + { ERROR_NO_PASSWORD, N_("Please enter your password.") } }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -64,12 +83,17 @@ mail_account_view_init (MailAccountView *shell) { shell->priv = g_new0(MailAccountViewPrivate, 1); + shell->priv->is_gmail = FALSE; + shell->priv->is_yahoo = FALSE; + shell->priv->username = NULL; } static void mail_account_view_finalize (GObject *object) { - /*MailAccountView *shell = (MailAccountView *)object;*/ + MailAccountView *shell = (MailAccountView *)object; + + g_free(shell->priv->username); G_OBJECT_CLASS (mail_account_view_parent_class)->finalize (object); } @@ -136,11 +160,17 @@ validate_identity (MailAccountView *view) gchar *user = (gchar *)e_account_get_string(em_account_editor_get_modified_account(view->edit), E_ACCOUNT_ID_NAME); gchar *email = (gchar *)e_account_get_string(em_account_editor_get_modified_account(view->edit), E_ACCOUNT_ID_ADDRESS); gchar *tmp; + const gchar *pwd = gtk_entry_get_text ((GtkEntry *)view->password); if (!user || !*user) return ERROR_NO_FULLNAME; if (!email || !*email) return ERROR_NO_EMAIL; + if (view->original) /* We don't query/store pwd on edit. */ + return 0; + if (!pwd || !*pwd) + return ERROR_NO_PASSWORD; + tmp = strchr(email, '@'); if (!tmp || tmp[1] == 0) return ERROR_INVALID_EMAIL; @@ -162,6 +192,258 @@ save_account (MailAccountView *view) #define PACK_BOX(w) box = gtk_hbox_new(FALSE, 0); gtk_box_pack_start((GtkBox *)box, w, FALSE, FALSE, 12); gtk_widget_show(box); #define PACK_BOXF(w) box = gtk_hbox_new(FALSE, 0); gtk_box_pack_start((GtkBox *)box, w, FALSE, FALSE, 0); gtk_widget_show(box); +#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 gboolean +is_email (const gchar *address) +{ + /* This is supposed to check if the address's domain could be + an FQDN but alas, it's not worth the pain and suffering. */ + const gchar *at; + + at = strchr (address, '@'); + /* make sure we have an '@' and that it's not the first or last gchar */ + if (!at || at == address || *(at + 1) == '\0') + return FALSE; + + return TRUE; +} + +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_yahoo_account (MailAccountView *mav) +{ + GConfClient *gconf = gconf_client_get_default (); + + mav->priv->do_gcontacts = gtk_toggle_button_get_active((GtkToggleButton *)mav->priv->gcontacts); + mav->priv->do_calendar = gtk_toggle_button_get_active((GtkToggleButton *)mav->priv->calendar); + + if (mav->priv->do_calendar) { + ESourceList *slist; + ESourceGroup *sgrp; + ESource *calendar; + gchar *sanitize_uname, *abs_uri, *rel_uri; + GSList *ids, *temp; + const gchar *email = e_account_get_string(em_account_editor_get_modified_account(mav->edit), 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 *)mav->priv->yahoo_cal_entry)); + e_passwords_add_password (abs_uri, gtk_entry_get_text((GtkEntry *)mav->password)); + e_passwords_remember_password ("Calendar", abs_uri); + + rel_uri = g_strdup_printf (YAHOO_CALENDAR_LOCATION, sanitize_uname, email, gtk_entry_get_text((GtkEntry *)mav->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); + } else + printf("Not setting up Yahoo Calendar\n"); + + if (mav->priv->do_gcontacts) { + ESourceList *slist; + ESourceGroup *sgrp; + ESource *abook; + gchar *rel_uri;; + + slist = e_source_list_new_for_gconf (gconf, "/apps/evolution/addressbook/sources" ); + + sgrp = e_source_list_peek_group_by_base_uri (slist, "google://"); + + /* 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", mav->priv->username); + e_source_set_relative_uri (abook, mav->priv->username); + + rel_uri = g_strdup_printf("google://%s/", mav->priv->username); + e_passwords_add_password (rel_uri, gtk_entry_get_text((GtkEntry *)mav->password)); + e_passwords_remember_password ("Addressbook", rel_uri); + e_source_group_add_source (sgrp, abook, -1); + e_source_list_sync (slist, NULL); + + g_free(rel_uri); + g_object_unref(slist); + g_object_unref(sgrp); + g_object_unref(abook); + + } + + g_object_unref (gconf); +} + +static void +setup_google_accounts (MailAccountView *mav) +{ + GConfClient *gconf = gconf_client_get_default (); + + mav->priv->do_gcontacts = gtk_toggle_button_get_active((GtkToggleButton *)mav->priv->gcontacts); + mav->priv->do_calendar = gtk_toggle_button_get_active((GtkToggleButton *)mav->priv->calendar); + + if (mav->priv->do_calendar) { + ESourceList *slist; + ESourceGroup *sgrp; + ESource *calendar; + gchar *sanitize_uname, *abs_uri, *rel_uri; + GSList *ids, *temp; + + slist = e_source_list_new_for_gconf (gconf, "/apps/evolution/calendar/sources"); + sgrp = e_source_list_peek_group_by_base_uri (slist, "google://"); + if (!sgrp) { + sgrp = e_source_list_ensure_group (slist, _("Google"), "google://", TRUE); + } + + printf("Setting up Google Calendar: list:%p GoogleGrp: %p\n", slist, sgrp); + + /* 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", mav->priv->username); + e_source_set_property (calendar, "setup-username", mav->priv->username); + e_source_set_property (calendar, "default", "true"); + e_source_set_readonly (calendar, FALSE); + + sanitize_uname = sanitize_user_mail (mav->priv->username); + + abs_uri = g_strdup_printf (CALENDAR_CALDAV_URI, sanitize_uname, mav->priv->username); + e_source_set_absolute_uri (calendar, abs_uri); + + e_passwords_add_password (abs_uri, gtk_entry_get_text((GtkEntry *)mav->password)); + e_passwords_remember_password ("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_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); + } else + printf("Not setting up Google Calendar\n"); + + if (mav->priv->do_gcontacts) { + ESourceList *slist; + ESourceGroup *sgrp; + ESource *abook; + gchar *rel_uri;; + + slist = e_source_list_new_for_gconf (gconf, "/apps/evolution/addressbook/sources" ); + + sgrp = e_source_list_peek_group_by_base_uri (slist, "google://"); + + /* 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", mav->priv->username); + e_source_set_relative_uri (abook, mav->priv->username); + + rel_uri = g_strdup_printf("google://%s/", mav->priv->username); + e_passwords_add_password (rel_uri, gtk_entry_get_text((GtkEntry *)mav->password)); + e_passwords_remember_password ("Addressbook", rel_uri); + e_source_group_add_source (sgrp, abook, -1); + e_source_list_sync (slist, NULL); + + g_free(rel_uri); + g_object_unref(slist); + g_object_unref(sgrp); + g_object_unref(abook); + + } + + g_object_unref (gconf); +} + +#define INDENTATION 10 + static GtkWidget * create_review (MailAccountView *view) { @@ -184,128 +466,115 @@ create_review (MailAccountView *view) g_free (buff); gtk_widget_show (label); PACK_BOXF(label) - gtk_table_attach ((GtkTable *)table, box, 0, 1, 0, 1, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 0, 1, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (_("Name:")); gtk_widget_show (label); PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 1, 2, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 1, 2, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); entry = gtk_label_new(e_account_get_string(em_account_editor_get_modified_account(view->edit), E_ACCOUNT_ID_NAME)); gtk_widget_show(entry); PACK_BOX(entry) - gtk_table_attach ((GtkTable *)table, box, 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (_("Email address:")); gtk_widget_show (label); PACK_BOX(label) - gtk_table_attach ((GtkTable *)table, box, 0, 1, 2, 3, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 2, 3, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); entry = gtk_label_new (e_account_get_string(em_account_editor_get_modified_account(view->edit), E_ACCOUNT_ID_ADDRESS)); gtk_widget_show(entry); PACK_BOX(entry) - gtk_table_attach ((GtkTable *)table, box, 1, 2, 2, 3, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 2, 3, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (NULL); - buff = g_strconcat ("<span size=\"large\" weight=\"bold\">", _("Receiving details:"), "</span>", NULL); - gtk_label_set_markup ((GtkLabel *)label, buff); - g_free (buff); + gtk_label_set_markup ((GtkLabel *)label, _("<span size=\"large\" weight=\"bold\">Details:</span>")); + gtk_widget_show (label); + PACK_BOXF(label); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 3, 4, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); + + label = gtk_label_new (NULL); + gtk_label_set_markup ((GtkLabel *)label, _("<span size=\"large\" weight=\"bold\">Receiving</span>")); gtk_widget_show (label); PACK_BOXF(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 3, 4, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 3, 4, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (_("Server type:")); gtk_widget_show (label); PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 4, 5, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 4, 5, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); entry = gtk_label_new (url->protocol); gtk_widget_show(entry); PACK_BOX(entry) - gtk_table_attach ((GtkTable *)table, box, 1, 2, 4, 5, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 4, 5, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (_("Server address:")); gtk_widget_show (label); PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 5, 6, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 5, 6, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); entry = gtk_label_new (url->host); gtk_widget_show(entry); PACK_BOX(entry); - gtk_table_attach ((GtkTable *)table, box, 1, 2, 5, 6, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 5, 6, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (_("Username:")); gtk_widget_show (label); PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 6, 7, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 6, 7, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); entry = gtk_label_new (url->user); gtk_widget_show(entry); PACK_BOX(entry); - gtk_table_attach ((GtkTable *)table, box, 1, 2, 6, 7, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 6, 7, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); label = gtk_label_new (_("Use encryption:")); gtk_widget_show (label); PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 7, 8, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 0, 1, 7, 8, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); enc = (gchar *)camel_url_get_param(url, "use_ssl"); entry = gtk_label_new (enc ? enc : _("never")); gtk_widget_show(entry); PACK_BOX(entry); - gtk_table_attach ((GtkTable *)table, box, 1, 2, 7, 8, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 1, 2, 7, 8, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); + view->priv->username = g_strdup(url->user); camel_url_free(url); uri =(gchar *) e_account_get_string(em_account_editor_get_modified_account(view->edit), E_ACCOUNT_TRANSPORT_URL); if (!uri || (url = camel_url_new(uri, NULL)) == NULL) return NULL; label = gtk_label_new (NULL); - buff = g_strconcat ("<span size=\"large\" weight=\"bold\">", _("Sending details:"), "</span>", NULL); - gtk_label_set_markup ((GtkLabel *)label, buff); - g_free (buff); + gtk_label_set_markup ((GtkLabel *)label, _("<span size=\"large\" weight=\"bold\">Sending</span>")); gtk_widget_show (label); PACK_BOXF(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 8, 9, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 2, 3, 3, 4, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); - label = gtk_label_new (_("Server type:")); - gtk_widget_show (label); - PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 9, 10, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); entry = gtk_label_new (url->protocol); gtk_widget_show(entry); PACK_BOX(entry) - gtk_table_attach ((GtkTable *)table, box, 1, 2, 9, 10, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 2, 3, 4, 5, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); - label = gtk_label_new (_("Server address:")); - gtk_widget_show (label); - PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 10, 11, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); entry = gtk_label_new (url->host); gtk_widget_show(entry); PACK_BOX(entry); - gtk_table_attach ((GtkTable *)table, box, 1, 2, 10, 11, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 2, 3, 5, 6, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); - label = gtk_label_new (_("Username:")); - gtk_widget_show (label); - PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 11, 12, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); entry = gtk_label_new (url->user); gtk_widget_show(entry); PACK_BOX(entry); - gtk_table_attach ((GtkTable *)table, box, 1, 2, 11, 12, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 2, 3, 6, 7, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); - label = gtk_label_new (_("Use encryption:")); - gtk_widget_show (label); - PACK_BOX(label); - gtk_table_attach ((GtkTable *)table, box, 0, 1, 12, 13, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); enc = (gchar *)camel_url_get_param(url, "use_ssl"); entry = gtk_label_new (enc ? enc : _("never")); gtk_widget_show(entry); PACK_BOX(entry); - gtk_table_attach ((GtkTable *)table, box, 1, 2, 12, 13, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach ((GtkTable *)table, box, 2, 3, 7, 8, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); /* label = gtk_label_new (_("Organization:")); gtk_widget_show (label); entry = gtk_entry_new (); gtk_widget_show(entry); - gtk_table_attach (table, label, 0, 1, 3, 4, GTK_SHRINK, GTK_SHRINK, 10, 3); - gtk_table_attach (table, entry, 1, 2, 3, 4, GTK_EXPAND|GTK_FILL, GTK_SHRINK, 10, 3); + gtk_table_attach (table, label, 0, 1, 3, 4, GTK_SHRINK, GTK_SHRINK, INDENTATION, 0); + gtk_table_attach (table, entry, 1, 2, 3, 4, GTK_EXPAND|GTK_FILL, GTK_SHRINK, INDENTATION, 0); */ gtk_widget_show(table); @@ -385,6 +654,25 @@ mav_next_pressed (GtkButton *button, MailAccountView *mav) g_free(uri); camel_url_free(url); } + + if (!mav->original) { + EAccount *account = em_account_editor_get_modified_account(mav->edit); + CamelURL *aurl; + gchar *surl; + /* Save the password ahead of time */ + aurl = camel_url_new (account->source->url, NULL); + surl = camel_url_to_string(aurl, CAMEL_URL_HIDE_ALL); + e_passwords_add_password (surl, gtk_entry_get_text((GtkEntry *)mav->password)); + e_passwords_remember_password ("Mail", surl); + camel_url_free(aurl); + g_free(surl); + } + + if (mav->priv->is_gmail && !mav->original) + setup_google_accounts (mav); + else if (mav->priv->is_yahoo && !mav->original) + setup_yahoo_account (mav); + em_account_editor_commit (mav->edit); g_signal_emit (mav, signals[VIEW_CLOSE], 0); return; @@ -400,6 +688,7 @@ mav_next_pressed (GtkButton *button, MailAccountView *mav) if (mav->current_page == MAV_LAST - 1) { MAVPage *page = mav->pages[mav->current_page]; GtkWidget *tmp; + EAccount *account = em_account_editor_get_modified_account(mav->edit); if (page->main) gtk_widget_destroy (page->main); @@ -410,6 +699,96 @@ mav_next_pressed (GtkButton *button, MailAccountView *mav) gtk_box_pack_start((GtkBox *)page->main, tmp, FALSE, FALSE, 0); gtk_widget_show(tmp); gtk_box_pack_start((GtkBox *)page->box, page->main, FALSE, FALSE, 3); + + if (mav->priv->is_gmail) { + gtk_widget_destroy (mav->priv->gcontacts); + gtk_widget_destroy (mav->priv->calendar); + gtk_widget_destroy (mav->priv->gmail_info_label); + } else if (mav->priv->is_yahoo) { + gtk_widget_destroy (mav->priv->calendar); + gtk_widget_destroy (mav->priv->gmail_info_label); + gtk_widget_destroy (mav->priv->yahoo_cal_entry); + } + + if (mav->original == NULL && (g_strrstr(account->source->url, "gmail") || + g_strrstr(account->source->url, "googlemail"))) { + /* Google accounts*/ + GtkWidget *tmp; + mav->priv->is_gmail = TRUE; + + mav->priv->gcontacts = gtk_check_button_new_with_label (_("Setup Google contacts with Evolution")); + mav->priv->calendar = gtk_check_button_new_with_label (_("Setup Google calendar with Evolution")); + + gtk_toggle_button_set_active ((GtkToggleButton *)mav->priv->gcontacts, TRUE); + gtk_toggle_button_set_active ((GtkToggleButton *)mav->priv->calendar, TRUE); + + mav->priv->gmail_info_label = gtk_label_new (_("You may need to enable IMAP access.")); + gtk_label_set_selectable ((GtkLabel *)mav->priv->gmail_info_label, TRUE); + + gtk_widget_show (mav->priv->gcontacts); + gtk_widget_show (mav->priv->calendar); + gtk_widget_show (mav->priv->gmail_info_label); + + tmp = gtk_label_new (NULL); + gtk_label_set_markup ((GtkLabel *)tmp, _("<span size=\"large\" weight=\"bold\">Google account settings:</span>")); + gtk_widget_show(tmp); + +#define PACK_IN_BOX(wid,child,num) { GtkWidget *tbox; tbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start ((GtkBox *)tbox, child, FALSE, FALSE, num); gtk_widget_show (tbox); gtk_box_pack_start ((GtkBox *)wid, tbox, FALSE, FALSE, 0); } + + PACK_IN_BOX(page->box,tmp,12); + PACK_IN_BOX(page->box,mav->priv->gcontacts,24); + PACK_IN_BOX(page->box,mav->priv->calendar,24); +#undef PACK_IN_BOX +#define PACK_IN_BOX(wid,child1,child2,num1,num2) { GtkWidget *tbox; tbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start ((GtkBox *)tbox, child1, FALSE, FALSE, num1); gtk_box_pack_start ((GtkBox *)tbox, child2, FALSE, FALSE, num2); gtk_widget_show_all (tbox); gtk_box_pack_start ((GtkBox *)wid, tbox, FALSE, FALSE, 0); } + + PACK_IN_BOX(page->box,mav->priv->gmail_info_label,gtk_link_button_new("https://mail.google.com/mail/?ui=2&shva=1#settings/fwdandpop"), 24, 0); +#undef PACK_IN_BOX + } else if (mav->original == NULL && + (g_strrstr(account->source->url, "yahoo.") || + g_strrstr(account->source->url, "ymail.") || + g_strrstr(account->source->url, "rocketmail."))) { + /* Yahoo accounts*/ + GtkWidget *tmp; + gchar *cal_name; + GtkWidget *tmpbox; + + mav->priv->is_yahoo = TRUE; + printf("Google account: %s\n", account->source->url); + mav->priv->calendar = gtk_check_button_new_with_label (_("Setup Yahoo calendar with Evolution")); + + gtk_toggle_button_set_active ((GtkToggleButton *)mav->priv->calendar, TRUE); + + mav->priv->gmail_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_selectable ((GtkLabel *)mav->priv->gmail_info_label, TRUE); + + gtk_widget_show (mav->priv->calendar); + gtk_widget_show (mav->priv->gmail_info_label); + + tmp = gtk_label_new (NULL); + gtk_label_set_markup ((GtkLabel *)tmp, _("<span size=\"large\" weight=\"bold\">Yahoo account settings:</span>")); + gtk_widget_show(tmp); + +#define PACK_IN_BOX(wid,child,num) { GtkWidget *tbox; tbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start ((GtkBox *)tbox, child, FALSE, FALSE, num); gtk_widget_show (tbox); gtk_box_pack_start ((GtkBox *)wid, tbox, FALSE, FALSE, 0); } +#define PACK_IN_BOX_AND_TEXT(txt, child,num) { GtkWidget *txtlbl = gtk_label_new (txt); tmpbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start ((GtkBox *)tmpbox, txtlbl, FALSE, FALSE, num); gtk_box_pack_start ((GtkBox *)tmpbox, child, FALSE, FALSE, num); gtk_widget_show_all (tmpbox);} + + PACK_IN_BOX(page->box,tmp,12); + PACK_IN_BOX(page->box,mav->priv->calendar,24); + + mav->priv->yahoo_cal_entry = gtk_entry_new (); + gtk_widget_show (mav->priv->yahoo_cal_entry); + PACK_IN_BOX(page->box,mav->priv->gmail_info_label, 24); + PACK_IN_BOX_AND_TEXT(_("Yahoo Calendar name:"), mav->priv->yahoo_cal_entry, 0); + PACK_IN_BOX(page->box, tmpbox, 24); + cal_name = g_strdup(e_account_get_string(em_account_editor_get_modified_account(mav->edit), E_ACCOUNT_ID_NAME)); + cal_name = g_strdelimit(cal_name, " ", '_'); + gtk_entry_set_text ((GtkEntry *)mav->priv->yahoo_cal_entry, cal_name); + g_free (cal_name); +#undef PACK_IN_BOX + } else { + mav->priv->is_gmail = FALSE; + mav->priv->is_yahoo = FALSE; + } + } gtk_widget_show (mav->pages[mav->current_page]->box); @@ -516,6 +895,9 @@ mav_construct_page(MailAccountView *view, MAVPageType type) gtk_box_pack_start((GtkBox *)box, tmp, FALSE, FALSE, 0); } page->next = gtk_button_new (); + gtk_widget_set_can_default (page->next, TRUE); + g_signal_connect (page->next, "hierarchy-changed", + G_CALLBACK (gtk_widget_grab_default), NULL); gtk_container_add ((GtkContainer *)page->next, box); gtk_widget_show_all(page->next); g_signal_connect(page->next, "clicked", G_CALLBACK(mav_next_pressed), view); @@ -593,9 +975,16 @@ emae_check_servers (const gchar *email) } static void +next_page (GtkWidget *entry, MailAccountView *mav) +{ + mav_next_pressed (NULL, mav); +} + +static void mail_account_view_construct (MailAccountView *view) { gint i; + EShell *shell; view->scroll = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy ((GtkScrolledWindow *)view->scroll, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); @@ -623,8 +1012,29 @@ mail_account_view_construct (MailAccountView *view) em_account_editor_check (view->edit, mail_account_pages[0].path); view->pages[0]->done = TRUE; - if (e_shell_get_express_mode (e_shell_get_default ())) + shell = e_shell_get_default (); + if (!shell || e_shell_get_express_mode (shell)) { + GtkWidget *table = em_account_editor_get_widget (view->edit, "identity_required_table"); + GtkWidget *label, *pwd; gtk_widget_hide (em_account_editor_get_widget (view->edit, "identity_optional_frame")); + + if (!view->original) { + label = gtk_label_new (_("Password:")); + pwd = gtk_entry_new (); + gtk_entry_set_visibility ((GtkEntry *)pwd, FALSE); +/* gtk_entry_set_activates_default ((GtkEntry *)pwd, TRUE); */ + g_signal_connect (pwd, "activate", G_CALLBACK (next_page), view); + gtk_widget_show(label); + gtk_widget_show(pwd); + gtk_table_attach ((GtkTable *)table, label, 0, 1, 2, 3, GTK_FILL, 0, 0, 0); + gtk_table_attach ((GtkTable *)table, pwd, 1, 2, 2, 3, GTK_FILL|GTK_EXPAND, 0, 0, 0); + + view->password = pwd; + } + } + + /* assume the full name is known from the system */ + gtk_widget_grab_focus (em_account_editor_get_widget (view->edit, "identity_address")); } MailAccountView * diff --git a/capplet/settings/mail-account-view.h b/capplet/settings/mail-account-view.h index df0a7a1114..3d01156e5b 100644 --- a/capplet/settings/mail-account-view.h +++ b/capplet/settings/mail-account-view.h @@ -74,6 +74,7 @@ typedef struct _MailAccountView { GtkWidget *wpages[6]; gint current_page; struct _EMAccountEditor *edit; + GtkWidget *password; MailAccountViewPrivate *priv; } MailAccountView; diff --git a/capplet/settings/mail-guess-servers.c b/capplet/settings/mail-guess-servers.c index fe71153655..d6a65e8c53 100644 --- a/capplet/settings/mail-guess-servers.c +++ b/capplet/settings/mail-guess-servers.c @@ -42,6 +42,8 @@ #include <libxml/tree.h> #include <libxml/xmlmemory.h> +#include <libedataserver/e-proxy.h> + #include <shell/e-shell.h> #include "mail-guess-servers.h" @@ -242,13 +244,15 @@ guess_when_online (EmailProvider *provider) { const gchar *cafile = NULL; gchar *url; - SoupURI *proxy = NULL, *parsed; + EProxy *proxy; + SoupURI *parsed; SoupMessage *msg; SoupSession *session; - url = g_strdup_printf ( - "https://live.mozillamessaging.com/autoconfig/%s", - provider->domain); + proxy = e_proxy_new (); + e_proxy_setup_proxy (proxy); + + url = g_strdup_printf("%s/%s", "http://api.gnome.org/evolution/autoconfig", provider->domain); parsed = soup_uri_new (url); soup_uri_free (parsed); @@ -257,10 +261,11 @@ guess_when_online (EmailProvider *provider) SOUP_SESSION_USER_AGENT, "get ", NULL); - if (proxy) { - g_object_set (G_OBJECT (session), - SOUP_SESSION_PROXY_URI, proxy, - NULL); + if (e_proxy_require_proxy_for_uri (proxy, url)) { + SoupURI *proxy_uri = e_proxy_peek_uri_for (proxy, url); +/* fprintf (stderr, "URL '%s' requires a proxy: '%s'\n", + url, soup_uri_to_string (proxy_uri, FALSE)); */ + g_object_set (session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL); } msg = get_url (session, url); @@ -269,6 +274,7 @@ guess_when_online (EmailProvider *provider) parse_soup_message (msg, provider); + g_object_unref (proxy); g_object_unref (msg); g_object_unref(session); g_free(url); |