[evolution-activesync] Add auto detect button
- From: dwmw2 <dwmw2 src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-activesync] Add auto detect button
- Date: Thu, 11 Jun 2015 16:01:24 +0000 (UTC)
commit 91164629580256b6dde29da6d115c3128edbbae9
Author: Oliver Luo <lyc pku eecs gmail com>
Date: Sat Jun 6 22:59:49 2015 +0800
Add auto detect button
Add auto detect button to detect the server url using ActiveSync's auto
discover function.
configuration/Makefile.am | 3 +-
configuration/e-mail-config-eas-backend.c | 65 ++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 6 deletions(-)
---
diff --git a/configuration/Makefile.am b/configuration/Makefile.am
index 3d6a5b5..e133e3b 100644
--- a/configuration/Makefile.am
+++ b/configuration/Makefile.am
@@ -4,7 +4,7 @@ evo_module_LTLIBRARIES = module-eas-mail-config.la
module_eas_mail_config_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
- -I$(top_srcdir) \
+ -I$(top_srcdir)/libeasclient \
$(EVOLUTION_MAIL_CFLAGS) \
$(LIBEDATASERVER_CFLAGS) \
$(LIBEBACKEND_CFLAGS) \
@@ -18,6 +18,7 @@ module_eas_mail_config_la_SOURCES = \
$(NULL)
module_eas_mail_config_la_LIBADD = \
+ $(top_builddir)/libeasclient/libeasclient.la \
$(EVOLUTION_MAIL_LIBS) \
$(LIBEDATASERVER_LIBS) \
$(LIBEBACKEND_LIBS) \
diff --git a/configuration/e-mail-config-eas-backend.c b/configuration/e-mail-config-eas-backend.c
index dc8fa8d..3608e48 100644
--- a/configuration/e-mail-config-eas-backend.c
+++ b/configuration/e-mail-config-eas-backend.c
@@ -28,6 +28,7 @@
#include <camel/camel.h>
#include <libebackend/libebackend.h>
+#include <libeasmail.h>
#include <mail/e-mail-config-auth-check.h>
#include <mail/e-mail-config-receiving-page.h>
@@ -42,6 +43,7 @@ struct _EMailConfigEasBackendPrivate {
GtkWidget *user_entry; /* not referenced */
GtkWidget *host_entry; /* not referenced */
GtkWidget *auth_check; /* not referenced */
+ GtkWidget *autodiscover_button;
};
G_DEFINE_DYNAMIC_TYPE (
@@ -78,6 +80,50 @@ mail_config_eas_backend_new_collection (EMailConfigServiceBackend *backend)
}
static void
+discover_server_url (GtkWidget *button, EMailConfigServiceBackend *backend)
+{
+ EasEmailHandler *handler;
+ GError *error = NULL;
+ EMailConfigServicePage *page;
+ const gchar * email_address;
+ gchar *uri = NULL;
+ gchar *username;
+ GtkWidget *username_entry = (GtkWidget *)g_object_get_data ((GObject *)button, "username-entry");
+ GtkWidget *host_entry = (GtkWidget *)g_object_get_data ((GObject *)button, "url-entry");
+
+ page = e_mail_config_service_backend_get_page (backend);
+ email_address = e_mail_config_service_page_get_email_address (page);
+
+ handler = eas_mail_handler_new(email_address, &error);
+ if (error) {
+ g_warning ("Unable to create mailHandler. We don't suppport auto-discover: %s\n",
error->message);
+ g_error_free (error);
+ gtk_widget_set_sensitive (button, FALSE);
+ return;
+ }
+
+ username = g_strdup (gtk_entry_get_text(username_entry));
+ if (username == NULL || *username == '\0' || strcmp (username, email_address) == 0) {
+ g_free (username);
+ username = NULL;
+ }
+
+ eas_mail_handler_autodiscover(
+ handler,
+ email_address,
+ username,
+ &uri,
+ NULL,
+ &error);
+
+ if (!error && uri && uri[0])
+ gtk_entry_set_text ((GtkEntry *)host_entry, uri);
+
+ g_free (username);
+ g_object_unref (handler);
+}
+
+static void
mail_config_eas_backend_insert_widgets (EMailConfigServiceBackend *backend,
GtkBox *parent)
{
@@ -140,7 +186,7 @@ mail_config_eas_backend_insert_widgets (EMailConfigServiceBackend *backend,
priv->user_entry = widget; /* do not reference */
gtk_widget_show (widget);
- widget = gtk_label_new_with_mnemonic (_("_Host URL:"));
+ widget = gtk_label_new_with_mnemonic (_("_Server URL:"));
gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
gtk_widget_show (widget);
@@ -170,6 +216,15 @@ mail_config_eas_backend_insert_widgets (EMailConfigServiceBackend *backend,
priv->auth_check = widget; /* do not reference */
gtk_widget_show (widget);
+ widget = gtk_button_new_with_mnemonic (_("_Auto Detect"));
+ gtk_grid_attach(GTK_GRID (container), widget, 2, 1, 1, 1);
+ priv->autodiscover_button = widget;
+ gtk_widget_show (widget);
+
+ g_object_set_data ((GObject *)widget, "username-entry", (gpointer)priv->user_entry);
+ g_object_set_data ((GObject *)widget, "url-entry", (gpointer)priv->host_entry);
+ g_signal_connect (widget, "clicked", G_CALLBACK(discover_server_url), backend);
+
g_object_bind_property (
settings, "user",
priv->user_entry, "text",
@@ -232,19 +287,19 @@ mail_config_eas_backend_setup_defaults (EMailConfigServiceBackend *backend)
gchar *hosturl;
GConfClient *client = gconf_client_get_default();
gchar *key;
-
+
key = g_strdup_printf ("/apps/activesyncd/accounts/%s/username", email_address);
username = gconf_client_get_string (client, key, NULL);
g_free (key);
-
+
if (username == NULL || *username == '\0') {
username = g_strdup (email_address);
}
-
+
key = g_strdup_printf ("/apps/activesyncd/accounts/%s/serverUri", email_address);
hosturl = gconf_client_get_string (client, key, NULL);
g_free (key);
-
+
network_settings = CAMEL_NETWORK_SETTINGS (settings);
camel_network_settings_set_user (network_settings, username);
if (hosturl && hosturl[0]) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]