aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaul Gutierrez Segales <rgs@collabora.co.uk>2011-09-19 22:09:57 +0800
committerRaul Gutierrez Segales <rgs@collabora.co.uk>2011-09-19 22:27:38 +0800
commitaaff7e95f9dd66f94a3b85e910b049daf9097a0c (patch)
tree36dd2c6d2b77e675f3ccc96cb894d6b1e49aeb62
parentccd55bf7585624f1aab05525444449c44310d642 (diff)
downloadgsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.tar
gsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.tar.gz
gsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.tar.bz2
gsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.tar.lz
gsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.tar.xz
gsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.tar.zst
gsoc2013-empathy-aaff7e95f9dd66f94a3b85e910b049daf9097a0c.zip
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.
-rw-r--r--libempathy-gtk/empathy-individual-menu.c5
-rw-r--r--libempathy/empathy-utils.c94
-rw-r--r--libempathy/empathy-utils.h6
3 files changed, 83 insertions, 22 deletions
diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c
index 745474d84..5d24cf120 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 172e9e182..66add2f7d 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 69a7d6287..ed603a80f 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);