]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-dialogs.c
contact-dialogs: use tp-glib blocking API
[empathy.git] / libempathy-gtk / empathy-contact-dialogs.c
index fb57f348b247883116ce1c7d60dd2334935359b0..130fbc224061b8c867999878e82be6aeee79f749 100644 (file)
@@ -17,6 +17,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  * Authors: Xavier Claessens <xclaesse@gmail.com>
+ *          Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
 
 #include <config.h>
@@ -83,9 +84,32 @@ subscription_dialog_response_cb (GtkDialog *dialog,
                empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
                                             contact, "");
        }
+       else if (response == GTK_RESPONSE_REJECT) {
+               gboolean abusive;
+
+               /* confirm the blocking */
+               if (empathy_block_contact_dialog_show (GTK_WINDOW (dialog), contact,
+                                                      NULL, &abusive)) {
+                       TpContact *tp_contact;
+
+                       empathy_contact_list_remove (
+                                       EMPATHY_CONTACT_LIST (manager),
+                                       contact, "");
+
+                       tp_contact = empathy_contact_get_tp_contact (contact);
+
+                       tp_contact_block_async (tp_contact, abusive, NULL, NULL);
+               } else {
+                       /* if they don't confirm, return back to the
+                        * first dialog */
+                       goto finally;
+               }
+       }
 
        subscription_dialogs = g_list_remove (subscription_dialogs, dialog);
        gtk_widget_destroy (GTK_WIDGET (dialog));
+
+finally:
        g_object_unref (manager);
 }
 
@@ -99,8 +123,10 @@ empathy_subscription_dialog_show (EmpathyContact *contact,
        GtkWidget *hbox_subscription;
        GtkWidget *vbox;
        GtkWidget *contact_widget;
+       GtkWidget *block_user_button;
        GList     *l;
        gchar     *filename;
+       TpConnection *conn;
 
        g_return_if_fail (EMPATHY_IS_CONTACT (contact));
 
@@ -117,6 +143,7 @@ empathy_subscription_dialog_show (EmpathyContact *contact,
        gui = empathy_builder_get_file (filename,
                                      "subscription_request_dialog", &dialog,
                                      "hbox_subscription", &hbox_subscription,
+                                     "block-user-button", &block_user_button,
                                      NULL);
        g_free (filename);
        g_object_unref (gui);
@@ -130,7 +157,8 @@ empathy_subscription_dialog_show (EmpathyContact *contact,
        contact_widget = empathy_contact_widget_new (contact,
                                                     EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS |
                                                     EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
-                                                    EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_GROUPS |
+                                                    EMPATHY_CONTACT_WIDGET_SHOW_DETAILS);
        gtk_box_pack_start (GTK_BOX (vbox),
                          contact_widget,
                          TRUE, TRUE,
@@ -160,6 +188,12 @@ empathy_subscription_dialog_show (EmpathyContact *contact,
                          G_CALLBACK (subscription_dialog_response_cb),
                          contact_widget);
 
+       conn = empathy_contact_get_connection (contact);
+
+       if (tp_proxy_has_interface_by_id (conn,
+               TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
+               gtk_widget_show (block_user_button);
+
        if (parent) {
                gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
        }
@@ -467,3 +501,75 @@ empathy_new_contact_dialog_show_with_contact (GtkWindow *parent,
        gtk_widget_show (dialog);
 }
 
+/**
+ * empathy_block_contact_dialog_show:
+ * @parent: the parent of this dialog (or %NULL)
+ * @contact: the contact for this dialog
+ * @abusive: a pointer to store the value of the abusive contact check box
+ *  (or %NULL)
+ *
+ * Returns: %TRUE if the user wishes to block the contact
+ */
+gboolean
+empathy_block_contact_dialog_show (GtkWindow      *parent,
+                                  EmpathyContact *contact,
+                                  GdkPixbuf      *avatar,
+                                  gboolean       *abusive)
+{
+       GtkWidget *dialog;
+       GtkWidget *abusive_check = NULL;
+       int res;
+       TpConnection *conn;
+
+       dialog = gtk_message_dialog_new (parent,
+                       GTK_DIALOG_MODAL,
+                       GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
+                       _("Block %s?"),
+                       empathy_contact_get_alias (contact));
+
+       gtk_message_dialog_format_secondary_text (
+                       GTK_MESSAGE_DIALOG (dialog),
+                       _("Are you sure you want to block '%s' from "
+                         "contacting you again?"),
+                       empathy_contact_get_alias (contact));
+       gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                       _("_Block"), GTK_RESPONSE_REJECT,
+                       NULL);
+
+       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);
+       }
+
+       conn = empathy_contact_get_connection (contact);
+
+       /* ask the user if they want to also report the contact as abusive */
+       if (tp_connection_can_report_abusive (conn)) {
+               GtkWidget *vbox;
+
+               vbox = gtk_message_dialog_get_message_area (
+                               GTK_MESSAGE_DIALOG (dialog));
+               abusive_check = gtk_check_button_new_with_mnemonic (
+                               _("_Report this contact as abusive"));
+
+               gtk_box_pack_start (GTK_BOX (vbox), abusive_check,
+                                   FALSE, TRUE, 0);
+               gtk_widget_show (abusive_check);
+       }
+
+       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;
+}