[gnome-contacts] Hide google contacts not in My Contacts



commit a3eaab0b0159adfc2131a541d58780c08ae6695e
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Nov 29 12:10:56 2011 +0100

    Hide google contacts not in My Contacts
    
    These contacts are autogenerated stuff which is not supposed
    to be visible in the UI.

 src/contacts-contact.vala |    8 ++++++++
 src/contacts-esd-setup.c  |   34 ++++++++++++++++++++++++++++++++++
 src/contacts-esd-setup.h  |    2 ++
 vapi/custom.vapi          |    4 ++++
 4 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index fd9dcc0..d598563 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -277,7 +277,15 @@ public class Contacts.Contact : GLib.Object  {
       if (store.type_id == "telepathy" &&
 	  store.trust_level == PersonaStoreTrust.NONE)
 	return true;
+
+      // Filter out google contacts not in "My Contacts" as these are not really useful
+      if (store.type_id == "eds" && esource_uid_is_google (store.id)) {
+	var g = persona as GroupDetails;
+	if (g != null && !g.groups.contains (eds_personal_google_group_name ()))
+	  return true;
+      }
     }
+
     return false;
   }
 
diff --git a/src/contacts-esd-setup.c b/src/contacts-esd-setup.c
index 20fd3cd..4e8d650 100644
--- a/src/contacts-esd-setup.c
+++ b/src/contacts-esd-setup.c
@@ -25,6 +25,7 @@
 #include <libedataserver/e-source.h>
 #include <libedataserver/e-source-group.h>
 #include <libedataserver/e-uid.h>
+#include <libedataserver/eds-version.h>
 #include <glib/gi18n-lib.h>
 
 char *contacts_eds_local_store = NULL;
@@ -572,6 +573,39 @@ void contacts_ensure_eds_accounts (void)
 }
 
 
+/* This is an enourmous hack to find google eds contacts that are
+   in the "My Contacts" system group. */
+char *
+eds_personal_google_group_name (void)
+{
+  static char *name = NULL;
+  char *domain;
+
+  if (name == NULL) {
+    domain = g_strdup_printf ("evolution-data-server-%d.%d\n",
+			      EDS_MAJOR_VERSION,
+			      EDS_MINOR_VERSION + ((EDS_MINOR_VERSION + 1) % 2));
+    name = dgettext (domain, "Personal");
+    g_free (domain);
+  }
+
+  return name;
+}
+
+gboolean
+contacts_esource_uid_is_google (const char *uid)
+{
+  if (contacts_source_list) {
+    ESource *source = e_source_list_peek_source_by_uid (contacts_source_list, uid);
+    if (source) {
+      const char *relative_uri = e_source_peek_relative_uri (source);
+      if (relative_uri && g_str_has_suffix (relative_uri, "@gmail.com"))
+	return TRUE;
+    }
+  }
+  return FALSE;
+}
+
 const char *
 contacts_lookup_esource_name_by_uid (const char *uid)
 {
diff --git a/src/contacts-esd-setup.h b/src/contacts-esd-setup.h
index d71a9e4..bda6294 100644
--- a/src/contacts-esd-setup.h
+++ b/src/contacts-esd-setup.h
@@ -1,3 +1,5 @@
 void contacts_ensure_eds_accounts (void);
 extern char *contacts_eds_local_store;
 const char *contacts_lookup_esource_name_by_uid (const char *uid);
+gboolean contacts_esource_uid_is_google (const char *uid);
+char *eds_personal_google_group_name (void);
diff --git a/vapi/custom.vapi b/vapi/custom.vapi
index 1e73b83..0ec822c 100644
--- a/vapi/custom.vapi
+++ b/vapi/custom.vapi
@@ -31,4 +31,8 @@ namespace Contacts {
 	public static string? eds_local_store;
 	[CCode (cname = "contacts_lookup_esource_name_by_uid")]
 	public static unowned string? lookup_esource_name_by_uid (string uid);
+	[CCode (cname = "contacts_esource_uid_is_google")]
+	public static bool esource_uid_is_google (string uid);
+	[CCode (cname = "eds_personal_google_group_name")]
+	public static unowned string? eds_personal_google_group_name ();
 }



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