diff options
26 files changed, 1686 insertions, 33 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 91d396e24..ca14833d2 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -45,6 +45,7 @@ libempathy_gtk_handwritten_source = \ empathy-chat-text-view.c \ empathy-chat-view.c \ empathy-chat.c \ + empathy-contact-blocking-dialog.c \ empathy-contact-dialogs.c \ empathy-contact-list-store.c \ empathy-contact-list-view.c \ @@ -108,6 +109,7 @@ libempathy_gtk_headers = \ empathy-chat-text-view.h \ empathy-chat-view.h \ empathy-chat.h \ + empathy-contact-blocking-dialog.h \ empathy-contact-dialogs.h \ empathy-contact-list-store.h \ empathy-contact-list-view.h \ @@ -190,6 +192,7 @@ uidir = $(datadir)/empathy ui_DATA = \ empathy-contact-widget.ui \ empathy-contact-dialogs.ui \ + empathy-contact-blocking-dialog.ui \ empathy-account-widget-generic.ui \ empathy-account-widget-jabber.ui \ empathy-account-widget-msn.ui \ diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 550f2a709..f9c5e4272 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -3171,7 +3171,8 @@ empathy_chat_get_contact_menu (EmpathyChat *chat) menu = empathy_contact_menu_new (priv->remote_contact, EMPATHY_CONTACT_FEATURE_CALL | EMPATHY_CONTACT_FEATURE_LOG | - EMPATHY_CONTACT_FEATURE_INFO); + EMPATHY_CONTACT_FEATURE_INFO | + EMPATHY_CONTACT_FEATURE_BLOCK); } else if (priv->contact_list_view) { EmpathyContactListView *view; diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c new file mode 100644 index 000000000..3d0b9afe9 --- /dev/null +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -0,0 +1,789 @@ +/* + * empathy-contact-blocking-dialog.c + * + * EmpathyContactBlockingDialog + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk> + */ + +#include <glib/gi18n.h> + +#include <libempathy/empathy-utils.h> + +#include <libempathy/empathy-contact-manager.h> +#include <libempathy/empathy-tp-contact-list.h> + +#include <libempathy-gtk/empathy-account-chooser.h> +#include <libempathy-gtk/empathy-ui-utils.h> + +#include "empathy-contact-blocking-dialog.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include <libempathy/empathy-debug.h> + +#define GET_PRIVATE(o) (EMPATHY_CONTACT_BLOCKING_DIALOG (o)->priv) +#define DECLARE_CALLBACK(func) \ + static void func (GObject *, GAsyncResult *, gpointer); + +G_DEFINE_TYPE (EmpathyContactBlockingDialog, empathy_contact_blocking_dialog, + GTK_TYPE_DIALOG); + +struct _EmpathyContactBlockingDialogPrivate +{ + /* a map of all active connections to their 'deny' channel */ + GHashTable *channels; /* reffed TpConnection* -> reffed TpChannel* */ + + guint block_account_changed; + + GtkListStore *blocked_contacts; + GtkListStore *completion_contacts; + GtkTreeSelection *selection; + + GtkWidget *account_chooser; + GtkWidget *add_button; + GtkWidget *add_contact_entry; + GtkWidget *info_bar; + GtkWidget *info_bar_label; + GtkWidget *remove_button; +}; + +enum /* blocked-contacts columns */ +{ + COL_IDENTIFIER, + COL_HANDLE, + N_COLUMNS +}; + +static const char * +get_pretty_conn_name (TpConnection *conn) +{ + return tp_proxy_get_object_path (conn) + strlen (TP_CONN_OBJECT_PATH_BASE); +} + +static void +contact_blocking_dialog_filter_account_chooser (TpAccount *account, + EmpathyAccountChooserFilterResultCallback callback, + gpointer callback_data, + gpointer user_data) +{ + EmpathyContactBlockingDialog *self = user_data; + TpConnection *conn = tp_account_get_connection (account); + gboolean enable; + + enable = + conn != NULL && + g_hash_table_lookup (self->priv->channels, conn) != NULL; + + callback (enable, callback_data); +} + +static void contact_blocking_dialog_account_changed (GtkWidget *, + EmpathyContactBlockingDialog *); + +static void +contact_blocking_dialog_refilter_account_chooser ( + EmpathyContactBlockingDialog *self) +{ + EmpathyAccountChooser *chooser = + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser); + TpConnection *conn; + gboolean enabled; + + DEBUG ("Refiltering account chooser"); + + /* set the filter to refilter the account chooser */ + self->priv->block_account_changed++; + empathy_account_chooser_set_filter (chooser, + contact_blocking_dialog_filter_account_chooser, self); + self->priv->block_account_changed--; + + conn = empathy_account_chooser_get_connection (chooser); + enabled = (empathy_account_chooser_get_account (chooser) != NULL && + conn != NULL && + g_hash_table_lookup (self->priv->channels, conn) != NULL); + + if (!enabled) + DEBUG ("No account selected"); + + gtk_widget_set_sensitive (self->priv->add_button, enabled); + gtk_widget_set_sensitive (self->priv->add_contact_entry, enabled); + + contact_blocking_dialog_account_changed (self->priv->account_chooser, self); +} + +static void contact_blocking_dialog_inspected_handles (TpConnection *, + const char **, const GError *, gpointer, GObject *); + +static void +contact_blocking_dialog_add_contacts_to_list ( + EmpathyContactBlockingDialog *self, + TpConnection *conn, + GArray *handles) +{ + if (handles->len > 0) + tp_cli_connection_call_inspect_handles (conn, -1, + TP_HANDLE_TYPE_CONTACT, handles, + contact_blocking_dialog_inspected_handles, + g_boxed_copy (DBUS_TYPE_G_UINT_ARRAY, handles), + (GDestroyNotify) g_array_unref, G_OBJECT (self)); +} + +static void +contact_blocking_dialog_inspected_handles (TpConnection *conn, + const char **identifiers, + const GError *in_error, + gpointer user_data, + GObject *self) +{ + EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self); + GArray *handles = user_data; + guint i; + + if (in_error != NULL) + { + DEBUG ("Failed to inspect handles: %s", in_error->message); + return; + } + + DEBUG ("Adding %u identifiers", handles->len); + + for (i = 0; i < handles->len; i++) + { + const char *identifier = identifiers[i]; + TpHandle handle = g_array_index (handles, TpHandle, i); + + gtk_list_store_insert_with_values (priv->blocked_contacts, NULL, -1, + COL_IDENTIFIER, identifier, + COL_HANDLE, handle, + -1); + } +} + +DECLARE_CALLBACK (contact_blocking_dialog_connection_prepared); + +static void +contact_blocking_dialog_connection_status_changed (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + const char *dbus_reason, + GHashTable *details, + EmpathyContactBlockingDialog *self) +{ + TpConnection *conn = tp_account_get_connection (account); + + switch (new_status) + { + case TP_CONNECTION_STATUS_DISCONNECTED: + DEBUG ("Connection %s invalidated", get_pretty_conn_name (conn)); + + /* remove the channel from the hash table */ + g_hash_table_remove (self->priv->channels, conn); + contact_blocking_dialog_refilter_account_chooser (self); + break; + + case TP_CONNECTION_STATUS_CONNECTING: + break; + + case TP_CONNECTION_STATUS_CONNECTED: + DEBUG ("Connection %s reconnected", get_pretty_conn_name (conn)); + + tp_proxy_prepare_async (conn, NULL, + contact_blocking_dialog_connection_prepared, self); + } +} + +static void +contact_blocking_dialog_deny_channel_members_changed (TpChannel *channel, + const char *message, + GArray *added, + GArray *removed, + GArray *local_pending, + GArray *remote_pending, + TpHandle actor, + guint reason, + EmpathyContactBlockingDialog *self) +{ + TpConnection *conn = tp_channel_borrow_connection (channel); + GtkTreeModel *model = GTK_TREE_MODEL (self->priv->blocked_contacts); + GtkTreeIter iter; + TpIntset *removed_set; + gboolean valid; + + /* we only care about changes to the selected connection */ + /* FIXME: can we compare proxy pointers directly? */ + if (tp_strdiff ( + tp_proxy_get_object_path (tp_channel_borrow_connection (channel)), + tp_proxy_get_object_path (empathy_account_chooser_get_connection ( + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser))))) + return; + + DEBUG ("deny list changed: %u added, %u removed", added->len, removed->len); + + /* add contacts */ + contact_blocking_dialog_add_contacts_to_list (self, conn, added); + + /* remove contacts */ + removed_set = tp_intset_from_array (removed); + + valid = gtk_tree_model_get_iter_first (model, &iter); + while (valid) + { + TpHandle handle; + + gtk_tree_model_get (model, &iter, + COL_HANDLE, &handle, + -1); + + if (tp_intset_is_member (removed_set, handle)) + valid = gtk_list_store_remove (self->priv->blocked_contacts, &iter); + else + valid = gtk_tree_model_iter_next (model, &iter); + } + + tp_intset_destroy (removed_set); +} + +DECLARE_CALLBACK (contact_blocking_dialog_connection_prepared); + +static void +contact_blocking_dialog_am_prepared (GObject *am, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyContactBlockingDialog *self = user_data; + GList *accounts, *ptr; + GError *error = NULL; + + if (!tp_proxy_prepare_finish (am, result, &error)) + { + g_critical ("Could not prepare Account Manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (TP_ACCOUNT_MANAGER (am)); + + for (ptr = accounts; ptr != NULL; ptr = ptr->next) + { + TpAccount *account = ptr->data; + TpConnection *conn; + + g_signal_connect (account, "status-changed", + G_CALLBACK (contact_blocking_dialog_connection_status_changed), self); + + conn = tp_account_get_connection (TP_ACCOUNT (account)); + + if (conn != NULL) + { + tp_proxy_prepare_async (conn, NULL, + contact_blocking_dialog_connection_prepared, self); + } + } + + g_list_free (accounts); +} + +static void contact_blocking_dialog_got_deny_channel (TpConnection *, + gboolean, const char *, GHashTable *, const GError *, gpointer, GObject *); + +static void +contact_blocking_dialog_connection_prepared (GObject *conn, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyContactBlockingDialog *self = user_data; + GHashTable *request; + GError *error = NULL; + + if (!tp_proxy_prepare_finish (conn, result, &error)) + { + DEBUG ("Failed to prepare connection: %s", error->message); + g_error_free (error); + return; + } + + /* request the deny channel */ + request = tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, + G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_CONTACT_LIST, + + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, + G_TYPE_UINT, + TP_HANDLE_TYPE_LIST, + + TP_PROP_CHANNEL_TARGET_ID, + G_TYPE_STRING, + "deny", + + NULL); + + tp_cli_connection_interface_requests_call_ensure_channel ( + TP_CONNECTION (conn), -1, request, + contact_blocking_dialog_got_deny_channel, NULL, NULL, G_OBJECT (self)); + + g_hash_table_destroy (request); +} + +DECLARE_CALLBACK (contact_blocking_dialog_deny_channel_prepared); + +static void +contact_blocking_dialog_got_deny_channel (TpConnection *conn, + gboolean yours, + const char *channel_path, + GHashTable *props, + const GError *in_error, + gpointer user_data, + GObject *self) +{ + TpChannel *channel; + GError *error = NULL; + + const GQuark features[] = { + TP_CHANNEL_FEATURE_CORE, + TP_CHANNEL_FEATURE_GROUP, + 0 }; + + if (in_error != NULL) + { + DEBUG ("Failed to get 'deny' channel: %s", in_error->message); + return; + } + + channel = tp_channel_new_from_properties (conn, channel_path, props, &error); + + if (error != NULL) + { + DEBUG ("Failed to create channel proxy: %s", error->message); + g_error_free (error); + return; + } + + tp_proxy_prepare_async (channel, features, + contact_blocking_dialog_deny_channel_prepared, self); +} + +static void +contact_blocking_dialog_deny_channel_prepared (GObject *channel, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyContactBlockingDialog *self = user_data; + TpConnection *conn; + GError *error = NULL; + + if (!tp_proxy_prepare_finish (channel, result, &error)) + { + DEBUG ("Failed to prepare channel: %s", error->message); + g_error_free (error); + return; + } + + conn = tp_channel_borrow_connection (TP_CHANNEL (channel)); + + DEBUG ("Channel prepared for connection %s", get_pretty_conn_name (conn)); + + g_hash_table_insert (self->priv->channels, + g_object_ref (conn), channel); + contact_blocking_dialog_refilter_account_chooser (self); + + g_signal_connect (channel, "group-members-changed", + G_CALLBACK (contact_blocking_dialog_deny_channel_members_changed), self); +} + +static void +contact_blocking_dialog_set_error (EmpathyContactBlockingDialog *self, + const GError *error) +{ + const char *msg = NULL; + + if (error->domain == TP_ERRORS) + { + if (error->code == TP_ERROR_INVALID_HANDLE) + msg = _("Unknown or invalid identifier"); + else if (error->code == TP_ERROR_NOT_AVAILABLE) + msg = _("Contact blocking temporarily unavailable"); + else if (error->code == TP_ERROR_NOT_CAPABLE) + msg = _("Contact blocking unavailable"); + else if (error->code == TP_ERROR_PERMISSION_DENIED) + msg = _("Permission Denied"); + } + + if (msg == NULL) + msg = _("Could not block contact"); + + gtk_label_set_text (GTK_LABEL (self->priv->info_bar_label), msg); + gtk_widget_show (self->priv->info_bar); +} + +static void contact_blocking_dialog_add_contact_got_handle (TpConnection *, + const GArray *, const GError *, gpointer, GObject *); + +static void +contact_blocking_dialog_add_contact (GtkWidget *widget, + EmpathyContactBlockingDialog *self) +{ + TpConnection *conn = empathy_account_chooser_get_connection ( + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser)); + const char *identifiers[2] = { NULL, }; + + identifiers[0] = gtk_entry_get_text ( + GTK_ENTRY (self->priv->add_contact_entry)); + + DEBUG ("Looking up handle for '%s'", identifiers[0]); + + tp_cli_connection_call_request_handles (conn, -1, + TP_HANDLE_TYPE_CONTACT, identifiers, + contact_blocking_dialog_add_contact_got_handle, + NULL, NULL, G_OBJECT (self)); + + gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), ""); + gtk_widget_hide (self->priv->info_bar); +} + +static void +contact_blocking_dialog_added_contact (TpChannel *, const GError *, + gpointer, GObject *); + +static void +contact_blocking_dialog_add_contact_got_handle (TpConnection *conn, + const GArray *handles, + const GError *in_error, + gpointer user_data, + GObject *self) +{ + EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self); + TpChannel *channel = g_hash_table_lookup (priv->channels, conn); + + if (in_error != NULL) + { + DEBUG ("Error getting handle: %s", in_error->message); + + contact_blocking_dialog_set_error ( + EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error); + + return; + } + + g_return_if_fail (handles->len == 1); + + DEBUG ("Adding handle %u to deny channel", + g_array_index (handles, TpHandle, 0)); + + tp_cli_channel_interface_group_call_add_members (channel, -1, + handles, "", + contact_blocking_dialog_added_contact, NULL, NULL, self); +} + +static void +contact_blocking_dialog_added_contact (TpChannel *channel, + const GError *in_error, + gpointer user_data, + GObject *self) +{ + if (in_error != NULL) + { + DEBUG ("Error adding contact to deny list: %s", in_error->message); + + contact_blocking_dialog_set_error ( + EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error); + + return; + } + + DEBUG ("Contact added"); +} + +static void +contact_blocking_dialog_removed_contacts (TpChannel *, + const GError *, gpointer, GObject *); + +static void +contact_blocking_dialog_remove_contacts (GtkWidget *button, + EmpathyContactBlockingDialog *self) +{ + TpConnection *conn = empathy_account_chooser_get_connection ( + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser)); + TpChannel *channel = g_hash_table_lookup (self->priv->channels, conn); + GtkTreeModel *model; + GList *rows, *ptr; + GArray *handles = g_array_new (FALSE, FALSE, sizeof (TpHandle)); + + rows = gtk_tree_selection_get_selected_rows (self->priv->selection, &model); + + for (ptr = rows; ptr != NULL; ptr = ptr->next) + { + GtkTreePath *path = ptr->data; + GtkTreeIter iter; + TpHandle handle; + + if (!gtk_tree_model_get_iter (model, &iter, path)) + continue; + + gtk_tree_model_get (model, &iter, + COL_HANDLE, &handle, + -1); + + g_array_append_val (handles, handle); + gtk_tree_path_free (path); + } + + g_list_free (rows); + + if (handles->len > 0) + { + DEBUG ("Removing %u handles", handles->len); + + tp_cli_channel_interface_group_call_remove_members (channel, -1, + handles, "", + contact_blocking_dialog_removed_contacts, + NULL, NULL, G_OBJECT (self)); + } + + g_array_unref (handles); +} + +static void +contact_blocking_dialog_removed_contacts (TpChannel *channel, + const GError *in_error, + gpointer user_data, + GObject *self) +{ + if (in_error != NULL) + { + DEBUG ("Error removing contacts from deny list: %s", in_error->message); + + contact_blocking_dialog_set_error ( + EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error); + + return; + } + + DEBUG ("Contacts removed"); +} + +static void +contact_blocking_dialog_account_changed (GtkWidget *account_chooser, + EmpathyContactBlockingDialog *self) +{ + TpConnection *conn = empathy_account_chooser_get_connection ( + EMPATHY_ACCOUNT_CHOOSER (account_chooser)); + TpChannel *channel; + GArray *blocked; + EmpathyContactManager *contact_manager; + EmpathyTpContactList *contact_list; + GList *members, *ptr; + + if (self->priv->block_account_changed > 0) + return; + + /* clear the lists of contacts */ + gtk_list_store_clear (self->priv->blocked_contacts); + gtk_list_store_clear (self->priv->completion_contacts); + + if (conn == NULL) + return; + + DEBUG ("Account changed: %s", get_pretty_conn_name (conn)); + + /* load the deny list */ + channel = g_hash_table_lookup (self->priv->channels, conn); + + if (channel == NULL) + return; + + g_return_if_fail (TP_IS_CHANNEL (channel)); + + blocked = tp_intset_to_array (tp_channel_group_get_members (channel)); + + DEBUG ("%u contacts on blocked list", blocked->len); + + contact_blocking_dialog_add_contacts_to_list (self, conn, blocked); + g_array_unref (blocked); + + /* load the completion list */ + g_return_if_fail (empathy_contact_manager_initialized ()); + + DEBUG ("Loading contacts"); + + contact_manager = empathy_contact_manager_dup_singleton (); + contact_list = empathy_contact_manager_get_list (contact_manager, conn); + members = empathy_contact_list_get_members ( + EMPATHY_CONTACT_LIST (contact_list)); + + for (ptr = members; ptr != NULL; ptr = ptr->next) + { + EmpathyContact *contact = ptr->data; + + gtk_list_store_insert_with_values (self->priv->completion_contacts, + NULL, -1, + COL_IDENTIFIER, empathy_contact_get_id (contact), + -1); + + g_object_unref (contact); + } + + g_list_free (members); + g_object_unref (contact_manager); +} + +static void +contact_blocking_dialog_view_selection_changed (GtkTreeSelection *selection, + EmpathyContactBlockingDialog *self) +{ + GList *rows = gtk_tree_selection_get_selected_rows (selection, NULL); + + /* update the sensitivity of the remove button */ + gtk_widget_set_sensitive (self->priv->remove_button, rows != NULL); + + g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL); + g_list_free (rows); +} + +static void +contact_blocking_dialog_dispose (GObject *self) +{ + EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self); + + tp_clear_pointer (&priv->channels, g_hash_table_destroy); + + G_OBJECT_CLASS (empathy_contact_blocking_dialog_parent_class)->dispose (self); +} + +static void +empathy_contact_blocking_dialog_class_init ( + EmpathyContactBlockingDialogClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = contact_blocking_dialog_dispose; + + g_type_class_add_private (gobject_class, + sizeof (EmpathyContactBlockingDialogPrivate)); +} + +static void +empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) +{ + GtkBuilder *gui; + char *filename; + GtkWidget *contents; + GtkWidget *account_hbox, *blocked_contacts_view; + GtkEntryCompletion *completion; + TpAccountManager *am; + + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, + EmpathyContactBlockingDialogPrivate); + + self->priv->channels = g_hash_table_new_full (NULL, NULL, + g_object_unref, g_object_unref); + + gtk_window_set_title (GTK_WINDOW (self), _("Edit Blocked Contacts")); + gtk_dialog_add_button (GTK_DIALOG (self), + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); + + filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui", + "libempathy-gtk"); + + gui = empathy_builder_get_file (filename, + "contents", &contents, + "account-hbox", &account_hbox, + "add-button", &self->priv->add_button, + "add-contact-entry", &self->priv->add_contact_entry, + "blocked-contacts", &self->priv->blocked_contacts, + "blocked-contacts-view", &blocked_contacts_view, + "remove-button", &self->priv->remove_button, + NULL); + + empathy_builder_connect (gui, self, + "add-button", "clicked", contact_blocking_dialog_add_contact, + "add-contact-entry", "activate", contact_blocking_dialog_add_contact, + "remove-button", "clicked", contact_blocking_dialog_remove_contacts, + NULL); + + /* add the contents to the dialog */ + gtk_container_add ( + GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))), + contents); + gtk_widget_show (contents); + + /* set up the tree selection */ + self->priv->selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (blocked_contacts_view)); + gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_MULTIPLE); + g_signal_connect (self->priv->selection, "changed", + G_CALLBACK (contact_blocking_dialog_view_selection_changed), self); + + /* build the contact entry */ + self->priv->completion_contacts = gtk_list_store_new (1, G_TYPE_STRING); + completion = gtk_entry_completion_new (); + gtk_entry_completion_set_model (completion, + GTK_TREE_MODEL (self->priv->completion_contacts)); + gtk_entry_completion_set_text_column (completion, COL_IDENTIFIER); + gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry), + completion); + g_object_unref (completion); + g_object_unref (self->priv->completion_contacts); + + /* add the account chooser */ + self->priv->account_chooser = empathy_account_chooser_new (); + contact_blocking_dialog_refilter_account_chooser (self); + g_signal_connect (self->priv->account_chooser, "changed", + G_CALLBACK (contact_blocking_dialog_account_changed), self); + + gtk_box_pack_start (GTK_BOX (account_hbox), self->priv->account_chooser, + TRUE, TRUE, 0); + gtk_widget_show (self->priv->account_chooser); + + /* add an error warning info bar */ + self->priv->info_bar = gtk_info_bar_new (); + gtk_box_pack_start (GTK_BOX (contents), self->priv->info_bar, FALSE, TRUE, 0); + gtk_info_bar_set_message_type (GTK_INFO_BAR (self->priv->info_bar), + GTK_MESSAGE_ERROR); + + self->priv->info_bar_label = gtk_label_new (""); + gtk_container_add (GTK_CONTAINER ( + gtk_info_bar_get_content_area (GTK_INFO_BAR (self->priv->info_bar))), + self->priv->info_bar_label); + gtk_widget_show (self->priv->info_bar_label); + + /* prepare the account manager */ + am = tp_account_manager_dup (); + tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self); + g_object_unref (am); + + g_free (filename); + g_object_unref (gui); +} + +GtkWidget * +empathy_contact_blocking_dialog_new (GtkWindow *parent) +{ + GtkWidget *self = g_object_new (EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, + NULL); + + if (parent != NULL) + { + gtk_window_set_transient_for (GTK_WINDOW (self), parent); + } + + return self; +} diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.h b/libempathy-gtk/empathy-contact-blocking-dialog.h new file mode 100644 index 000000000..96451c6c3 --- /dev/null +++ b/libempathy-gtk/empathy-contact-blocking-dialog.h @@ -0,0 +1,60 @@ +/* + * empathy-contact-blocking-dialog.h + * + * EmpathyContactBlockingDialog + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk> + */ + +#ifndef __EMPATHY_CONTACT_BLOCKING_DIALOG_H__ +#define __EMPATHY_CONTACT_BLOCKING_DIALOG_H__ + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG (empathy_contact_blocking_dialog_get_type ()) +#define EMPATHY_CONTACT_BLOCKING_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, EmpathyContactBlockingDialog)) +#define EMPATHY_CONTACT_BLOCKING_DIALOG_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, EmpathyContactBlockingDialogClass)) +#define EMPATHY_IS_CONTACT_BLOCKING_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG)) +#define EMPATHY_IS_CONTACT_BLOCKING_DIALOG_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG)) +#define EMPATHY_CONTACT_BLOCKING_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, EmpathyContactBlockingDialogClass)) + +typedef struct _EmpathyContactBlockingDialog EmpathyContactBlockingDialog; +typedef struct _EmpathyContactBlockingDialogClass EmpathyContactBlockingDialogClass; +typedef struct _EmpathyContactBlockingDialogPrivate EmpathyContactBlockingDialogPrivate; + +struct _EmpathyContactBlockingDialog +{ + GtkDialog parent; + EmpathyContactBlockingDialogPrivate *priv; +}; + +struct _EmpathyContactBlockingDialogClass +{ + GtkDialogClass parent_class; +}; + +GType empathy_contact_blocking_dialog_get_type (void); + +GtkWidget *empathy_contact_blocking_dialog_new (GtkWindow *parent); + +G_END_DECLS + +#endif diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.ui b/libempathy-gtk/empathy-contact-blocking-dialog.ui new file mode 100644 index 000000000..b2ea89b81 --- /dev/null +++ b/libempathy-gtk/empathy-contact-blocking-dialog.ui @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="2.16"/> + <!-- interface-naming-policy project-wide --> + <object class="GtkListStore" id="blocked-contacts"> + <columns> + <!-- column-name identifier --> + <column type="gchararray"/> + <!-- column-name handle --> + <column type="guint"/> + </columns> + </object> + <object class="GtkVBox" id="contents"> + <property name="visible">True</property> + <property name="border_width">6</property> + <property name="spacing">6</property> + <child> + <object class="GtkHBox" id="account-hbox"> + <property name="visible">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Account:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">never</property> + <property name="vscrollbar_policy">automatic</property> + <property name="shadow_type">etched-in</property> + <child> + <object class="GtkTreeView" id="blocked-contacts-view"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="model">blocked-contacts</property> + <property name="headers_clickable">False</property> + <property name="search_column">0</property> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn1"> + <property name="title">Blocked Contacts</property> + <property name="sort_indicator">True</property> + <property name="sort_column_id">0</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext1"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkVButtonBox" id="vbuttonbox1"> + <property name="visible">True</property> + <property name="layout_style">start</property> + <child> + <object class="GtkButton" id="remove-button"> + <property name="label">gtk-remove</property> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="add-contact-hbox"> + <property name="visible">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkEntry" id="add-contact-entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="add-button"> + <property name="label">gtk-add</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">2</property> + </packing> + </child> + </object> + <object class="GtkSizeGroup" id="sizegroup1"> + <widgets> + <widget name="add-button"/> + <widget name="remove-button"/> + </widgets> + </object> +</interface> diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 7aba1fd7c..0b388851e 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -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,27 @@ subscription_dialog_response_cb (GtkDialog *dialog, empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager), contact, ""); } + else if (response == GTK_RESPONSE_REJECT) { + /* confirm the blocking */ + if (empathy_block_contact_dialog_show (GTK_WINDOW (dialog), + contact, NULL)) { + empathy_contact_list_remove ( + EMPATHY_CONTACT_LIST (manager), + contact, ""); + empathy_contact_list_set_blocked ( + EMPATHY_CONTACT_LIST (manager), + contact, TRUE); + } 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); } @@ -97,8 +116,13 @@ empathy_subscription_dialog_show (EmpathyContact *contact, GtkWidget *dialog; GtkWidget *hbox_subscription; GtkWidget *contact_widget; + GtkWidget *block_user_button; GList *l; gchar *filename; + EmpathyContactManager *manager; + EmpathyContactListFlags flags; + + manager = empathy_contact_manager_dup_singleton (); g_return_if_fail (EMPATHY_IS_CONTACT (contact)); @@ -115,6 +139,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); @@ -137,10 +162,17 @@ empathy_subscription_dialog_show (EmpathyContact *contact, G_CALLBACK (subscription_dialog_response_cb), contact_widget); + flags = empathy_contact_manager_get_flags_for_connection (manager, + empathy_contact_get_connection (contact)); + + if (flags & EMPATHY_CONTACT_LIST_CAN_BLOCK) + gtk_widget_show (block_user_button); + if (parent) { gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); } + g_object_unref (manager); gtk_widget_show (dialog); } @@ -444,3 +476,72 @@ 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, + gboolean *abusive) +{ + EmpathyContactManager *manager; + EmpathyContactListFlags flags; + GtkWidget *dialog; + GtkWidget *abusive_check = NULL; + int res; + + manager = empathy_contact_manager_dup_singleton (); + flags = empathy_contact_manager_get_flags_for_connection (manager, + empathy_contact_get_connection (contact)); + + dialog = gtk_message_dialog_new (parent, + GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, + _("Block %s?"), + empathy_contact_get_id (contact)); + + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dialog), + _("Are you sure you want to block the contact %s?"), + empathy_contact_get_id (contact)); + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + _("_Block"), GTK_RESPONSE_REJECT, + NULL); + + /* ask the user if they want to also report the contact as abusive */ + if (flags & EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE) { + 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)); + 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; + } + } + + g_object_unref (manager); + + return res == GTK_RESPONSE_REJECT; +} diff --git a/libempathy-gtk/empathy-contact-dialogs.h b/libempathy-gtk/empathy-contact-dialogs.h index 21aa5ce73..33e2cf054 100644 --- a/libempathy-gtk/empathy-contact-dialogs.h +++ b/libempathy-gtk/empathy-contact-dialogs.h @@ -38,6 +38,9 @@ void empathy_contact_personal_dialog_show (GtkWindow *parent); void empathy_new_contact_dialog_show (GtkWindow *parent); void empathy_new_contact_dialog_show_with_contact (GtkWindow *parent, EmpathyContact *contact); +gboolean empathy_block_contact_dialog_show (GtkWindow *parent, + EmpathyContact *contact, + gboolean *abusive); G_END_DECLS diff --git a/libempathy-gtk/empathy-contact-dialogs.ui b/libempathy-gtk/empathy-contact-dialogs.ui index 0986de1f5..ecafddb69 100644 --- a/libempathy-gtk/empathy-contact-dialogs.ui +++ b/libempathy-gtk/empathy-contact-dialogs.ui @@ -1,14 +1,14 @@ -<?xml version="1.0"?> -<!--*- mode: xml -*--> +<?xml version="1.0" encoding="UTF-8"?> <interface> + <!-- interface-requires gtk+ 2.12 --> + <!-- interface-naming-policy toplevel-contextual --> <object class="GtkDialog" id="subscription_request_dialog"> <property name="border_width">5</property> <property name="title" translatable="yes">Subscription Request</property> <property name="role">subscription_request</property> <property name="resizable">False</property> - <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property> - <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> - <property name="has_separator">False</property> + <property name="window_position">center-on-parent</property> + <property name="type_hint">dialog</property> <child internal-child="vbox"> <object class="GtkVBox" id="dialog-vbox4"> <property name="visible">True</property> @@ -23,11 +23,12 @@ <property name="visible">True</property> <property name="yalign">0</property> <property name="stock">gtk-dialog-question</property> - <property name="icon_size">6</property> + <property name="icon-size">6</property> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> + <property name="position">0</property> </packing> </child> <child> @@ -41,50 +42,77 @@ <child internal-child="action_area"> <object class="GtkHButtonBox" id="dialog-action_area4"> <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="block-user-button"> + <property name="label" translatable="yes">_Block User</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> <child> <object class="GtkButton" id="button19"> + <property name="label" translatable="yes">Decide _Later</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="can_default">True</property> - <property name="label" translatable="yes">Decide _Later</property> + <property name="receives_default">False</property> <property name="use_underline">True</property> </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> </child> <child> <object class="GtkButton" id="button20"> + <property name="label">gtk-no</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="can_default">True</property> - <property name="label">gtk-no</property> + <property name="receives_default">False</property> <property name="use_stock">True</property> </object> <packing> - <property name="position">1</property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> </packing> </child> <child> <object class="GtkButton" id="button21"> + <property name="label">gtk-yes</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="can_default">True</property> <property name="has_default">True</property> - <property name="label">gtk-yes</property> + <property name="receives_default">False</property> <property name="use_stock">True</property> </object> <packing> - <property name="position">2</property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">3</property> </packing> </child> </object> <packing> <property name="expand">False</property> - <property name="pack_type">GTK_PACK_END</property> + <property name="pack_type">end</property> + <property name="position">0</property> </packing> </child> </object> </child> <action-widgets> + <action-widget response="-2">block-user-button</action-widget> <action-widget response="-6">button19</action-widget> <action-widget response="-9">button20</action-widget> <action-widget response="-8">button21</action-widget> diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index bbd4ecc8e..9984de42d 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -40,6 +40,8 @@ #include "empathy-ui-utils.h" #include "empathy-share-my-desktop.h" +static GtkWidget *empathy_contact_block_menu_item_new (EmpathyContact *); + GtkWidget * empathy_contact_menu_new (EmpathyContact *contact, EmpathyContactFeatureFlags features) @@ -137,6 +139,19 @@ empathy_contact_menu_new (EmpathyContact *contact, gtk_widget_show (item); } + /* Separator & Block */ + if (features & EMPATHY_CONTACT_FEATURE_BLOCK && + (item = empathy_contact_block_menu_item_new (contact)) != NULL) { + GtkWidget *sep; + + sep = gtk_separator_menu_item_new (); + gtk_menu_shell_append (shell, sep); + gtk_widget_show (sep); + + gtk_menu_shell_append (shell, item); + gtk_widget_show (item); + } + return menu; } @@ -212,6 +227,84 @@ empathy_contact_add_menu_item_new (EmpathyContact *contact) } static void +empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item, + EmpathyContact *contact) +{ + static guint block_signal = 0; + EmpathyContactManager *manager; + gboolean blocked; + + if (block_signal > 0) + return; + + blocked = gtk_check_menu_item_get_active (item); + + if (blocked) { + /* confirm the user really wishes to block the contact */ + GtkWidget *parent; + + /* gtk_menu_get_attach_widget() doesn't behave properly here + * for some reason */ + parent = g_object_get_data ( + G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))), + "window"); + + if (!empathy_block_contact_dialog_show (GTK_WINDOW (parent), + contact, NULL)) + return; + } + + manager = empathy_contact_manager_dup_singleton (); + empathy_contact_list_set_blocked (EMPATHY_CONTACT_LIST (manager), + contact, blocked); + g_object_unref (manager); + + /* update the toggle with the blocked status */ + block_signal++; + gtk_check_menu_item_set_active (item, blocked); + block_signal--; +} + +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); + + 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_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; +} + +static void empathy_contact_chat_menu_item_activated (GtkMenuItem *item, EmpathyContact *contact) { diff --git a/libempathy-gtk/empathy-contact-menu.h b/libempathy-gtk/empathy-contact-menu.h index 4c6d62f9d..d7248da9e 100644 --- a/libempathy-gtk/empathy-contact-menu.h +++ b/libempathy-gtk/empathy-contact-menu.h @@ -36,7 +36,8 @@ typedef enum { EMPATHY_CONTACT_FEATURE_EDIT = 1 << 3, EMPATHY_CONTACT_FEATURE_INFO = 1 << 4, EMPATHY_CONTACT_FEATURE_FAVOURITE = 1 << 5, - EMPATHY_CONTACT_FEATURE_ALL = (1 << 6) - 1, + EMPATHY_CONTACT_FEATURE_BLOCK = 1 << 6, + EMPATHY_CONTACT_FEATURE_ALL = (1 << 7) - 1, } EmpathyContactFeatureFlags; GtkWidget * empathy_contact_menu_new (EmpathyContact *contact, diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index f262772c6..e32ff05b6 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -29,6 +29,7 @@ #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> @@ -37,6 +38,8 @@ #include "empathy-contact-widget.h" #include "empathy-ui-utils.h" +#define BULLET_POINT "\342\200\242" + static GtkWidget *new_individual_dialog = NULL; /* @@ -157,3 +160,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 " BULLET_POINT " %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..1444d5ac8 100644 --- a/libempathy-gtk/empathy-individual-dialogs.h +++ b/libempathy-gtk/empathy-individual-dialogs.h @@ -32,6 +32,9 @@ 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 63c5a8d90..55d25f801 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -47,6 +47,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" @@ -2206,16 +2207,22 @@ empathy_individual_view_get_selected_group (EmpathyIndividualView *view, return name; } -static gboolean +static int individual_view_remove_dialog_show (GtkWindow *parent, const gchar *message, - const gchar *secondary_text) + const gchar *secondary_text, + gboolean block_button) { GtkWidget *dialog; gboolean res; dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message); + + if (block_button) + gtk_dialog_add_button (GTK_DIALOG (dialog), + _("Delete and Block"), GTK_RESPONSE_REJECT); + gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_NO, GTK_STOCK_DELETE, GTK_RESPONSE_YES, NULL); @@ -2227,7 +2234,7 @@ individual_view_remove_dialog_show (GtkWindow *parent, res = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); - return (res == GTK_RESPONSE_YES); + return res; } static void @@ -2247,7 +2254,7 @@ individual_view_group_remove_activate_cb (GtkMenuItem *menuitem, group); parent = empathy_get_toplevel_window (GTK_WIDGET (view)); if (individual_view_remove_dialog_show (parent, _("Removing group"), - text)) + text, FALSE) == GTK_RESPONSE_YES) { EmpathyIndividualManager *manager = empathy_individual_manager_dup_singleton (); @@ -2326,26 +2333,43 @@ individual_view_remove_activate_cb (GtkMenuItem *menuitem, if (individual != NULL) { + EmpathyIndividualManager *manager; gchar *text; GtkWindow *parent; + gboolean can_block; + int res; + + manager = empathy_individual_manager_dup_singleton (); + can_block = empathy_individual_manager_supports_blocking (manager, + individual); parent = empathy_get_toplevel_window (GTK_WIDGET (view)); text = - g_strdup_printf (_ - ("Do you really want to remove the contact '%s'?"), + g_strdup_printf ( + _("Do you really want to remove the contact '%s'?"), folks_aliasable_get_alias (FOLKS_ALIASABLE (individual))); - if (individual_view_remove_dialog_show (parent, _("Removing contact"), - text)) + res = individual_view_remove_dialog_show (parent, _("Removing contact"), + text, can_block); + if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_REJECT) { - EmpathyIndividualManager *manager; + if (res == GTK_RESPONSE_REJECT && + empathy_block_individual_dialog_show (parent, individual, NULL)) + { + empathy_individual_manager_set_blocked (manager, individual, + TRUE); + } + else + { + goto finally; + } - manager = empathy_individual_manager_dup_singleton (); empathy_individual_manager_remove (manager, individual, ""); - g_object_unref (G_OBJECT (manager)); } +finally: g_free (text); g_object_unref (individual); + g_object_unref (manager); } } diff --git a/libempathy/empathy-contact-list.c b/libempathy/empathy-contact-list.c index 631bb4a37..d8af8938f 100644 --- a/libempathy/empathy-contact-list.c +++ b/libempathy/empathy-contact-list.c @@ -278,3 +278,26 @@ empathy_contact_list_remove_from_favourites (EmpathyContactList *list, contact); } } + +void +empathy_contact_list_set_blocked (EmpathyContactList *list, + EmpathyContact *contact, + gboolean blocked) +{ + EmpathyContactListIface *iface = EMPATHY_CONTACT_LIST_GET_IFACE (list); + + if (iface->set_blocked != NULL) + iface->set_blocked (list, contact, blocked); +} + +gboolean +empathy_contact_list_get_blocked (EmpathyContactList *list, + EmpathyContact *contact) +{ + EmpathyContactListIface *iface = EMPATHY_CONTACT_LIST_GET_IFACE (list); + + if (iface->get_blocked != NULL) + return iface->get_blocked (list, contact); + else + return FALSE; +} diff --git a/libempathy/empathy-contact-list.h b/libempathy/empathy-contact-list.h index 3817af876..8be93baf9 100644 --- a/libempathy/empathy-contact-list.h +++ b/libempathy/empathy-contact-list.h @@ -39,6 +39,8 @@ typedef enum { EMPATHY_CONTACT_LIST_CAN_REMOVE = 1 << 1, EMPATHY_CONTACT_LIST_CAN_ALIAS = 1 << 2, EMPATHY_CONTACT_LIST_CAN_GROUP = 1 << 3, + EMPATHY_CONTACT_LIST_CAN_BLOCK = 1 << 4, + EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE = 1 << 5, } EmpathyContactListFlags; typedef struct _EmpathyContactListIface EmpathyContactListIface; @@ -77,6 +79,11 @@ struct _EmpathyContactListIface { EmpathyContact *contact); void (*remove_favourite) (EmpathyContactList *list, EmpathyContact *contact); + void (*set_blocked) (EmpathyContactList *list, + EmpathyContact *contact, + gboolean blocked); + gboolean (*get_blocked) (EmpathyContactList *list, + EmpathyContact *contact); }; GType empathy_contact_list_get_type (void) G_GNUC_CONST; @@ -116,6 +123,12 @@ void empathy_contact_list_remove_from_favourites (EmpathyContactList *list, EmpathyContact *contact); +void empathy_contact_list_set_blocked (EmpathyContactList *list, + EmpathyContact *contact, + gboolean blocked); +gboolean empathy_contact_list_get_blocked (EmpathyContactList *list, + EmpathyContact *contact); + G_END_DECLS diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c index a900fa610..2242159b5 100644 --- a/libempathy/empathy-contact-manager.c +++ b/libempathy/empathy-contact-manager.c @@ -865,6 +865,45 @@ contact_manager_remove_group (EmpathyContactList *manager, } static void +contact_manager_set_blocked (EmpathyContactList *manager, + EmpathyContact *contact, + gboolean blocked) +{ + EmpathyContactManagerPriv *priv = GET_PRIV (manager); + EmpathyContactList *list; + TpConnection *connection; + + g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager)); + + connection = empathy_contact_get_connection (contact); + list = g_hash_table_lookup (priv->lists, connection); + + if (list != NULL) { + empathy_contact_list_set_blocked (list, contact, blocked); + } +} + +static gboolean +contact_manager_get_blocked (EmpathyContactList *manager, + EmpathyContact *contact) +{ + EmpathyContactManagerPriv *priv = GET_PRIV (manager); + EmpathyContactList *list; + TpConnection *connection; + + g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), FALSE); + + connection = empathy_contact_get_connection (contact); + list = g_hash_table_lookup (priv->lists, connection); + + if (list != NULL) { + return empathy_contact_list_get_blocked (list, contact); + } else { + return FALSE; + } +} + +static void contact_manager_iface_init (EmpathyContactListIface *iface) { iface->add = contact_manager_add; @@ -880,6 +919,8 @@ contact_manager_iface_init (EmpathyContactListIface *iface) iface->is_favourite = contact_manager_is_favourite; iface->remove_favourite = contact_manager_remove_favourite; iface->add_favourite = contact_manager_add_favourite; + iface->set_blocked = contact_manager_set_blocked; + iface->get_blocked = contact_manager_get_blocked; } EmpathyContactListFlags diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index fa5bd38b5..4adf8e1cb 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -30,6 +30,7 @@ #include <telepathy-glib/util.h> #include <folks/folks.h> +#include <folks/folks-telepathy.h> #include <extensions/extensions.h> @@ -459,6 +460,79 @@ empathy_individual_manager_remove (EmpathyIndividualManager *self, aggregator_remove_individual_cb, self); } +/** + * 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) +{ + EmpathyIndividualManagerPriv *priv; + GList *personas, *l; + + g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE); + + priv = GET_PRIV (self); + + personas = folks_individual_get_personas (individual); + + for (l = personas; l != NULL; l = l->next) + { + TpfPersona *persona = l->data; + TpConnection *conn; + + if (!TPF_IS_PERSONA (persona)) + continue; + + conn = tp_contact_get_connection (tpf_persona_get_contact (persona)); + + if (empathy_individual_manager_get_flags_for_connection (self, conn) & + EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK) + return TRUE; + } + + return FALSE; +} + +void +empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, + FolksIndividual *individual, + gboolean blocked) +{ + EmpathyIndividualManagerPriv *priv; + GList *personas, *l; + + g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self)); + + priv = GET_PRIV (self); + + personas = folks_individual_get_personas (individual); + + for (l = personas; l != NULL; l = l->next) + { + TpfPersona *persona = l->data; + EmpathyContact *contact; + + if (!TPF_IS_PERSONA (persona)) + continue; + + contact = empathy_contact_dup_from_tp_contact ( + tpf_persona_get_contact (persona)); + empathy_contact_set_persona (contact, FOLKS_PERSONA (persona)); + empathy_contact_list_set_blocked ( + EMPATHY_CONTACT_LIST (priv->contact_manager), + contact, blocked); + + g_object_unref (contact); + } +} + static void groups_change_group_cb (GObject *source, GAsyncResult *result, @@ -528,6 +602,10 @@ empathy_individual_manager_get_flags_for_connection ( flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_ALIAS; if (list_flags & EMPATHY_CONTACT_LIST_CAN_GROUP) flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_GROUP; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_BLOCK) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_REPORT_ABUSIVE; return flags; } diff --git a/libempathy/empathy-individual-manager.h b/libempathy/empathy-individual-manager.h index 72104fc40..cace94794 100644 --- a/libempathy/empathy-individual-manager.h +++ b/libempathy/empathy-individual-manager.h @@ -42,6 +42,8 @@ G_BEGIN_DECLS EMPATHY_INDIVIDUAL_MANAGER_CAN_REMOVE = 1 << 1, EMPATHY_INDIVIDUAL_MANAGER_CAN_ALIAS = 1 << 2, EMPATHY_INDIVIDUAL_MANAGER_CAN_GROUP = 1 << 3, + EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK = 1 << 4, + EMPATHY_INDIVIDUAL_MANAGER_CAN_REPORT_ABUSIVE = 1 << 5, } EmpathyIndividualManagerFlags; typedef struct _EmpathyIndividualManager EmpathyIndividualManager; @@ -94,5 +96,13 @@ void empathy_individual_manager_unlink_individual ( EmpathyIndividualManager *self, FolksIndividual *individual); +gboolean empathy_individual_manager_supports_blocking ( + EmpathyIndividualManager *self, + FolksIndividual *individual); + +void empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, + FolksIndividual *individual, + gboolean blocked); + G_END_DECLS #endif /* __EMPATHY_INDIVIDUAL_MANAGER_H__ */ diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index 263c379f6..ec4f17245 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -46,6 +46,7 @@ typedef struct { TpChannel *publish; TpChannel *subscribe; TpChannel *stored; + TpChannel *deny; /* contact handle (TpHandle) => reffed (EmpathyContact *) * * Union of: @@ -722,6 +723,10 @@ tp_contact_list_finalize (GObject *object) g_object_unref (priv->stored); } + if (priv->deny) { + g_object_unref (priv->deny); + } + if (priv->connection) { g_object_unref (priv->connection); } @@ -773,6 +778,11 @@ got_list_channel (EmpathyTpContactList *list, g_signal_connect (priv->subscribe, "group-members-changed", G_CALLBACK (tp_contact_list_subscribe_group_members_changed_cb), list); + } else if (!tp_strdiff (id, "deny")) { + if (priv->deny != NULL) + return; + DEBUG ("Got 'deny' channel"); + priv->deny = g_object_ref (channel); } } @@ -881,8 +891,8 @@ conn_ready_cb (TpConnection *connection, NULL, NULL, G_OBJECT (list)); request = tp_asv_new ( - TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST, - TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_LIST, + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_LIST, NULL); /* Watch the NewChannels signal so if ensuring list channels fails (for @@ -892,17 +902,22 @@ conn_ready_cb (TpConnection *connection, priv->connection, new_channels_cb, NULL, NULL, G_OBJECT (list), NULL); /* Request the 'stored' list. */ - tp_asv_set_static_string (request, TP_IFACE_CHANNEL ".TargetID", "stored"); + tp_asv_set_static_string (request, TP_PROP_CHANNEL_TARGET_ID, "stored"); tp_cli_connection_interface_requests_call_ensure_channel (priv->connection, G_MAXINT, request, list_ensure_channel_cb, list, NULL, G_OBJECT (list)); /* Request the 'publish' list. */ - tp_asv_set_static_string (request, TP_IFACE_CHANNEL ".TargetID", "publish"); + tp_asv_set_static_string (request, TP_PROP_CHANNEL_TARGET_ID, "publish"); tp_cli_connection_interface_requests_call_ensure_channel (priv->connection, G_MAXINT, request, list_ensure_channel_cb, list, NULL, G_OBJECT (list)); /* Request the 'subscribe' list. */ - tp_asv_set_static_string (request, TP_IFACE_CHANNEL ".TargetID", "subscribe"); + tp_asv_set_static_string (request, TP_PROP_CHANNEL_TARGET_ID, "subscribe"); + tp_cli_connection_interface_requests_call_ensure_channel (priv->connection, + G_MAXINT, request, list_ensure_channel_cb, list, NULL, G_OBJECT (list)); + + /* Request the 'deny' list */ + tp_asv_set_static_string (request, TP_PROP_CHANNEL_TARGET_ID, "deny"); tp_cli_connection_interface_requests_call_ensure_channel (priv->connection, G_MAXINT, request, list_ensure_channel_cb, list, NULL, G_OBJECT (list)); @@ -1289,10 +1304,46 @@ tp_contact_list_get_flags (EmpathyContactList *list) } } + if (priv->deny != NULL) + flags |= EMPATHY_CONTACT_LIST_CAN_BLOCK; + return flags; } static void +tp_contact_list_set_blocked (EmpathyContactList *list, + EmpathyContact *contact, + gboolean blocked) +{ + EmpathyTpContactListPriv *priv = GET_PRIV (list); + TpHandle handle = empathy_contact_get_handle (contact); + GArray handles = { (char *) &handle, 1 }; + + g_return_if_fail (TP_IS_CHANNEL (priv->deny)); + + if (blocked) + tp_cli_channel_interface_group_call_add_members ( + priv->deny, -1, + &handles, NULL, NULL, NULL, NULL, NULL); + else + tp_cli_channel_interface_group_call_remove_members ( + priv->deny, -1, + &handles, NULL, NULL, NULL, NULL, NULL); +} + +static gboolean +tp_contact_list_get_blocked (EmpathyContactList *list, + EmpathyContact *contact) +{ + EmpathyTpContactListPriv *priv = GET_PRIV (list); + + g_return_val_if_fail (TP_IS_CHANNEL (priv->deny), FALSE); + + return tp_intset_is_member (tp_channel_group_get_members (priv->deny), + empathy_contact_get_handle (contact)); +} + +static void tp_contact_list_iface_init (EmpathyContactListIface *iface) { iface->add = tp_contact_list_add; @@ -1306,6 +1357,8 @@ tp_contact_list_iface_init (EmpathyContactListIface *iface) iface->rename_group = tp_contact_list_rename_group; iface->remove_group = tp_contact_list_remove_group; iface->get_flags = tp_contact_list_get_flags; + iface->set_blocked = tp_contact_list_set_blocked; + iface->get_blocked = tp_contact_list_get_blocked; } void @@ -1334,4 +1387,3 @@ empathy_tp_contact_list_remove_all (EmpathyTpContactList *list) } g_hash_table_remove_all (priv->pendings); } - diff --git a/libempathy/empathy-tp-contact-list.h b/libempathy/empathy-tp-contact-list.h index 071fc0b91..9a555bc7a 100644 --- a/libempathy/empathy-tp-contact-list.h +++ b/libempathy/empathy-tp-contact-list.h @@ -26,6 +26,7 @@ #include <glib.h> #include <telepathy-glib/connection.h> +#include <libempathy/empathy-contact.h> G_BEGIN_DECLS diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 0455642f8..f8a89a101 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -403,6 +403,10 @@ chat_window_contact_menu_update (EmpathyChatWindowPriv *priv, if (orig_submenu == NULL || !gtk_widget_get_visible (orig_submenu)) { submenu = empathy_chat_get_contact_menu (priv->current_chat); + + /* gtk_menu_attach_to_widget() doesn't behave nicely here */ + g_object_set_data (G_OBJECT (submenu), "window", priv->dialog); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu); gtk_widget_show (menu); } else { diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index e953cb01c..6656ee0e4 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -51,6 +51,7 @@ #include <libempathy-gtk/empathy-contact-list-store.h> #include <libempathy-gtk/empathy-contact-list-view.h> #include <libempathy-gtk/empathy-live-search.h> +#include <libempathy-gtk/empathy-contact-blocking-dialog.h> #include <libempathy-gtk/empathy-contact-search-dialog.h> #include <libempathy-gtk/empathy-geometry.h> #include <libempathy-gtk/empathy-gtk-enum-types.h> @@ -1436,6 +1437,18 @@ main_window_edit_personal_information_cb (GtkAction *action, } static void +main_window_edit_blocked_contacts_cb (GtkAction *action, + EmpathyMainWindow *window) +{ + GtkWidget *dialog; + + dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window)); + gtk_widget_show (dialog); + g_signal_connect (dialog, "response", + G_CALLBACK (gtk_widget_destroy), NULL); +} + +static void main_window_edit_preferences_cb (GtkAction *action, EmpathyMainWindow *window) { @@ -1586,7 +1599,8 @@ main_window_connection_items_setup (EmpathyMainWindow *window, "chat_new_message", "chat_new_call", "chat_add_contact", - "edit_personal_information" + "edit_personal_information", + "edit_blocked_contacts" }; for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) { @@ -1764,6 +1778,7 @@ empathy_main_window_init (EmpathyMainWindow *window) "edit", "activate", main_window_edit_cb, "edit_accounts", "activate", main_window_edit_accounts_cb, "edit_personal_information", "activate", main_window_edit_personal_information_cb, + "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb, "edit_preferences", "activate", main_window_edit_preferences_cb, "help_about", "activate", main_window_help_about_cb, "help_debug", "activate", main_window_help_debug_cb, diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index c57a9df64..a538e0120 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -107,6 +107,12 @@ </object> </child> <child> + <object class="GtkAction" id="edit_blocked_contacts"> + <property name="name">edit_blocked_contacts</property> + <property name="label" translatable="yes">_Blocked Contacts</property> + </object> + </child> + <child> <object class="GtkAction" id="edit_preferences"> <property name="stock_id">gtk-preferences</property> <property name="name">edit_preferences</property> @@ -242,6 +248,7 @@ <separator name="edit_context_separator"/> <menuitem action="edit_accounts"/> <menuitem action="edit_personal_information"/> + <menuitem action="edit_blocked_contacts"/> <separator/> <menuitem action="edit_preferences"/> </menu> diff --git a/tests/interactive/.gitignore b/tests/interactive/.gitignore index ebaa4d1e9..ea3271654 100644 --- a/tests/interactive/.gitignore +++ b/tests/interactive/.gitignore @@ -4,6 +4,7 @@ contact-run-until-ready contact-run-until-ready-2 empetit test-empathy-account-assistant +test-empathy-contact-blocking-dialog test-empathy-presence-chooser test-empathy-status-preset-dialog test-empathy-protocol-chooser diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am index 258b86d45..d2f79f1f7 100644 --- a/tests/interactive/Makefile.am +++ b/tests/interactive/Makefile.am @@ -20,6 +20,7 @@ noinst_PROGRAMS = \ empathy-logs \ empetit \ test-empathy-account-assistant \ + test-empathy-contact-blocking-dialog \ test-empathy-presence-chooser \ test-empathy-status-preset-dialog \ test-empathy-protocol-chooser \ @@ -28,6 +29,7 @@ noinst_PROGRAMS = \ contact_manager_SOURCES = contact-manager.c empathy_logs_SOURCES = empathy-logs.c empetit_SOURCES = empetit.c +test_empathy_contact_blocking_dialog_SOURCES = test-empathy-contact-blocking-dialog.c test_empathy_presence_chooser_SOURCES = test-empathy-presence-chooser.c test_empathy_status_preset_dialog_SOURCES = test-empathy-status-preset-dialog.c test_empathy_protocol_chooser_SOURCES = test-empathy-protocol-chooser.c diff --git a/tests/interactive/test-empathy-contact-blocking-dialog.c b/tests/interactive/test-empathy-contact-blocking-dialog.c new file mode 100644 index 000000000..6c5615ec3 --- /dev/null +++ b/tests/interactive/test-empathy-contact-blocking-dialog.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk> + */ + +#include <config.h> + +#include <gtk/gtk.h> + +#include <libempathy/empathy-contact-manager.h> + +#include <libempathy-gtk/empathy-ui-utils.h> +#include <libempathy-gtk/empathy-contact-blocking-dialog.h> + +int +main (int argc, + char **argv) + { + EmpathyContactManager *manager; + GtkWidget *dialog; + + gtk_init (&argc, &argv); + empathy_gtk_init (); + + manager = empathy_contact_manager_dup_singleton (); + dialog = empathy_contact_blocking_dialog_new (NULL); + + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (gtk_main_quit), NULL); + + gtk_widget_show (dialog); + + gtk_main (); + + gtk_widget_destroy (dialog); + g_object_unref (manager); + + return 0; + } |