]> git.0d.be Git - empathy.git/blobdiff - src/empathy-invite-participant-dialog.c
invite-participant-dialog: activate the dialog when the chooser is activated
[empathy.git] / src / empathy-invite-participant-dialog.c
index c40bb945888b1b4316cbeb2cdb82b9de749755c1..7651fad3874e70fb7628c3aca43a516872a835d3 100644 (file)
 
 #include "empathy-invite-participant-dialog.h"
 
+#include <libempathy/empathy-utils.h>
+
+#include <libempathy-gtk/empathy-contact-chooser.h>
 #include <libempathy-gtk/empathy-individual-view.h>
+#include <libempathy-gtk/empathy-ui-utils.h>
 
 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
     empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
@@ -28,9 +32,7 @@ struct _EmpathyInviteParticipantDialogPrivate
 {
   EmpathyTpChat *tp_chat;
 
-  EmpathyIndividualStore *store;
-  EmpathyIndividualView *view;
-
+  GtkWidget *chooser;
   GtkWidget *invite_button;
 };
 
@@ -82,43 +84,24 @@ invite_participant_dialog_dispose (GObject *object)
     object;
 
   tp_clear_object (&self->priv->tp_chat);
-  tp_clear_object (&self->priv->store);
 
   G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
       object);
 }
 
 static void
-empathy_invite_participant_dialog_class_init (
-    EmpathyInviteParticipantDialogClass *klass)
+selection_changed_cb (GtkWidget *treeview,
+    FolksIndividual *selected,
+    EmpathyInviteParticipantDialog *self)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-  object_class->get_property = invite_participant_dialog_get_property;
-  object_class->set_property = invite_participant_dialog_set_property;
-  object_class->dispose = invite_participant_dialog_dispose;
-
-  g_type_class_add_private (object_class,
-      sizeof (EmpathyInviteParticipantDialogPrivate));
-
-  g_object_class_install_property (object_class,
-      PROP_TP_CHAT,
-      g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
-          EMPATHY_TYPE_TP_CHAT,
-          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+  gtk_widget_set_sensitive (self->priv->invite_button, selected != NULL);
 }
 
 static void
-view_selection_changed_cb (GtkWidget *treeview,
+activate_cb (GtkWidget *chooser,
     EmpathyInviteParticipantDialog *self)
 {
-  FolksIndividual *individual;
-
-  individual = empathy_individual_view_dup_selected (self->priv->view);
-
-  gtk_widget_set_sensitive (self->priv->invite_button, individual != NULL);
-
-  g_object_unref (individual);
+  gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
 }
 
 /* Return the TpContact of @individual which is on the same connection as the
@@ -127,69 +110,40 @@ static TpContact *
 get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
     FolksIndividual *individual)
 {
-  GList *personas, *l;
   TpConnection *chat_conn;
 
-  chat_conn = empathy_tp_chat_get_connection (self->priv->tp_chat);
-
-  personas = folks_individual_get_personas (individual);
-
-  for (l = personas; l != NULL; l = g_list_next (l))
-    {
-      TpfPersona *persona = l->data;
-      TpContact *contact;
-      TpConnection *contact_conn;
-
-      if (!TPF_IS_PERSONA (persona))
-        continue;
-
-      contact = tpf_persona_get_contact (persona);
-      if (contact == NULL)
-        continue;
+  chat_conn = tp_channel_borrow_connection (TP_CHANNEL (self->priv->tp_chat));
 
-      contact_conn = tp_contact_get_connection (contact);
-
-      if (!tp_strdiff (tp_proxy_get_object_path (contact_conn),
-            tp_proxy_get_object_path (chat_conn)))
-        return contact;
-    }
-
-  return NULL;
+  return empathy_get_tp_contact_for_individual (individual, chat_conn);
 }
 
 static gboolean
-filter_func (GtkTreeModel *model,
-    GtkTreeIter *iter,
+filter_individual (EmpathyContactChooser *chooser,
+    FolksIndividual *individual,
+    gboolean is_online,
+    gboolean searching,
     gpointer user_data)
 {
   EmpathyInviteParticipantDialog *self = user_data;
-  FolksIndividual *individual;
-  TpContact *contact;
-  gboolean is_online;
   GList *members, *l;
-  gboolean display = FALSE;
-
-  gtk_tree_model_get (model, iter,
-      EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
-      EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &is_online,
-      -1);
+  TpContact *contact;
+  gboolean display = TRUE;
 
-  if (individual == NULL || !is_online)
-    goto out;
+  /* Filter out offline contacts if we are not searching */
+  if (!searching && !is_online)
+    return FALSE;
 
   /* Filter out individuals not having a persona on the same connection as the
    * EmpathyTpChat. */
   contact = get_tp_contact_for_chat (self, individual);
 
   if (contact == NULL)
-    goto out;
+    return FALSE;
 
   /* Filter out contacts which are already in the chat */
   members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (
         self->priv->tp_chat));
 
-  display = TRUE;
-
   for (l = members; l != NULL; l = g_list_next (l))
     {
       EmpathyContact *member = l->data;
@@ -211,25 +165,18 @@ filter_func (GtkTreeModel *model,
 
   g_list_free_full (members, g_object_unref);
 
-out:
-  tp_clear_object (&individual);
   return display;
 }
 
 static void
-empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
+invite_participant_dialog_constructed (GObject *object)
 {
+  EmpathyInviteParticipantDialog *self =
+    (EmpathyInviteParticipantDialog *) object;
   GtkDialog *dialog = GTK_DIALOG (self);
   GtkWidget *label;
   char *str;
   GtkWidget *content;
-  EmpathyIndividualManager *mgr;
-  GtkTreeSelection *selection;
-  GtkWidget *scroll;
-
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
-      self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
-      EmpathyInviteParticipantDialogPrivate);
 
   content = gtk_dialog_get_content_area (dialog);
 
@@ -246,31 +193,19 @@ empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
 
   gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
 
-  /* Add the treeview */
-  mgr = empathy_individual_manager_dup_singleton ();
-  self->priv->store = empathy_individual_store_new (mgr);
-  g_object_unref (mgr);
-
-  empathy_individual_store_set_show_groups (self->priv->store, FALSE);
+  /* contact chooser */
+  self->priv->chooser = empathy_contact_chooser_new ();
 
-  self->priv->view = empathy_individual_view_new (self->priv->store,
-      EMPATHY_INDIVIDUAL_VIEW_FEATURE_NONE, EMPATHY_INDIVIDUAL_FEATURE_NONE);
+  empathy_contact_chooser_set_filter_func (
+      EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
 
-  empathy_individual_view_set_custom_filter (self->priv->view,
-      filter_func, self);
+  gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
+  gtk_widget_show (self->priv->chooser);
 
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->view));
-
-  g_signal_connect (selection, "changed",
-      G_CALLBACK (view_selection_changed_cb), self);
-
-  scroll = gtk_scrolled_window_new (NULL, NULL);
-
-  gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (self->priv->view));
-
-  gtk_box_pack_start (GTK_BOX (content), scroll, TRUE, TRUE, 6);
-  gtk_widget_show (GTK_WIDGET (self->priv->view));
-  gtk_widget_show (scroll);
+  g_signal_connect (self->priv->chooser, "selection-changed",
+      G_CALLBACK (selection_changed_cb), self);
+  g_signal_connect (self->priv->chooser, "activate",
+      G_CALLBACK (activate_cb), self);
 
   self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
       GTK_RESPONSE_ACCEPT);
@@ -283,6 +218,35 @@ empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
   gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
 }
 
+static void
+empathy_invite_participant_dialog_class_init (
+    EmpathyInviteParticipantDialogClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->get_property = invite_participant_dialog_get_property;
+  object_class->set_property = invite_participant_dialog_set_property;
+  object_class->constructed = invite_participant_dialog_constructed;
+  object_class->dispose = invite_participant_dialog_dispose;
+
+  g_type_class_add_private (object_class,
+      sizeof (EmpathyInviteParticipantDialogPrivate));
+
+  g_object_class_install_property (object_class,
+      PROP_TP_CHAT,
+      g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
+          EMPATHY_TYPE_TP_CHAT,
+          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+      self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
+      EmpathyInviteParticipantDialogPrivate);
+}
+
 GtkWidget *
 empathy_invite_participant_dialog_new (GtkWindow *parent,
     EmpathyTpChat *tp_chat)
@@ -306,7 +270,8 @@ empathy_invite_participant_dialog_get_selected (
   FolksIndividual *individual;
   TpContact *contact;
 
-  individual = empathy_individual_view_dup_selected (self->priv->view);
+  individual = empathy_contact_chooser_dup_selected (
+      EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
   if (individual == NULL)
     return NULL;