*
* Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
*/
+#include "config.h"
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
#include <libempathy/empathy-utils.h>
enum /* blocked-contacts columns */
{
- COL_IDENTIFIER,
- COL_HANDLE,
- N_COLUMNS
+ COL_BLOCKED_IDENTIFIER,
+ COL_BLOCKED_HANDLE,
+ N_BLOCKED_COLUMNS
+};
+
+enum /* completion_contacts columns */
+{
+ COL_COMPLETION_IDENTIFIER,
+ COL_COMPLETION_TEXT,
+ N_COMPLETION_COLUMNS
};
static const char *
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,
+ COL_BLOCKED_IDENTIFIER, identifier,
+ COL_BLOCKED_HANDLE, handle,
-1);
}
}
EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser)))))
return;
- DEBUG ("deny list changed: %u added, %u removed", added->len, removed->len);
+ DEBUG ("deny list changed on %s: %u added, %u removed",
+ get_pretty_conn_name (conn), added->len, removed->len);
/* add contacts */
contact_blocking_dialog_add_contacts_to_list (self, conn, added);
TpHandle handle;
gtk_tree_model_get (model, &iter,
- COL_HANDLE, &handle,
+ COL_BLOCKED_HANDLE, &handle,
-1);
if (tp_intset_is_member (removed_set, handle))
if (!tp_proxy_prepare_finish (conn, result, &error))
{
- DEBUG ("Failed to prepare connection: %s", error->message);
+ DEBUG ("Failed to prepare connection %s: %s",
+ get_pretty_conn_name ((TpConnection *) conn), error->message);
g_error_free (error);
return;
}
if (in_error != NULL)
{
- DEBUG ("Failed to get 'deny' channel: %s", in_error->message);
+ DEBUG ("Failed to get 'deny' channel on %s: %s",
+ get_pretty_conn_name (conn), in_error->message);
return;
}
if (error != NULL)
{
- DEBUG ("Failed to create channel proxy: %s", error->message);
+ DEBUG ("Failed to create channel proxy on %s: %s",
+ get_pretty_conn_name (conn), in_error->message);
g_error_free (error);
return;
}
if (!tp_proxy_prepare_finish (channel, result, &error))
{
- DEBUG ("Failed to prepare channel: %s", error->message);
+ DEBUG ("Failed to prepare channel %s: %s",
+ tp_proxy_get_object_path (channel), 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));
+ DEBUG ("Channel %s prepared for connection %s",
+ tp_proxy_get_object_path (channel), get_pretty_conn_name (conn));
g_hash_table_insert (self->priv->channels,
g_object_ref (conn), channel);
identifiers[0] = gtk_entry_get_text (
GTK_ENTRY (self->priv->add_contact_entry));
- DEBUG ("Looking up handle for '%s'", identifiers[0]);
+ DEBUG ("Looking up handle for '%s' on %s",
+ identifiers[0], get_pretty_conn_name (conn));
tp_cli_connection_call_request_handles (conn, -1,
TP_HANDLE_TYPE_CONTACT, identifiers,
if (in_error != NULL)
{
- DEBUG ("Error getting handle: %s", in_error->message);
+ DEBUG ("Error getting handle on %s: %s",
+ get_pretty_conn_name (conn), in_error->message);
contact_blocking_dialog_set_error (
EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
g_return_if_fail (handles->len == 1);
- DEBUG ("Adding handle %u to deny channel",
- g_array_index (handles, TpHandle, 0));
+ DEBUG ("Adding handle %u to deny channel on %s",
+ g_array_index (handles, TpHandle, 0), get_pretty_conn_name (conn));
tp_cli_channel_interface_group_call_add_members (channel, -1,
handles, "",
{
if (in_error != NULL)
{
- DEBUG ("Error adding contact to deny list: %s", in_error->message);
+ DEBUG ("Error adding contact to deny list %s: %s",
+ tp_proxy_get_object_path (channel), in_error->message);
contact_blocking_dialog_set_error (
EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
return;
}
- DEBUG ("Contact added");
+ DEBUG ("Contact added to %s", tp_proxy_get_object_path (channel));
}
static void
continue;
gtk_tree_model_get (model, &iter,
- COL_HANDLE, &handle,
+ COL_BLOCKED_HANDLE, &handle,
-1);
g_array_append_val (handles, handle);
for (ptr = members; ptr != NULL; ptr = ptr->next)
{
EmpathyContact *contact = ptr->data;
+ gchar *tmpstr;
+
+ tmpstr = g_strdup_printf ("%s (%s)",
+ empathy_contact_get_alias (contact),
+ empathy_contact_get_id (contact));
gtk_list_store_insert_with_values (self->priv->completion_contacts,
NULL, -1,
- COL_IDENTIFIER, empathy_contact_get_id (contact),
+ COL_COMPLETION_IDENTIFIER, empathy_contact_get_id (contact),
+ COL_COMPLETION_TEXT, tmpstr,
-1);
+ g_free (tmpstr);
g_object_unref (contact);
}
g_list_free (rows);
}
+static gboolean
+contact_selector_dialog_match_func (GtkEntryCompletion *completion,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ GtkTreeModel *model;
+ gchar *str, *lower;
+ gboolean v = FALSE;
+
+ model = gtk_entry_completion_get_model (completion);
+ if (model == NULL || iter == NULL)
+ return FALSE;
+
+ gtk_tree_model_get (model, iter, COL_COMPLETION_TEXT, &str, -1);
+ lower = g_utf8_strdown (str, -1);
+ if (strstr (lower, key))
+ {
+ DEBUG ("Key %s is matching name **%s**", key, str);
+ v = TRUE;
+ goto out;
+ }
+ g_free (str);
+ g_free (lower);
+
+ gtk_tree_model_get (model, iter, COL_COMPLETION_IDENTIFIER, &str, -1);
+ lower = g_utf8_strdown (str, -1);
+ if (strstr (lower, key))
+ {
+ DEBUG ("Key %s is matching ID **%s**", key, str);
+ v = TRUE;
+ goto out;
+ }
+
+out:
+ g_free (str);
+ g_free (lower);
+
+ return v;
+}
+
+static gboolean
+contact_selector_dialog_match_selected_cb (GtkEntryCompletion *widget,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ EmpathyContactBlockingDialog *self)
+{
+ gchar *id;
+
+ if (iter == NULL || model == NULL)
+ return FALSE;
+
+ gtk_tree_model_get (model, iter, COL_COMPLETION_IDENTIFIER, &id, -1);
+ gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), id);
+
+ DEBUG ("Got selected match **%s**", id);
+
+ g_free (id);
+
+ return TRUE;
+}
+
static void
contact_blocking_dialog_dispose (GObject *self)
{
GtkBuilder *gui;
char *filename;
GtkWidget *contents;
- GtkWidget *account_hbox, *blocked_contacts_view;
+ GtkWidget *account_hbox, *blocked_contacts_view, *blocked_contacts_sw,
+ *remove_toolbar;
GtkEntryCompletion *completion;
TpAccountManager *am;
+ GtkStyleContext *context;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
"add-button", &self->priv->add_button,
"add-contact-entry", &self->priv->add_contact_entry,
"blocked-contacts", &self->priv->blocked_contacts,
+ "blocked-contacts-sw", &blocked_contacts_sw,
"blocked-contacts-view", &blocked_contacts_view,
"remove-button", &self->priv->remove_button,
+ "remove-toolbar", &remove_toolbar,
NULL);
empathy_builder_connect (gui, self,
"remove-button", "clicked", contact_blocking_dialog_remove_contacts,
NULL);
+ /* join the remove toolbar to the treeview */
+ context = gtk_widget_get_style_context (blocked_contacts_sw);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
+ context = gtk_widget_get_style_context (remove_toolbar);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+
/* add the contents to the dialog */
gtk_container_add (
GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))),
G_CALLBACK (contact_blocking_dialog_view_selection_changed), self);
/* build the contact entry */
- self->priv->completion_contacts = gtk_list_store_new (1, G_TYPE_STRING);
+ self->priv->completion_contacts = gtk_list_store_new (N_COMPLETION_COLUMNS,
+ G_TYPE_STRING, /* id */
+ G_TYPE_UINT, /* handle */
+ G_TYPE_STRING); /* text */
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_completion_set_text_column (completion, COL_COMPLETION_TEXT);
+ gtk_entry_completion_set_match_func (completion,
+ contact_selector_dialog_match_func,
+ NULL, NULL);
+ g_signal_connect (completion, "match-selected",
+ G_CALLBACK (contact_selector_dialog_match_selected_cb),
+ self);
gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry),
completion);
g_object_unref (completion);