From 068551e68046f42a8278c01186e10fb1142493f9 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Feb 2011 16:17:48 +1100 Subject: Add confirmation dialog to Remove Also includes the future Report Abusive check box, so that all the strings are in place now. --- libempathy-gtk/empathy-individual-dialogs.c | 94 +++++++++++++++++++++++++++++ libempathy-gtk/empathy-individual-dialogs.h | 2 + libempathy-gtk/empathy-individual-view.c | 16 ++++- 3 files changed, 109 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index f262772c6..5bc4b8b9f 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -157,3 +158,96 @@ empathy_new_individual_dialog_show_with_individual (GtkWindow *parent, tp_clear_object (&contact); } + +/* + * Block contact dialog + */ +gboolean +empathy_block_individual_dialog_show (GtkWindow *parent, + FolksIndividual *individual, + gboolean *abusive) +{ + EmpathyIndividualManager *manager = + empathy_individual_manager_dup_singleton (); + GtkWidget *dialog; + GtkWidget *abusive_check = NULL; + GList *personas, *l; + GString *str = g_string_new (""); + guint npersonas = 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_aliasable_get_alias (FOLKS_ALIASABLE (individual))); + + /* build a list of personas that support blocking */ + personas = folks_individual_get_personas (individual); + + for (l = personas; l != NULL; l = l->next) + { + TpfPersona *persona = l->data; + TpContact *contact; + EmpathyIndividualManagerFlags flags; + + if (!TPF_IS_PERSONA (persona)) + continue; + + contact = tpf_persona_get_contact (persona); + flags = empathy_individual_manager_get_flags_for_connection (manager, + tp_contact_get_connection (contact)); + + if (!(flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK)) + continue; + else if (flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_REPORT_ABUSIVE) + can_report_abuse = TRUE; + + g_string_append_printf (str, "\n \342\200\242 %s", + tp_contact_get_identifier (contact)); + npersonas++; + } + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + "%s\n%s", + ngettext ("Are you sure you want to block the following contact?", + "Are you sure you want to block the following contacts?", + npersonas), + str->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)); + + gtk_box_pack_start (GTK_BOX (vbox), abusive_check, FALSE, TRUE, 0); + gtk_widget_show (abusive_check); + } + + g_object_unref (manager); + g_string_free (str, TRUE); + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + if (abusive != NULL) + { + if (abusive_check != NULL) + *abusive = gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON (abusive_check)); + else + *abusive = FALSE; + } + + return res == GTK_RESPONSE_REJECT; +} diff --git a/libempathy-gtk/empathy-individual-dialogs.h b/libempathy-gtk/empathy-individual-dialogs.h index b34a7ab18..f6c402014 100644 --- a/libempathy-gtk/empathy-individual-dialogs.h +++ b/libempathy-gtk/empathy-individual-dialogs.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS void empathy_new_individual_dialog_show (GtkWindow *parent); void empathy_new_individual_dialog_show_with_individual (GtkWindow *parent, FolksIndividual *individual); +gboolean empathy_block_individual_dialog_show (GtkWindow *parent, + FolksIndividual *individual, gboolean *abusive); G_END_DECLS diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c index 8da849503..f719dfa74 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -48,6 +48,7 @@ #include "empathy-individual-menu.h" #include "empathy-individual-store.h" #include "empathy-contact-dialogs.h" +#include "empathy-individual-dialogs.h" #include "empathy-images.h" #include "empathy-linking-dialog.h" #include "empathy-cell-renderer-expander.h" @@ -2352,12 +2353,21 @@ individual_view_remove_activate_cb (GtkMenuItem *menuitem, text, can_block); if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_REJECT) { - empathy_individual_manager_remove (manager, individual, ""); + if (res == GTK_RESPONSE_REJECT && + empathy_block_individual_dialog_show (parent, individual, NULL)) + { + empathy_individual_manager_set_blocked (manager, individual, + TRUE); + } + else + { + goto finally; + } - if (res == GTK_RESPONSE_REJECT) - empathy_individual_manager_set_blocked (manager, individual, TRUE); + empathy_individual_manager_remove (manager, individual, ""); } +finally: g_free (text); g_object_unref (individual); g_object_unref (manager); -- cgit v1.2.3