GtkWidget *
empathy_contact_add_menu_item_new (EmpathyContact *contact)
{
	GtkWidget *item;
	GtkWidget *image;
	EmpathyContactManager *manager;
	TpConnection *connection;
	GList *l, *members;
	gboolean found = FALSE;
	EmpathyContactListFlags flags;

	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

	if (!empathy_contact_manager_initialized ()) {
		return NULL;
	}

	manager = empathy_contact_manager_dup_singleton ();
	connection = empathy_contact_get_connection (contact);

	flags = empathy_contact_manager_get_flags_for_connection (manager,
			connection);

	if (!(flags & EMPATHY_CONTACT_LIST_CAN_ADD)) {
		return NULL;
	}

	members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (manager));
	for (l = members; l; l = l->next) {
		if (!found && empathy_contact_equal (l->data, contact)) {
			found = TRUE;
			/* we keep iterating so that we don't leak contact
			 * refs */
		}

		g_object_unref (l->data);
	}
	g_list_free (members);
	g_object_unref (manager);

	if (found) {
		return NULL;
	}

	item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
	image = gtk_image_new_from_icon_name (GTK_STOCK_ADD,
					      GTK_ICON_SIZE_MENU);
	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);

	g_signal_connect (item, "activate",
			G_CALLBACK (empathy_contact_add_menu_item_activated),
			contact);

	return item;
}
Ejemplo n.º 2
0
static gboolean
can_add_contact_to_account (EmpathyAccount *account,
			    gpointer   user_data)
{
	EmpathyContactManager *contact_manager;
	TpConnection          *connection;
	gboolean               result;

	connection = empathy_account_get_connection (account);
	if (connection == NULL)
		return FALSE;

	contact_manager = empathy_contact_manager_dup_singleton ();
	result = empathy_contact_manager_get_flags_for_connection (
		contact_manager, connection) & EMPATHY_CONTACT_LIST_CAN_ADD;
	g_object_unref (contact_manager);

	return result;
}
GtkWidget *
empathy_contact_edit_menu_item_new (EmpathyContact *contact)
{
	EmpathyContactManager *manager;
	GtkWidget *item;
	GtkWidget *image;
	gboolean enable = FALSE;

	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

	if (empathy_contact_manager_initialized ()) {
		TpConnection *connection;
		EmpathyContactListFlags flags;

		manager = empathy_contact_manager_dup_singleton ();
		connection = empathy_contact_get_connection (contact);
		flags = empathy_contact_manager_get_flags_for_connection (
				manager, connection);

		enable = (flags & EMPATHY_CONTACT_LIST_CAN_ALIAS ||
		          flags & EMPATHY_CONTACT_LIST_CAN_GROUP);

		g_object_unref (manager);
	}

	item = gtk_image_menu_item_new_with_mnemonic (
						     C_("Edit contact (contextual menu)",
						        "_Edit"));
	image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
					      GTK_ICON_SIZE_MENU);
	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
	gtk_widget_show (image);

	gtk_widget_set_sensitive (item, enable);

	g_signal_connect_swapped (item, "activate",
				  G_CALLBACK (contact_edit_menu_item_activate_cb),
				  contact);

	return item;
}
static GtkWidget *
empathy_contact_block_menu_item_new (EmpathyContact *contact)
{
	GtkWidget *item;
	EmpathyContactManager *manager;
	TpConnection *connection;
	EmpathyContactListFlags flags;
	gboolean blocked;

	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

	manager = empathy_contact_manager_dup_singleton ();

	if (!empathy_contact_manager_initialized ()) {
		return NULL;
	}

	connection = empathy_contact_get_connection (contact);

	flags = empathy_contact_manager_get_flags_for_connection (manager,
			connection);

	if (!(flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)) {
		return NULL;
	}

	item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
	blocked = empathy_contact_list_get_blocked (
			EMPATHY_CONTACT_LIST (manager),
			contact);

	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), blocked);

	g_signal_connect (item, "toggled",
			G_CALLBACK (empathy_contact_block_menu_item_toggled),
			contact);

	return item;
}
/*
 * Block contact dialog
 */
gboolean
empathy_block_individual_dialog_show (GtkWindow *parent,
    FolksIndividual *individual,
    GdkPixbuf *avatar,
    gboolean *abusive)
{
  EmpathyContactManager *contact_manager =
    empathy_contact_manager_dup_singleton ();
  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;
      EmpathyContactListFlags flags;
      GString *s;
      char *str;

      if (!TPF_IS_PERSONA (persona))
          goto while_finish;

      contact = tpf_persona_get_contact (persona);
      if (contact == NULL)
        goto while_finish;

      flags = empathy_contact_manager_get_flags_for_connection (
          contact_manager, tp_contact_get_connection (contact));

      if (flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)
        {
          s = blocked_str;
          npersonas_blocked++;
        }
      else
        {
          s = notblocked_str;
          npersonas_notblocked++;
        }

      if (flags & EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE)
        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_object_unref (contact_manager);
  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;
}
Ejemplo n.º 6
0
static void
contact_list_store_add_contact (EmpathyContactListStore *store,
				EmpathyContact          *contact)
{
	EmpathyContactListStorePriv *priv;
	GtkTreeIter                 iter;
	GList                      *groups = NULL, *l;
	TpConnection               *connection;
	EmpathyContactListFlags     flags = 0;

	priv = GET_PRIV (store);

	if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
	    (!priv->show_offline && !empathy_contact_is_online (contact))) {
		return;
	}

	if (priv->show_groups) {
		groups = empathy_contact_list_get_groups (priv->list, contact);
	}

	connection = empathy_contact_get_connection (contact);
	if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
		flags = empathy_contact_manager_get_flags_for_connection (
			EMPATHY_CONTACT_MANAGER (priv->list), connection);
	}
	/* If no groups just add it at the top level. */
	if (!groups) {
		GtkTreeModel *model = GTK_TREE_MODEL (store);

		if (gtk_tree_model_get_iter_first (model, &iter)) do {
			EmpathyContact *c;

			gtk_tree_model_get (model, &iter,
				EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
				-1);

			if (c == contact) {
				g_object_unref (c);
				return;
			}
			if (c != NULL)
				g_object_unref (c);
		} while (gtk_tree_model_iter_next (model, &iter));

		gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
				    -1);
	}

	/* Else add to each group. */
	for (l = groups; l; l = l->next) {
		GtkTreeIter iter_group;

		contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);

		gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
					     &iter_group, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
				    -1);
		g_free (l->data);
	}
	g_list_free (groups);

	contact_list_store_contact_update (store, contact);

}