[evolution-data-server] uoa: Add e_source_get_ag_service_type().



commit 190a0e7188148c970d4e0bb5c05197bde0d31621
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Feb 2 08:35:30 2013 -0500

    uoa: Add e_source_get_ag_service_type().
    
    Returns an appropriate service type name for an ESource.

 .../module-ubuntu-online-accounts.c                |   36 ++-----------------
 modules/ubuntu-online-accounts/uoa-utils.c         |   37 ++++++++++++++++++++
 modules/ubuntu-online-accounts/uoa-utils.h         |    2 +
 3 files changed, 43 insertions(+), 32 deletions(-)
---
diff --git a/modules/ubuntu-online-accounts/module-ubuntu-online-accounts.c b/modules/ubuntu-online-accounts/module-ubuntu-online-accounts.c
index fdcfe29..7e0e926 100644
--- a/modules/ubuntu-online-accounts/module-ubuntu-online-accounts.c
+++ b/modules/ubuntu-online-accounts/module-ubuntu-online-accounts.c
@@ -21,8 +21,6 @@
 #include <libsignon-glib/signon-glib.h>
 #include <libaccounts-glib/accounts-glib.h>
 
-#include <libebackend/libebackend.h>
-
 #include "uoa-utils.h"
 
 /* Standard GObject macros */
@@ -148,36 +146,10 @@ ubuntu_online_accounts_ref_account_service (EUbuntuOnlineAccounts *extension,
 	ESourceRegistryServer *server;
 	AgAccountService *ag_account_service = NULL;
 	const gchar *extension_name;
-	const gchar *service_name = NULL;
-
-	/* Figure out which AgAccountService to use based
-	 * on which extensions are present in the ESource. */
-
-	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
-	if (e_source_has_extension (source, extension_name))
-		service_name = E_AG_SERVICE_TYPE_CONTACTS;
-
-	extension_name = E_SOURCE_EXTENSION_CALENDAR;
-	if (e_source_has_extension (source, extension_name))
-		service_name = E_AG_SERVICE_TYPE_CALENDAR;
-
-	extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
-	if (e_source_has_extension (source, extension_name))
-		service_name = E_AG_SERVICE_TYPE_CALENDAR;
-
-	extension_name = E_SOURCE_EXTENSION_TASK_LIST;
-	if (e_source_has_extension (source, extension_name))
-		service_name = E_AG_SERVICE_TYPE_CALENDAR;
-
-	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
-	if (e_source_has_extension (source, extension_name))
-		service_name = E_AG_SERVICE_TYPE_MAIL;
-
-	extension_name = E_SOURCE_EXTENSION_MAIL_TRANSPORT;
-	if (e_source_has_extension (source, extension_name))
-		service_name = E_AG_SERVICE_TYPE_MAIL;
+	const gchar *service_type;
 
-	g_return_val_if_fail (service_name != NULL, NULL);
+	service_type = e_source_get_ag_service_type (source);
+	g_return_val_if_fail (service_type != NULL, NULL);
 
 	extension_name = E_SOURCE_EXTENSION_UOA;
 	server = ubuntu_online_accounts_get_server (extension);
@@ -192,7 +164,7 @@ ubuntu_online_accounts_ref_account_service (EUbuntuOnlineAccounts *extension,
 
 		if (account_services != NULL) {
 			ag_account_service = g_hash_table_lookup (
-				account_services, service_name);
+				account_services, service_type);
 			if (ag_account_service != NULL)
 				g_object_ref (ag_account_service);
 		}
diff --git a/modules/ubuntu-online-accounts/uoa-utils.c b/modules/ubuntu-online-accounts/uoa-utils.c
index ade5dbf..7078ea9 100644
--- a/modules/ubuntu-online-accounts/uoa-utils.c
+++ b/modules/ubuntu-online-accounts/uoa-utils.c
@@ -360,3 +360,40 @@ e_ag_account_collect_userinfo_finish (AgAccount *ag_account,
 	return TRUE;
 }
 
+const gchar *
+e_source_get_ag_service_type (ESource *source)
+{
+	const gchar *extension_name;
+
+	g_return_val_if_fail (E_IS_SOURCE (source), NULL);
+
+	/* Determine an appropriate service type based on
+	 * which extensions are present in the ESource. */
+
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	if (e_source_has_extension (source, extension_name))
+		return E_AG_SERVICE_TYPE_CONTACTS;
+
+	extension_name = E_SOURCE_EXTENSION_CALENDAR;
+	if (e_source_has_extension (source, extension_name))
+		return E_AG_SERVICE_TYPE_CALENDAR;
+
+	extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+	if (e_source_has_extension (source, extension_name))
+		return E_AG_SERVICE_TYPE_CALENDAR;
+
+	extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+	if (e_source_has_extension (source, extension_name))
+		return E_AG_SERVICE_TYPE_CALENDAR;
+
+	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
+	if (e_source_has_extension (source, extension_name))
+		return E_AG_SERVICE_TYPE_MAIL;
+
+	extension_name = E_SOURCE_EXTENSION_MAIL_TRANSPORT;
+	if (e_source_has_extension (source, extension_name))
+		return E_AG_SERVICE_TYPE_MAIL;
+
+	g_return_val_if_reached (NULL);
+}
+
diff --git a/modules/ubuntu-online-accounts/uoa-utils.h b/modules/ubuntu-online-accounts/uoa-utils.h
index f900484..6216b9e 100644
--- a/modules/ubuntu-online-accounts/uoa-utils.h
+++ b/modules/ubuntu-online-accounts/uoa-utils.h
@@ -19,6 +19,7 @@
 #ifndef UOA_UTILS_H
 #define UOA_UTILS_H
 
+#include <libebackend/libebackend.h>
 #include <libaccounts-glib/accounts-glib.h>
 
 /* Service types we support. */
@@ -38,6 +39,7 @@ gboolean	e_ag_account_collect_userinfo_finish
 						 gchar **out_user_identity,
 						 gchar **out_email_address,
 						 GError **error);
+const gchar *	e_source_get_ag_service_type	(ESource *source);
 
 G_END_DECLS
 



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