#include <telepathy-glib/util.h>
#include <folks/folks.h>
+#include <folks/folks-telepathy.h>
#include <libempathy/empathy-individual-manager.h>
#include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-contact-manager.h>
#include "empathy-individual-dialogs.h"
#include "empathy-contact-widget.h"
#include "empathy-ui-utils.h"
+#define BULLET_POINT "\342\200\242"
+
static GtkWidget *new_individual_dialog = NULL;
/*
* New contact dialog
*/
-static gboolean
+static void
can_add_contact_to_account (TpAccount *account,
+ EmpathyAccountChooserFilterResultCallback callback,
+ gpointer callback_data,
gpointer user_data)
{
EmpathyIndividualManager *individual_manager;
connection = tp_account_get_connection (account);
if (connection == NULL)
- return FALSE;
+ {
+ callback (FALSE, callback_data);
+ return;
+ }
individual_manager = empathy_individual_manager_dup_singleton ();
- result = empathy_individual_manager_get_flags_for_connection (
- individual_manager, connection) & EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD;
+ result = empathy_connection_can_add_personas (connection);
g_object_unref (individual_manager);
- return result;
+ callback (result, callback_data);
}
static void
/* Create dialog */
dialog = gtk_dialog_new ();
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_window_set_title (GTK_WINDOW (dialog), _("New Contact"));
gtk_widget_show (button);
/* Contact info widget */
- if (FOLKS_IS_INDIVIDUAL (individual))
+ if (individual != NULL)
contact = empathy_contact_dup_from_folks_individual (individual);
contact_widget = empathy_contact_widget_new (contact,
tp_clear_object (&contact);
}
+
+static char *
+contact_pretty_name (TpContact *contact)
+{
+ const char *alias = tp_contact_get_alias (contact);
+ const char *identifier = tp_contact_get_identifier (contact);
+
+ if (tp_strdiff (alias, identifier))
+ return g_strdup_printf ("%s (%s)", alias, identifier);
+ else
+ return g_strdup (alias);
+}
+
+/*
+ * 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;
+}