From 736b4f3d04f1e826dd8252fed88a7445b52ad461 Mon Sep 17 00:00:00 2001 From: Travis Reitter Date: Fri, 29 Apr 2011 13:33:04 -0700 Subject: Adapt to API break in folks_individual_get_personas. Helps: bgo#648822 - Port Empathy to Folks 0.5.1 --- libempathy/empathy-contact.c | 44 ++++++++++-------- libempathy/empathy-individual-manager.c | 82 ++++++++++++++++++--------------- libempathy/empathy-individual-manager.h | 2 +- libempathy/empathy-utils.c | 61 ++++++++++++++++++------ libempathy/empathy-utils.h | 2 +- 5 files changed, 119 insertions(+), 72 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 7b23df0fc..44a561b6e 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -877,13 +877,16 @@ empathy_contact_get_persona (EmpathyContact *contact) for (l = individuals; l != NULL; l = l->next) { - GList *personas, *j; FolksIndividual *individual = FOLKS_INDIVIDUAL (l->data); + GeeSet *personas; + GeeIterator *iter; + gboolean persona_found = FALSE; personas = folks_individual_get_personas (individual); - for (j = personas; j != NULL; j = j->next) + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (!persona_found && gee_iterator_next (iter)) { - TpfPersona *persona = j->data; + TpfPersona *persona = gee_iterator_get (iter); if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona))) { @@ -894,13 +897,14 @@ empathy_contact_get_persona (EmpathyContact *contact) /* Found the right persona */ empathy_contact_set_persona (contact, (FolksPersona *) persona); - goto finished; + persona_found = TRUE; } + g_clear_object (&persona); } } + g_clear_object (&iter); } -finished: g_list_free (individuals); g_object_unref (manager); } @@ -1983,35 +1987,39 @@ EmpathyContact * empathy_contact_dup_best_for_action (FolksIndividual *individual, EmpathyActionType action_type) { - GList *personas, *contacts, *l; + GeeSet *personas; + GeeIterator *iter; + GList *contacts; EmpathyContact *best_contact = NULL; /* Build a list of EmpathyContacts that we can sort */ personas = folks_individual_get_personas (individual); contacts = NULL; - for (l = personas; l != NULL; l = l->next) + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (gee_iterator_next (iter)) { + FolksPersona *persona = gee_iterator_get (iter); TpContact *tp_contact; - EmpathyContact *contact; + EmpathyContact *contact = NULL; - if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data))) - continue; + if (!empathy_folks_persona_is_interesting (persona)) + goto while_finish; - tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data)); + tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona)); contact = empathy_contact_dup_from_tp_contact (tp_contact); - empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data)); + empathy_contact_set_persona (contact, FOLKS_PERSONA (persona)); /* Only choose the contact if they're actually capable of the specified * action. */ - if (!empathy_contact_can_do_action (contact, action_type)) - { - g_object_unref (contact); - continue; - } + if (empathy_contact_can_do_action (contact, action_type)) + contacts = g_list_prepend (contacts, g_object_ref (contact)); - contacts = g_list_prepend (contacts, contact); +while_finish: + g_clear_object (&contact); + g_clear_object (&persona); } + g_clear_object (&iter); /* Sort the contacts by some heuristic based on the action type, then take * the top contact. */ diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index 088c67fd8..00e685c68 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -500,32 +500,36 @@ gboolean empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self, FolksIndividual *individual) { - GList *personas, *l; + GeeSet *personas; + GeeIterator *iter; + gboolean retval = FALSE; g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE); personas = folks_individual_get_personas (individual); - - for (l = personas; l != NULL; l = l->next) + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (!retval && gee_iterator_next (iter)) { - TpfPersona *persona = l->data; + TpfPersona *persona = gee_iterator_get (iter); TpConnection *conn; EmpathyContactManager *manager; - if (!TPF_IS_PERSONA (persona)) - continue; - - conn = tp_contact_get_connection (tpf_persona_get_contact (persona)); - manager = empathy_contact_manager_dup_singleton (); + if (TPF_IS_PERSONA (persona)) + { + conn = tp_contact_get_connection (tpf_persona_get_contact (persona)); + manager = empathy_contact_manager_dup_singleton (); - if (empathy_contact_manager_get_flags_for_connection (manager, conn) & - EMPATHY_CONTACT_LIST_CAN_BLOCK) - return TRUE; + if (empathy_contact_manager_get_flags_for_connection (manager, conn) & + EMPATHY_CONTACT_LIST_CAN_BLOCK) + retval = TRUE; - g_object_unref (manager); + g_object_unref (manager); + } + g_clear_object (&persona); } + g_clear_object (&iter); - return FALSE; + return retval; } void @@ -534,37 +538,40 @@ empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, gboolean blocked, gboolean abusive) { - GList *personas, *l; + GeeSet *personas; + GeeIterator *iter; g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self)); personas = folks_individual_get_personas (individual); - - for (l = personas; l != NULL; l = l->next) + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (gee_iterator_next (iter)) { - TpfPersona *persona = l->data; + TpfPersona *persona = gee_iterator_get (iter); EmpathyContact *contact; EmpathyContactManager *manager; EmpathyContactListFlags flags; - 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)); - manager = empathy_contact_manager_dup_singleton (); - flags = empathy_contact_manager_get_flags_for_connection (manager, - empathy_contact_get_connection (contact)); - - if (flags & EMPATHY_CONTACT_LIST_CAN_BLOCK) - empathy_contact_list_set_blocked ( - EMPATHY_CONTACT_LIST (manager), - contact, blocked, abusive); - - g_object_unref (manager); - g_object_unref (contact); + if (TPF_IS_PERSONA (persona)) + { + contact = empathy_contact_dup_from_tp_contact ( + tpf_persona_get_contact (persona)); + empathy_contact_set_persona (contact, FOLKS_PERSONA (persona)); + manager = empathy_contact_manager_dup_singleton (); + flags = empathy_contact_manager_get_flags_for_connection (manager, + empathy_contact_get_connection (contact)); + + if (flags & EMPATHY_CONTACT_LIST_CAN_BLOCK) + empathy_contact_list_set_blocked ( + EMPATHY_CONTACT_LIST (manager), + contact, blocked, abusive); + + g_object_unref (manager); + g_object_unref (contact); + } + g_clear_object (&persona); } + g_clear_object (&iter); } static void @@ -629,7 +636,7 @@ link_personas_cb (FolksIndividualAggregator *aggregator, void empathy_individual_manager_link_personas (EmpathyIndividualManager *self, - GList *personas) + GeeSet *personas) { EmpathyIndividualManagerPriv *priv; @@ -638,7 +645,8 @@ empathy_individual_manager_link_personas (EmpathyIndividualManager *self, priv = GET_PRIV (self); - DEBUG ("Linking %u personas", g_list_length (personas)); + DEBUG ("Linking %u personas", + gee_collection_get_size (GEE_COLLECTION (personas))); folks_individual_aggregator_link_personas (priv->aggregator, personas, (GAsyncReadyCallback) link_personas_cb, NULL); diff --git a/libempathy/empathy-individual-manager.h b/libempathy/empathy-individual-manager.h index 1fec67d91..0d5cc74d4 100644 --- a/libempathy/empathy-individual-manager.h +++ b/libempathy/empathy-individual-manager.h @@ -75,7 +75,7 @@ void empathy_individual_manager_remove_group (EmpathyIndividualManager *manager, const gchar *group); void empathy_individual_manager_link_personas (EmpathyIndividualManager *self, - GList *personas); + GeeSet *personas); void empathy_individual_manager_unlink_individual ( EmpathyIndividualManager *self, diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index d62066fb3..bdec98833 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -776,18 +776,30 @@ empathy_folks_presence_type_to_tp (FolksPresenceType type) gboolean empathy_folks_individual_contains_contact (FolksIndividual *individual) { - GList *personas, *l; + GeeSet *personas; + GeeIterator *iter; + gboolean retval = FALSE; g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), FALSE); personas = folks_individual_get_personas (individual); - for (l = personas; l != NULL; l = l->next) + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (!retval && gee_iterator_next (iter)) { - if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data))) - return (tpf_persona_get_contact (TPF_PERSONA (l->data)) != NULL); + FolksPersona *persona = gee_iterator_get (iter); + TpContact *contact = NULL; + + if (empathy_folks_persona_is_interesting (persona)) + contact = tpf_persona_get_contact (TPF_PERSONA (persona)); + + g_clear_object (&persona); + + if (contact != NULL) + retval = TRUE; } + g_clear_object (&iter); - return FALSE; + return retval; } /* TODO: this needs to be eliminated (and replaced in some cases with user @@ -800,15 +812,17 @@ empathy_folks_individual_contains_contact (FolksIndividual *individual) EmpathyContact * empathy_contact_dup_from_folks_individual (FolksIndividual *individual) { - GList *personas, *l; + GeeSet *personas; + GeeIterator *iter; EmpathyContact *contact = NULL; g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL); personas = folks_individual_get_personas (individual); - for (l = personas; (l != NULL) && (contact == NULL); l = l->next) + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (gee_iterator_next (iter) && (contact == NULL)) { - TpfPersona *persona = l->data; + TpfPersona *persona = gee_iterator_get (iter); if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona))) { @@ -818,7 +832,9 @@ empathy_contact_dup_from_folks_individual (FolksIndividual *individual) contact = empathy_contact_dup_from_tp_contact (tp_contact); empathy_contact_set_persona (contact, FOLKS_PERSONA (persona)); } + g_clear_object (&persona); } + g_clear_object (&iter); return contact; } @@ -831,7 +847,7 @@ tp_channel_group_change_reason_from_folks_groups_change_reason ( } TpfPersonaStore * -empathy_get_persona_store_for_connection (TpConnection *connection) +empathy_dup_persona_store_for_connection (TpConnection *connection) { FolksBackendStore *backend_store; FolksBackend *backend; @@ -871,43 +887,58 @@ empathy_get_persona_store_for_connection (TpConnection *connection) gboolean empathy_connection_can_add_personas (TpConnection *connection) { + gboolean retval; FolksPersonaStore *persona_store; g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE); persona_store = FOLKS_PERSONA_STORE ( - empathy_get_persona_store_for_connection (connection)); + empathy_dup_persona_store_for_connection (connection)); - return (folks_persona_store_get_can_add_personas (persona_store) == + retval = (folks_persona_store_get_can_add_personas (persona_store) == FOLKS_MAYBE_BOOL_TRUE); + + g_clear_object (&persona_store); + + return retval; } gboolean empathy_connection_can_alias_personas (TpConnection *connection) { + gboolean retval; FolksPersonaStore *persona_store; g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE); persona_store = FOLKS_PERSONA_STORE ( - empathy_get_persona_store_for_connection (connection)); + empathy_dup_persona_store_for_connection (connection)); - return (folks_persona_store_get_can_alias_personas (persona_store) == + retval = (folks_persona_store_get_can_alias_personas (persona_store) == FOLKS_MAYBE_BOOL_TRUE); + + g_clear_object (&persona_store); + + return retval; } gboolean empathy_connection_can_group_personas (TpConnection *connection) { + gboolean retval; FolksPersonaStore *persona_store; g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE); persona_store = FOLKS_PERSONA_STORE ( - empathy_get_persona_store_for_connection (connection)); + empathy_dup_persona_store_for_connection (connection)); - return (folks_persona_store_get_can_group_personas (persona_store) == + retval = (folks_persona_store_get_can_group_personas (persona_store) == FOLKS_MAYBE_BOOL_TRUE); + + g_clear_object (&persona_store); + + return retval; } gboolean diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index ac44535b8..157569453 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -109,7 +109,7 @@ TpConnectionPresenceType empathy_folks_presence_type_to_tp (FolksPresenceType ty gboolean empathy_folks_individual_contains_contact (FolksIndividual *individual); EmpathyContact * empathy_contact_dup_from_folks_individual (FolksIndividual *individual); TpChannelGroupChangeReason tp_channel_group_change_reason_from_folks_groups_change_reason (FolksGroupDetailsChangeReason reason); -TpfPersonaStore * empathy_get_persona_store_for_connection (TpConnection *connection); +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); -- cgit v1.2.3