From 83e88245ea04ee0d66c98ce36bf4f7112cbd2f23 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 4 Feb 2011 17:47:31 +1100 Subject: Beginning of contact blocking dialog Can currently select an account and view the contact blocking 'deny' list. List reponds to changes in the group membership. Add/Remove buttons do not yet do anything. --- libempathy-gtk/Makefile.am | 3 + libempathy-gtk/empathy-contact-blocking-dialog.c | 514 ++++++++++++++++++++++ libempathy-gtk/empathy-contact-blocking-dialog.h | 60 +++ libempathy-gtk/empathy-contact-blocking-dialog.ui | 145 ++++++ 4 files changed, 722 insertions(+) create mode 100644 libempathy-gtk/empathy-contact-blocking-dialog.c create mode 100644 libempathy-gtk/empathy-contact-blocking-dialog.h create mode 100644 libempathy-gtk/empathy-contact-blocking-dialog.ui diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 47b416fa0..18f9a1cdc 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -39,6 +39,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 \ @@ -98,6 +99,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 \ @@ -177,6 +179,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-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c new file mode 100644 index 000000000..33dfb2e28 --- /dev/null +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -0,0 +1,514 @@ +/* + * 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 + */ + +#include + +#include + +#include +#include + +#include "empathy-contact-blocking-dialog.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include + +#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 +{ + GHashTable *channels; /* TpConnection* -> TpChannel* */ + GtkListStore *blocked_contacts; + + GtkWidget *account_chooser; +}; + +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_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); + + /* set the filter again to refilter the account list */ + empathy_account_chooser_set_filter ( + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser), + contact_blocking_dialog_filter_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_account_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; + + tp_proxy_prepare_async (account, NULL, + contact_blocking_dialog_account_prepared, self); + } + + g_list_free (accounts); +} + +static void +contact_blocking_dialog_account_prepared (GObject *account, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyContactBlockingDialog *self = user_data; + TpConnection *conn; + GError *error = NULL; + + if (!tp_proxy_prepare_finish (account, result, &error)) + { + DEBUG ("Could not prepare Account: %s", error->message); + g_error_free (error); + return; + } + + 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); + } +} + +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); + + /* set the filter again to refilter the account list */ + empathy_account_chooser_set_filter ( + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser), + contact_blocking_dialog_filter_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_account_changed (GtkWidget *account_chooser, + EmpathyContactBlockingDialog *self) +{ + TpConnection *conn = empathy_account_chooser_get_connection ( + EMPATHY_ACCOUNT_CHOOSER (account_chooser)); + TpChannel *channel; + GArray *blocked; + + if (conn == NULL) + return; + + DEBUG ("Account changed: %s", get_pretty_conn_name (conn)); + + /* FIXME: clear the completion, get the new blocked list */ + + /* clear the list of blocked contacts */ + gtk_list_store_clear (self->priv->blocked_contacts); + + /* load the deny list */ + channel = g_hash_table_lookup (self->priv->channels, conn); + + 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); +} + +static void +contact_blocking_dialog_dispose (GObject *self) +{ + EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self); + + tp_clear_pointer (&priv->channels, g_hash_table_destroy); +} + +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, *add_contact_entry; + 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-contact-entry", &add_contact_entry, + "blocked-contacts", &self->priv->blocked_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); + + /* add the account chooser */ + self->priv->account_chooser = empathy_account_chooser_new (); + empathy_account_chooser_set_filter ( + EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser), + contact_blocking_dialog_filter_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); + + /* build the contact entry */ + // FIXME + + /* prepare the account manager */ + am = tp_account_manager_dup (); + tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self); + + 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 + */ + +#ifndef __EMPATHY_CONTACT_BLOCKING_DIALOG_H__ +#define __EMPATHY_CONTACT_BLOCKING_DIALOG_H__ + +#include + +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..648850e13 --- /dev/null +++ b/libempathy-gtk/empathy-contact-blocking-dialog.ui @@ -0,0 +1,145 @@ + + + + + + True + 6 + 6 + + + True + 6 + + + True + 0 + Account: + + + False + 0 + + + + + + + + False + 0 + + + + + True + 6 + + + True + True + never + automatic + etched-in + + + True + True + blocked-contacts + False + + + Blocked Contacts + 0 + + + + 0 + + + + + + + + + 0 + + + + + True + start + + + gtk-remove + True + True + True + True + + + False + 0 + + + + + False + 1 + + + + + 1 + + + + + True + 6 + + + True + True + + + + 0 + + + + + gtk-add + True + True + True + True + + + False + 1 + + + + + False + 2 + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From a859b6a6a2f9dde93ef52b445266b5df3f50373a Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 4 Feb 2011 17:55:24 +1100 Subject: Test for contact blocking dialog --- tests/interactive/.gitignore | 1 + tests/interactive/Makefile.am | 2 + .../test-empathy-contact-blocking-dialog.c | 45 ++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/interactive/test-empathy-contact-blocking-dialog.c 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 24e674c6a..bf2e83929 100644 --- a/tests/interactive/Makefile.am +++ b/tests/interactive/Makefile.am @@ -18,6 +18,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 \ @@ -26,6 +27,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..b2038cbce --- /dev/null +++ b/tests/interactive/test-empathy-contact-blocking-dialog.c @@ -0,0 +1,45 @@ +/* + * 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 + */ + +#include + +#include + +#include +#include + +int +main (int argc, + char **argv) + { + GtkWidget *dialog; + + gtk_init (&argc, &argv); + empathy_gtk_init (); + + dialog = empathy_contact_blocking_dialog_new (NULL); + + gtk_widget_show (dialog); + + gtk_main (); + + return 0; + } -- cgit v1.2.3 From f6b306beda8ade7053786826eb470005b42fea36 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Sun, 6 Feb 2011 11:04:11 +1100 Subject: Connect ::response in test --- tests/interactive/test-empathy-contact-blocking-dialog.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/interactive/test-empathy-contact-blocking-dialog.c b/tests/interactive/test-empathy-contact-blocking-dialog.c index b2038cbce..11f199fb9 100644 --- a/tests/interactive/test-empathy-contact-blocking-dialog.c +++ b/tests/interactive/test-empathy-contact-blocking-dialog.c @@ -37,6 +37,9 @@ main (int argc, 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 (); -- cgit v1.2.3 From 290021178e77efb4324b4204d2ecf8124e60c65a Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Sun, 6 Feb 2011 12:13:43 +1100 Subject: Add and remove contacts from deny list --- libempathy-gtk/empathy-contact-blocking-dialog.c | 171 +++++++++++++++++++++- libempathy-gtk/empathy-contact-blocking-dialog.ui | 24 +-- 2 files changed, 183 insertions(+), 12 deletions(-) diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index 33dfb2e28..703ca8b89 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -45,8 +45,11 @@ struct _EmpathyContactBlockingDialogPrivate { GHashTable *channels; /* TpConnection* -> TpChannel* */ GtkListStore *blocked_contacts; + GtkTreeSelection *selection; GtkWidget *account_chooser; + GtkWidget *add_contact_entry; + GtkWidget *remove_button; }; enum /* blocked-contacts columns */ @@ -387,6 +390,142 @@ contact_blocking_dialog_deny_channel_prepared (GObject *channel, G_CALLBACK (contact_blocking_dialog_deny_channel_members_changed), self); } +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), ""); +} + +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); + /* FIXME: expose error to user */ + 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); + /* FIXME: expose error to user */ + 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); + /* FIXME: expose error to user */ + return; + } + + DEBUG ("Contacts removed"); +} + static void contact_blocking_dialog_account_changed (GtkWidget *account_chooser, EmpathyContactBlockingDialog *self) @@ -420,6 +559,19 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser, g_array_unref (blocked); } +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) { @@ -446,7 +598,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) GtkBuilder *gui; char *filename; GtkWidget *contents; - GtkWidget *account_hbox, *add_contact_entry; + GtkWidget *account_hbox, *blocked_contacts_view; TpAccountManager *am; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, @@ -466,8 +618,16 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) gui = empathy_builder_get_file (filename, "contents", &contents, "account-hbox", &account_hbox, - "add-contact-entry", &add_contact_entry, + "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 */ @@ -488,6 +648,13 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) TRUE, TRUE, 0); gtk_widget_show (self->priv->account_chooser); + /* 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 */ // FIXME diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.ui b/libempathy-gtk/empathy-contact-blocking-dialog.ui index 648850e13..b2ea89b81 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.ui +++ b/libempathy-gtk/empathy-contact-blocking-dialog.ui @@ -2,6 +2,14 @@ + + + + + + + + True 6 @@ -42,14 +50,16 @@ automatic etched-in - + True True blocked-contacts False + 0 Blocked Contacts + True 0 @@ -74,12 +84,14 @@ gtk-remove True + False True True True False + False 0 @@ -128,18 +140,10 @@ - - - - - - - - - + -- cgit v1.2.3 From fe902c25eaf5944bba218bddd1484e87a85d9905 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 7 Feb 2011 10:58:32 +1100 Subject: Provide autocompletion of known contacts in the entry box --- libempathy-gtk/empathy-contact-blocking-dialog.c | 52 +++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index 703ca8b89..5cb3d4e76 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -26,6 +26,9 @@ #include +#include +#include + #include #include @@ -45,6 +48,7 @@ struct _EmpathyContactBlockingDialogPrivate { GHashTable *channels; /* TpConnection* -> TpChannel* */ GtkListStore *blocked_contacts; + GtkListStore *completion_contacts; GtkTreeSelection *selection; GtkWidget *account_chooser; @@ -534,16 +538,18 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser, EMPATHY_ACCOUNT_CHOOSER (account_chooser)); TpChannel *channel; GArray *blocked; + EmpathyContactManager *contact_manager; + EmpathyTpContactList *contact_list; + GList *members, *ptr; if (conn == NULL) return; DEBUG ("Account changed: %s", get_pretty_conn_name (conn)); - /* FIXME: clear the completion, get the new blocked list */ - - /* clear the list of blocked contacts */ + /* clear the lists of contacts */ gtk_list_store_clear (self->priv->blocked_contacts); + gtk_list_store_clear (self->priv->completion_contacts); /* load the deny list */ channel = g_hash_table_lookup (self->priv->channels, conn); @@ -555,8 +561,32 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser, 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 @@ -578,6 +608,8 @@ 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 @@ -599,6 +631,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) char *filename; GtkWidget *contents; GtkWidget *account_hbox, *blocked_contacts_view; + GtkEntryCompletion *completion; TpAccountManager *am; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, @@ -656,11 +689,20 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) G_CALLBACK (contact_blocking_dialog_view_selection_changed), self); /* build the contact entry */ - // FIXME + 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); /* 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); -- cgit v1.2.3 From bf0586ea17afcd2ad04fefa24b8e74cd5e1f4b23 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 7 Feb 2011 10:59:14 +1100 Subject: Prepare EmpathyContactManager in test --- tests/interactive/test-empathy-contact-blocking-dialog.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/interactive/test-empathy-contact-blocking-dialog.c b/tests/interactive/test-empathy-contact-blocking-dialog.c index 11f199fb9..6c5615ec3 100644 --- a/tests/interactive/test-empathy-contact-blocking-dialog.c +++ b/tests/interactive/test-empathy-contact-blocking-dialog.c @@ -23,6 +23,8 @@ #include +#include + #include #include @@ -30,11 +32,13 @@ 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", @@ -44,5 +48,8 @@ main (int argc, gtk_main (); + gtk_widget_destroy (dialog); + g_object_unref (manager); + return 0; } -- cgit v1.2.3 From 65bf3f42d6699ce32edccab2412dabe195eac68d Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 7 Feb 2011 10:59:33 +1100 Subject: Add blocked contacts dialog to Empathy main window menu --- src/empathy-main-window.c | 17 ++++++++++++++++- src/empathy-main-window.ui | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 8e3f2d89b..8c7642581 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1460,6 +1461,18 @@ main_window_edit_personal_information_cb (GtkAction *action, empathy_contact_personal_dialog_show (GTK_WINDOW (window)); } +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) @@ -1619,7 +1632,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++) { @@ -1798,6 +1812,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, "edit_search_contacts", "activate", main_window_edit_search_contacts_cb, "help_about", "activate", main_window_help_about_cb, diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 3c015392d..b32878bdc 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -106,6 +106,12 @@ _Personal Information + + + edit_blocked_contacts + _Blocked Contacts + + gtk-preferences @@ -249,6 +255,7 @@ + -- cgit v1.2.3 From ac5479e2ab5b1291afd853892238b0eb22c6e345 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 8 Feb 2011 12:16:15 +1100 Subject: Don't need to prepare accounts separately --- libempathy-gtk/empathy-contact-blocking-dialog.c | 41 +++++++----------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index 5cb3d4e76..c378db3f6 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -223,7 +223,7 @@ contact_blocking_dialog_deny_channel_members_changed (TpChannel *channel, tp_intset_destroy (removed_set); } -DECLARE_CALLBACK (contact_blocking_dialog_account_prepared); +DECLARE_CALLBACK (contact_blocking_dialog_connection_prepared); static void contact_blocking_dialog_am_prepared (GObject *am, @@ -246,40 +246,21 @@ contact_blocking_dialog_am_prepared (GObject *am, for (ptr = accounts; ptr != NULL; ptr = ptr->next) { TpAccount *account = ptr->data; + TpConnection *conn; - tp_proxy_prepare_async (account, NULL, - contact_blocking_dialog_account_prepared, self); - } - - g_list_free (accounts); -} + g_signal_connect (account, "status-changed", + G_CALLBACK (contact_blocking_dialog_connection_status_changed), self); -static void -contact_blocking_dialog_account_prepared (GObject *account, - GAsyncResult *result, - gpointer user_data) -{ - EmpathyContactBlockingDialog *self = user_data; - TpConnection *conn; - GError *error = NULL; + conn = tp_account_get_connection (TP_ACCOUNT (account)); - if (!tp_proxy_prepare_finish (account, result, &error)) - { - DEBUG ("Could not prepare Account: %s", error->message); - g_error_free (error); - return; + if (conn != NULL) + { + tp_proxy_prepare_async (conn, NULL, + contact_blocking_dialog_connection_prepared, self); + } } - 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 *, -- cgit v1.2.3 From 67d602af3ed86c8df908dd8ad429bdb3f8ff5d5b Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 8 Feb 2011 13:53:11 +1100 Subject: Handle the case where there are no accounts with deny channels --- libempathy-gtk/empathy-contact-blocking-dialog.c | 88 +++++++++++++++++------- 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index c378db3f6..81fd4d99b 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -46,12 +46,17 @@ G_DEFINE_TYPE (EmpathyContactBlockingDialog, empathy_contact_blocking_dialog, struct _EmpathyContactBlockingDialogPrivate { - GHashTable *channels; /* TpConnection* -> TpChannel* */ + /* 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 *remove_button; }; @@ -86,6 +91,40 @@ contact_blocking_dialog_filter_account_chooser (TpAccount *account, 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 *); @@ -154,11 +193,7 @@ contact_blocking_dialog_connection_status_changed (TpAccount *account, /* remove the channel from the hash table */ g_hash_table_remove (self->priv->channels, conn); - - /* set the filter again to refilter the account list */ - empathy_account_chooser_set_filter ( - EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser), - contact_blocking_dialog_filter_account_chooser, self); + contact_blocking_dialog_refilter_account_chooser (self); break; case TP_CONNECTION_STATUS_CONNECTING: @@ -365,11 +400,7 @@ contact_blocking_dialog_deny_channel_prepared (GObject *channel, g_hash_table_insert (self->priv->channels, g_object_ref (conn), channel); - - /* set the filter again to refilter the account list */ - empathy_account_chooser_set_filter ( - EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser), - contact_blocking_dialog_filter_account_chooser, self); + contact_blocking_dialog_refilter_account_chooser (self); g_signal_connect (channel, "group-members-changed", G_CALLBACK (contact_blocking_dialog_deny_channel_members_changed), self); @@ -523,18 +554,24 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser, EmpathyTpContactList *contact_list; GList *members, *ptr; - if (conn == NULL) + if (self->priv->block_account_changed > 0) return; - DEBUG ("Account changed: %s", get_pretty_conn_name (conn)); - /* 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)); @@ -632,6 +669,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) 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, @@ -650,18 +688,6 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) contents); gtk_widget_show (contents); - /* add the account chooser */ - self->priv->account_chooser = empathy_account_chooser_new (); - empathy_account_chooser_set_filter ( - EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser), - contact_blocking_dialog_filter_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); - /* set up the tree selection */ self->priv->selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (blocked_contacts_view)); @@ -680,6 +706,16 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) 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); + /* prepare the account manager */ am = tp_account_manager_dup (); tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self); -- cgit v1.2.3 From 35500a8b9e672f703059707039a1ccee23dd3597 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 7 Feb 2011 13:41:40 +1100 Subject: Add contact blocking to EmpathyContactList and friends --- libempathy/empathy-contact-list.c | 23 +++++++++++++ libempathy/empathy-contact-list.h | 12 +++++++ libempathy/empathy-contact-manager.c | 41 +++++++++++++++++++++++ libempathy/empathy-tp-contact-list.c | 64 ++++++++++++++++++++++++++++++++---- libempathy/empathy-tp-contact-list.h | 1 + 5 files changed, 135 insertions(+), 6 deletions(-) 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..683974906 100644 --- a/libempathy/empathy-contact-list.h +++ b/libempathy/empathy-contact-list.h @@ -39,6 +39,7 @@ 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, } EmpathyContactListFlags; typedef struct _EmpathyContactListIface EmpathyContactListIface; @@ -77,6 +78,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 +122,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 @@ -864,6 +864,45 @@ contact_manager_remove_group (EmpathyContactList *manager, (gpointer) group); } +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) { @@ -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-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,9 +1304,45 @@ 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) { @@ -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 #include +#include G_BEGIN_DECLS -- cgit v1.2.3 From 4f3b2d373b9f22abdbf2679a8c87ec68c1ae1d20 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Wed, 9 Feb 2011 13:05:20 +1100 Subject: Add 'Block Contact' to empathy-contact-menu --- libempathy-gtk/empathy-chat.c | 3 +- libempathy-gtk/empathy-contact-menu.c | 71 +++++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-contact-menu.h | 3 +- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 72e906079..b696963ac 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -3590,7 +3590,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); } return menu; diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index 3bf415746..03e0db3aa 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) @@ -139,6 +141,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; } @@ -213,6 +228,62 @@ empathy_contact_add_menu_item_new (EmpathyContact *contact) return item; } +static void +empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item, + EmpathyContact *contact) +{ + EmpathyContactManager *manager; + gboolean blocked; + + manager = empathy_contact_manager_dup_singleton (); + blocked = gtk_check_menu_item_get_active (item); + + empathy_contact_list_set_blocked (EMPATHY_CONTACT_LIST (manager), + contact, blocked); + + g_object_unref (manager); +} + +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")); + /* FIXME: this doesn't always get updated immediately */ + 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 2e0247420..35d6479e6 100644 --- a/libempathy-gtk/empathy-contact-menu.h +++ b/libempathy-gtk/empathy-contact-menu.h @@ -37,7 +37,8 @@ typedef enum { EMPATHY_CONTACT_FEATURE_INFO = 1 << 4, EMPATHY_CONTACT_FEATURE_FAVOURITE = 1 << 5, EMPATHY_CONTACT_FEATURE_FT = 1 << 6, - EMPATHY_CONTACT_FEATURE_ALL = (1 << 7) - 1, + EMPATHY_CONTACT_FEATURE_BLOCK = 1 << 7, + EMPATHY_CONTACT_FEATURE_ALL = (1 << 8) - 1, } EmpathyContactFeatureFlags; GtkWidget * empathy_contact_menu_new (EmpathyContact *contact, -- cgit v1.2.3 From 6da159d09091d68a102c142b10747ae58755de51 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Wed, 9 Feb 2011 17:24:27 +1100 Subject: Add contact blocking support to EmpathyIndividualManager --- libempathy/empathy-individual-manager.c | 104 ++++++++++++++++++++++++++++++++ libempathy/empathy-individual-manager.h | 18 ++++++ 2 files changed, 122 insertions(+) diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index 894ae648b..a2432effe 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -30,6 +30,7 @@ #include #include +#include #include @@ -483,6 +484,77 @@ 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); + } +} + static void groups_change_group_cb (GObject *source, GAsyncResult *result, @@ -526,6 +598,38 @@ empathy_individual_manager_remove_group (EmpathyIndividualManager *manager, (gpointer) group); } +EmpathyIndividualManagerFlags +empathy_individual_manager_get_flags_for_connection ( + EmpathyIndividualManager *self, + TpConnection *connection) +{ + EmpathyIndividualManagerPriv *priv; + EmpathyContactListFlags list_flags; + EmpathyIndividualManagerFlags flags; + + g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), + EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS); + + priv = GET_PRIV (self); + + list_flags = empathy_contact_manager_get_flags_for_connection ( + priv->contact_manager, connection); + + flags = EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_ADD) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_REMOVE) + flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_REMOVE; + if (list_flags & EMPATHY_CONTACT_LIST_CAN_ALIAS) + 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; + + return flags; +} + static void link_personas_cb (FolksIndividualAggregator *aggregator, GAsyncResult *async_result, diff --git a/libempathy/empathy-individual-manager.h b/libempathy/empathy-individual-manager.h index f2f5f5b56..daa7ec86a 100644 --- a/libempathy/empathy-individual-manager.h +++ b/libempathy/empathy-individual-manager.h @@ -36,6 +36,16 @@ G_BEGIN_DECLS #define EMPATHY_IS_INDIVIDUAL_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_INDIVIDUAL_MANAGER)) #define EMPATHY_INDIVIDUAL_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_INDIVIDUAL_MANAGER, EmpathyIndividualManagerClass)) +typedef enum +{ + EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS = 0, + EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD = 1 << 0, + 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, +} EmpathyIndividualManagerFlags; + typedef struct _EmpathyIndividualManager EmpathyIndividualManager; typedef struct _EmpathyIndividualManagerClass EmpathyIndividualManagerClass; @@ -81,5 +91,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__ */ -- cgit v1.2.3 From 630a864d8ebac32fb7c11317308468ddbc535815 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Wed, 9 Feb 2011 17:29:18 +1100 Subject: Add 'Delete and Block' as an option to the Remove Contact dialog --- libempathy-gtk/empathy-individual-view.c | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c index 9be022139..4cb8a76f4 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -2269,16 +2269,22 @@ empathy_individual_view_dup_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); @@ -2290,7 +2296,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 @@ -2310,7 +2316,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 (); @@ -2389,10 +2395,13 @@ individual_view_remove_activate_cb (GtkMenuItem *menuitem, if (individual != NULL) { + EmpathyIndividualManager *manager; gchar *text; GtkWindow *parent; GList *l, *personas; guint persona_count = 0; + gboolean can_block; + int res; personas = folks_individual_get_personas (individual); @@ -2428,20 +2437,25 @@ individual_view_remove_activate_cb (GtkMenuItem *menuitem, folks_aliasable_get_alias (FOLKS_ALIASABLE (individual))); } + + manager = empathy_individual_manager_dup_singleton (); + can_block = empathy_individual_manager_supports_blocking (manager, + individual); parent = empathy_get_toplevel_window (GTK_WIDGET (view)); + res = individual_view_remove_dialog_show (parent, _("Removing contact"), + text, can_block); - if (individual_view_remove_dialog_show (parent, _("Removing contact"), - text)) + if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_REJECT) { - EmpathyIndividualManager *manager; - - manager = empathy_individual_manager_dup_singleton (); empathy_individual_manager_remove (manager, individual, ""); - g_object_unref (G_OBJECT (manager)); + + if (res == GTK_RESPONSE_REJECT) + empathy_individual_manager_set_blocked (manager, individual, TRUE); } g_free (text); g_object_unref (individual); + g_object_unref (manager); } } -- cgit v1.2.3 From 8e95ee8c1455390b18126d2280bcd218777379a8 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 10 Feb 2011 13:19:35 +1100 Subject: Add a confirmation dialog when you block a contact from the Contact menu --- libempathy-gtk/empathy-contact-menu.c | 43 ++++++++++++++++++++++++++++++++++- src/empathy-chat-window.c | 7 ++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index 03e0db3aa..e03444ac9 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -232,15 +232,57 @@ 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; + manager = empathy_contact_manager_dup_singleton (); blocked = gtk_check_menu_item_get_active (item); + if (blocked) { + /* confirm the user really wishes to block the contact */ + int res; + GtkWidget *parent, *dialog; + + /* 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"); + dialog = gtk_message_dialog_new (GTK_WINDOW (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); + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + if (res != GTK_RESPONSE_REJECT) + goto finally; + } + empathy_contact_list_set_blocked (EMPATHY_CONTACT_LIST (manager), contact, blocked); + /* update the toggle with the blocked status */ + block_signal++; + gtk_check_menu_item_set_active (item, blocked); + block_signal--; + +finally: g_object_unref (manager); } @@ -270,7 +312,6 @@ empathy_contact_block_menu_item_new (EmpathyContact *contact) } item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact")); - /* FIXME: this doesn't always get updated immediately */ blocked = empathy_contact_list_get_blocked ( EMPATHY_CONTACT_LIST (manager), contact); diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 799a8254d..73856adde 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -417,12 +417,15 @@ 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); + if (submenu != NULL) { gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu); gtk_widget_show (menu); gtk_widget_set_sensitive (menu, TRUE); - } - else { + } else { gtk_widget_set_sensitive (menu, FALSE); } } else { -- cgit v1.2.3 From 9968dc5978d6eb12ccc1f1cc76ca08fc0a739e85 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 10 Feb 2011 15:45:17 +1100 Subject: Add Block button to the subscription authorization dialog --- libempathy-gtk/empathy-contact-dialogs.c | 21 +++++++++++- libempathy-gtk/empathy-contact-dialogs.ui | 53 ++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index fb67c41cc..15f344bb8 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -79,9 +79,15 @@ subscription_dialog_response_cb (GtkDialog *dialog, empathy_contact_set_alias (contact, empathy_contact_widget_get_alias (contact_widget)); } - else if (response == GTK_RESPONSE_NO) { + else if (response == GTK_RESPONSE_NO || + response == GTK_RESPONSE_REJECT) { empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager), contact, ""); + + if (response == GTK_RESPONSE_REJECT) { + empathy_contact_list_set_blocked ( + EMPATHY_CONTACT_LIST (manager), contact, TRUE); + } } subscription_dialogs = g_list_remove (subscription_dialogs, dialog); @@ -99,8 +105,13 @@ empathy_subscription_dialog_show (EmpathyContact *contact, GtkWidget *hbox_subscription; GtkWidget *vbox; 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)); @@ -117,6 +128,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); @@ -161,10 +173,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); } diff --git a/libempathy-gtk/empathy-contact-dialogs.ui b/libempathy-gtk/empathy-contact-dialogs.ui index c18bfabb4..ecafddb69 100644 --- a/libempathy-gtk/empathy-contact-dialogs.ui +++ b/libempathy-gtk/empathy-contact-dialogs.ui @@ -1,13 +1,14 @@ - - + + + 5 Subscription Request subscription_request False - GTK_WIN_POS_CENTER_ON_PARENT - GDK_WINDOW_TYPE_HINT_DIALOG + center-on-parent + dialog True @@ -22,11 +23,12 @@ True 0 gtk-dialog-question - 6 + 6 False False + 0 @@ -40,50 +42,77 @@ True - GTK_BUTTONBOX_END + end + + + _Block User + True + True + True + + + False + False + 0 + + + Decide _Later True True True - Decide _Later + False True + + False + False + 1 + + gtk-no True True True - gtk-no + False True - 1 + False + False + 2 + gtk-yes True True True True - gtk-yes + False True - 2 + False + False + 3 False - GTK_PACK_END + end + 0 + block-user-button button19 button20 button21 -- cgit v1.2.3 From 1a2bbd7b2824e683c772b4784b98dcd531e91089 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 10 Feb 2011 15:56:02 +1100 Subject: Don't leak EmpathyContact --- libempathy/empathy-individual-manager.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index a2432effe..01eb51951 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -552,6 +552,8 @@ empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, empathy_contact_list_set_blocked ( EMPATHY_CONTACT_LIST (priv->contact_manager), contact, blocked); + + g_object_unref (contact); } } -- cgit v1.2.3 From 0c363023bd77f286bc6257db3f7d90aeb4e7b0f0 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 10 Feb 2011 16:23:58 +1100 Subject: contact-blocking-dialog: report errors to the user --- libempathy-gtk/empathy-contact-blocking-dialog.c | 55 ++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index 81fd4d99b..3d0b9afe9 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -58,6 +58,8 @@ struct _EmpathyContactBlockingDialogPrivate GtkWidget *account_chooser; GtkWidget *add_button; GtkWidget *add_contact_entry; + GtkWidget *info_bar; + GtkWidget *info_bar_label; GtkWidget *remove_button; }; @@ -406,6 +408,31 @@ contact_blocking_dialog_deny_channel_prepared (GObject *channel, 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 *); @@ -428,6 +455,7 @@ contact_blocking_dialog_add_contact (GtkWidget *widget, 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 @@ -447,7 +475,10 @@ contact_blocking_dialog_add_contact_got_handle (TpConnection *conn, if (in_error != NULL) { DEBUG ("Error getting handle: %s", in_error->message); - /* FIXME: expose error to user */ + + contact_blocking_dialog_set_error ( + EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error); + return; } @@ -470,7 +501,10 @@ contact_blocking_dialog_added_contact (TpChannel *channel, if (in_error != NULL) { DEBUG ("Error adding contact to deny list: %s", in_error->message); - /* FIXME: expose error to user */ + + contact_blocking_dialog_set_error ( + EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error); + return; } @@ -535,7 +569,10 @@ contact_blocking_dialog_removed_contacts (TpChannel *channel, if (in_error != NULL) { DEBUG ("Error removing contacts from deny list: %s", in_error->message); - /* FIXME: expose error to user */ + + contact_blocking_dialog_set_error ( + EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error); + return; } @@ -716,6 +753,18 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) 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); -- cgit v1.2.3 From 9cf8d924a615ead7f3e74644d0b9d39532645649 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Feb 2011 13:31:26 +1100 Subject: Factor out common blocking confirmation dialog --- libempathy-gtk/empathy-contact-dialogs.c | 43 ++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-contact-dialogs.h | 3 +++ libempathy-gtk/empathy-contact-menu.c | 33 ++++++------------------ 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 15f344bb8..11b608bef 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 + * Danielle Madeley */ #include @@ -487,3 +488,45 @@ 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) +{ + GtkWidget *dialog; + int res; + + 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); + + /* FIXME: support reporting abusive contacts */ + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + if (abusive != NULL) + *abusive = FALSE; + + return res == GTK_RESPONSE_REJECT; +} diff --git a/libempathy-gtk/empathy-contact-dialogs.h b/libempathy-gtk/empathy-contact-dialogs.h index 8c3ffc6c1..7dc1db10f 100644 --- a/libempathy-gtk/empathy-contact-dialogs.h +++ b/libempathy-gtk/empathy-contact-dialogs.h @@ -39,6 +39,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-menu.c b/libempathy-gtk/empathy-contact-menu.c index e03444ac9..64825b43c 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -239,51 +239,32 @@ empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item, if (block_signal > 0) return; - manager = empathy_contact_manager_dup_singleton (); blocked = gtk_check_menu_item_get_active (item); if (blocked) { /* confirm the user really wishes to block the contact */ - int res; - GtkWidget *parent, *dialog; + 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"); - dialog = gtk_message_dialog_new (GTK_WINDOW (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); - - res = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - if (res != GTK_RESPONSE_REJECT) - goto finally; + + 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--; - -finally: - g_object_unref (manager); } static GtkWidget * -- cgit v1.2.3 From 95283d6bffb0b907ec1741c6c685e7fe67d701a0 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Feb 2011 13:46:07 +1100 Subject: Add UI to blocking confirmation dialog for future "report as abusive" function --- libempathy-gtk/empathy-contact-dialogs.c | 33 +++++++++++++++++++++++++++++--- libempathy/empathy-contact-list.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 11b608bef..8408ed6ca 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -502,9 +502,16 @@ 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, @@ -520,13 +527,33 @@ empathy_block_contact_dialog_show (GtkWindow *parent, _("_Block"), GTK_RESPONSE_REJECT, NULL); - /* FIXME: support reporting abusive contacts */ + /* 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) - *abusive = FALSE; + 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/empathy-contact-list.h b/libempathy/empathy-contact-list.h index 683974906..8be93baf9 100644 --- a/libempathy/empathy-contact-list.h +++ b/libempathy/empathy-contact-list.h @@ -40,6 +40,7 @@ typedef enum { 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; -- cgit v1.2.3 From 1e15d1b253163c98064997aabe6b127acbecc64b Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Feb 2011 15:27:05 +1100 Subject: Add block confirmation to the authorise publication dialog --- libempathy-gtk/empathy-contact-dialogs.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 8408ed6ca..73a458cb9 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -80,19 +80,31 @@ subscription_dialog_response_cb (GtkDialog *dialog, empathy_contact_set_alias (contact, empathy_contact_widget_get_alias (contact_widget)); } - else if (response == GTK_RESPONSE_NO || - response == GTK_RESPONSE_REJECT) { + else if (response == GTK_RESPONSE_NO) { empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager), contact, ""); - - if (response == GTK_RESPONSE_REJECT) { + } + 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); + 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); } -- cgit v1.2.3 From 95bbacd1eda4500ef9cef0f998ebb485861a3a3d 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 ++++- libempathy/empathy-individual-manager.c | 2 + libempathy/empathy-individual-manager.h | 1 + 5 files changed, 112 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index 2c9801059..f7ca788c1 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -156,3 +157,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 4cb8a76f4..cea55a200 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" @@ -2447,12 +2448,21 @@ individual_view_remove_activate_cb (GtkMenuItem *menuitem, 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); diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index 01eb51951..fd74e4bbe 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -628,6 +628,8 @@ empathy_individual_manager_get_flags_for_connection ( 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 daa7ec86a..12f8ccdb0 100644 --- a/libempathy/empathy-individual-manager.h +++ b/libempathy/empathy-individual-manager.h @@ -44,6 +44,7 @@ typedef enum 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; -- cgit v1.2.3 From 3ff78cbfcfe5dd8cbda7263764d3a8d93995bc20 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Feb 2011 20:30:56 +1100 Subject: Style fixes from review --- libempathy-gtk/empathy-individual-dialogs.c | 4 +++- libempathy-gtk/empathy-individual-dialogs.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index f7ca788c1..75e69709a 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -38,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; /* @@ -202,7 +204,7 @@ empathy_block_individual_dialog_show (GtkWindow *parent, else if (flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_REPORT_ABUSIVE) can_report_abuse = TRUE; - g_string_append_printf (str, "\n \342\200\242 %s", + g_string_append_printf (str, "\n " BULLET_POINT " %s", tp_contact_get_identifier (contact)); npersonas++; } diff --git a/libempathy-gtk/empathy-individual-dialogs.h b/libempathy-gtk/empathy-individual-dialogs.h index f6c402014..1444d5ac8 100644 --- a/libempathy-gtk/empathy-individual-dialogs.h +++ b/libempathy-gtk/empathy-individual-dialogs.h @@ -33,7 +33,8 @@ 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); + FolksIndividual *individual, + gboolean *abusive); G_END_DECLS -- cgit v1.2.3 From 81ba0edc73b6a226a054b76539645b7b4e5e2a99 Mon Sep 17 00:00:00 2001 From: Chandni Verma Date: Tue, 8 Mar 2011 13:36:05 +0530 Subject: Use Contact Manager flags instead of Individual Manager flags --- libempathy-gtk/empathy-individual-dialogs.c | 17 +++++----- libempathy/empathy-individual-manager.c | 48 +++++++---------------------- libempathy/empathy-individual-manager.h | 11 ------- 3 files changed, 20 insertions(+), 56 deletions(-) diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index 75e69709a..1d3fcb8e2 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -33,6 +33,7 @@ #include #include +#include #include "empathy-individual-dialogs.h" #include "empathy-contact-widget.h" @@ -168,8 +169,8 @@ empathy_block_individual_dialog_show (GtkWindow *parent, FolksIndividual *individual, gboolean *abusive) { - EmpathyIndividualManager *manager = - empathy_individual_manager_dup_singleton (); + EmpathyContactManager *contact_manager = + empathy_contact_manager_dup_singleton (); GtkWidget *dialog; GtkWidget *abusive_check = NULL; GList *personas, *l; @@ -190,18 +191,18 @@ empathy_block_individual_dialog_show (GtkWindow *parent, { TpfPersona *persona = l->data; TpContact *contact; - EmpathyIndividualManagerFlags flags; + EmpathyContactListFlags 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)); + flags = empathy_contact_manager_get_flags_for_connection ( + contact_manager, tp_contact_get_connection (contact)); - if (!(flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK)) + if (!(flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)) continue; - else if (flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_REPORT_ABUSIVE) + else if (flags & EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE) can_report_abuse = TRUE; g_string_append_printf (str, "\n " BULLET_POINT " %s", @@ -235,7 +236,7 @@ empathy_block_individual_dialog_show (GtkWindow *parent, gtk_widget_show (abusive_check); } - g_object_unref (manager); + g_object_unref (contact_manager); g_string_free (str, TRUE); res = gtk_dialog_run (GTK_DIALOG (dialog)); diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index fd74e4bbe..71d15bb34 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -37,6 +37,7 @@ #include "empathy-individual-manager.h" #include "empathy-marshal.h" #include "empathy-utils.h" +#include "empathy-contact-manager.h" #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT #include "empathy-debug.h" @@ -510,15 +511,19 @@ empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self, { TpfPersona *persona = l->data; TpConnection *conn; + EmpathyContactManager *manager; if (!TPF_IS_PERSONA (persona)) continue; conn = tp_contact_get_connection (tpf_persona_get_contact (persona)); + manager = empathy_contact_manager_dup_singleton (); - if (empathy_individual_manager_get_flags_for_connection (self, conn) & - EMPATHY_INDIVIDUAL_MANAGER_CAN_BLOCK) + if (empathy_contact_manager_get_flags_for_connection (manager, conn) & + EMPATHY_CONTACT_LIST_CAN_BLOCK) return TRUE; + + g_object_unref (manager); } return FALSE; @@ -542,6 +547,7 @@ empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, { TpfPersona *persona = l->data; EmpathyContact *contact; + EmpathyContactManager *manager; if (!TPF_IS_PERSONA (persona)) continue; @@ -549,10 +555,12 @@ empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, contact = empathy_contact_dup_from_tp_contact ( tpf_persona_get_contact (persona)); empathy_contact_set_persona (contact, FOLKS_PERSONA (persona)); + manager = empathy_contact_manager_dup_singleton (); empathy_contact_list_set_blocked ( - EMPATHY_CONTACT_LIST (priv->contact_manager), + EMPATHY_CONTACT_LIST (manager), contact, blocked); + g_object_unref (manager); g_object_unref (contact); } } @@ -600,40 +608,6 @@ empathy_individual_manager_remove_group (EmpathyIndividualManager *manager, (gpointer) group); } -EmpathyIndividualManagerFlags -empathy_individual_manager_get_flags_for_connection ( - EmpathyIndividualManager *self, - TpConnection *connection) -{ - EmpathyIndividualManagerPriv *priv; - EmpathyContactListFlags list_flags; - EmpathyIndividualManagerFlags flags; - - g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), - EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS); - - priv = GET_PRIV (self); - - list_flags = empathy_contact_manager_get_flags_for_connection ( - priv->contact_manager, connection); - - flags = EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS; - if (list_flags & EMPATHY_CONTACT_LIST_CAN_ADD) - flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD; - if (list_flags & EMPATHY_CONTACT_LIST_CAN_REMOVE) - flags |= EMPATHY_INDIVIDUAL_MANAGER_CAN_REMOVE; - if (list_flags & EMPATHY_CONTACT_LIST_CAN_ALIAS) - 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; -} - static void link_personas_cb (FolksIndividualAggregator *aggregator, GAsyncResult *async_result, diff --git a/libempathy/empathy-individual-manager.h b/libempathy/empathy-individual-manager.h index 12f8ccdb0..75411b49c 100644 --- a/libempathy/empathy-individual-manager.h +++ b/libempathy/empathy-individual-manager.h @@ -36,17 +36,6 @@ G_BEGIN_DECLS #define EMPATHY_IS_INDIVIDUAL_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_INDIVIDUAL_MANAGER)) #define EMPATHY_INDIVIDUAL_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_INDIVIDUAL_MANAGER, EmpathyIndividualManagerClass)) -typedef enum -{ - EMPATHY_INDIVIDUAL_MANAGER_NO_FLAGS = 0, - EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD = 1 << 0, - 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; typedef struct _EmpathyIndividualManagerClass EmpathyIndividualManagerClass; -- cgit v1.2.3 From dfbccc45923082027415c3c76322febf470c5901 Mon Sep 17 00:00:00 2001 From: Chandni Verma Date: Fri, 11 Mar 2011 07:50:51 +0530 Subject: Setting "window" data on submenu only if it's not NULL --- src/empathy-chat-window.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 73856adde..23c93a15b 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -418,10 +418,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); - if (submenu != NULL) { + /* 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); gtk_widget_set_sensitive (menu, TRUE); -- cgit v1.2.3 From 0a9fd8a0a7517f099ca1b908679ab7935513cd9a Mon Sep 17 00:00:00 2001 From: Chandni Verma Date: Fri, 11 Mar 2011 07:53:15 +0530 Subject: Initialize EmpathyContactManager before creating a new contact->Block menuitem --- libempathy-gtk/empathy-contact-menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index 64825b43c..7f3091a9b 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -278,11 +278,12 @@ empathy_contact_block_menu_item_new (EmpathyContact *contact) g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + manager = empathy_contact_manager_dup_singleton (); + 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, -- cgit v1.2.3 From 103b4d5da19bf7ebf648658b8ff0ccab88aa24bd Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 14 Feb 2011 12:00:56 +1100 Subject: Hook up abusive argument into TpContactList backend --- libempathy-gtk/empathy-contact-dialogs.c | 6 ++++-- libempathy-gtk/empathy-contact-menu.c | 6 +++--- libempathy-gtk/empathy-individual-view.c | 7 +++++-- libempathy/empathy-contact-list.c | 5 +++-- libempathy/empathy-contact-list.h | 6 ++++-- libempathy/empathy-contact-manager.c | 6 ++++-- libempathy/empathy-individual-manager.c | 5 +++-- libempathy/empathy-individual-manager.h | 3 ++- libempathy/empathy-tp-contact-list.c | 3 ++- 9 files changed, 30 insertions(+), 17 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 73a458cb9..737a449d2 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -85,15 +85,17 @@ subscription_dialog_response_cb (GtkDialog *dialog, contact, ""); } else if (response == GTK_RESPONSE_REJECT) { + gboolean abusive; + /* confirm the blocking */ if (empathy_block_contact_dialog_show (GTK_WINDOW (dialog), - contact, NULL)) { + contact, &abusive)) { empathy_contact_list_remove ( EMPATHY_CONTACT_LIST (manager), contact, ""); empathy_contact_list_set_blocked ( EMPATHY_CONTACT_LIST (manager), - contact, TRUE); + contact, TRUE, abusive); } else { /* if they don't confirm, return back to the * first dialog */ diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index 7f3091a9b..9f36cf552 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -234,7 +234,7 @@ empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item, { static guint block_signal = 0; EmpathyContactManager *manager; - gboolean blocked; + gboolean blocked, abusive; if (block_signal > 0) return; @@ -252,13 +252,13 @@ empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item, "window"); if (!empathy_block_contact_dialog_show (GTK_WINDOW (parent), - contact, NULL)) + contact, &abusive)) return; } manager = empathy_contact_manager_dup_singleton (); empathy_contact_list_set_blocked (EMPATHY_CONTACT_LIST (manager), - contact, blocked); + contact, blocked, abusive); g_object_unref (manager); /* update the toggle with the blocked status */ diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c index cea55a200..172b1facd 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -2448,11 +2448,14 @@ individual_view_remove_activate_cb (GtkMenuItem *menuitem, if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_REJECT) { + gboolean abusive; + if (res == GTK_RESPONSE_REJECT && - empathy_block_individual_dialog_show (parent, individual, NULL)) + empathy_block_individual_dialog_show (parent, individual, + &abusive)) { empathy_individual_manager_set_blocked (manager, individual, - TRUE); + TRUE, abusive); } else { diff --git a/libempathy/empathy-contact-list.c b/libempathy/empathy-contact-list.c index d8af8938f..d28866735 100644 --- a/libempathy/empathy-contact-list.c +++ b/libempathy/empathy-contact-list.c @@ -282,12 +282,13 @@ empathy_contact_list_remove_from_favourites (EmpathyContactList *list, void empathy_contact_list_set_blocked (EmpathyContactList *list, EmpathyContact *contact, - gboolean blocked) + gboolean blocked, + gboolean abusive) { EmpathyContactListIface *iface = EMPATHY_CONTACT_LIST_GET_IFACE (list); if (iface->set_blocked != NULL) - iface->set_blocked (list, contact, blocked); + iface->set_blocked (list, contact, blocked, abusive); } gboolean diff --git a/libempathy/empathy-contact-list.h b/libempathy/empathy-contact-list.h index 8be93baf9..cf523bf2a 100644 --- a/libempathy/empathy-contact-list.h +++ b/libempathy/empathy-contact-list.h @@ -81,7 +81,8 @@ struct _EmpathyContactListIface { EmpathyContact *contact); void (*set_blocked) (EmpathyContactList *list, EmpathyContact *contact, - gboolean blocked); + gboolean blocked, + gboolean abusive); gboolean (*get_blocked) (EmpathyContactList *list, EmpathyContact *contact); }; @@ -125,7 +126,8 @@ void empathy_contact_list_remove_from_favourites void empathy_contact_list_set_blocked (EmpathyContactList *list, EmpathyContact *contact, - gboolean blocked); + gboolean blocked, + gboolean abusive); gboolean empathy_contact_list_get_blocked (EmpathyContactList *list, EmpathyContact *contact); diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c index 2242159b5..b00f82477 100644 --- a/libempathy/empathy-contact-manager.c +++ b/libempathy/empathy-contact-manager.c @@ -867,7 +867,8 @@ contact_manager_remove_group (EmpathyContactList *manager, static void contact_manager_set_blocked (EmpathyContactList *manager, EmpathyContact *contact, - gboolean blocked) + gboolean blocked, + gboolean abusive) { EmpathyContactManagerPriv *priv = GET_PRIV (manager); EmpathyContactList *list; @@ -879,7 +880,8 @@ contact_manager_set_blocked (EmpathyContactList *manager, list = g_hash_table_lookup (priv->lists, connection); if (list != NULL) { - empathy_contact_list_set_blocked (list, contact, blocked); + empathy_contact_list_set_blocked (list, contact, + blocked, abusive); } } diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index 71d15bb34..d56570c92 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -532,7 +532,8 @@ empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self, void empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, FolksIndividual *individual, - gboolean blocked) + gboolean blocked, + gboolean abusive) { EmpathyIndividualManagerPriv *priv; GList *personas, *l; @@ -558,7 +559,7 @@ empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, manager = empathy_contact_manager_dup_singleton (); empathy_contact_list_set_blocked ( EMPATHY_CONTACT_LIST (manager), - contact, blocked); + contact, blocked, abusive); g_object_unref (manager); g_object_unref (contact); diff --git a/libempathy/empathy-individual-manager.h b/libempathy/empathy-individual-manager.h index 75411b49c..1fec67d91 100644 --- a/libempathy/empathy-individual-manager.h +++ b/libempathy/empathy-individual-manager.h @@ -87,7 +87,8 @@ gboolean empathy_individual_manager_supports_blocking ( void empathy_individual_manager_set_blocked (EmpathyIndividualManager *self, FolksIndividual *individual, - gboolean blocked); + gboolean blocked, + gboolean abusive); 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 ec4f17245..9b3383d9f 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -1313,7 +1313,8 @@ tp_contact_list_get_flags (EmpathyContactList *list) static void tp_contact_list_set_blocked (EmpathyContactList *list, EmpathyContact *contact, - gboolean blocked) + gboolean blocked, + gboolean abusive) { EmpathyTpContactListPriv *priv = GET_PRIV (list); TpHandle handle = empathy_contact_get_handle (contact); -- cgit v1.2.3 From 428ac8930ef8cf312523a4d8b24eeda26729c4b3 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 14 Feb 2011 12:10:35 +1100 Subject: Add draft Conn.I.ContactBlocking (danni's version) to extensions --- .../Connection_Interface_Contact_Blocking.xml | 172 +++++++++++++++++++++ extensions/Makefile.am | 1 + extensions/misc.xml | 1 + 3 files changed, 174 insertions(+) create mode 100644 extensions/Connection_Interface_Contact_Blocking.xml diff --git a/extensions/Connection_Interface_Contact_Blocking.xml b/extensions/Connection_Interface_Contact_Blocking.xml new file mode 100644 index 000000000..543d43a5c --- /dev/null +++ b/extensions/Connection_Interface_Contact_Blocking.xml @@ -0,0 +1,172 @@ + + + Copyright © 2009-2010 Collabora Ltd. + Copyright © 2009 Nokia Corporation + +

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 Street, Fifth Floor, Boston, MA 02110-1301, + USA.

+
+ + + + +

An interface for connections where contacts can be blocked from + communicating with this user and receiving this user's presence.

+ +

When this interface becomes stable, it will replace the ContactList channel with TargetHandleType + Handle_Type_List and TargetID 'deny'.

+
+ + + +

Direct the server to block some contacts. The precise effect is + protocol-dependent, but SHOULD include ignoring all current and + subsequent communications from the given contacts, avoiding sending + presence to them in future, and if they were already receiving the + local user's presence, behaving as if the local user went + offline.

+ +

FIXME: do we need to allow this on protocols where it won't + persist, or where we can't edit the block lists?

+
+ + + Some contacts to block. + + + + +

In addition to blocking, report these contacts as abusive to the + server administrators.

+ +

Clients can determine whether this capability is available by + checking the + ContactBlockingCapabilities + property. If the capability is not present and this argument is + true, the error NotCapable SHOULD + be raised.

+ + + Some protocol libraries, in their conformance requirements, + require the ability to report blocked contacts as abusive. + +
+
+ + + + + + + +
+ + + +

Reverse the effects of a previous call to + BlockContacts.

+
+ + + Some contacts to unblock. + + + + + + + +
+ + + +

List the contacts that are blocked.

+ +

Clients SHOULD allow a relatively long timeout for calls to this + method, since on some protocols contact blocking is part of the + contact list, which can take a significant time to retrieve.

+
+ + + The list of blocked contacts. + + + + + + + +
+ + + +

Emitted when the list of blocked contacts is first retrieved + (before returning from any pending calls to + RequestBlockedContacts), and + whenever the list of blocked contacts subsequently changes.

+
+ + + Contacts added to the result of + RequestBlockedContacts. + + + + Contacts removed from the result of + RequestBlockedContacts. + +
+ + + +

True if the contact would be in the result of + RequestBlockedContacts; + False or omitted if the contact is not blocked, or if it is + unknown whether the contact is blocked.

+
+
+ + + +

Additional capabilities for contact blocking (i.e. whether we can + report abusive contacts).

+ +

Note: there is no capability for supporting blocking itself, + the presence of this interface indicates that contact blocking is + supported.

+
+
+ + + + + This protocol is capable of reporting abusive contacts to the server + administrators. + + + + +
+
+ diff --git a/extensions/Makefile.am b/extensions/Makefile.am index d0f104821..b3147f301 100644 --- a/extensions/Makefile.am +++ b/extensions/Makefile.am @@ -18,6 +18,7 @@ EXTRA_DIST = \ Authentication_TLS_Certificate.xml \ Channel_Interface_Credentials_Storage.xml \ Channel_Type_Server_TLS_Connection.xml \ + Connection_Interface_Contact_Blocking.xml \ $(NULL) noinst_LTLIBRARIES = libemp-extensions.la diff --git a/extensions/misc.xml b/extensions/misc.xml index b1f6e88eb..9b153f11a 100644 --- a/extensions/misc.xml +++ b/extensions/misc.xml @@ -10,5 +10,6 @@ + -- cgit v1.2.3 From 80d502ca384aaf07e2b572da7414d7ff36e91936 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 14 Feb 2011 12:24:58 +1100 Subject: Determine whether a connection supports reporting abuse, set the connection flag --- libempathy/empathy-tp-contact-list.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index 9b3383d9f..028744285 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -31,6 +31,8 @@ #include #include +#include + #include "empathy-tp-contact-list.h" #include "empathy-tp-contact-factory.h" #include "empathy-contact-list.h" @@ -808,6 +810,27 @@ list_ensure_channel_cb (TpConnection *conn, g_object_unref (channel); } +static void +list_get_contact_blocking_capabilities_cb (TpProxy *conn, + const GValue *value, + const GError *in_error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyTpContactList *list = EMPATHY_TP_CONTACT_LIST (weak_object); + EmpathyTpContactListPriv *priv = GET_PRIV (list); + EmpContactBlockingCapabilities caps; + + g_return_if_fail (G_VALUE_HOLDS_UINT (value)); + + caps = g_value_get_uint (value); + + if (caps & EMP_CONTACT_BLOCKING_CAPABILITY_CAN_REPORT_ABUSIVE) { + DEBUG ("Connection can report abusive contacts"); + priv->flags |= EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE; + } +} + static void iterate_on_channels (EmpathyTpContactList *list, const GPtrArray *channels) @@ -922,6 +945,19 @@ conn_ready_cb (TpConnection *connection, G_MAXINT, request, list_ensure_channel_cb, list, NULL, G_OBJECT (list)); g_hash_table_unref (request); + + /* Find out if we support reporting abusive contacts -- + * this is done via the new Conn.I.ContactBlocking interface */ + if (tp_proxy_has_interface_by_id (priv->connection, + EMP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)) { + DEBUG ("Have Conn.I.ContactBlocking"); + + tp_cli_dbus_properties_call_get (priv->connection, -1, + EMP_IFACE_CONNECTION_INTERFACE_CONTACT_BLOCKING, + "ContactBlockingCapabilities", + list_get_contact_blocking_capabilities_cb, + NULL, NULL, G_OBJECT (list)); + } out: g_object_unref (list); } -- cgit v1.2.3 From 4b7d2787c3d4487647628109e14a6618e3db8da8 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 14 Feb 2011 12:36:22 +1100 Subject: Only destroy block confirmation dialogs after we've read out the abusive state --- libempathy-gtk/empathy-contact-dialogs.c | 3 +-- libempathy-gtk/empathy-individual-dialogs.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 737a449d2..06481cf7d 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -556,8 +556,6 @@ empathy_block_contact_dialog_show (GtkWindow *parent, } res = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - if (abusive != NULL) { if (abusive_check != NULL) { *abusive = gtk_toggle_button_get_active ( @@ -567,6 +565,7 @@ empathy_block_contact_dialog_show (GtkWindow *parent, } } + gtk_widget_destroy (dialog); g_object_unref (manager); return res == GTK_RESPONSE_REJECT; diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index 1d3fcb8e2..e141182ba 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -240,7 +240,6 @@ empathy_block_individual_dialog_show (GtkWindow *parent, g_string_free (str, TRUE); res = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); if (abusive != NULL) { @@ -251,5 +250,7 @@ empathy_block_individual_dialog_show (GtkWindow *parent, *abusive = FALSE; } + gtk_widget_destroy (dialog); + return res == GTK_RESPONSE_REJECT; } -- cgit v1.2.3 From 5690460d1809f6e181c3eeed2aa930af1253b38c Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 14 Feb 2011 12:44:34 +1100 Subject: Use Conn.I.CB to report contacts as abusive when blocking them --- libempathy/empathy-tp-contact-list.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index 028744285..90932a20a 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -1358,14 +1358,23 @@ tp_contact_list_set_blocked (EmpathyContactList *list, g_return_if_fail (TP_IS_CHANNEL (priv->deny)); - if (blocked) + if (blocked && abusive) { + /* we have to do this via the new interface */ + g_return_if_fail (priv->flags & + EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE); + + emp_cli_connection_interface_contact_blocking_call_block_contacts ( + TP_PROXY (priv->connection), -1, + &handles, TRUE, NULL, NULL, NULL, NULL); + } else if (blocked) { tp_cli_channel_interface_group_call_add_members ( priv->deny, -1, &handles, NULL, NULL, NULL, NULL, NULL); - else + } else { tp_cli_channel_interface_group_call_remove_members ( priv->deny, -1, &handles, NULL, NULL, NULL, NULL, NULL); + } } static gboolean -- cgit v1.2.3 From 0deb4db1b785bfe4497de50cf04efdd873f58009 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 15 Feb 2011 08:19:46 +1100 Subject: Use tp_g_signal_connect_object for Tp proxies that outlive the CB dialog --- libempathy-gtk/empathy-contact-blocking-dialog.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index 3d0b9afe9..a46820c5d 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -285,8 +285,9 @@ contact_blocking_dialog_am_prepared (GObject *am, TpAccount *account = ptr->data; TpConnection *conn; - g_signal_connect (account, "status-changed", - G_CALLBACK (contact_blocking_dialog_connection_status_changed), self); + tp_g_signal_connect_object (account, "status-changed", + G_CALLBACK (contact_blocking_dialog_connection_status_changed), + self, 0); conn = tp_account_get_connection (TP_ACCOUNT (account)); @@ -404,8 +405,9 @@ contact_blocking_dialog_deny_channel_prepared (GObject *channel, 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); + tp_g_signal_connect_object (channel, "group-members-changed", + G_CALLBACK (contact_blocking_dialog_deny_channel_members_changed), + self, 0); } static void -- cgit v1.2.3 From 0b2f92fa593370c799cc16b8cecf575cf3e5b130 Mon Sep 17 00:00:00 2001 From: Chandni Verma Date: Fri, 11 Mar 2011 12:27:23 +0530 Subject: Add FIXME to empathy_individual_manager_supports_blocking() The parameter @self is not required and the method can be placed in utility. I left it as it is to stay coherent with empathy-2.34 and attached a FIXME to be fixed after empathy 2.x is done. --- libempathy/empathy-individual-manager.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index d56570c92..137d00f1f 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -485,6 +485,8 @@ empathy_individual_manager_remove (EmpathyIndividualManager *self, aggregator_remove_individual_cb, self); } +/* FIXME: The parameter @self is not required and the method can be placed in + * utilities. I left it as it is to stay coherent with empathy-2.34 */ /** * empathy_individual_manager_supports_blocking * @self: the #EmpathyIndividualManager -- cgit v1.2.3 From 355a558cfa919b1fa91f7c430c738b6d762239fb Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Mar 2011 11:08:06 +1100 Subject: Update the wording of the contact blocking dialog Include the list of personas which will not be blocked. --- libempathy-gtk/empathy-individual-dialogs.c | 71 +++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c index e141182ba..67ec22164 100644 --- a/libempathy-gtk/empathy-individual-dialogs.c +++ b/libempathy-gtk/empathy-individual-dialogs.c @@ -161,6 +161,18 @@ empathy_new_individual_dialog_show_with_individual (GtkWindow *parent, 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 */ @@ -174,8 +186,10 @@ empathy_block_individual_dialog_show (GtkWindow *parent, GtkWidget *dialog; GtkWidget *abusive_check = NULL; GList *personas, *l; - GString *str = g_string_new (""); - guint npersonas = 0; + 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; @@ -192,6 +206,8 @@ empathy_block_individual_dialog_show (GtkWindow *parent, TpfPersona *persona = l->data; TpContact *contact; EmpathyContactListFlags flags; + GString *s; + char *str; if (!TPF_IS_PERSONA (persona)) continue; @@ -200,22 +216,45 @@ empathy_block_individual_dialog_show (GtkWindow *parent, flags = empathy_contact_manager_get_flags_for_connection ( contact_manager, tp_contact_get_connection (contact)); - if (!(flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)) - continue; - else if (flags & EMPATHY_CONTACT_LIST_CAN_REPORT_ABUSIVE) + 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; - g_string_append_printf (str, "\n " BULLET_POINT " %s", - tp_contact_get_identifier (contact)); - npersonas++; + str = contact_pretty_name (contact); + g_string_append_printf (s, "\n " BULLET_POINT " %s", str); + g_free (str); } + g_string_append_printf (text, + _("Are you sure you want to block '%s' from contacting you again?"), + folks_aliasable_get_alias (FOLKS_ALIASABLE (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\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); + "%s", text->str); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, @@ -230,14 +269,16 @@ empathy_block_individual_dialog_show (GtkWindow *parent, abusive_check = gtk_check_button_new_with_mnemonic ( ngettext ("_Report this contact as abusive", "_Report these contacts as abusive", - npersonas)); + 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 (str, TRUE); + g_string_free (text, TRUE); + g_string_free (blocked_str, TRUE); + g_string_free (notblocked_str, TRUE); res = gtk_dialog_run (GTK_DIALOG (dialog)); -- cgit v1.2.3 From c0eca0414ca529da3b083c099ec3031436420b00 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 11 Mar 2011 12:05:24 +1100 Subject: Update the wording of the other contact blocking dialog --- libempathy-gtk/empathy-contact-dialogs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 06481cf7d..d16062eff 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -530,12 +530,13 @@ empathy_block_contact_dialog_show (GtkWindow *parent, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Block %s?"), - empathy_contact_get_id (contact)); + empathy_contact_get_alias (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)); + _("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, -- cgit v1.2.3