aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-individual-dialogs.c15
-rw-r--r--libempathy-gtk/empathy-individual-information-dialog.c13
-rw-r--r--libempathy-gtk/empathy-individual-linker.c70
-rw-r--r--libempathy-gtk/empathy-individual-linker.h2
-rw-r--r--libempathy-gtk/empathy-individual-menu.c93
-rw-r--r--libempathy-gtk/empathy-individual-store.c121
-rw-r--r--libempathy-gtk/empathy-individual-view.c70
-rw-r--r--libempathy-gtk/empathy-individual-widget.c193
-rw-r--r--libempathy-gtk/empathy-linking-dialog.c14
-rw-r--r--libempathy-gtk/empathy-persona-store.c27
-rw-r--r--libempathy-gtk/empathy-ui-utils.c57
-rw-r--r--libempathy/empathy-contact.c44
-rw-r--r--libempathy/empathy-individual-manager.c82
-rw-r--r--libempathy/empathy-individual-manager.h2
-rw-r--r--libempathy/empathy-utils.c61
-rw-r--r--libempathy/empathy-utils.h2
-rw-r--r--src/empathy-invite-participant-dialog.c39
17 files changed, 573 insertions, 332 deletions
diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c
index 2e88a742b..a19787662 100644
--- a/libempathy-gtk/empathy-individual-dialogs.c
+++ b/libempathy-gtk/empathy-individual-dialogs.c
@@ -186,7 +186,8 @@ empathy_block_individual_dialog_show (GtkWindow *parent,
empathy_contact_manager_dup_singleton ();
GtkWidget *dialog;
GtkWidget *abusive_check = NULL;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
GString *text = g_string_new ("");
GString *blocked_str = g_string_new ("");
GString *notblocked_str = g_string_new ("");
@@ -208,17 +209,17 @@ empathy_block_individual_dialog_show (GtkWindow *parent,
/* build a list of personas that support blocking */
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);
TpContact *contact;
EmpathyContactListFlags flags;
GString *s;
char *str;
if (!TPF_IS_PERSONA (persona))
- continue;
+ goto while_finish;
contact = tpf_persona_get_contact (persona);
flags = empathy_contact_manager_get_flags_for_connection (
@@ -241,7 +242,11 @@ empathy_block_individual_dialog_show (GtkWindow *parent,
str = contact_pretty_name (contact);
g_string_append_printf (s, "\n " BULLET_POINT " %s", str);
g_free (str);
+
+while_finish:
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
g_string_append_printf (text,
_("Are you sure you want to block '%s' from contacting you again?"),
diff --git a/libempathy-gtk/empathy-individual-information-dialog.c b/libempathy-gtk/empathy-individual-information-dialog.c
index e14293d45..42bfb2053 100644
--- a/libempathy-gtk/empathy-individual-information-dialog.c
+++ b/libempathy-gtk/empathy-individual-information-dialog.c
@@ -129,19 +129,26 @@ static void
set_label_visibility (EmpathyIndividualInformationDialog *dialog)
{
EmpathyIndividualInformationDialogPriv *priv = GET_PRIV (dialog);
- GList *personas, *l;
guint num_personas = 0;
/* Count how many Telepathy personas we have, to see whether we can
* unlink */
if (priv->individual != NULL)
{
+ GeeSet *personas;
+ GeeIterator *iter;
+
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
num_personas++;
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
/* Only make the label visible if we have enough personas */
diff --git a/libempathy-gtk/empathy-individual-linker.c b/libempathy-gtk/empathy-individual-linker.c
index a291a6dee..3a1551a70 100644
--- a/libempathy-gtk/empathy-individual-linker.c
+++ b/libempathy-gtk/empathy-individual-linker.c
@@ -141,21 +141,34 @@ link_individual (EmpathyIndividualLinker *self,
FolksIndividual *individual)
{
EmpathyIndividualLinkerPriv *priv = GET_PRIV (self);
- GList *new_persona_list;
+ GeeSet *old_personas, *new_personas;
+ GeeHashSet *final_personas;
+ gboolean personas_changed;
/* Add the individual to the link */
g_hash_table_insert (priv->changed_individuals, individual,
GUINT_TO_POINTER (TRUE));
- /* Add personas which are in @individual to priv->new_individual, appending
- * them to the list of personas.
- * This is rather slow. */
- new_persona_list = g_list_copy (folks_individual_get_personas (
- priv->new_individual));
- new_persona_list = g_list_concat (new_persona_list,
- g_list_copy (folks_individual_get_personas (individual)));
- folks_individual_set_personas (priv->new_individual, new_persona_list);
- g_list_free (new_persona_list);
+ /* Add personas which are in @individual to priv->new_individual, adding them
+ * to the set of personas. */
+ old_personas = folks_individual_get_personas (individual);
+ new_personas = folks_individual_get_personas (priv->new_individual);
+ final_personas = gee_hash_set_new (FOLKS_TYPE_PERSONA, g_object_ref,
+ g_object_unref, g_direct_hash, g_direct_equal);
+ gee_collection_add_all (GEE_COLLECTION (final_personas),
+ GEE_COLLECTION (old_personas));
+ personas_changed = gee_collection_add_all (GEE_COLLECTION (final_personas),
+ GEE_COLLECTION (new_personas));
+
+ /* avoid updating all values in the Individual if the set of personas doesn't
+ * actually change */
+ if (personas_changed)
+ {
+ folks_individual_set_personas (priv->new_individual,
+ GEE_SET (final_personas));
+ }
+
+ g_clear_object (&final_personas);
/* Update the toggle renderers, so that if this Individual is listed in
* another group in the EmpathyIndividualView, the toggle button for that
@@ -170,28 +183,31 @@ unlink_individual (EmpathyIndividualLinker *self,
FolksIndividual *individual)
{
EmpathyIndividualLinkerPriv *priv = GET_PRIV (self);
- GList *new_persona_list, *old_persona_list, *removing_personas, *l;
+ GeeSet *removed_personas, *old_personas;
+ GeeHashSet *final_personas;
+ gboolean personas_changed;
/* Remove the individual from the link */
g_hash_table_remove (priv->changed_individuals, individual);
- /* Remove personas which are in @individual from priv->new_individual.
- * This is rather slow. */
- old_persona_list = folks_individual_get_personas (priv->new_individual);
- removing_personas = folks_individual_get_personas (individual);
- new_persona_list = NULL;
+ /* Remove personas which are in @individual from priv->new_individual. */
+ old_personas = folks_individual_get_personas (priv->new_individual);
+ removed_personas = folks_individual_get_personas (individual);
- for (l = old_persona_list; l != NULL; l = l->next)
- {
- GList *removing = g_list_find (removing_personas, l->data);
+ final_personas = gee_hash_set_new (FOLKS_TYPE_PERSONA, g_object_ref,
+ g_object_unref, g_direct_hash, g_direct_equal);
+ gee_collection_add_all (GEE_COLLECTION (final_personas),
+ GEE_COLLECTION (old_personas));
+ personas_changed = gee_collection_remove_all (GEE_COLLECTION (final_personas),
+ GEE_COLLECTION (removed_personas));
- if (removing == NULL)
- new_persona_list = g_list_prepend (new_persona_list, l->data);
+ if (personas_changed)
+ {
+ folks_individual_set_personas (priv->new_individual,
+ GEE_SET (final_personas));
}
- new_persona_list = g_list_reverse (new_persona_list);
- folks_individual_set_personas (priv->new_individual, new_persona_list);
- g_list_free (new_persona_list);
+ g_clear_object (&final_personas);
/* Update the toggle renderers, so that if this Individual is listed in
* another group in the EmpathyIndividualView, the toggle button for that
@@ -732,14 +748,14 @@ empathy_individual_linker_set_start_individual (EmpathyIndividualLinker *self,
*
* The return value is guaranteed to contain at least one element.
*
- * Return value: (transfer none) (element-type Folks.Persona): a list of
+ * Return value: (transfer none) (element-type Folks.Persona): a set of
* #FolksPersona<!-- -->s to link together
*/
-GList *
+GeeSet *
empathy_individual_linker_get_linked_personas (EmpathyIndividualLinker *self)
{
EmpathyIndividualLinkerPriv *priv;
- GList *personas;
+ GeeSet *personas;
g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_LINKER (self), NULL);
diff --git a/libempathy-gtk/empathy-individual-linker.h b/libempathy-gtk/empathy-individual-linker.h
index 9d122dc51..dcf75189b 100644
--- a/libempathy-gtk/empathy-individual-linker.h
+++ b/libempathy-gtk/empathy-individual-linker.h
@@ -62,7 +62,7 @@ void empathy_individual_linker_set_start_individual (
EmpathyIndividualLinker *self,
FolksIndividual *individual);
-GList * empathy_individual_linker_get_linked_personas (
+GeeSet * empathy_individual_linker_get_linked_personas (
EmpathyIndividualLinker *self);
gboolean empathy_individual_linker_get_has_changed (
diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c
index 4a0b45cab..8a2654b8f 100644
--- a/libempathy-gtk/empathy-individual-menu.c
+++ b/libempathy-gtk/empathy-individual-menu.c
@@ -74,23 +74,28 @@ individual_menu_add_personas (GtkMenuShell *menu,
EmpathyIndividualFeatureFlags features)
{
GtkWidget *item;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
guint persona_count = 0;
+ gboolean c;
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
g_return_if_fail (empathy_folks_individual_contains_contact (individual));
personas = folks_individual_get_personas (individual);
+ /* we'll re-use this iterator throughout */
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
/* Make sure we've got enough valid entries for these menu items to add
* functionality */
- for (l = personas; l != NULL; l = l->next)
+ while (gee_iterator_next (iter))
{
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
+ persona_count++;
- persona_count++;
+ g_clear_object (&persona);
}
/* return early if these entries would add nothing beyond the "quick" items */
@@ -103,21 +108,21 @@ individual_menu_add_personas (GtkMenuShell *menu,
gtk_widget_show (item);
personas = folks_individual_get_personas (individual);
- for (l = personas; l != NULL; l = l->next)
+ for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
{
GtkWidget *image;
GtkWidget *contact_item;
GtkWidget *contact_submenu;
TpContact *tp_contact;
EmpathyContact *contact;
- TpfPersona *persona = l->data;
+ TpfPersona *persona = gee_iterator_get (iter);
gchar *label;
FolksPersonaStore *store;
const gchar *account;
GtkWidget *action;
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
+ if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ goto while_finish;
tp_contact = tpf_persona_get_contact (persona);
contact = empathy_contact_dup_from_tp_contact (tp_contact);
@@ -199,7 +204,12 @@ individual_menu_add_personas (GtkMenuShell *menu,
g_free (label);
g_object_unref (contact);
+
+while_finish:
+ g_clear_object (&persona);
}
+
+ g_clear_object (&iter);
}
static void
@@ -981,7 +991,6 @@ room_sub_menu_activate_cb (GtkWidget *item,
EmpathyTpChat *chat;
EmpathyChatroomManager *mgr;
EmpathyContact *contact = NULL;
- GList *personas, *l;
chat = empathy_chatroom_get_tp_chat (data->chatroom);
if (chat == NULL)
@@ -996,30 +1005,37 @@ room_sub_menu_activate_cb (GtkWidget *item,
contact = g_object_ref (data->contact);
else
{
+ GeeSet *personas;
+ GeeIterator *iter;
+
/* find the first of this Individual's contacts who can join this room */
personas = folks_individual_get_personas (data->individual);
- for (l = personas; l != NULL && contact == NULL; l = g_list_next (l))
+
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter) && (contact == NULL))
{
- TpfPersona *persona = l->data;
+ TpfPersona *persona = gee_iterator_get (iter);
TpContact *tp_contact;
GList *rooms;
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
-
- tp_contact = tpf_persona_get_contact (persona);
- contact = empathy_contact_dup_from_tp_contact (tp_contact);
+ if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ {
+ tp_contact = tpf_persona_get_contact (persona);
+ contact = empathy_contact_dup_from_tp_contact (tp_contact);
- rooms = empathy_chatroom_manager_get_chatrooms (mgr,
- empathy_contact_get_account (contact));
+ rooms = empathy_chatroom_manager_get_chatrooms (mgr,
+ empathy_contact_get_account (contact));
- if (g_list_find (rooms, data->chatroom) == NULL)
- tp_clear_object (&contact);
+ if (g_list_find (rooms, data->chatroom) == NULL)
+ g_clear_object (&contact);
- /* if contact != NULL here, we've found our match */
+ /* if contact != NULL here, we've found our match */
- g_list_free (rooms);
+ g_list_free (rooms);
+ }
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
g_object_unref (mgr);
@@ -1065,7 +1081,6 @@ empathy_individual_invite_menu_item_new (FolksIndividual *individual,
GtkWidget *image;
GtkWidget *room_item;
EmpathyChatroomManager *mgr;
- GList *personas;
GList *rooms = NULL;
GList *names = NULL;
GList *l;
@@ -1095,27 +1110,33 @@ empathy_individual_invite_menu_item_new (FolksIndividual *individual,
}
else
{
- /* collect the rooms from amongst all accounts for this Individual */
+ GeeSet *personas;
+ GeeIterator *iter;
+
+ /* find the first of this Individual's contacts who can join this room */
personas = folks_individual_get_personas (individual);
- for (l = personas; l != NULL; l = g_list_next (l))
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- TpfPersona *persona = l->data;
+ TpfPersona *persona = gee_iterator_get (iter);
GList *rooms_cur;
TpContact *tp_contact;
EmpathyContact *contact_cur;
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
-
- tp_contact = tpf_persona_get_contact (persona);
- contact_cur = empathy_contact_dup_from_tp_contact (tp_contact);
+ if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ {
+ tp_contact = tpf_persona_get_contact (persona);
+ contact_cur = empathy_contact_dup_from_tp_contact (tp_contact);
- rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
- empathy_contact_get_account (contact_cur));
- rooms = g_list_concat (rooms, rooms_cur);
+ rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
+ empathy_contact_get_account (contact_cur));
+ rooms = g_list_concat (rooms, rooms_cur);
- g_object_unref (contact_cur);
+ g_object_unref (contact_cur);
+ }
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
/* alphabetize the rooms */
diff --git a/libempathy-gtk/empathy-individual-store.c b/libempathy-gtk/empathy-individual-store.c
index b804b2259..331a0e8a5 100644
--- a/libempathy-gtk/empathy-individual-store.c
+++ b/libempathy-gtk/empathy-individual-store.c
@@ -123,21 +123,24 @@ individual_can_audio_video_call (FolksIndividual *individual,
gboolean *can_audio_call,
gboolean *can_video_call)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
gboolean can_audio = FALSE, can_video = FALSE;
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))
{
+ FolksPersona *persona = gee_iterator_get (iter);
TpContact *tp_contact;
EmpathyContact *contact;
- 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, persona);
can_audio = can_audio || empathy_contact_get_capabilities (contact) &
EMPATHY_CAPABILITIES_AUDIO;
@@ -145,10 +148,13 @@ individual_can_audio_video_call (FolksIndividual *individual,
EMPATHY_CAPABILITIES_VIDEO;
g_object_unref (contact);
+while_finish:
+ g_clear_object (&persona);
if (can_audio && can_video)
break;
}
+ g_clear_object (&iter);
*can_audio_call = can_audio;
*can_video_call = can_video;
@@ -157,20 +163,23 @@ individual_can_audio_video_call (FolksIndividual *individual,
static const gchar * const *
individual_get_client_types (FolksIndividual *individual)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
const gchar * const *types = NULL;
FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
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))
{
FolksPresenceDetails *presence;
+ FolksPersona *persona = gee_iterator_get (iter);
/* We only want personas which have presence and a TpContact */
if (!empathy_folks_persona_is_interesting (persona))
- continue;
+ goto while_finish;
- presence = FOLKS_PRESENCE_DETAILS (l->data);
+ presence = FOLKS_PRESENCE_DETAILS (persona);
if (folks_presence_details_typecmp (
folks_presence_details_get_presence_type (presence),
@@ -180,10 +189,14 @@ individual_get_client_types (FolksIndividual *individual)
presence_type = folks_presence_details_get_presence_type (presence);
- tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
+ tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
types = tp_contact_get_client_types (tp_contact);
}
+
+while_finish:
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
return types;
}
@@ -858,62 +871,74 @@ individual_store_contact_updated_cb (EmpathyContact *contact,
static void
individual_personas_changed_cb (FolksIndividual *individual,
- GList *added,
- GList *removed,
+ GeeSet *added,
+ GeeSet *removed,
EmpathyIndividualStore *self)
{
- GList *l;
+ GeeIterator *iter;
DEBUG ("Individual '%s' personas-changed.",
folks_individual_get_id (individual));
+ iter = gee_iterable_iterator (GEE_ITERABLE (removed));
/* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
* through the EmpathyContacts for them. */
- for (l = removed; l != NULL; l = l->next)
+ while (gee_iterator_next (iter))
{
+ TpfPersona *persona = gee_iterator_get (iter);
TpContact *tp_contact;
EmpathyContact *contact;
- if (!TPF_IS_PERSONA (l->data))
- continue;
+ if (TPF_IS_PERSONA (persona))
+ {
+ tp_contact = tpf_persona_get_contact (persona);
+ contact = empathy_contact_dup_from_tp_contact (tp_contact);
+ empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
- tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
- contact = empathy_contact_dup_from_tp_contact (tp_contact);
- empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
+ g_object_set_data (G_OBJECT (contact), "individual", NULL);
+ g_signal_handlers_disconnect_by_func (contact,
+ (GCallback) individual_store_contact_updated_cb, self);
- g_object_set_data (G_OBJECT (contact), "individual", NULL);
- g_signal_handlers_disconnect_by_func (contact,
- (GCallback) individual_store_contact_updated_cb, self);
+ g_object_unref (contact);
+ }
- g_object_unref (contact);
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
- for (l = added; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (added));
+ while (gee_iterator_next (iter))
{
+ TpfPersona *persona = gee_iterator_get (iter);
TpContact *tp_contact;
EmpathyContact *contact;
- if (!TPF_IS_PERSONA (l->data))
- continue;
+ if (TPF_IS_PERSONA (persona))
+ {
+ tp_contact = tpf_persona_get_contact (persona);
+ contact = empathy_contact_dup_from_tp_contact (tp_contact);
+ empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
- tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
- contact = empathy_contact_dup_from_tp_contact (tp_contact);
- empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
+ g_object_set_data (G_OBJECT (contact), "individual", individual);
+ g_signal_connect (contact, "notify::capabilities",
+ (GCallback) individual_store_contact_updated_cb, self);
+ g_signal_connect (contact, "notify::client-types",
+ (GCallback) individual_store_contact_updated_cb, self);
- g_object_set_data (G_OBJECT (contact), "individual", individual);
- g_signal_connect (contact, "notify::capabilities",
- (GCallback) individual_store_contact_updated_cb, self);
- g_signal_connect (contact, "notify::client-types",
- (GCallback) individual_store_contact_updated_cb, self);
+ g_object_unref (contact);
+ }
- g_object_unref (contact);
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
void
individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
FolksIndividual *individual)
{
+ GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
+
individual_store_add_individual (self, individual);
g_signal_connect (individual, "notify::avatar",
@@ -927,16 +952,22 @@ individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
g_signal_connect (individual, "personas-changed",
(GCallback) individual_personas_changed_cb, self);
+ /* provide an empty set so the callback can assume non-NULL sets */
individual_personas_changed_cb (individual,
- folks_individual_get_personas (individual), NULL, self);
+ folks_individual_get_personas (individual), empty_set, self);
+ g_clear_object (&empty_set);
}
static void
individual_store_disconnect_individual (EmpathyIndividualStore *self,
FolksIndividual *individual)
{
- individual_personas_changed_cb (individual, NULL,
+ GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
+
+ /* provide an empty set so the callback can assume non-NULL sets */
+ individual_personas_changed_cb (individual, empty_set,
folks_individual_get_personas (individual), self);
+ g_clear_object (&empty_set);
g_signal_handlers_disconnect_by_func (individual,
(GCallback) individual_store_individual_updated_cb, self);
@@ -1925,22 +1956,28 @@ individual_store_get_individual_status_icon_with_icon_name (
EmpathyIndividualStorePriv *priv;
const gchar *protocol_name = NULL;
gchar *icon_name = NULL;
- GList *personas, *l;
- guint contact_count;
+ GeeSet *personas;
+ GeeIterator *iter;
+ guint contact_count = 0;
EmpathyContact *contact = NULL;
gboolean show_protocols_here;
priv = GET_PRIV (self);
personas = folks_individual_get_personas (individual);
- for (l = personas, contact_count = 0; l; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
contact_count++;
+ g_clear_object (&persona);
+
if (contact_count > 1)
break;
}
+ g_clear_object (&iter);
show_protocols_here = (priv->show_protocols && (contact_count == 1));
if (show_protocols_here)
diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c
index c467e9091..52ceff6c7 100644
--- a/libempathy-gtk/empathy-individual-view.c
+++ b/libempathy-gtk/empathy-individual-view.c
@@ -417,6 +417,7 @@ individual_view_persona_drag_received (GtkWidget *self,
FolksPersona *persona = NULL;
const gchar *persona_uid;
GList *individuals, *l;
+ GeeIterator *iter = NULL;
gboolean retval = FALSE;
persona_uid = (const gchar *) gtk_selection_data_get_data (selection);
@@ -428,23 +429,28 @@ individual_view_persona_drag_received (GtkWidget *self,
for (l = individuals; l != NULL; l = l->next)
{
- GList *personas, *p;
+ GeeSet *personas;
personas = folks_individual_get_personas (FOLKS_INDIVIDUAL (l->data));
-
- for (p = personas; p != NULL; p = p->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- if (!tp_strdiff (folks_persona_get_uid (FOLKS_PERSONA (p->data)),
- persona_uid))
+ FolksPersona *persona_cur = gee_iterator_get (iter);
+
+ if (!tp_strdiff (folks_persona_get_uid (persona), persona_uid))
{
- persona = g_object_ref (p->data);
+ /* takes ownership of the ref */
+ persona = persona_cur;
individual = g_object_ref (l->data);
goto got_persona;
}
+ g_clear_object (&persona_cur);
}
+ g_clear_object (&iter);
}
got_persona:
+ g_clear_object (&iter);
g_list_free (individuals);
if (persona == NULL || individual == NULL)
@@ -1692,7 +1698,8 @@ individual_view_is_visible_individual (EmpathyIndividualView *self,
{
EmpathyIndividualViewPriv *priv = GET_PRIV (self);
EmpathyLiveSearch *live = EMPATHY_LIVE_SEARCH (priv->search_widget);
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
gboolean is_favorite, contains_interesting_persona = FALSE;
/* We're only giving the visibility wrt filtering here, not things like
@@ -1705,14 +1712,17 @@ individual_view_is_visible_individual (EmpathyIndividualView *self,
/* Hide all individuals which consist entirely of uninteresting personas */
personas = folks_individual_get_personas (individual);
- for (l = personas; l; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (!contains_interesting_persona && gee_iterator_next (iter))
{
- if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- {
- contains_interesting_persona = TRUE;
- break;
- }
+ FolksPersona *persona = gee_iterator_get (iter);
+
+ if (empathy_folks_persona_is_interesting (persona))
+ contains_interesting_persona = TRUE;
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
if (contains_interesting_persona == FALSE)
return FALSE;
@@ -2438,7 +2448,8 @@ got_avatar (GObject *source_object,
EmpathyIndividualManager *manager;
gchar *text;
GtkWindow *parent;
- GList *l, *personas;
+ GeeSet *personas;
+ GeeIterator *iter;
guint persona_count = 0;
gboolean can_block;
GError *error = NULL;
@@ -2457,19 +2468,21 @@ got_avatar (GObject *source_object,
* so we still display the remove dialog. */
personas = folks_individual_get_personas (individual);
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
/* If we have more than one TpfPersona, display a different message
* ensuring the user knows that *all* of the meta-contacts' personas will
* be removed. */
- for (l = personas; l != NULL; l = l->next)
+ while (persona_count < 2 && gee_iterator_next (iter))
{
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
+ FolksPersona *persona = gee_iterator_get (iter);
+
+ if (empathy_folks_persona_is_interesting (persona))
+ persona_count++;
- persona_count++;
- if (persona_count >= 2)
- break;
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
if (persona_count < 2)
{
@@ -2561,7 +2574,8 @@ empathy_individual_view_get_individual_menu (EmpathyIndividualView *view)
GtkWidget *item;
GtkWidget *image;
gboolean can_remove = FALSE;
- GList *l;
+ GeeSet *personas;
+ GeeIterator *iter;
g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view), NULL);
@@ -2577,19 +2591,21 @@ empathy_individual_view_get_individual_menu (EmpathyIndividualView *view)
* remove. This will act as a best-effort option. If any Personas cannot be
* removed from the server, then this option will just be inactive upon
* subsequent menu openings */
- for (l = folks_individual_get_personas (individual); l != NULL; l = l->next)
+ personas = folks_individual_get_personas (individual);
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (!can_remove && gee_iterator_next (iter))
{
- FolksPersona *persona = FOLKS_PERSONA (l->data);
+ FolksPersona *persona = gee_iterator_get (iter);
FolksPersonaStore *store = folks_persona_get_store (persona);
FolksMaybeBool maybe_can_remove =
folks_persona_store_get_can_remove_personas (store);
if (maybe_can_remove == FOLKS_MAYBE_BOOL_TRUE)
- {
- can_remove = TRUE;
- break;
- }
+ can_remove = TRUE;
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
menu = empathy_individual_menu_new (individual, priv->individual_features);
diff --git a/libempathy-gtk/empathy-individual-widget.c b/libempathy-gtk/empathy-individual-widget.c
index d0697d261..20f3403b7 100644
--- a/libempathy-gtk/empathy-individual-widget.c
+++ b/libempathy-gtk/empathy-individual-widget.c
@@ -222,30 +222,37 @@ update_weak_contact (EmpathyIndividualWidget *self)
* details for every TpContact in the Individual and merge them
* all, but that requires vCard support in libfolks for it to
* not be hideously complex. (bgo#627399) */
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- FolksPresenceDetails *presence;
- FolksPresenceType presence_type_cur;
+ FolksPersona *persona = gee_iterator_get (iter);
/* We only want personas which have presence and a TpContact */
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (presence)))
- continue;
+ if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ {
+ FolksPresenceDetails *presence;
+ FolksPresenceType presence_type_cur;
- presence = FOLKS_PRESENCE_DETAILS (l->data);
- presence_type_cur = folks_presence_details_get_presence_type (
- presence);
+ presence = FOLKS_PRESENCE_DETAILS (persona);
+ presence_type_cur = folks_presence_details_get_presence_type (
+ presence);
- if (folks_presence_details_typecmp (
- presence_type_cur, presence_type) > 0)
- {
- presence_type = presence_type_cur;
- tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
+ if (folks_presence_details_typecmp (
+ presence_type_cur, presence_type) > 0)
+ {
+ presence_type = presence_type_cur;
+ tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+ }
}
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
if (tp_contact != NULL)
@@ -565,7 +572,8 @@ location_update (EmpathyIndividualWidget *self)
int i;
const gchar *skey;
gboolean display_map = FALSE;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
if (!(priv->flags & EMPATHY_INDIVIDUAL_WIDGET_SHOW_LOCATION) ||
priv->individual == NULL)
@@ -577,10 +585,12 @@ location_update (EmpathyIndividualWidget *self)
/* FIXME: For the moment, we just display the first location data we can
* find amongst the Individual's Personas. Once libfolks grows a location
* interface, we can use that. (bgo#627400) */
+
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (location == NULL && gee_iterator_next (iter))
{
- FolksPersona *persona = FOLKS_PERSONA (l->data);
+ FolksPersona *persona = gee_iterator_get (iter);
if (empathy_folks_persona_is_interesting (persona))
{
@@ -595,13 +605,16 @@ location_update (EmpathyIndividualWidget *self)
/* Try and get a location */
location = empathy_contact_get_location (contact);
- if (location != NULL && g_hash_table_size (location) > 0)
- break;
-
- location = NULL;
- tp_clear_object (&contact);
+ /* if location isn't fully valid, treat the contact as insufficient */
+ if (location != NULL && g_hash_table_size (location) <= 0)
+ {
+ location = NULL;
+ g_clear_object (&contact);
+ }
}
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
if (contact == NULL || location == NULL)
{
@@ -745,10 +758,12 @@ location_update (EmpathyIndividualWidget *self)
/* FIXME: For now, we have to do this manually. Once libfolks grows a
* location interface, we can use that. (bgo#627400) */
+
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- FolksPersona *persona = FOLKS_PERSONA (l->data);
+ FolksPersona *persona = gee_iterator_get (iter);
if (empathy_folks_persona_is_interesting (persona))
{
@@ -764,27 +779,18 @@ location_update (EmpathyIndividualWidget *self)
/* Try and get a location */
location = empathy_contact_get_location (contact);
if (location == NULL || g_hash_table_size (location) == 0)
- {
- g_object_unref (contact);
- continue;
- }
+ goto while_finish;
/* Get this persona's latitude and longitude */
value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
if (value == NULL)
- {
- g_object_unref (contact);
- continue;
- }
+ goto while_finish;
lat = g_value_get_double (value);
value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
if (value == NULL)
- {
- g_object_unref (contact);
- continue;
- }
+ goto while_finish;
lon = g_value_get_double (value);
@@ -796,10 +802,13 @@ location_update (EmpathyIndividualWidget *self)
lat, lon);
champlain_marker_layer_add_marker (layer,
CHAMPLAIN_MARKER (marker));
-
- g_object_unref (contact);
}
+
+while_finish:
+ g_clear_object (&persona);
+ g_clear_object (&contact);
}
+ g_clear_object (&iter);
/* Zoom to show all of the markers */
champlain_view_ensure_layers_visible (priv->map_view, FALSE);
@@ -887,20 +896,25 @@ persona_dup_avatar (FolksPersona *persona)
static EmpathyAvatar *
individual_dup_avatar (FolksIndividual *individual)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
EmpathyAvatar *avatar = NULL;
/* FIXME: We just choose the first Persona which has an avatar, and save that.
* The avatar handling in EmpathyContact needs to be moved into libfolks as
* much as possible, and this code rewritten to use FolksHasAvatar.
* (bgo#627401) */
+
personas = folks_individual_get_personas (individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (avatar == NULL && gee_iterator_next (iter))
{
- avatar = persona_dup_avatar (FOLKS_PERSONA (l->data));
- if (avatar != NULL)
- break;
+ FolksPersona *persona = gee_iterator_get (iter);
+ avatar = persona_dup_avatar (persona);
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
return avatar;
}
@@ -1060,14 +1074,17 @@ avatar_widget_button_press_event_cb (GtkWidget *widget,
static TpAccount *
individual_is_user (FolksIndividual *individual)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
+ TpAccount *retval = NULL;
/* FIXME: This should move into libfolks when libfolks grows a way of
* determining "self". (bgo#627402) */
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))
{
- FolksPersona *persona = FOLKS_PERSONA (l->data);
+ FolksPersona *persona = gee_iterator_get (iter);
if (TPF_IS_PERSONA (persona))
{
@@ -1081,16 +1098,15 @@ individual_is_user (FolksIndividual *individual)
/* Determine if the contact is the user */
if (empathy_contact_is_user (contact))
- {
- g_object_unref (contact);
- return g_object_ref (empathy_contact_get_account (contact));
- }
+ retval = g_object_ref (empathy_contact_get_account (contact));
g_object_unref (contact);
}
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
- return NULL;
+ return retval;
}
static void
@@ -1633,16 +1649,22 @@ individual_table_set_up (EmpathyIndividualWidget *self)
{
gchar *message;
GtkWidget *label;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
guint num_personas = 0;
/* Meta-contacts message displaying how many Telepathy personas we have */
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
num_personas++;
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
/* Translators: the plurality applies to both instances of the word
* "contact" */
@@ -1694,21 +1716,28 @@ personas_changed_cb (FolksIndividual *individual,
EmpathyIndividualWidget *self)
{
EmpathyIndividualWidgetPriv *priv = GET_PRIV (self);
- GList *personas, *l, *children;
+ GList *l, *children;
+ GeeSet *personas;
+ GeeIterator *iter;
gboolean show_personas, was_showing_personas, will_show_personas, is_last;
guint old_num_personas, new_num_personas = 0;
personas = folks_individual_get_personas (individual);
+ /* we'll re-use this iterator throughout */
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
/* Note that old_num_personas is the number of persona tables we were
* displaying, not the number of Personas which were in the Individual
* before. */
old_num_personas = g_hash_table_size (priv->persona_tables);
- for (l = personas; l != NULL; l = l->next)
+ while (gee_iterator_next (iter))
{
- if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
new_num_personas++;
+
+ g_clear_object (&persona);
}
/*
@@ -1750,24 +1779,38 @@ personas_changed_cb (FolksIndividual *individual,
}
else if (!was_showing_personas && will_show_personas)
{
+ gboolean c;
+
/* Remove the old Individual table */
individual_table_destroy (self);
/* Set up all the Persona tables instead */
- for (l = personas; l != NULL; l = l->next)
- add_persona (self, FOLKS_PERSONA (l->data));
+ for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+ {
+ FolksPersona *persona = gee_iterator_get (iter);
+ add_persona (self, persona);
+ g_clear_object (&persona);
+ }
}
else if (was_showing_personas && !will_show_personas)
{
+ gboolean c;
+
/* Remove all Personas */
- for (l = personas; l != NULL; l = l->next)
- remove_persona (self, FOLKS_PERSONA (l->data));
+ for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+ {
+ FolksPersona *persona = gee_iterator_get (iter);
+ remove_persona (self, persona);
+ g_clear_object (&persona);
+ }
+
for (l = removed; l != NULL; l = l->next)
remove_persona (self, FOLKS_PERSONA (l->data));
/* Set up the Individual table instead */
individual_table_set_up (self);
}
+ g_clear_object (&iter);
/* Hide the last separator and show the others */
children = gtk_container_get_children (GTK_CONTAINER (priv->vbox_individual));
@@ -1800,7 +1843,8 @@ remove_individual (EmpathyIndividualWidget *self)
EmpathyIndividualWidgetPriv *priv = GET_PRIV (self);
if (priv->individual != NULL)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
g_signal_handlers_disconnect_by_func (priv->individual,
notify_alias_cb, self);
@@ -1820,8 +1864,14 @@ remove_individual (EmpathyIndividualWidget *self)
}
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
- remove_persona (self, FOLKS_PERSONA (l->data));
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
+ {
+ FolksPersona *persona = gee_iterator_get (iter);
+ remove_persona (self, persona);
+ g_clear_object (&persona);
+ }
+ g_clear_object (&iter);
individual_table_destroy (self);
if (priv->contact != NULL)
@@ -1878,16 +1928,21 @@ individual_update (EmpathyIndividualWidget *self)
else
{
/* We need to update the details for every Persona in the Individual */
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
+ FolksPersona *persona = gee_iterator_get (iter);
+
+ if (empathy_folks_persona_is_interesting (persona))
+ update_persona (self, persona);
- update_persona (self, FOLKS_PERSONA (l->data));
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
gtk_widget_show (priv->vbox_individual);
}
diff --git a/libempathy-gtk/empathy-linking-dialog.c b/libempathy-gtk/empathy-linking-dialog.c
index 7e11b91cd..350bfdc22 100644
--- a/libempathy-gtk/empathy-linking-dialog.c
+++ b/libempathy-gtk/empathy-linking-dialog.c
@@ -159,7 +159,7 @@ linking_response_cb (EmpathyLinkingDialog *self,
if (response == GTK_RESPONSE_OK)
{
EmpathyIndividualManager *manager;
- GList *personas;
+ GeeSet *personas;
manager = empathy_individual_manager_dup_singleton ();
@@ -223,7 +223,8 @@ empathy_linking_dialog_show (FolksIndividual *individual,
GtkWindow *parent)
{
EmpathyLinkingDialogPriv *priv;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
guint num_personas = 0;
/* Create the dialogue if it doesn't exist */
@@ -246,11 +247,16 @@ empathy_linking_dialog_show (FolksIndividual *individual,
/* Count how many Telepathy personas we have, to see whether we can
* unlink */
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))
{
- if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
num_personas++;
+
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
/* Only make the "Unlink" button sensitive if we have enough personas */
gtk_dialog_set_response_sensitive (GTK_DIALOG (linking_dialog),
diff --git a/libempathy-gtk/empathy-persona-store.c b/libempathy-gtk/empathy-persona-store.c
index 75827c572..aea205932 100644
--- a/libempathy-gtk/empathy-persona-store.c
+++ b/libempathy-gtk/empathy-persona-store.c
@@ -995,15 +995,22 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
/* Remove the old individual */
if (priv->individual != NULL)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
g_signal_handlers_disconnect_by_func (priv->individual,
(GCallback) individual_personas_changed_cb, self);
/* Disconnect from and remove all personas belonging to this individual */
personas = folks_individual_get_personas (priv->individual);
- for (l = personas; l != NULL; l = l->next)
- remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
+ {
+ FolksPersona *persona = gee_iterator_get (iter);
+ remove_persona_and_disconnect (self, persona);
+ g_clear_object (&persona);
+ }
+ g_clear_object (&iter);
g_object_unref (priv->individual);
}
@@ -1013,7 +1020,8 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
/* Add the new individual */
if (individual != NULL)
{
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
g_object_ref (individual);
@@ -1021,9 +1029,16 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
(GCallback) individual_personas_changed_cb, self);
/* Add pre-existing Personas */
+
personas = folks_individual_get_personas (individual);
- for (l = personas; l != NULL; l = l->next)
- add_persona_and_connect (self, FOLKS_PERSONA (l->data));
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
+ {
+ FolksPersona *persona = gee_iterator_get (iter);
+ add_persona_and_connect (self, persona);
+ g_clear_object (&persona);
+ }
+ g_clear_object (&iter);
}
g_object_notify (G_OBJECT (self), "individual");
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index cf3228da5..0b0bf3050 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -1959,7 +1959,9 @@ empathy_individual_match_string (FolksIndividual *individual,
GPtrArray *words)
{
const gchar *str;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
+ gboolean retval = FALSE;
/* check alias name */
str = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual));
@@ -1970,33 +1972,42 @@ empathy_individual_match_string (FolksIndividual *individual,
personas = folks_individual_get_personas (individual);
/* check contact id, remove the @server.com part */
- for (l = personas; l; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (retval == FALSE && gee_iterator_next (iter))
{
+ FolksPersona *persona = gee_iterator_get (iter);
const gchar *p;
- gchar *dup_str = NULL;
- gboolean visible;
- if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
- continue;
-
- str = folks_persona_get_display_id (l->data);
-
- /* Accept the persona if @text is a full prefix of his ID; that allows
- * user to find, say, a jabber contact by typing his JID. */
- if (g_str_has_prefix (str, text))
- return TRUE;
-
- p = strstr (str, "@");
- if (p != NULL)
- str = dup_str = g_strndup (str, p - str);
-
- visible = empathy_live_search_match_words (str, words);
- g_free (dup_str);
- if (visible)
- return TRUE;
+ if (empathy_folks_persona_is_interesting (persona))
+ {
+ str = folks_persona_get_display_id (persona);
+
+ /* Accept the persona if @text is a full prefix of his ID; that allows
+ * user to find, say, a jabber contact by typing his JID. */
+ if (!g_str_has_prefix (str, text))
+ {
+ retval = TRUE;
+ }
+ else
+ {
+ gchar *dup_str = NULL;
+ gboolean visible;
+
+ p = strstr (str, "@");
+ if (p != NULL)
+ str = dup_str = g_strndup (str, p - str);
+
+ visible = empathy_live_search_match_words (str, words);
+ g_free (dup_str);
+ if (visible)
+ retval = TRUE;
+ }
+ }
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
/* FIXME: Add more rules here, we could check phone numbers in
* contact's vCard for example. */
- return FALSE;
+ return retval;
}
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);
diff --git a/src/empathy-invite-participant-dialog.c b/src/empathy-invite-participant-dialog.c
index 1d2ccb32e..539f3679d 100644
--- a/src/empathy-invite-participant-dialog.c
+++ b/src/empathy-invite-participant-dialog.c
@@ -181,34 +181,39 @@ static TpContact *
get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
FolksIndividual *individual)
{
- GList *personas, *l;
+ TpContact *contact = NULL;
TpConnection *chat_conn;
+ GeeSet *personas;
+ GeeIterator *iter;
chat_conn = tp_channel_borrow_connection ((TpChannel *) self->priv->tp_chat);
personas = folks_individual_get_personas (individual);
-
- for (l = personas; l != NULL; l = g_list_next (l))
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (contact == FALSE && gee_iterator_next (iter))
{
- TpfPersona *persona = l->data;
- TpContact *contact;
+ TpfPersona *persona = gee_iterator_get (iter);
TpConnection *contact_conn;
+ TpContact *contact_cur = NULL;
- if (!TPF_IS_PERSONA (persona))
- continue;
-
- contact = tpf_persona_get_contact (persona);
- if (contact == NULL)
- continue;
-
- contact_conn = tp_contact_get_connection (contact);
+ if (TPF_IS_PERSONA (persona))
+ {
+ contact_cur = tpf_persona_get_contact (persona);
+ if (contact_cur != NULL)
+ {
+ contact_conn = tp_contact_get_connection (contact_cur);
+
+ if (!tp_strdiff (tp_proxy_get_object_path (contact_conn),
+ tp_proxy_get_object_path (chat_conn)))
+ contact = contact_cur;
+ }
+ }
- if (!tp_strdiff (tp_proxy_get_object_path (contact_conn),
- tp_proxy_get_object_path (chat_conn)))
- return contact;
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
- return NULL;
+ return contact;
}
static gboolean