/* Return the TpContact on @conn associated with @individual, if any */ TpContact * empathy_get_tp_contact_for_individual (FolksIndividual *individual, TpConnection *conn) { TpContact *contact = NULL; GeeSet *personas; GeeIterator *iter; personas = folks_individual_get_personas (individual); iter = gee_iterable_iterator (GEE_ITERABLE (personas)); while (contact == NULL && gee_iterator_next (iter)) { TpfPersona *persona = gee_iterator_get (iter); TpConnection *contact_conn; TpContact *contact_cur = NULL; 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 (conn))) contact = contact_cur; } } g_clear_object (&persona); } g_clear_object (&iter); return contact; }
static gboolean individual_has_contact (FolksIndividual *individual, TpContact *contact) { GeeSet *personas; GeeIterator *iter; gboolean found = FALSE; personas = folks_individual_get_personas (individual); iter = gee_iterable_iterator (GEE_ITERABLE (personas)); while (!found && gee_iterator_next (iter)) { TpfPersona *persona = gee_iterator_get (iter); if (TPF_IS_PERSONA (persona)) { TpContact *c = tpf_persona_get_contact (persona); if (c == contact) found = TRUE; } g_clear_object (&persona); } g_clear_object (&iter); return found; }
static void remove_persona_and_disconnect (EmpathyPersonaStore *self, FolksPersona *persona) { if (!TPF_IS_PERSONA (persona)) return; g_signal_handlers_disconnect_by_func (persona, (GCallback) persona_updated_cb, self); remove_persona (self, persona); }
static void add_persona (EmpathyPersonaStore *self, FolksPersona *persona) { EmpathyPersonaStorePriv *priv; GtkTreeIter iter; GtkTreePath *path; FolksPersonaStore *store; EmpathyContact *contact; const gchar *alias; if (!TPF_IS_PERSONA (persona)) return; priv = GET_PRIV (self); alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona)); if (EMP_STR_EMPTY (alias)) return; contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact ( TPF_PERSONA (persona))); store = folks_persona_get_store (persona); gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0, EMPATHY_PERSONA_STORE_COL_NAME, alias, EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME, folks_persona_store_get_display_name (store), EMPATHY_PERSONA_STORE_COL_DISPLAY_ID, folks_persona_get_display_id (persona), EMPATHY_PERSONA_STORE_COL_PERSONA, persona, EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_AUDIO, EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_VIDEO, -1); g_object_unref (contact); path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter); g_hash_table_replace (priv->personas, g_object_ref (persona), gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path)); gtk_tree_path_free (path); update_persona (self, persona); }
gboolean empathy_folks_persona_is_interesting (FolksPersona *persona) { /* We're not interested in non-Telepathy personas */ if (!TPF_IS_PERSONA (persona)) return FALSE; /* We're not interested in user personas which haven't been added to the * contact list (see bgo#637151). */ if (folks_persona_get_is_user (persona) && !tpf_persona_get_is_in_contact_list (TPF_PERSONA (persona))) { return FALSE; } return TRUE; }
static void add_persona_and_connect (EmpathyPersonaStore *self, FolksPersona *persona) { /* We don't want any non-Telepathy personas */ if (!TPF_IS_PERSONA (persona)) return; g_signal_connect (persona, "notify::presence", (GCallback) persona_updated_cb, self); g_signal_connect (persona, "notify::presence-message", (GCallback) persona_updated_cb, self); g_signal_connect (persona, "notify::alias", (GCallback) persona_updated_cb, self); g_signal_connect (persona, "notify::avatar", (GCallback) persona_updated_cb, self); add_persona (self, persona); }
void empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, FolksIndividual *individual, gboolean blocked, gboolean abusive) { GeeSet *personas; GeeIterator *iter; g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self)); personas = folks_individual_get_personas (individual); iter = gee_iterable_iterator (GEE_ITERABLE (personas)); while (gee_iterator_next (iter)) { TpfPersona *persona = gee_iterator_get (iter); if (TPF_IS_PERSONA (persona)) { TpContact *tp_contact; TpConnection *conn; tp_contact = tpf_persona_get_contact (persona); if (tp_contact == NULL) continue; conn = tp_contact_get_connection (tp_contact); if (!tp_proxy_has_interface_by_id (conn, TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)) continue; if (blocked) tp_contact_block_async (tp_contact, abusive, NULL, NULL); else tp_contact_unblock_async (tp_contact, NULL, NULL); } g_clear_object (&persona); } g_clear_object (&iter); }
static void remove_persona (EmpathyPersonaStore *self, FolksPersona *persona) { EmpathyPersonaStorePriv *priv; GtkTreePath *path; GtkTreeIter iter; if (!TPF_IS_PERSONA (persona)) return; priv = GET_PRIV (self); path = find_persona (self, persona); if (path == NULL) return; g_hash_table_remove (priv->personas, persona); gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path); gtk_list_store_remove (GTK_LIST_STORE (self), &iter); gtk_tree_path_free (path); }
/** * 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) { GeeSet *personas; GeeIterator *iter; gboolean retval = FALSE; g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE); personas = folks_individual_get_personas (individual); iter = gee_iterable_iterator (GEE_ITERABLE (personas)); while (!retval && gee_iterator_next (iter)) { TpfPersona *persona = gee_iterator_get (iter); TpConnection *conn; if (TPF_IS_PERSONA (persona)) { TpContact *tp_contact; tp_contact = tpf_persona_get_contact (persona); if (tp_contact != NULL) { conn = tp_contact_get_connection (tp_contact); if (tp_proxy_has_interface_by_id (conn, TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)) retval = TRUE; } } g_clear_object (&persona); } g_clear_object (&iter); return retval; }
/* * Block contact dialog */ gboolean empathy_block_individual_dialog_show (GtkWindow *parent, FolksIndividual *individual, GdkPixbuf *avatar, gboolean *abusive) { GtkWidget *dialog; GtkWidget *abusive_check = NULL; GeeSet *personas; GeeIterator *iter; GString *text = g_string_new (""); GString *blocked_str = g_string_new (""); GString *notblocked_str = g_string_new (""); guint npersonas_blocked = 0, npersonas_notblocked = 0; gboolean can_report_abuse = FALSE; int res; dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Block %s?"), folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual))); if (avatar != NULL) { GtkWidget *image = gtk_image_new_from_pixbuf (avatar); gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image); gtk_widget_show (image); } /* build a list of personas that support blocking */ personas = folks_individual_get_personas (individual); iter = gee_iterable_iterator (GEE_ITERABLE (personas)); while (gee_iterator_next (iter)) { TpfPersona *persona = gee_iterator_get (iter); TpContact *contact; GString *s; char *str; TpConnection *conn; if (!TPF_IS_PERSONA (persona)) goto while_finish; contact = tpf_persona_get_contact (persona); if (contact == NULL) goto while_finish; conn = tp_contact_get_connection (contact); if (tp_proxy_has_interface_by_id (conn, TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)) { s = blocked_str; npersonas_blocked++; } else { s = notblocked_str; npersonas_notblocked++; } if (tp_connection_can_report_abusive (conn)) can_report_abuse = TRUE; 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?"), folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual))); if (npersonas_blocked > 0) g_string_append_printf (text, "\n\n%s\n%s", ngettext ("The following identity will be blocked:", "The following identities will be blocked:", npersonas_blocked), blocked_str->str); if (npersonas_notblocked > 0) g_string_append_printf (text, "\n\n%s\n%s", ngettext ("The following identity can not be blocked:", "The following identities can not be blocked:", npersonas_notblocked), notblocked_str->str); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", text->str); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Block"), GTK_RESPONSE_REJECT, NULL); if (can_report_abuse) { GtkWidget *vbox; vbox = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog)); abusive_check = gtk_check_button_new_with_mnemonic ( ngettext ("_Report this contact as abusive", "_Report these contacts as abusive", npersonas_blocked)); gtk_box_pack_start (GTK_BOX (vbox), abusive_check, FALSE, TRUE, 0); gtk_widget_show (abusive_check); } g_string_free (text, TRUE); g_string_free (blocked_str, TRUE); g_string_free (notblocked_str, TRUE); res = gtk_dialog_run (GTK_DIALOG (dialog)); if (abusive != NULL) { if (abusive_check != NULL) *abusive = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (abusive_check)); else *abusive = FALSE; } gtk_widget_destroy (dialog); return res == GTK_RESPONSE_REJECT; }