[evolution-patches] Exchange: Remove usage of e_notice in e-d-s/servers/exchange



Hi,

In evolution-data-server/servers/exchange/,
this patch removes the usage of e_notice calls.

Please review it.

Thanks,
Arunprakash.

Index: servers/exchange/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/ChangeLog,v
retrieving revision 1.14
diff -u -p -r1.14 ChangeLog
--- servers/exchange/ChangeLog	8 Jul 2005 13:04:05 -0000	1.14
+++ servers/exchange/ChangeLog	8 Jul 2005 16:19:29 -0000
@@ -1,3 +1,12 @@
+2005-07-08  Arunprakash <arunp novell com>
+
+	* storage/exchange-account.c : Modify exchange_account_connect and
+	exchange_account_set_password to report the error back through
+	ExchangeAccountResult. 
+	* storage/exchange-account.h : Added ExchangeAccountResult enumeration.
+	Modified signatures of exchange_account_set_password and 
+	exchange_account_connect.
+
 2005-07-08  Praveen Kumar <kpraveen novell com>
 
 	* lib/Makefile.am : Added entry for ek-sid.h in the headers files to 
Index: servers/exchange/storage/exchange-account.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-account.c,v
retrieving revision 1.4
diff -u -p -r1.4 exchange-account.c
--- servers/exchange/storage/exchange-account.c	7 Jul 2005 11:23:49 -0000	1.4
+++ servers/exchange/storage/exchange-account.c	8 Jul 2005 16:19:30 -0000
@@ -869,12 +869,12 @@ account_moved (ExchangeAccount *account,
 }
 
 static gboolean
-get_password (ExchangeAccount *account, E2kAutoconfig *ac, const char *errmsg)
+get_password (ExchangeAccount *account, E2kAutoconfig *ac, ExchangeAccountResult error)
 {
 	char *password;
 	gboolean remember, oldremember;
 
-	if (*errmsg)
+	if (error != EXCHANGE_ACCOUNT_CONNECT_SUCCESS)
 		e_passwords_forget_password ("Exchange", account->priv->password_key);
 
 	password = e_passwords_get_password ("Exchange", account->priv->password_key);
@@ -883,8 +883,8 @@ get_password (ExchangeAccount *account, 
 		if (!password) {
 			char *prompt;
 
-			prompt = g_strdup_printf (_("%sEnter password for %s"),
-						  errmsg, account->account_name);
+			prompt = g_strdup_printf (_("Enter password for %s"),
+						  account->account_name);
 			oldremember = remember = 
 					account->priv->account->source->save_passwd;
 			password = e_passwords_ask_password (
@@ -912,6 +912,7 @@ get_password (ExchangeAccount *account, 
 	if (password) {
 		e2k_autoconfig_set_password (ac, password);
 		memset (password, 0, strlen (password));
+		g_free (password);
 		return TRUE;
 	} else
 		return FALSE;
@@ -1069,15 +1070,15 @@ exchange_account_forget_password (Exchan
 }
 
 #ifdef HAVE_KRB5
-void
+ExchangeAccountResult
 exchange_account_set_password (ExchangeAccount *account, char *old_pass, char *new_pass)
 {
 	E2kKerberosResult result;
 	char *domain;
 
-	g_return_if_fail (EXCHANGE_IS_ACCOUNT (account));
-	g_return_if_fail (old_pass != NULL);
-	g_return_if_fail (new_pass != NULL);
+	g_return_val_if_fail (EXCHANGE_IS_ACCOUNT (account), EXCHANGE_ACCOUNT_PASSWORD_CHANGE_FAILED);
+	g_return_val_if_fail (old_pass != NULL, EXCHANGE_ACCOUNT_PASSWORD_CHANGE_FAILED);
+	g_return_val_if_fail (new_pass != NULL, EXCHANGE_ACCOUNT_PASSWORD_CHANGE_FAILED);
 
 	domain = account->priv->gc ? account->priv->gc->domain : NULL;
 	if (!domain) {
@@ -1087,8 +1088,7 @@ exchange_account_set_password (ExchangeA
 	}
 	if (!domain) {
 		/* email id is not proper, we return instead of trying nt_domain */
-		// SURF : e_notice (NULL, GTK_MESSAGE_ERROR, _("Cannot change password due to configuration problems"));
-		return;
+		return EXCHANGE_ACCOUNT_CONFIG_ERROR;
 	}
 
 	result = e2k_kerberos_change_password (account->priv->username, domain,
@@ -1110,14 +1110,14 @@ exchange_account_set_password (ExchangeA
 		break;
 
 	case E2K_KERBEROS_PASSWORD_TOO_WEAK:
-		// SURF : e_notice (NULL, GTK_MESSAGE_ERROR, _("Server rejected password because it is too weak.\nTry again with a different password."));
-		break;
+		return EXCHANGE_ACCOUNT_PASSWORD_WEAK_ERROR;
 
 	case E2K_KERBEROS_FAILED:
 	default:
-		// SURF : e_notice (NULL, GTK_MESSAGE_ERROR, _("Could not change password"));
-		break;
+		return EXCHANGE_ACCOUNT_PASSWORD_CHANGE_FAILED;
 	}
+	
+	return EXCHANGE_ACCOUNT_PASSWORD_CHANGE_SUCCESS;
 }
 #endif
 
@@ -1162,10 +1162,11 @@ gboolean
 exchange_account_set_online (ExchangeAccount *account)
 {
 	E2kContext *ctx;
+	ExchangeAccountResult result;
 	g_return_val_if_fail (EXCHANGE_IS_ACCOUNT (account), FALSE);
 
 	if (!account->priv->account_online) {
-		ctx = exchange_account_connect (account);
+		ctx = exchange_account_connect (account, &result); /* error not handled. */
 		return ctx ? TRUE : FALSE;
 	} else {
 		return TRUE;
@@ -1351,12 +1352,11 @@ SURF :
  * failed.
  **/
 E2kContext *
-exchange_account_connect (ExchangeAccount *account)
+exchange_account_connect (ExchangeAccount *account, ExchangeAccountResult *info_result)
 {
 	E2kAutoconfig *ac;
 	E2kAutoconfigResult result;
 	E2kHTTPStatus status;
-	char *errmsg = "";
 	gboolean redirected = FALSE;
 	E2kResult *results;
 	int nresults;
@@ -1366,12 +1366,13 @@ exchange_account_connect (ExchangeAccoun
 	E2kGlobalCatalogStatus gcstatus;
 	E2kGlobalCatalogEntry *entry;
 	E2kOperation gcop;
-	const char *quota_msg = NULL;
 	char *user_name = NULL;
 	int offline;
 
 	g_return_val_if_fail (EXCHANGE_IS_ACCOUNT (account), NULL);
 
+	*info_result = EXCHANGE_ACCOUNT_CONNECT_SUCCESS;
+
 	exchange_account_is_offline (account, &offline);
 	g_mutex_lock (account->priv->connect_lock);
 
@@ -1379,7 +1380,8 @@ exchange_account_connect (ExchangeAccoun
 		g_mutex_unlock (account->priv->connect_lock);
 		if (offline == OFFLINE_MODE) {
 			setup_account_hierarchies (account);
-			// SURF : e_notice (NULL, GTK_MESSAGE_ERROR, _("Exchange Account is offline. Cannot display folders\n"));
+
+			*info_result = EXCHANGE_ACCOUNT_OFFLINE;
 		}
 		return NULL;
 	} else if (account->priv->ctx) {
@@ -1405,7 +1407,7 @@ exchange_account_connect (ExchangeAccoun
 				      account->priv->ad_limit);
 
  try_password_again:
-	if (!get_password (account, ac, errmsg)) {
+	if (!get_password (account, ac, *info_result)) {
 		account->priv->connecting = FALSE;
 		return NULL;
 	}
@@ -1425,32 +1427,33 @@ exchange_account_connect (ExchangeAccoun
 			//new_password = exchange_get_new_password (old_password, 0);
 
 			if (new_password) {
-				exchange_account_set_password (account, old_password, new_password);
-				e2k_autoconfig_set_password (ac, new_password);
+				ExchangeAccountResult res;
+				res = exchange_account_set_password (account, old_password, new_password);
+				if (res == EXCHANGE_ACCOUNT_PASSWORD_CHANGE_SUCCESS) {
+					e2k_autoconfig_set_password (ac, new_password);
+					goto try_connect_again;
+				}
+				else
+					*info_result = res;
+				
 				g_free (old_password);
 				g_free (new_password);
-				goto try_connect_again;
+			}
+			else {
+				*info_result = EXCHANGE_ACCOUNT_PASSWORD_EXPIRED;
+				g_free (old_password);
 			}
 
-			g_free (old_password);
 			result = E2K_AUTOCONFIG_CANCELLED;
 		}
 #endif
 		switch (result) {
 		case E2K_AUTOCONFIG_AUTH_ERROR:
-			errmsg = _("Could not authenticate to server. "
-				   "(Password incorrect?)\n\n");
+			*info_result = EXCHANGE_ACCOUNT_PASSWORD_INCORRECT;
 			goto try_password_again;
 
 		case E2K_AUTOCONFIG_AUTH_ERROR_TRY_DOMAIN:
-			errmsg = _("Could not authenticate to server."
-				   "\n\nThis probably means that your "
-				   "server requires you\nto specify "
-				   "the Windows domain name as part "
-				   "of your\nusername (eg, "
-				   "\"DOMAIN\\user\").\n\nOr you "
-				   "might have just typed your "
-				   "password wrong.\n\n");
+			*info_result = EXCHANGE_ACCOUNT_DOMAIN_ERROR;
 			goto try_password_again;
 
 		case E2K_AUTOCONFIG_AUTH_ERROR_TRY_NTLM:
@@ -1484,55 +1487,31 @@ exchange_account_connect (ExchangeAccoun
 		switch (result) {
 		case E2K_AUTOCONFIG_REDIRECT:
 		case E2K_AUTOCONFIG_TRY_SSL:
-			errmsg = g_strdup_printf (
-				_("Mailbox for %s is not on this server."),
-				account->priv->username);
+			*info_result = EXCHANGE_ACCOUNT_MAILBOX_NA;
 			break;
 		case E2K_AUTOCONFIG_EXCHANGE_5_5:
-			errmsg = g_strdup (
-				_("The server '%s' is running Exchange 5.5 "
-				  "and is\ntherefore not compatible with "
-				  "Ximian Connector"));
+			*info_result = EXCHANGE_ACCOUNT_VERSION_ERROR;
 			break;
 		case E2K_AUTOCONFIG_NOT_EXCHANGE:
 		case E2K_AUTOCONFIG_NO_OWA:
-			errmsg = g_strdup_printf (
-				_("Could not find Exchange Web Storage System "
-				  "at %s.\nIf OWA is running on a different "
-				  "path, you must specify that in the\n"
-				  "account configuration dialog."),
-				account->home_uri);
+			*info_result = EXCHANGE_ACCOUNT_WSS_ERROR;
 			break;
 		case E2K_AUTOCONFIG_NO_MAILBOX:
-			errmsg = g_strdup_printf (
-				_("No mailbox for user %s on %s.\n"),
-				account->priv->username,
-				account->exchange_server);
+			*info_result = EXCHANGE_ACCOUNT_NO_MAILBOX;
 			break;
 		case E2K_AUTOCONFIG_CANT_RESOLVE:
-			errmsg = g_strdup_printf (
-				_("Could not connect to server %s: %s"),
-				account->exchange_server,
-				_("Could not resolve hostname"));
+			*info_result = EXCHANGE_ACCOUNT_RESOLVE_ERROR;
 			break;
 		case E2K_AUTOCONFIG_CANT_CONNECT:
-			errmsg = g_strdup_printf (
-				_("Could not connect to server %s: %s"),
-				account->exchange_server,
-				_("Network error"));
+			*info_result = EXCHANGE_ACCOUNT_CONNECT_ERROR;
 			break;
 		case E2K_AUTOCONFIG_CANCELLED:
 			return NULL;
 		default:
-			errmsg = g_strdup_printf (
-				_("Could not connect to server %s: %s"),
-				account->exchange_server,
-				_("Unknown error"));
+			*info_result = EXCHANGE_ACCOUNT_UNKNOWN_ERROR;
 			break;
 		}
 
-		// SURF : e_notice (NULL, GTK_MESSAGE_ERROR, errmsg);
-		g_free (errmsg);
 		return NULL;
 	}
 
@@ -1547,7 +1526,8 @@ exchange_account_connect (ExchangeAccoun
 
 	if (!E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
 		account->priv->connecting = FALSE;
-		return NULL;
+		*info_result = EXCHANGE_ACCOUNT_UNKNOWN_ERROR;
+		return NULL; /* FIXME: what error has happened? */
 	}
 
 	if (nresults) {
@@ -1566,8 +1546,10 @@ exchange_account_connect (ExchangeAccoun
 			account->default_timezone = g_strdup (timezone);
 	}
 
-	if (!setup_account_hierarchies (account)) 
-		return NULL;
+	if (!setup_account_hierarchies (account)) {
+		*info_result = EXCHANGE_ACCOUNT_UNKNOWN_ERROR;
+		return NULL; /* FIXME: what error has happened? */
+	}
 
 	/* Find the password expiery peripod and display warning */
 	find_passwd_exp_period(account, entry);
@@ -1588,15 +1570,14 @@ exchange_account_connect (ExchangeAccoun
 	if (gcstatus == E2K_GLOBAL_CATALOG_OK) {
 
 		if (entry->quota_norecv && account->mbox_size >= entry->quota_norecv) {
-			quota_msg = g_strdup_printf ("You have exceeded your quota for storing mails on this server. Your current usage is : %d . You will not be able to either send or recieve mails now\n", entry->quota_norecv);
+			*info_result = EXCHANGE_ACCOUNT_QUOTA_ERROR;
 		} else if (entry->quota_nosend && account->mbox_size >= entry->quota_nosend) {
-			quota_msg = g_strdup_printf ("You are nearing your quota available for storing mails on this server. Your current usage is : %d . You will not be able to send mails till you clear up some space by deleting some mails.\n", entry->quota_nosend);
+			*info_result = EXCHANGE_ACCOUNT_QUOTA_SEND_ERROR;
 		} else if (entry->quota_warn && account->mbox_size >= entry->quota_warn) {
-			quota_msg = g_strdup_printf ("You are nearing your quota available for storing mails on this server. Your current usage is : %d . Try to clear up some space by deleting some mails.\n", entry->quota_warn);
+			*info_result = EXCHANGE_ACCOUNT_QUOTA_WARN;
 		}
 		
-	// SURF :	if (quota_msg)
-			// SURF : e_notice (NULL, GTK_MESSAGE_INFO, quota_msg);
+	// SURF :	if (quota_msg) FIXME: the quota data has to be made available through helper functions here.
 	}
 	
 	account->priv->connected = TRUE;
Index: servers/exchange/storage/exchange-account.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-account.h,v
retrieving revision 1.4
diff -u -p -r1.4 exchange-account.h
--- servers/exchange/storage/exchange-account.h	7 Jul 2005 11:23:49 -0000	1.4
+++ servers/exchange/storage/exchange-account.h	8 Jul 2005 16:19:30 -0000
@@ -52,6 +52,28 @@ struct _ExchangeAccountClass {
 	void (*removed_folder) (ExchangeAccount *, EFolder *);
 };
 
+typedef enum {
+	EXCHANGE_ACCOUNT_CONFIG_ERROR,
+	EXCHANGE_ACCOUNT_PASSWORD_WEAK_ERROR,
+	EXCHANGE_ACCOUNT_PASSWORD_CHANGE_FAILED,
+	EXCHANGE_ACCOUNT_PASSWORD_CHANGE_SUCCESS,
+	EXCHANGE_ACCOUNT_OFFLINE,
+	EXCHANGE_ACCOUNT_PASSWORD_INCORRECT,
+	EXCHANGE_ACCOUNT_DOMAIN_ERROR,
+	EXCHANGE_ACCOUNT_MAILBOX_NA,
+	EXCHANGE_ACCOUNT_VERSION_ERROR,
+	EXCHANGE_ACCOUNT_WSS_ERROR,
+	EXCHANGE_ACCOUNT_NO_MAILBOX,
+	EXCHANGE_ACCOUNT_RESOLVE_ERROR,
+	EXCHANGE_ACCOUNT_CONNECT_ERROR,
+	EXCHANGE_ACCOUNT_PASSWORD_EXPIRED,
+	EXCHANGE_ACCOUNT_UNKNOWN_ERROR,
+	EXCHANGE_ACCOUNT_QUOTA_ERROR,
+	EXCHANGE_ACCOUNT_QUOTA_SEND_ERROR,
+	EXCHANGE_ACCOUNT_QUOTA_WARN,
+	EXCHANGE_ACCOUNT_CONNECT_SUCCESS
+} ExchangeAccountResult;
+
 GType                  exchange_account_get_type             (void);
 ExchangeAccount       *exchange_account_new                  (EAccountList *account_list,
 							      EAccount     *adata);
@@ -68,7 +90,8 @@ char                  *exchange_account_
 							      E2kGlobalCatalogEntry *entry,
 							      const char       *std_uri_prop);
 
-E2kContext            *exchange_account_connect              (ExchangeAccount  *acct);
+E2kContext            *exchange_account_connect              (ExchangeAccount  *acct,
+							      ExchangeAccountResult *result);
 
 EFolder               *exchange_account_get_folder           (ExchangeAccount  *acct,
 							      const char       *path_or_uri);
@@ -78,7 +101,7 @@ void                   exchange_account_
 
 char 		      *exchange_account_get_password 	     (ExchangeAccount  *acct);
 
-void		       exchange_account_set_password 	     (ExchangeAccount  *acct,
+ExchangeAccountResult exchange_account_set_password 	     (ExchangeAccount  *acct,
 							      char             *old_password,
 							      char             *new_password);
 void 		       exchange_account_forget_password       (ExchangeAccount  *acct);


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