[empathy] Use always-writeable and writeable-properties for alias and groups



commit aaff7e95f9dd66f94a3b85e910b049daf9097a0c
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date:   Mon Sep 19 15:09:57 2011 +0100

    Use always-writeable and writeable-properties for alias and groups
    
    Folks is in the way of deprecating the
    folks_persona_store_get_can_{alias,group}_personas methods in favour
    of directly checking alias and groups properties via
    folks_persona_store_get_always_writeable_properties and
    folks_persona_get_writeable_properties.

 libempathy-gtk/empathy-individual-menu.c |    5 +-
 libempathy/empathy-utils.c               |   94 ++++++++++++++++++++++++------
 libempathy/empathy-utils.h               |    6 +-
 3 files changed, 83 insertions(+), 22 deletions(-)
---
diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c
index 745474d..5d24cf1 100644
--- a/libempathy-gtk/empathy-individual-menu.c
+++ b/libempathy-gtk/empathy-individual-menu.c
@@ -1131,8 +1131,9 @@ empathy_individual_edit_menu_item_new (FolksIndividual *individual)
       manager = empathy_individual_manager_dup_singleton ();
       connection = empathy_contact_get_connection (contact);
 
-      enable = (empathy_connection_can_alias_personas (connection) &&
-                empathy_connection_can_group_personas (connection));
+      enable = (empathy_connection_can_alias_personas (connection,
+						       individual) &&
+                empathy_connection_can_group_personas (connection, individual));
 
       g_object_unref (manager);
     }
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 172e9e1..66add2f 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -80,6 +80,16 @@ static struct {
   { NULL, },
 };
 
+static gboolean
+properties_contains (gchar **list,
+		     gint length,
+		     const gchar *property);
+
+static gboolean
+check_writeable_property (TpConnection *connection,
+			  FolksIndividual *individual,
+			  gchar *property);
+
 void
 empathy_init (void)
 {
@@ -802,10 +812,10 @@ empathy_connection_can_add_personas (TpConnection *connection)
 }
 
 gboolean
-empathy_connection_can_alias_personas (TpConnection *connection)
+empathy_connection_can_alias_personas (TpConnection *connection,
+				       FolksIndividual *individual)
 {
   gboolean retval;
-  FolksPersonaStore *persona_store;
 
   g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE);
 
@@ -813,22 +823,16 @@ empathy_connection_can_alias_personas (TpConnection *connection)
           TP_CONNECTION_STATUS_CONNECTED)
       return FALSE;
 
-  persona_store = FOLKS_PERSONA_STORE (
-      empathy_dup_persona_store_for_connection (connection));
-
-  retval = (folks_persona_store_get_can_alias_personas (persona_store) ==
-      FOLKS_MAYBE_BOOL_TRUE);
-
-  g_clear_object (&persona_store);
+  retval = check_writeable_property (connection, individual, "alias");
 
   return retval;
 }
 
 gboolean
-empathy_connection_can_group_personas (TpConnection *connection)
+empathy_connection_can_group_personas (TpConnection *connection,
+				       FolksIndividual *individual)
 {
   gboolean retval;
-  FolksPersonaStore *persona_store;
 
   g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE);
 
@@ -836,13 +840,7 @@ empathy_connection_can_group_personas (TpConnection *connection)
           TP_CONNECTION_STATUS_CONNECTED)
       return FALSE;
 
-  persona_store = FOLKS_PERSONA_STORE (
-      empathy_dup_persona_store_for_connection (connection));
-
-  retval = (folks_persona_store_get_can_group_personas (persona_store) ==
-      FOLKS_MAYBE_BOOL_TRUE);
-
-  g_clear_object (&persona_store);
+  retval = check_writeable_property (connection, individual, "groups");
 
   return retval;
 }
@@ -1030,3 +1028,63 @@ empathy_get_tp_contact_for_individual (FolksIndividual *individual,
   return contact;
 }
 
+static gboolean
+properties_contains (gchar **list,
+		     gint length,
+		     const gchar *property)
+{
+  gint i;
+
+  for (i = 0; i < length; i++)
+    {
+      if (!tp_strdiff (list[i], property))
+	return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+check_writeable_property (TpConnection *connection,
+			  FolksIndividual *individual,
+			  gchar *property)
+{
+  gchar **properties;
+  gint prop_len;
+  gboolean retval = FALSE;
+  GeeSet *personas;
+  GeeIterator *iter;
+  FolksPersonaStore *persona_store;
+
+  persona_store = FOLKS_PERSONA_STORE (
+      empathy_dup_persona_store_for_connection (connection));
+
+  properties =
+    folks_persona_store_get_always_writeable_properties (persona_store,
+							 &prop_len);
+  retval = properties_contains (properties, prop_len, property);
+  if (retval == TRUE)
+    goto out;
+
+  /* Lets see if the Individual contains a Persona with the given property */
+  personas = folks_individual_get_personas (individual);
+  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+  while (!retval && gee_iterator_next (iter))
+    {
+      FolksPersona *persona = gee_iterator_get (iter);
+
+      properties =
+	folks_persona_get_writeable_properties (persona, &prop_len);
+      retval = properties_contains (properties, prop_len, property);
+
+      g_clear_object (&persona);
+
+      if (retval == TRUE)
+	break;
+    }
+  g_clear_object (&iter);
+
+out:
+  g_clear_object (&persona_store);
+  return retval;
+}
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 69a7d62..ed603a8 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -96,8 +96,10 @@ TpChannelGroupChangeReason tp_channel_group_change_reason_from_folks_groups_chan
 TpfPersonaStore * empathy_dup_persona_store_for_connection (
     TpConnection *connection);
 gboolean empathy_connection_can_add_personas (TpConnection *connection);
-gboolean empathy_connection_can_alias_personas (TpConnection *connection);
-gboolean empathy_connection_can_group_personas (TpConnection *connection);
+gboolean empathy_connection_can_alias_personas (TpConnection *connection,
+						FolksIndividual *individual);
+gboolean empathy_connection_can_group_personas (TpConnection *connection,
+						FolksIndividual *individual);
 gboolean empathy_folks_persona_is_interesting (FolksPersona *persona);
 
 gchar * empathy_get_x509_certificate_hostname (gnutls_x509_crt_t cert);



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