[Commits] cm_gdata_contacts.c 1.1.2.13 1.1.2.14
holger at claws-mail.org
holger at claws-mail.org
Sat Dec 31 01:40:12 CET 2011
Update of /home/claws-mail/plugins/gdata/src
In directory claws-mail:/tmp/cvs-serv6193/src
Modified Files:
Tag: gtk2
cm_gdata_contacts.c
Log Message:
2011-12-31 [holger] 0.3cvs2
* configure.ac
Also check for libgdata 0.9.1
* src/cm_gdata_contacts.c
When libgdata 0.9.1 is available, only fetch
contacts in the "My Contacts" system group.
Index: cm_gdata_contacts.c
===================================================================
RCS file: /home/claws-mail/plugins/gdata/src/Attic/cm_gdata_contacts.c,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -d -r1.1.2.13 -r1.1.2.14
--- cm_gdata_contacts.c 18 Dec 2011 23:53:15 -0000 1.1.2.13
+++ cm_gdata_contacts.c 31 Dec 2011 00:40:10 -0000 1.1.2.14
@@ -52,6 +52,7 @@
CmGDataContactsCache contacts_cache;
gboolean cm_gdata_contacts_query_running = FALSE;
+gchar *contacts_group_id = NULL;
static void write_cache_to_file(void)
{
@@ -206,9 +207,10 @@
log_message(LOG_PROTOCOL, _("GData plugin: Starting async contacts query\n"));
query = gdata_contacts_query_new(NULL);
+ gdata_contacts_query_set_group(query, contacts_group_id);
gdata_query_set_max_results(GDATA_QUERY(query), cm_gdata_config.max_num_results);
gdata_contacts_service_query_contacts_async(service, GDATA_QUERY(query), NULL, NULL, NULL,
-#ifdef HAVE_GDATA_VERSION_0_9
+#ifdef HAVE_GDATA_VERSION_0_9_1
NULL,
#endif
(GAsyncReadyCallback)cm_gdata_query_contacts_ready, NULL);
@@ -216,11 +218,81 @@
g_object_unref(query);
}
+#ifdef HAVE_GDATA_VERSION_0_9_1
+static void cm_gdata_query_groups_ready(GDataContactsService *service, GAsyncResult *res, gpointer data)
+{
+ GDataFeed *feed;
+ GList *walk;
+ GError *error = NULL;
+
+ feed = gdata_service_query_finish(GDATA_SERVICE(service), res, &error);
+ if(error)
+ {
+ g_object_unref(feed);
+ log_error(LOG_PROTOCOL, _("GData plugin: Error querying for groups: %s\n"), error->message);
+ g_error_free(error);
+ return;
+ }
+
+ /* Iterate through the returned groups and search for Contacts group id */
+ for(walk = gdata_feed_get_entries(feed); walk; walk = walk->next) {
+ const gchar *system_group_id;
+ GDataContactsGroup *group = GDATA_CONTACTS_GROUP(walk->data);
+
+ system_group_id = gdata_contacts_group_get_system_group_id(group);
+ if(system_group_id && !strcmp(system_group_id, GDATA_CONTACTS_GROUP_CONTACTS)) {
+ gchar *pos;
+ const gchar *id;
+
+ id = gdata_entry_get_id(GDATA_ENTRY(group));
+
+ /* possibly replace projection "full" by "base" */
+ pos = g_strrstr(id, "/full/");
+ if(pos) {
+ GString *str = g_string_new("\0");
+ int off = pos-id;
+
+ g_string_append_len(str, id, off);
+ g_string_append(str, "/base/");
+ g_string_append(str, id+off+strlen("/full/"));
+ g_string_append_c(str, '\0');
+ contacts_group_id = str->str;
+ g_string_free(str, FALSE);
+ }
+ else
+ contacts_group_id = g_strdup(id);
+ break;
+ }
+ }
+ g_object_unref(feed);
+
+ log_message(LOG_PROTOCOL, _("GData plugin: Groups received\n"));
+
+ query_after_auth(service);
+}
+#endif
+
#ifdef HAVE_GDATA_VERSION_0_9
+static void query_for_contacts_group_id(GDataClientLoginAuthorizer *authorizer)
+{
+ GDataContactsService *service;
+#ifdef HAVE_GDATA_VERSION_0_9_1
+
+ log_message(LOG_PROTOCOL, _("GData plugin: Starting async groups query\n"));
+
+ service = gdata_contacts_service_new(GDATA_AUTHORIZER(authorizer));
+ gdata_contacts_service_query_groups_async(service, NULL, NULL, NULL, NULL, NULL,
+ (GAsyncReadyCallback)cm_gdata_query_groups_ready, NULL);
+#else
+ service = gdata_contacts_service_new(GDATA_AUTHORIZER(authorizer));
+ query_after_auth(service);
+#endif
+ g_object_unref(service);
+}
+
static void cm_gdata_auth_ready(GDataClientLoginAuthorizer *authorizer, GAsyncResult *res, gpointer data)
{
GError *error = NULL;
- GDataContactsService *service;
if(gdata_client_login_authorizer_authenticate_finish(authorizer, res, &error) == FALSE)
{
@@ -232,11 +304,16 @@
log_message(LOG_PROTOCOL, _("GData plugin: Authenticated\n"));
- service = gdata_contacts_service_new(GDATA_AUTHORIZER(authorizer));
-
- query_after_auth(service);
-
- g_object_unref(service);
+ if(!contacts_group_id)
+ {
+ query_for_contacts_group_id(authorizer);
+ }
+ else {
+ GDataContactsService *service;
+ service = gdata_contacts_service_new(GDATA_AUTHORIZER(authorizer));
+ query_after_auth(service);
+ g_object_unref(service);
+ }
}
#else
static void cm_gdata_auth_ready(GDataContactsService *service, GAsyncResult *res, gpointer data)
@@ -345,6 +422,9 @@
void cm_gdata_contacts_done(void)
{
+ g_free(contacts_group_id);
+ contacts_group_id = NULL;
+
write_cache_to_file();
if(contacts_cache.contacts && !claws_is_exiting())
clear_contacts_cache();
More information about the Commits
mailing list