[evolution-mapi] Bug 585615 – Exchange MAPI account setup gets wrong userid in database



commit e21e2a672c614e40d29b6270feaebcd9a0966e8f
Author: Johnny Jacob <jjohnny novell com>
Date:   Wed Jun 24 18:32:21 2009 +0530

    Bug 585615 â?? Exchange MAPI account setup gets wrong userid in database
    
        * exchange-mapi-account-setup.c (create_profile_callback): Added. Callback for
        e.*create_profile. If ProcessNetworkProfile finds more than one match for
        username, a pop dialog allows the user to select the right one.
    
        * exchange-mapi-connection.c (exchange_mapi_create_profile): Added support
        for ProcessNetworkProfile callback data.

 src/account-setup-eplugin/ChangeLog                |    6 ++
 .../exchange-mapi-account-listener.c               |    2 +-
 .../exchange-mapi-account-setup.c                  |   90 +++++++++++++++++++-
 src/libexchangemapi/ChangeLog                      |    5 +
 src/libexchangemapi/exchange-mapi-connection.c     |   22 ++++--
 src/libexchangemapi/exchange-mapi-connection.h     |    4 +-
 6 files changed, 120 insertions(+), 9 deletions(-)
---
diff --git a/src/account-setup-eplugin/ChangeLog b/src/account-setup-eplugin/ChangeLog
index f4da41b..0e1bca1 100644
--- a/src/account-setup-eplugin/ChangeLog
+++ b/src/account-setup-eplugin/ChangeLog
@@ -1,3 +1,9 @@
+2009-06-24  Johnny Jacob  <jjohnny novell com>
+
+	* exchange-mapi-account-setup.c (create_profile_callback): Added. Callback for
+	e.*create_profile. If ProcessNetworkProfile finds more than one match for
+	username, a pop dialog allows the user to select the right one.
+
 2009-08-04  Johnny Jacob  <jjohnny novell com>
 
 	* org-gnome-exchange-mapi.eplug.xml: Removed a invalid hook definition.
diff --git a/src/account-setup-eplugin/exchange-mapi-account-listener.c b/src/account-setup-eplugin/exchange-mapi-account-listener.c
index 15b8934..4ac15c6 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-listener.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-listener.c
@@ -622,7 +622,7 @@ create_profile_entry (CamelURL *url)
 		g_free (key);
 
 		if (password)
-			status = exchange_mapi_create_profile (url->user, password, camel_url_get_param (url, "domain"), url->host, NULL);
+		  status = exchange_mapi_create_profile (url->user, password, camel_url_get_param (url, "domain"), url->host, NULL, NULL, NULL);
 
 		++attempts; 
 	}
diff --git a/src/account-setup-eplugin/exchange-mapi-account-setup.c b/src/account-setup-eplugin/exchange-mapi-account-setup.c
index 6648624..324dd02 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-setup.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-setup.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -94,6 +95,90 @@ exchange_mapi_accounts_peek_config_listener ()
 	return config_listener; 
 }
 
+enum {
+  COL_MAPI_FULL_NAME = 0,
+  COL_MAPI_ACCOUNT,
+  COL_MAPI_INDEX,
+  COLS_MAX
+};
+
+/* Callback for ProcessNetworkProfile. If we have more than one username, 
+ we need to let the user select. */
+static uint32_t
+create_profile_callback (struct SRowSet *rowset, gpointer data)
+{
+	struct SPropValue *lpProp_fullname, *lpProp_account;
+	gint response;
+	guint32	i, index = 0;
+	GtkTreeIter iter;
+	GtkListStore *store;
+	GtkCellRenderer *renderer;
+	GtkTreeSelection *selection;
+	GtkWidget *dialog, *view;
+	GtkVBox *vbox;
+
+	/* NOTE: A good way would be display the list of username entries */
+	/* using GtkEntryCompletion in the username gtkentry. But plugins */
+	/* as of now does not have access to it */
+
+	/*TODO : Fix strings*/
+	dialog = gtk_dialog_new_with_buttons (_("Select username"),
+					      NULL, GTK_DIALOG_MODAL,
+					      GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+					      GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+					      NULL);
+
+	/*Tree View */
+	view = gtk_tree_view_new ();
+	renderer = gtk_cell_renderer_text_new ();
+	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
+						     -1, _("Full name"), renderer,
+						     "text", COL_MAPI_FULL_NAME, NULL);
+
+	renderer = gtk_cell_renderer_text_new ();
+	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
+						     -1, _("User name"), renderer, 
+						     "text", COL_MAPI_ACCOUNT, NULL);
+
+	/* Model for TreeView */
+	store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
+	gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (store));
+
+	for (i = 0; i < rowset->cRows; i++) {
+		lpProp_fullname = get_SPropValue_SRow(&(rowset->aRow[i]), PR_DISPLAY_NAME);
+		lpProp_account = get_SPropValue_SRow(&(rowset->aRow[i]), PR_ACCOUNT);
+
+		if (lpProp_fullname && lpProp_fullname->value.lpszA &&
+		    lpProp_account && lpProp_account->value.lpszA) {
+			gtk_list_store_append (store, &iter);
+			/* Preserve the index inside the store*/
+			gtk_list_store_set (store, &iter,
+					    COL_MAPI_FULL_NAME, lpProp_fullname->value.lpszA,
+					    COL_MAPI_ACCOUNT, lpProp_account->value.lpszA,
+					    COL_MAPI_INDEX, i, -1);
+		}
+	}
+
+	/* Pack the TreeView into dialog's content area */
+	vbox = (GtkVBox *)gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+	gtk_box_pack_start (GTK_BOX (vbox), view, TRUE, TRUE, 6);
+	gtk_widget_show_all (GTK_WIDGET (vbox));
+
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+	if (response == GTK_RESPONSE_ACCEPT) {
+	       /* Get the index from the selected value */
+		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+		gtk_tree_selection_get_selected (selection, NULL, &iter);
+		gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_MAPI_INDEX, 
+				    &index, -1);
+	} else /* If we return a value > available, we are canceling the login.*/
+	       index = rowset->cRows + 1;
+
+	gtk_widget_destroy (dialog);
+
+	return index;
+}
+
 static void
 validate_credentials (GtkWidget *widget, EConfig *config)
 {
@@ -126,7 +211,10 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 	/*Can there be a account without password ?*/
 	if (password && *password && domain_name && *domain_name && *url->user && *url->host) {
 		char *error_msg = NULL;
-		gboolean status = exchange_mapi_create_profile (url->user, password, domain_name, url->host, &error_msg);
+		gboolean status = exchange_mapi_create_profile (url->user, password, domain_name,
+								url->host, &error_msg, 
+								(mapi_profile_callback_t) create_profile_callback,
+								NULL);
 		if (status) {
 			/* Things are successful */
 			gchar *profname = NULL, *uri = NULL; 
diff --git a/src/libexchangemapi/ChangeLog b/src/libexchangemapi/ChangeLog
index 80d5469..5a5944b 100644
--- a/src/libexchangemapi/ChangeLog
+++ b/src/libexchangemapi/ChangeLog
@@ -1,3 +1,8 @@
+2009-06-24  Johnny Jacob  <jjohnny novell com>
+
+	* exchange-mapi-connection.c (exchange_mapi_create_profile): Added support
+	for ProcessNetworkProfile callback data.
+
 2009-07-17  Johnny Jacob  <jjohnny novell com>
 
 	* exchange-mapi-connection.c (exchange_mapi_get_folders_list): Get size for mailbox.
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index ddcb397..8dd8f5a 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -116,8 +116,10 @@ mapi_profile_load (const char *profname, const char *password)
 	}
 
 cleanup:
-	if (retval != MAPI_E_SUCCESS && retval != MAPI_E_SESSION_LIMIT)
+	if (retval != MAPI_E_SUCCESS && retval != MAPI_E_SESSION_LIMIT &&
+	    retval != MAPI_E_LOGON_FAILED)
 		MAPIUninitialize ();
+
 	g_free (profpath);
 
 	d(g_print("\n%s: Leaving %s ", G_STRLOC, G_STRFUNC));
@@ -2971,8 +2973,11 @@ manage_mapi_error (const char *context, uint32_t error_id, char **error_msg)
 	}
 }
 
+
 gboolean
-exchange_mapi_create_profile (const char *username, const char *password, const char *domain, const char *server, char **error_msg)
+exchange_mapi_create_profile (const char *username, const char *password, const char *domain,
+			      const char *server, char **error_msg,
+			      mapi_profile_callback_t callback, gpointer data)
 {
 	enum MAPISTATUS	retval;
 	gboolean result = FALSE; 
@@ -3047,13 +3052,16 @@ exchange_mapi_create_profile (const char *username, const char *password, const
 			manage_mapi_error ("DeleteProfile", GetLastError(), error_msg);
 		goto cleanup; 
 	}
-	d(g_print("succeeded \n"));
+	d(g_print("MapiLogonProvider : succeeded \n"));
 
-	retval = ProcessNetworkProfile(session, username, NULL, NULL); 
+	retval = ProcessNetworkProfile(session, username, callback, NULL); 
 	if (retval != MAPI_E_SUCCESS) {
 		manage_mapi_error ("ProcessNetworkProfile", GetLastError(), error_msg);
-		goto cleanup; 
+		g_debug ("Deleting profile %s ", profname); 
+		DeleteProfile(profname); 
+		goto exit; 
 	}
+	d(g_print("ProcessNetworkProfile : succeeded \n"));
 
 	/* Set it as the default profile. Is this needed? */
 	retval = SetDefaultProfile(profname); 
@@ -3069,12 +3077,14 @@ exchange_mapi_create_profile (const char *username, const char *password, const
 	if (exchange_mapi_connection_new (profname, password)) {
 		result = TRUE;
 		exchange_mapi_peek_folder_list ();
-	}
+	} else 
+		goto exit;
 
 cleanup: 
 	if (!result)
 		MAPIUninitialize ();
 
+exit:
 	g_free (profname);
 	g_free (profpath);
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.h b/src/libexchangemapi/exchange-mapi-connection.h
index 86dcbb4..2059991 100644
--- a/src/libexchangemapi/exchange-mapi-connection.h
+++ b/src/libexchangemapi/exchange-mapi-connection.h
@@ -199,7 +199,9 @@ uint32_t
 exchange_mapi_util_create_named_prop (uint32_t olFolder, mapi_id_t fid, 
 				      const char *named_prop_name, uint32_t ptype);
 
-gboolean exchange_mapi_create_profile (const char *username, const char *password, const char *domain, const char *server, char **error_msg);
+gboolean exchange_mapi_create_profile (const char *username, const char *password,
+				       const char *domain, const char *server,
+				       char **error_msg, mapi_profile_callback_t cb, gpointer data);
 gboolean exchange_mapi_delete_profile (const char *profile);
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]