]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-blocking-dialog.c
Revert "contact-blocking-dialog: use tp-glib high level blocking API"
[empathy.git] / libempathy-gtk / empathy-contact-blocking-dialog.c
index a46820c5d8f1f015d328e8bc0a5da03fb8023d00..b000e24d4aeef6921a80ee92a99a590dc9f64e55 100644 (file)
@@ -21,8 +21,9 @@
  *
  * 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>
 
@@ -65,9 +66,16 @@ struct _EmpathyContactBlockingDialogPrivate
 
 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 *
@@ -169,8 +177,8 @@ contact_blocking_dialog_inspected_handles (TpConnection *conn,
       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);
     }
 }
@@ -234,7 +242,8 @@ contact_blocking_dialog_deny_channel_members_changed (TpChannel *channel,
             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);
@@ -248,7 +257,7 @@ contact_blocking_dialog_deny_channel_members_changed (TpChannel *channel,
       TpHandle handle;
 
       gtk_tree_model_get (model, &iter,
-          COL_HANDLE, &handle,
+          COL_BLOCKED_HANDLE, &handle,
           -1);
 
       if (tp_intset_is_member (removed_set, handle))
@@ -315,7 +324,8 @@ contact_blocking_dialog_connection_prepared (GObject *conn,
 
   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;
     }
@@ -364,7 +374,8 @@ contact_blocking_dialog_got_deny_channel (TpConnection *conn,
 
   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;
     }
 
@@ -372,7 +383,8 @@ contact_blocking_dialog_got_deny_channel (TpConnection *conn,
 
   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;
     }
@@ -392,14 +404,16 @@ contact_blocking_dialog_deny_channel_prepared (GObject *channel,
 
   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);
@@ -449,7 +463,8 @@ contact_blocking_dialog_add_contact (GtkWidget *widget,
   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,
@@ -476,7 +491,8 @@ contact_blocking_dialog_add_contact_got_handle (TpConnection *conn,
 
   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);
@@ -486,8 +502,8 @@ contact_blocking_dialog_add_contact_got_handle (TpConnection *conn,
 
   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, "",
@@ -502,7 +518,8 @@ contact_blocking_dialog_added_contact (TpChannel *channel,
 {
   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);
@@ -510,7 +527,7 @@ contact_blocking_dialog_added_contact (TpChannel *channel,
       return;
     }
 
-  DEBUG ("Contact added");
+  DEBUG ("Contact added to %s", tp_proxy_get_object_path (channel));
 }
 
 static void
@@ -540,7 +557,7 @@ contact_blocking_dialog_remove_contacts (GtkWidget *button,
         continue;
 
       gtk_tree_model_get (model, &iter,
-          COL_HANDLE, &handle,
+          COL_BLOCKED_HANDLE, &handle,
           -1);
 
       g_array_append_val (handles, handle);
@@ -633,12 +650,19 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
   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);
     }
 
@@ -659,6 +683,68 @@ contact_blocking_dialog_view_selection_changed (GtkTreeSelection *selection,
   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)
 {
@@ -687,9 +773,11 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *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,
@@ -711,8 +799,10 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self)
       "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,
@@ -721,6 +811,12 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *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))),
@@ -735,11 +831,20 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *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);