From 6da159d09091d68a102c142b10747ae58755de51 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Wed, 9 Feb 2011 17:24:27 +1100 Subject: Add contact blocking support to EmpathyIndividualManager --- libempathy/empathy-individual-manager.c | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'libempathy/empathy-individual-manager.c') diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index 894ae648b..a2432effe 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -30,6 +30,7 @@ #include #include +#include #include @@ -483,6 +484,77 @@ empathy_individual_manager_remove (EmpathyIndividualManager *self, aggregator_remove_individual_cb, self); } +/** + * empathy_individual_manager_supports_blocking + * @self: the #EmpathyIndividualManager + * @individual: an individual to check + * + * Indicates whether any personas of an @individual can be blocked. + * + * Returns: %TRUE if any persona supports contact blocking + */ +gboolean +empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self, + FolksIndividual *individual) +{ + EmpathyIndividualManagerPriv *priv; + GList *personas, *l; + + g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE); + + priv = GET_PRIV (self); + + personas = folks_individual_get_personas (individual); + + for (l = personas; l != NULL; l = l->next) + { + TpfPersona *persona = l->data; + TpConnection *conn; + + if (!TPF_IS_PERSONA (persona)) + continue; + + conn = tp_contact_get_connection (tpf_persona_get_contact (persona)); + + if (empathy_individual_manager_get_flags_for_connection (self, conn) & + EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK) + return TRUE; + } + + return FALSE; +} + +void +empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, + FolksIndividual *individual, + gboolean blocked) +{ + EmpathyIndividualManagerPriv *priv; + GList *personas, *l; + + g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self)); + + priv = GET_PRIV (self); + + personas = folks_individual_get_personas (individual); + + for (l = personas; l != NULL; l = l->next) + { + TpfPersona *persona = l->data; + EmpathyContact *contact; + + if (!TPF_IS_PERSONA (persona)) + continue; + + contact = empathy_contact_dup_from_tp_contact ( + tpf_persona_get_contact (persona)); + empathy_contact_set_persona (contact, FOLKS_PERSONA (persona)); + empathy_contact_list_set_blocked ( + EMPATHY_CONTACT_LIST (priv->contact_manager), + contact, blocked); + } +} + static void groups_change_group_cb (GObject *source, GAsyncResult *result, @@ -526,6 +598,38 @@ empathy_individual_manager_remove_group (EmpathyIndividualManager *manager, (gpointer) group); } +EmpathyIndividualManagerFlags +empathy_individual_manager_get_flags_for_connection ( + EmpathyIndividualManager *self, + TpConnection *connection) +{ + EmpathyIndividualManagerPriv *priv; + EmpathyContactListFlags list_flags; + EmpathyIndividualManagerFlags flags; + + g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), + EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS); + + priv = GET_PRIV (self); + + list_flags = empathy_contact_manager_get_flags_for_connection ( + priv->contact_manager, connection); + + flags = EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_ADD) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_REMOVE) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_REMOVE; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_ALIAS) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_ALIAS; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_GROUP) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_GROUP; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_BLOCK) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK; + + return flags; +} + static void link_personas_cb (FolksIndividualAggregator *aggregator, GAsyncResult *async_result, -- cgit v1.2.3